Need to start some were in modding right? Why not try the Half-Life modding Kit. This Kit is designed to have all the tools you need to start your own Half-Life mod, simple mods can be made or advance ones like Base Defense with this small set of tools. If you want to start modding Half-Life you should try this.

Post tutorial Report RSS Adding New Impulse "Cheat" Commands

This will cover how to add the basic impulse commands such as spawn monsters, items and weapons

Posted by on - Intermediate Server Side Coding

First most people know what impulse commands are but just in case you don't I will give you a quick run down. Impulse commands are essentially cheat codes most common know is impulse 101 which gives you all the weapons.
So there is 2 requirements for making these cheats, first they must have a unique case value, already used values are 99, 100, 201, 76, 101, 102, 103, 104, 105, 106, 107, 195,196, 197, 199, 202, 203. The second requirement is the value must be a number no letters. We will be doing this whole tutorial in player.cpp server side code.


Lets get started with the weapon/ item spawn first search case 101 and you should see the impulse commands scroll above one of them and add these lines of code.

case 1:
GiveNamedItem( "item_suit" );
GiveNamedItem( "item_battery" );

GiveNamedItem( "item_battery" );

GiveNamedItem( "item_battery" );

GiveNamedItem( "item_battery" );

GiveNamedItem( "item_battery" );
break;

This is very simple, case 1 sates that when the player types impulse 1 into the console it will activate this command. The GiveNamedItem( "item_suit" ); tells it to give player a suit, change item_suit to what ever item you want to spawn or what ever weapon. See how simple that was


Now lets do the harder code, we are going to spawn a monster like impulse 76 were it spawns a human grunt. We are going to spawn a rat to annoy code stealers it will be really easy to do your self if you actually read this. Here is the basic code we need to add in the player.cpp

case 7:
{
if (!giPrecahceRat)
{
giPrecahceRat = 1;
ALERT(at_console, "You must now restart to use Sawn-o-matic.\n");
}
else
{
UTIL_MakeVectors( Vector( 0, pev->v_angle.y, 0 ) );
Create("monster_rat", pev->origin + gpGlobals->v_forward * 128, pev->angles);
}
break;
}


Lets see what we have now. giPrecahceRat is seen 2 times the both have to be the same, this tells the code to set giPrecahceRat to 1 instead of 0 which we will add in a minute. and monster_rat is what it is going to spawn. ALERT(at_console, "You must now restart to use Sawn-o-matic.\n"); is suppose to tell the console to say restart but it does not work. Now search int gmsgShake = 0; and add this right above it

int giPrecahceRat =1;

this is the code I was talking about a minute ago, if this value is 0 then the spawner is off, when you enter the command it will turn on but if you enter it again to spawn the monster it will kick you out of the game because you did not restart. If you set it to 1 like we just did enter the command 1 time will spawn the monster with no restart required. Now go to your client.cpp and scroll down to you see

extern int giPrecacheGrunt;

and above that add

extern int giPrecahceRat;

Now we need to precache it scroll down till you see if if

(giPrecacheGrunt)
UTIL_PrecacheOther("monster_human_grunt");

and under that add


if (giPrecahceRat)
UTIL_PrecacheOther("monster_rat");

Now you are all done have fun with your new cheats

Post comment Comments
D-Wanderer
D-Wanderer - - 136 comments

Really nice!

Reply Good karma Bad karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: