70 likes | 184 Views
Introduction to Half Life 2 Modding. Seminar Eight The story so far: Creating a mod via Source SDK Introduction to Hammer Hammer techniques Importing custom art content Starting with code manipulation This week: Adding an item via code. Starting point.
E N D
Introduction to Half Life 2 Modding • Seminar Eight • The story so far: • Creating a mod via Source SDK • Introduction to Hammer • Hammer techniques • Importing custom art content • Starting with code manipulation • This week: • Adding an item via code
Starting point • Files available from http://www.hidden-source.com/downloads/itemcode.zip • Includes example code for adding an item • Create a new folder in the 'dlls' folder of the source directory – place the cpp file there. • Add the file to the server project • Also includes models, materials and an FGD • What else could this code be used for? • 'Relic' style pickups? • QuadDamage? • We'll look at making a QuadDamage pickup
Making a QuadDamage pickup • The theory: • Once the player touches our pickup we want to set a flag so that any further damage done by that player is multiplied • We need a way of setting a flag • We need a way of checking for the flag when damage is caused • If the flag is set, we need to multiply the damage done
Making a QuadDamage pickup • The practice • Adding a flag to the player • Open hl2mp_player.h and put the following below the line that reads “DECLARE_DATADESC” // private class members cannot be accessed from outside the class private:// bool variables are either true or false (boolean values)bool m_bQuad; // public class members can be accessed from anywhere (inside or out of the class) public:// IsQuadded returns a boolean valuebool IsQuadded() { return m_bQuad; }// SetQuad takes a boolean but doesn't return anything at allvoid SetQuad(bool value) { m_bQuad = value; }
Making a QuadDamage pickup • Multiplying the damage • In hl2mp_player.cpp find OnTakeDamage • Insert the following before the return statement: // cast from CBaseEntity to CHL2MP_PlayerCHL2MP_Player *pAttacker = dynamic_cast<CHL2MP_Player*>(inputInfo.GetAttacker()); // check pointer validityif ( pAttacker ){// copy inputInfoCTakeDamageInfo newInfo = inputInfo; // multiply the damage value by 4.newInfo.SetDamage(newInfo.GetDamage() * 4.0f);// replace the standard return with our new multipled damage versionreturn BaseClass::OnTakeDamage( newInfo );}
Making a QuadDamage pickup • Final touches • Ensure the player can't spawn with the quad damage effect • In CHL2MP_Player::Spawn • Set m_bQuad to false ( SetQuad(false) ) • Activate the effect when we pickup the quad damage item • Put the following code into our items “MyTouch” functionbefore the return call • // set the players quad flag to true.pHL2Player->SetQuad(true); • Create a suitable entry in the FGD file (use the flag example as a basis) remember to add the FGD when you open hammer!
Expanding on the pickup • How you could expand this system: • Setup a timer (look at CHL2MP_Player::PostThink) to control the duration of the quad effect • gpGlobals->curtime will give you the current time • You could store a time value when the quad is collected (current time + duration) and compare that against the current time in PostThink • Make more pickup items that have different effects • Increase health, boost speed, reduce damage (this ones easy!) • Create custom art content for each pickup you make!