alexx860 Posted February 16, 2006 Share Posted February 16, 2006 Hi! I have a question again : I'm making console commands, in g_cmds.c. I get the client num with the name in the argument with this : G_ClientNumberFromName(name); But if I want to use G_Sound( ent, CHAN_AUTO, G_SoundIndex( va("sound/.../...") ) ); I can't because I need an entity (ent)... So how do I do to have the player entity by his clientnum?? thanks in advance alexx860 Link to comment Share on other sites More sharing options...
ensiform Posted February 16, 2006 Share Posted February 16, 2006 what does your function look like? it should look something like this: void somefunction( gentity_t *ent) { ... your code here } then when u call it in ClientCommand you would do: somefunction(ent); if your trying to get the entity of someone u found its a bit more tricky, i can show u later when i get off of school. Link to comment Share on other sites More sharing options...
alexx860 Posted February 16, 2006 Author Share Posted February 16, 2006 Yes my function looks like this one, and yes I want to get the entity of another player, not the one who typed the command Link to comment Share on other sites More sharing options...
Tinny Posted February 16, 2006 Share Posted February 16, 2006 Gotcha, so the client types in a name and then the name goes into a function, translated to a clientNum to find the entity then the code deals with that entity? It sounds kinda like an admin mod. Link to comment Share on other sites More sharing options...
alexx860 Posted February 16, 2006 Author Share Posted February 16, 2006 clientNum to find the entity I want that, get the entity with the clientNum Link to comment Share on other sites More sharing options...
Vruki Salet Posted February 16, 2006 Share Posted February 16, 2006 gentity_t *entYouWant = &g_entities[G_ClientNumberFromName(name)]; G_Sound(entYouWant, CHAN_AUTO, G_SoundIndex( va("sound/.../...") ) ); Link to comment Share on other sites More sharing options...
alexx860 Posted February 16, 2006 Author Share Posted February 16, 2006 ok thanks Vruki Salet, it works perfectly Link to comment Share on other sites More sharing options...
Vruki Salet Posted February 17, 2006 Share Posted February 17, 2006 You're welcome. Link to comment Share on other sites More sharing options...
razorace Posted February 20, 2006 Share Posted February 20, 2006 Does your G_ClientNumberFromName always return a valid clientNum? If not, you need to have a check before the "gentity_t *entYouWant = &g_entities[G_ClientNumberFromName(name)];" to make sure that the number is valid and abort out if it isn't valid. Link to comment Share on other sites More sharing options...
ensiform Posted February 20, 2006 Share Posted February 20, 2006 i would suggest using ClientNumberFromString its a bit more efficient and the fact that G_ClientNumberFromName is a little bit dirty code. + does it even have color sanatizing? i removed it from my code cause its unused except in 1 place Link to comment Share on other sites More sharing options...
ensiform Posted February 20, 2006 Share Posted February 20, 2006 in fact to give u an example of how i do my commands involving finding slot# or name: int pid; char arg[MAX_TOKEN_CHARS]; gentity_t *player; trap_Argv(1, arg, sizeof(arg)); if(trap_Argc() < 2) { trap_SendServerCommand(ent-g_entities, "Usage: playSound [name|slot#]"); return; } if((pid = ClientNumberFromString(ent, arg)) == -1) return; player = g_entities + pid; if ( level.intermissiontime ) { // just return during intermission return; } if ( player->health <= 0 || player->client->ps.stats[sTAT_HEALTH] <= 0 ) { trap_SendServerCommand(ent-g_entities, "Cannot use 'playSound' on someone who is dead." ); return; } if ( player->client->sess.sessionTeam == TEAM_SPECTATOR ) { trap_SendServerCommand(ent-g_entities, "Cannot use 'playSound' on a spectator." ); return; } G_Sound( player, CHAN_AUTO, G_SoundIndex( va("sound/.../...") ) ); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.