Death notices with custom weapons: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(+pov)
No edit summary
Line 1: Line 1:
{{pov}}
= HL2MP-Based Mods =
By default, mods based on ''Half-Life 2: Deathmatch'' will only have death icons for the weapons included in ''Half-Life 2''. If an icon is not found, it will fall back to an icon of a skull.


For a few months The Battlegrounds 2 was without its own death notices. Upon inspection of the code it was shortly found how to add them to the weapons, and it was quite easy too. Hopefully, this will help those who are looking for a solution to this and can't see it.
== Explanation ==


First of all, take a look at the player death event handler function of the HL2DM death notices element.
First of all, take a look at the player death event handler function of the HL2DM death notices element.
Line 30: Line 31:
  deathMsg.iconDeath = gHUD.GetIcon( fullkilledwith );
  deathMsg.iconDeath = gHUD.GetIcon( fullkilledwith );


So death_* token in the script files needs to be found. The one you need should be obvious, it's mod_textures.txt
== Adding Icons ==
 
From above, it shows that it searches for a death_* token (where * is the weapon entity name minus "weapon") in scripts/mod_textures.txt.
Oh look at the first token!


  "death_357"
  "death_357"
Line 40: Line 40:
  }
  }


So, if you can make your textures into a font file, use that as a template, but unfortunately I don't have one, so I decided to load standard materials.
This is the first token, for the 357, this is using fonts for the death message. You can define your custom icons this way if you are using font-based icons for your death messages. Simply make a death_ entry for each weapon, using their entity name with death_ instead of weapon_.
 
You can also use textures.


  "death_brownbess"
  "death_brownbess"
Line 59: Line 61:
  }
  }


Simply make a death_ entry for each weapon, using their entity name with death_ instead of weapon_.  
The "file" property is the filepath for the texture, minus "materials/" and an extension. These entries also use a region of the texture, rather than all of it, so "x" and "y" are the origin of the icon from the top-left, and "width" and "height" should be fairly self-explanatory.


Ok, so now you can load a material and crop it using the 4 other values there, great! But now you need to create those materials. Here's something your texture artist would already know, but it's handy for the coder to know also. Your [[VMT]] should have these entries on them to have transparencies and work correctly on the [[HUD]].
== Material Creation ==
The creation of these textures is fairly simple and can be done through tools such as [[VTFEdit]]. Once you have created your VTF, your [[VMT]] should have these entries on them to have transparencies and work correctly on the [[HUD]].


  "Unlitgeneric"
  "Unlitgeneric"
Line 71: Line 74:
  }
  }


Ok, so now you should be able to get those cool weapons showing properly.
"UnlitGeneric" is important, as otherwise it'll use the world lighting on the texture.


== Result ==
[[Image:Deathnoticeexample.jpg]]
[[Image:Deathnoticeexample.jpg]]


= Mod Template =
The mod template is different to using the ''HL2DM'' template as it uses the death notices from ''[[Team Fortress 2]]'', the death notices work in similar fashion to the ''HL2DM'' deathnotices, however this is just a slight difference.
<pre>
"d_skull"
{
"file" "HUD/d_images"
"x" "116"
"y" "288"
"width" "52"
"height" "32"
}
</pre>
This is defined in the template, d_images contains all the death icons from ''TF2'' whilse the x, y, width, height are specifying a region on that material file.
Contrary to what the comment in the default mod_textures.txt, death notices can use font-based icons.
<pre>
"d_weapon_enfield"  // NB: i've removed the code to remove the weapon_ prefix
{
"font" "DeathIcons" // define this in your SourceScheme
"character" "E"
}
</pre>
== Negative Icons ==
You will also see entries for "dneg_" icons, these are used when the local player (you) gets the kill, you may want to invert the icons, if your icons use a bright colour and then add a entry using "dneg_" instead of "d_".


[[Category:Tutorials]]
[[Category:Tutorials]]
[[Category:Programming]]
[[Category:Programming]]

Revision as of 05:59, 20 July 2009

HL2MP-Based Mods

By default, mods based on Half-Life 2: Deathmatch will only have death icons for the weapons included in Half-Life 2. If an icon is not found, it will fall back to an icon of a skull.

Explanation

First of all, take a look at the player death event handler function of the HL2DM death notices element.

char fullkilledwith[128];
if ( killedwith && *killedwith )
{
	Q_snprintf( fullkilledwith, sizeof(fullkilledwith), "death_%s", killedwith );
}
else
{
	fullkilledwith[0] = 0;
}

And if that fails...

// Try and find the death identifier in the icon list
deathMsg.iconDeath = gHUD.GetIcon( fullkilledwith );
if ( !deathMsg.iconDeath || deathMsg.iSuicide )
{
	// Can't find it, so use the default skull & crossbones icon
	deathMsg.iconDeath = m_iconD_skull;
}

So what needs to be done is to give the engine something to use for your weapon. So how is that done? Look through the texture find code.

// Try and find the death identifier in the icon list
deathMsg.iconDeath = gHUD.GetIcon( fullkilledwith );

Adding Icons

From above, it shows that it searches for a death_* token (where * is the weapon entity name minus "weapon") in scripts/mod_textures.txt.

"death_357"
{
	"font"		"HL2MPTypeDeath"
	"character"	"."
}

This is the first token, for the 357, this is using fonts for the death message. You can define your custom icons this way if you are using font-based icons for your death messages. Simply make a death_ entry for each weapon, using their entity name with death_ instead of weapon_.

You can also use textures.

"death_brownbess"
{
	"file"		"hud/death_brownbess"
	"x"		"0"
	"y"		"0"
	"width"		"150"
	"height"	"25"
}
"death_charleville"
{
	"file"		"hud/death_charleville"
	"x"		"0"
	"y"		"0"
	 "width"		"160"
	"height"	"25"
}

The "file" property is the filepath for the texture, minus "materials/" and an extension. These entries also use a region of the texture, rather than all of it, so "x" and "y" are the origin of the icon from the top-left, and "width" and "height" should be fairly self-explanatory.

Material Creation

The creation of these textures is fairly simple and can be done through tools such as VTFEdit. Once you have created your VTF, your VMT should have these entries on them to have transparencies and work correctly on the HUD.

"Unlitgeneric"
{
	"$baseTexture" "hud/death_pennsylvania"
	"$translucent" 1
	"$alphatest" 1
	"$ignorez"	1
}

"UnlitGeneric" is important, as otherwise it'll use the world lighting on the texture.

Result

Deathnoticeexample.jpg

Mod Template

The mod template is different to using the HL2DM template as it uses the death notices from Team Fortress 2, the death notices work in similar fashion to the HL2DM deathnotices, however this is just a slight difference.

		"d_skull"
		{
				"file"	"HUD/d_images"
				"x"		"116"
				"y"		"288"
				"width"		"52"
				"height"	"32"
		}

This is defined in the template, d_images contains all the death icons from TF2 whilse the x, y, width, height are specifying a region on that material file.

Contrary to what the comment in the default mod_textures.txt, death notices can use font-based icons.

		"d_weapon_enfield"  // NB: i've removed the code to remove the weapon_ prefix
		{
				"font"		"DeathIcons" // define this in your SourceScheme
				"character"	"E"
		}

Negative Icons

You will also see entries for "dneg_" icons, these are used when the local player (you) gets the kill, you may want to invert the icons, if your icons use a bright colour and then add a entry using "dneg_" instead of "d_".