introduction to half life 2 modding ● seminar eight – the story so far: ● creating a mod via...

7
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

Upload: nickolas-anderson

Post on 30-Jan-2016

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Half Life 2 Modding ● Seminar Eight – The story so far: ● Creating a mod via Source SDK ● Introduction to Hammer ● Hammer techniques ●

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

Page 2: Introduction to Half Life 2 Modding ● Seminar Eight – The story so far: ● Creating a mod via Source SDK ● Introduction to Hammer ● Hammer techniques ●

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

Page 3: Introduction to Half Life 2 Modding ● Seminar Eight – The story so far: ● Creating a mod via Source SDK ● Introduction to Hammer ● Hammer techniques ●

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

Page 4: Introduction to Half Life 2 Modding ● Seminar Eight – The story so far: ● Creating a mod via Source SDK ● Introduction to Hammer ● Hammer techniques ●

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; }

Page 5: Introduction to Half Life 2 Modding ● Seminar Eight – The story so far: ● Creating a mod via Source SDK ● Introduction to Hammer ● Hammer techniques ●

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 );

}

Page 6: Introduction to Half Life 2 Modding ● Seminar Eight – The story so far: ● Creating a mod via Source SDK ● Introduction to Hammer ● Hammer techniques ●

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” function

before 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!

Page 7: Introduction to Half Life 2 Modding ● Seminar Eight – The story so far: ● Creating a mod via Source SDK ● Introduction to Hammer ● Hammer techniques ●

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!