I'm coding a weapon selecting command that works like this: /BIND 1 "weapselect [weapon type] [(optional) weapon type]". The mod has various classes of guns. So, some acceptable values for "weapon type" are grenade, sidearm, primary. The command also allows you to switch back and forth between the two weapon types you entered each time you press the bind.
There are several sidearms, several pistols, and several grenades, but you can only have one of each at a time (which is why this weapon selector makes sense instead of using weapon 11, weapon 6, etc
I'm following bits and peices from this tut: http://www.quake3hut.co.uk/q3coding/mor ... %20Mod.htm
There under Adding A New Command they add a command to g_cmds.c Since it's on the game it has no access to the client, and their command needs to get access to iCurrentWeapon, so they added iCurrentWeapon to the Client Struct in g_local.h
Now I'm making my function in g_cmds.c and now I need to be able to check *what guns the player has* and *what gun the player is currently using* to do what I need the function to do. So is it sensible that I would add those things to the Client Struct too???
It just made me pause because I'm thinking, this is really only a client side action (isn't it?) so why should I be making the command on the server (g_cmds.c) [keeping in mind I'm somewhat of a noob about q3 mod coding]
So am I going in the right direction?? I can keep coding but it's not really going to tell me if I'm doing this improperly.
is g_cmds.c the right place for a weapon selecter command?
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: is g_cmds.c the right place for a weapon selecter command?
Check out CG_Weapon_f() in cgame/cg_weapons.c. The key is cg.snap->ps.stats[STAT_WEAPONS]. You can add your own fields to the stats array (there is place for 16 STAT_* things but only seven or eight are used, see bg_public.h for details) and the server will automagically send them to the client whenever they are updated.
EDIT: I realize this might not be easily comprehensible, especially with the magic of the playerState_t struct involved. If you need more pointers, don't hesitate to ask.
EDIT: I realize this might not be easily comprehensible, especially with the magic of the playerState_t struct involved. If you need more pointers, don't hesitate to ask.
Re: is g_cmds.c the right place for a weapon selecter command?
Before I proceed though, I need to know if I'm doing the right thing in putting my function Cmd_WeapToggle_f( gentity_t *ent ) in g_cmds.c
I've added it near the bottom of g_cmds.c like this:
else if (Q_stricmp (cmd, "weaptoggle") == 0)
Cmd_WeapToggle_f( ent );
I've added it near the bottom of g_cmds.c like this:
else if (Q_stricmp (cmd, "weaptoggle") == 0)
Cmd_WeapToggle_f( ent );
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: is g_cmds.c the right place for a weapon selecter command?
Well, it's a possible solution. But as you already figured out, selecting a weapon is a client-side thing. There are better solutions, like the one I pointed out.
Re: is g_cmds.c the right place for a weapon selecter command?
Sorry, I thought you meant check out this code in CG_Weapon_f() because I might want to do something like that with [STATS] in my function in g_cmds.c, ie: I'm not proficient enough to have realized that you were posting a solution 
But I get it now

But I get it now

Re: is g_cmds.c the right place for a weapon selecter command?
I have finished this function now (although it could use some tidying up and maybe consolidate some parts into another function to reduce duplication of code).
(My initial problem was just knowing where to put the command, that it should in fact be client side and not server side)
Anyhow, I used cent->currentState.weapon to tell what weapon the user is currently holding.
(I see now that) STATS_ is key, and luckily another coder on the project had already coded qboolean BG_HasWeapon( int weapon, int stats[ ] ) (or borrowed it from some other open source, I don't know). So that made my job easier
(My initial problem was just knowing where to put the command, that it should in fact be client side and not server side)
Anyhow, I used cent->currentState.weapon to tell what weapon the user is currently holding.
(I see now that) STATS_ is key, and luckily another coder on the project had already coded qboolean BG_HasWeapon( int weapon, int stats[ ] ) (or borrowed it from some other open source, I don't know). So that made my job easier
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: is g_cmds.c the right place for a weapon selecter command?
Post your code if you want to. If there is room for improvement, I could perhaps give you a few pointers.
Re: is g_cmds.c the right place for a weapon selecter command?
Well, it's working, so I better save asking for help for the next thing I get stuck on 
