Client-Side Sticky Grenades?


(MessiaH) #1

Can anyone help me figure out how to implement a client-side sticky grenade command?
I want it so if a player types /stickygren in console, it toggles between normal grenades and sticky grenades.

Maybe just get me started?

Thanks.


(bacon) #2

Make a new command in g_cmds.c, it should work for clients. Make it so it toggles between 1 and 0 for a cvar.


(MessiaH) #3

Do I copy the same code from g_missile.c for the stickies into the new command in g_cmds?


(Ramoonus) #4

i think its done in the original file
i swear its build in already


(mgt) #5

no, only the main engine commands are built in, like connect/map/etc … game commands arent.

as bacon said, g_cmds.c, at the end of the file in the “command list” … copy&paste a new elseif wherever u want between the other elseif’s and rename it to “stickygren”, then either write the code to be performed directly inside the if bracket or create a new function for it. this code only has to be the thing which switches the weapons.


(MessiaH) #6

is this correct?
what do i do after this:


 } else if (Q_stricmp (cmd, "stickygren") == 0) {
		Cmd_SetSticky( ent );

(jamez) #7

i have no idea about the sticky grenade code but, u might want a boolean that has wether the nade is sticky or not then u could just do

} else if (Q_stricmp (cmd, “stickygren”) == 0) {
sticky=!sticky;

and while we are on the subject this is not actually client side either


(MessiaH) #8

It is client-side because the client calls the command and it sends to the server asking if sticky grenades are enabled, and then enables them to the client that sent the command.

I have the server-side code for it, but I’m not sure where to add it/modify it to make it answer the client’s command request.

See what I’m saying?


(jamez) #9

it really depends what u mean by client side, if ur talking about in the client game dll then you are wrong because the command gets added in the server game dll i think ( ClientCommand( int clientNum ) in g_cmds.c )

but if u mean the client does it then yes u are right

what you could do is declare the gren_sticky boolean in the g_weapon.c code i think it was and make the grenade type depend on that
then declare this in g_cmds.c


extern bool gren_sticky;

and have


} else if (Q_stricmp (cmd, "stickygren") == 0) { 
sticky=!sticky; 

this does sound like a good addition, good luck with it


(bacon) #10

All you have to do is make a new flag then check if the client is using that flag, if it is do the sticky grenade code.
Then you have the command in g_cmds.c toggle this flag on and off.

It can all be done server-side.