Thread: Two questions!
View Single Post
Old 06-06-2006, 05:04 PM   #7
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
to make it less bloated and work a little bit better:

Code:
#define AP(x) trap_SendServerCommand(-1, x)					// Print to all
#define CP(x) trap_SendServerCommand(ent-g_entities, x)		// Print to an ent
#define CPx(x, y) trap_SendServerCommand(x, y)				// Print to id = x

void Cmd_XtraModTakeSaber_f(gentity_t *taker)
{
	char arg[1024];
	int pid;
	gentity_t *victim;

	// Find the player to take saber from.
	trap_Argv(1, arg, sizeof(arg));
	
	if(trap_Argc() < 2) {
		CPx(taker-g_entities,va("print \"takeSaber [name|slot#]\n\""));
		return;
	}
	
	if((pid = ClientNumberFromString(ent, arg)) == -1) return;
	
	victim = g_entities + pid;
	
	if( level.intermissiontime ) return; // dont take during intermission
	
	if ( victim->health <= 0 || victim->client->ps.stats[STAT_HEALTH] <= 0 ) {
		CPx(taker-g_entities,va("print \"Cannot take away a dead person's saber.\n\""));
		return;
	}

	if ( victim->client->sess.sessionTeam == TEAM_SPECTATOR ) {
		CPx(taker-g_entities,va("print \"Cannot take away a spectator's saber.\n\""));
		return;
	}

	if ( victim->client->tempSpectate >= level.time ) {
		CPx(taker-g_entities,va("print \"Cannot take away a spectator's saber.\n\""));
		return;
	}

	if(victim->client->ps.weapon == WP_SABER) victim->client->ps.weapon = WP_NONE;
	
	CPx(victim-g_entities,va("cp \"%s^7 has taken your Lightsaber!\"", taker->client->pers.netname));
	
	AP(va("print \"%s^7 has had their Lightsaber taken away by %s^7\n\"", victim->client->pers.netname, taker->client->pers.netname));
}
hint: put the defines that are up top in g_local.h somewhere so you can use them again for other places in the server. btw, using ps.clientNum on the server-side is almost always bad because then it would be sending to someone followin that client only or to both i guess. it just makes more sense to do it by getting the real ent number. and btw, rcon status and serverstatus almost always show incorrect client numbers.


iojamp project lead / coder

Last edited by ensiform; 06-06-2006 at 05:32 PM.
ensiform is offline   you may: quote & reply,