Jump to content

Home

client to entity


alexx860

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...