Jump to content
The Dark Mod Forums

Custom items


VanishedOne

Recommended Posts

A thread for custom items which are not necessarily mines.

To get the ball rolling, here are a speed potion and slow-fall potion, approximating the T2 behaviour. Update: to get the latest version of the script component check the beta testing thread.

Default numbers aren't necessarily final, and of course, if you encounter any glitches please let me know. Defs go in /def/whatever.def, scripts go in /script/tdm_custom_scripts.script (or better still #include them). Also, if anyone's able and willing to create the missing art assets that would be great. :smile:

Speed potion. (Lacks an inventory icon.)

 

entityDef atdm:playertools_speed_potion {
	"inherit"						"atdm:playertool_stackable"
	"editor_usage"					"Speed potion: temporarily boosts walking/running speed and jump distance."
	"model"							"models/darkmod/player_equipment/speed_potion.lwo"
	"inv_icon"						"guis/assets/hud/inventory_icons/holywater_icon" // TEMP
	"inv_name"						"Speed Potion" // NOT MULTILANGUAGE
	"inv_category"					"#str_02393"
	"snd_swallow"					"potion_drink"
	"scriptobject"					"playertools_speedpotion"
	"duration"						"9"
	"editor_float duration"			"Time in seconds the speed potion is active."
	"speed_mod"						"9"
	"liquid_penalty"				"0.5"
	"editor_float speed_mod"		"The higher the number, the faster you walk/run. High speed leads to collision damage."
	"editor_float liquid_penalty"	"Multiplier between 0 and 1 for liquid drag, to prevent leaping out of water like a dolphin."
}

entityDef ShopItem_playertools_speed_potion {
	"inherit"			"atdm:shopitem_base"
	"editor_usage"		"Speed Potion"
	"displayName"		"Speed Potion"	// NOT MULTILANGUAGE
	"displayDesc"		"These usually enter the black market from military sources, but thieves use them to jump between rooftops or to make a swift escape."	// NOT MULTILANGUAGE
	"itemClassname"		"atdm:playertools_speed_potion"
	"image"				"guis/assets/purchase_menu/potion_speed"
	"price"				"30"
	"stackable"			"1"
}
/*
/*
* SPEED POTION scriptobject
*/
object playertools_speedpotion : player_tools {
	/**
	* [ Comment copied from health potion script object: ]
	* greebo: This is the method that gets called from within the SDK
	*		  when the player "uses" this tool as inventory item.
	*
	* @userEntity: the entity that is using this item, usually $player1
	* @frobbedEntity: the entity the player is currently frobbing, may be $null_entity
	* @buttonState: a float telling about the current button state (pressed, released)
	*/
	void inventoryUse(player userEntity, entity frobbedEntity, float buttonState);
	void update(player userEntity);
	
	float duration;
	float speed_mod;
	float liquid_penalty;
	float endTime;
};

/**
* =============== SPEED POTION ======================================
*/
void playertools_speedpotion::inventoryUse(player userEntity, entity frobbedEntity, float buttonState)
{
	// Callback to decrease the inventory stack count
	userEntity.changeInvItemCount(getKey("inv_name"), getKey("inv_category"), -1);

	// Play the activate sound
	userEntity.startSoundShader(getKey("snd_swallow"), SND_CHANNEL_VOICE);
	
	duration = getFloatKey("duration");
	speed_mod = getFloatKey("speed_mod");
	liquid_penalty = getFloatKey("liquid_penalty");
	
	endTime = (sys.getTime() + duration);
	
	update(userEntity);
}

void playertools_speedpotion::update(player userEntity) {
	sys.killthread("speed_potion");
	sys.threadname("speed_potion");
	
	while (sys.getTime() < endTime) {sys.wait(0.01);
		vector player_direction = userEntity.getViewAngles();
		float player_angle_h = player_direction_y;
		float player_angle_v = 0 - player_direction_x;
		vector player_movement = userEntity.getMove();
		vector player_movement_world = player_movement;
		vector boost_movement = '0 0 0';
		
		if ( userEntity.getImmobilization( "MantleMove" ) != 0 ) continue;
		
		if (userEntity.AI_ONGROUND) {
			player_movement_world_x = 
				(player_movement_x * sys.cos(player_angle_h)) 
				+ (player_movement_y * sys.cos(player_angle_h-90));
			player_movement_world_y = 
				(player_movement_x * sys.sin(player_angle_h)) 
				+ (player_movement_y * sys.sin(player_angle_h-90));
			
			boost_movement_x = player_movement_world_x * speed_mod;
			boost_movement_y = player_movement_world_y * speed_mod;
		}
		else if (userEntity.isInLiquid()) {
			player_movement_world_x = 
				(player_movement_x * sys.cos(player_angle_v) * sys.cos(player_angle_h)) 
				+ (player_movement_y * sys.cos(player_angle_v) * sys.cos(player_angle_h-90));
			player_movement_world_y = 
				(player_movement_x * sys.cos(player_angle_v) * sys.sin(player_angle_h)) 
				+ (player_movement_y * sys.cos(player_angle_v) * sys.sin(player_angle_h-90));
			player_movement_world_z = 
			(player_movement_x * sys.sin(player_angle_v)) + (player_movement_y * sys.sin(player_angle_v));
			
			// jump button
			if (player_movement_world_z < player_movement_z) player_movement_world_z = player_movement_z;
			
			boost_movement_x = player_movement_world_x * speed_mod * liquid_penalty;
			boost_movement_y = player_movement_world_y * speed_mod * liquid_penalty;
			boost_movement_z = player_movement_world_z * speed_mod * liquid_penalty;
		};
		
		userEntity.applyImpulse(userEntity,0,userEntity.getOrigin(),boost_movement);
	};
}

 



Slow-fall potion. (Lacks a model - or failing that a skin for an existing model - an inventory icon and shop art.)

 

entityDef atdm:playertools_slow_fall_potion {
	"inherit"					"atdm:playertool_stackable"
	"editor_usage"				"Slow-fall potion. Reduces falling damage but slows movement."
	"model"						"models/darkmod/player_equipment/speed_potion.lwo" // TEMP
	"inv_icon"					"guis/assets/hud/inventory_icons/breathpotion_icon" // TEMP
	"inv_name"					"Slow-fall Potion" // NOT MULTILANGUAGE
	"inv_category"				"#str_02393"
	"snd_swallow"				"potion_drink"
	"scriptobject"				"playertools_slowfallpotion"
	"duration"					"9"
	"editor_float duration"		"Time in seconds the slow-fall potion is active."
	"lift_force"				"900"
	"editor_float lift_force"	"The higher the number, the more lift you get while falling or underwater."
}

entityDef ShopItem_playertools_slow_fall_potion {
	"inherit"			"atdm:shopitem_base"
	"editor_usage"		"Slow-fall Potion"
	"displayName"		"Slow-fall Potion"	// NOT MULTILANGUAGE
	"displayDesc"		"Less tightly restricted than Potions of Levitation, their weakened cousin is sold by mages to roofers and mountaineers."	// NOT MULTILANGUAGE
	"itemClassname"		"atdm:playertools_slow_fall_potion"
	"image"				"" // MISSING
	"price"				"15"
	"stackable"			"1"
}
/*
* SLOW-FALL POTION scriptobject
*/
object playertools_slowfallpotion : player_tools {
	/**
	* [ Comment copied from health potion script object: ]
	* greebo: This is the method that gets called from within the SDK
	*		  when the player "uses" this tool as inventory item.
	*
	* @userEntity: the entity that is using this item, usually $player1
	* @frobbedEntity: the entity the player is currently frobbing, may be $null_entity
	* @buttonState: a float telling about the current button state (pressed, released)
	*/
	void inventoryUse(player userEntity, entity frobbedEntity, float buttonState);
	void update(player userEntity);
	
	float  duration;
	float  lift_force;
	vector lastPos;
	float  endTime;
};

/**
* =============== SLOW-FALL POTION ==================================
*/
void playertools_slowfallpotion::inventoryUse(player userEntity, entity frobbedEntity, float buttonState)
{
	// Callback to decrease the inventory stack count
	userEntity.changeInvItemCount(getKey("inv_name"), getKey("inv_category"), -1);

	// Play the activate sound
	userEntity.startSoundShader(getKey("snd_swallow"), SND_CHANNEL_VOICE);
	
	duration = getFloatKey("duration");
	lift_force = getFloatKey("lift_force");
	
	lastPos = userEntity.getOrigin();
	endTime = (sys.getTime() + duration);
	
	thread update(userEntity);
}

void playertools_slowfallpotion::update(player userEntity) {
	sys.killthread("slowfall_potion");
	sys.threadname("slowfall_potion");
	
	while (sys.getTime() < endTime) {sys.wait(0.01);
		vector newPos = userEntity.getOrigin();
		float  player_movement = newPos_z - lastPos_z;
		vector boost_movement = '0 0 0';
		
		if ( userEntity.getImmobilization( "MantleMove" ) != 0 ) {
			lastPos = newPos;
			continue;
		};
		
		if ( ( (player_movement < 0) && !userEntity.AI_ONGROUND && !userEntity.AI_ONLADDER ) || userEntity.isInLiquid() && !userEntity.AI_ONLADDER ) boost_movement_z = lift_force;
		userEntity.applyImpulse(userEntity,0,userEntity.getOrigin(),boost_movement);
		lastPos = newPos;
	};
}

 

 

Edited by VanishedOne
  • Like 3

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

Cool. How does the speed potion affect things like head-bob and footsteps?

Link to comment
Share on other sites

Head-bob might feel a bit more noticeable because the scenery goes by faster.

 

Footsteps don't seem to be affected, which is a shame. I ran into a problem when I tried to modify the walkspeed directly, so instead the potion gets your current movement and gives you a push in the same direction. Judging by this bit of my Darkmod.cfg footstep sounds are also controlled by persistent cvars, so the same problem arises:

seta pm_min_stepsound_interval "200"
seta pm_stepvol_crouch_creep "-7"
seta pm_stepvol_crouch_run "4"
seta pm_stepvol_crouch_walk "-2"
seta pm_stepvol_creep "-5"
seta pm_stepvol_run "8"
seta pm_stepvol_walk "0"

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

It looks as though the threading code I added to the slow-fall potion today has diminished its potency somehow. :blink: It still works but the default "lift_force" spawnarg is now badly calibrated; something 900-ish looks about right.

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

One question to the slow-fall potion: Does it invfluence jumping behaviour, when you apply the lift_force? I would assume, that you might increase jumping height as well as reducing fall speed.

The lift isn't applied while you're jumping. (c0mputer-fr0d told me he might make a jump potion, though.)

 

@VanishedOne, can you organise a beta test please? As I would like to recomends these be added to the core mod.

Yes, after I try to work out why the last code change I made seems to have altered performance. I'm wondering whether the call to waitFrame() could make the boost vary with framerate - something it would definitely be good to check across different maps and machines - but if the framerate in my test map were that variable I'd expect to have noticed before.

 

If anyone would like to offer to beta-test, though, feel free to post to this thread now rather than wait. :smile:

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

Well, I still don't know why the code change had that effect, but I've altered the slow-fall potion's default "lift_force" and replaced sys.waitFrame with sys.wait to be on the safe side. Now the question is how it works in other people's machines. I'll open another thread to request beta testers.

 

Edit: and here it is: http://forums.thedarkmod.com/topic/17370-beta-testers-sought-speed-potion-slow-fall-potion/

Edited by VanishedOne

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

Hey, this is really cool, let me see if I can help you with those model and graphics. ;)

 

EDIT: Oh, Biker is on it.

Well, optimally we also need a shop image for the slow-fall potion. (One already exists for the speed potion.) So you're welcome to volunteer for that... :smile:

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

Excellent!

 

By the way, the current status of the beta test is that there's a nasty bug in both potions that can't really be fixed while scripts have no way to know when the player's mantling (which would need a code change).

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

By the way, the current status of the beta test is that there's a nasty bug in both potions that can't really be fixed while scripts have no way to know when the player's mantling (which would need a code change).

 

Hmm mantling sets an immobilization on the player to prevent the player changing weapon or attacking while mantling. That might be a way for scripts to pick it up. if ( $player1.getImmobilization( "MantleMove" ) != 0 )

 

The script reference for getImmobilization says "new feature, use at your own risk!" or words to that effect, but that note was added 10 years ago and I guess we can consider it a stable part of TDM by now :)

  • Like 1
Link to comment
Share on other sites

 

Hmm mantling sets an immobilization on the player to prevent the player changing weapon or attacking while mantling. That might be a way for scripts to pick it up. if ( $player1.getImmobilization( "MantleMove" ) != 0 )

 

The script reference for getImmobilization says "new feature, use at your own risk!" or words to that effect, but that note was added 10 years ago and I guess we can consider it a stable part of TDM by now :)

Thanks for this! In a quick test the mantling problems seemed to have gone. I'll post the updated script to the beta test thread.

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 2 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
    • The Black Arrow

      I wanna play Doom 3, but fhDoom has much better features than dhewm3, yet fhDoom is old, outdated and probably not supported. Damn!
      Makes me think that TDM engine for Doom 3 itself would actually be perfect.
      · 6 replies
    • Petike the Taffer

      Maybe a bit of advice ? In the FM series I'm preparing, the two main characters have the given names Toby and Agnes (it's the protagonist and deuteragonist, respectively), I've been toying with the idea of giving them family names as well, since many of the FM series have named protagonists who have surnames. Toby's from a family who were usually farriers, though he eventually wound up working as a cobbler (this serves as a daylight "front" for his night time thieving). Would it make sense if the man's popularly accepted family name was Farrier ? It's an existing, though less common English surname, and it directly refers to the profession practiced by his relatives. Your suggestions ?
      · 9 replies
×
×
  • Create New...