Jump to content

Home

Two questions!


Dom_152

Recommended Posts

HELP!

 

I'm trying to add a command which removes the victims lightsaber. My first question is how can I make it so that once the command has been called that player cannot use their Saber at all afterwards until it's been reversed. My current code:

 

if(victim->client->ps.weapon == WP_SABER)
{
	victim->client->ps.weapon = WP_NONE;		
}

 

This *SHOULD* set their weapon to NONE if they currently have their saber out. Great. But now they can easily switch back to their Saber again. Is there any way of removing it completely from the player "inventory"?

 

Lastly when compiling I get this error:

 

 error C2143: syntax error : missing ')' before 'type'

 

For this line:

 

victimnum  = ClientNumberFromString( gentity_t *victim, arg); //Victims Client Number, the name is from the given arguments

 

All it does is get the client number from the name provided as the command argument. But it gives me that error... I'm nto sure why. Any help?

Link to comment
Share on other sites

It's probably a bit bloated and some things could be done more effectivly because I'm new to this but here it is.

 

void Cmd_XtraModTakeSaber_f(gentity_t *taker)
{
gentity_t *victim;
gentity_t *others;
char arg[1024]; //Command arguments
char *msg = " has taken your Lightsaber\n"; //Message to display to the victim
char *bmsg1 = "Player "; //Message to display if command bad
char *bmsg2 = " does not exist\n"; //Second messgage to display if command bad
char *bmsg3 = "You must provide the name of the player of whom you wish to take the Lightsaber from.\ne.g. /takeSaber XharocK";
char *msg2 = " has had their Lightsaber taken away by ";
char *takername = taker->client->pers.netname;
int victimnum = 0;
int i = 0;

trap_Argv(1, arg, 1024); //get the commands arguments

if(arg == NULL)
{
	trap_SendServerCommand(taker->client->ps.clientNum, va("print \"%s\"", bmsg3));

	return;
}


victimnum  = G_ClientNumFromNetname(arg); //Victims Client Number, the name is from the given arguments

victim = &g_entities[victimnum];

if(!victim->client) //Check if the client does not exist
{
	trap_SendServerCommand(taker->client->ps.clientNum, va("print \"%s%s%s\"", bmsg1, arg, bmsg2));

	return;
}

if(victim->client->ps.weapon == WP_SABER)
{
	victim->client->ps.weapon = WP_NONE;
	//victim->client->NoSaber == qtrue;
}

trap_SendServerCommand(victimnum,  va("print \"%s%s\"", takername, msg));

for(i = 0; i < MAX_CLIENTS; i++)
{
	if(i == victimnum)
	{
		break; //Don't send this message to the victim
	}

	others = &g_entities[i];

	if(!others->client)
	{
		break; //If the client doesn't exist don't send the message
	}

	trap_SendServerCommand(i,  va("print \"%s%s%s\n\"", victim->client->pers.netname, msg2, takername));
}

}

Link to comment
Share on other sites

to make it less bloated and work a little bit better:

 

#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.

Link to comment
Share on other sites

Thank you very much. I'm nowe trying to do teleportation. I'm basically making the players origin the same as (Slightly Offsetted) the target players. Is this the right way of doing it? Because it won't let me assign my modifed vector to ent->client->ps.origin.

Link to comment
Share on other sites

Yes thanks. It works nicely. Now yet another query :-D I have a kick function that works OK but it's messy. It uses trap_DropClient() which gives a nasty looking dialog box when it's called saying Server Disconnected -9999. Which isn't that useful to the user. I couldn't find in the SDK the code for the normal kick function. I want to know how to display my own personalised message in that dialog that appears.

Link to comment
Share on other sites

hmm try this:

 

// Kicks a player
void Cmd_XtraModKick_f(gentity_t *ent)
{
int pid;
char arg[MAX_TOKEN_CHARS];
char reason[MAX_TOKEN_CHARS];
gentity_t *victim;

// Find the player to kick.
trap_Argv(1, arg, sizeof(arg));
if(trap_Argc() < 2) {
	CP(va("print \"Usage: xkick [name|slot#|allbots|all] [reason]\n\""));
	return;
}

if ( !Q_stricmp( arg, "all" ) ) {
	gentity_t	*cl_ent;
	int i,idnum;

	for ( i=0 ; i< g_maxclients.integer ; i++ )
	{
		idnum = level.sortedClients[i];
		cl_ent = g_entities + idnum;
		if ( cl_ent->client->pers.connected != CON_CONNECTED )
			continue;
		//if ( cl_ent->client->sess.isAdmin ) // uncomment this section if you have an admin variable.
		//	continue;
		if ( cl_ent->client->pers.localClient )
			continue;
		trap_SendConsoleCommand( EXEC_INSERT, va2("clientkick \"%d\"\n", idnum));
	}
	return;
} else if ( !Q_stricmp( arg, "allbots" ) ) {
	gentity_t	*cl_ent;
	int i,idnum;

	for ( i=0 ; i< g_maxclients.integer ; i++ )
	{
		idnum = level.sortedClients[i];
		cl_ent = g_entities + idnum;
		if ( cl_ent->client->pers.connected != CON_CONNECTED )
			continue;
		if ( !(cl_ent->r.svFlags & SVF_BOT ) )
			continue;
		trap_SendConsoleCommand( EXEC_INSERT, va2("clientkick \"%d\"\n", idnum));
	}
	return;
} else {
	// continue
}

if((pid = ClientNumberFromString(ent, arg)) == -1) return;

victim = g_entities + pid;

/*if( victim->client->sess.isAdmin == qtrue ) {	// uncomment this section if you have an admin variable.
	CP(va("print \"Cannot kick an admin.\n\""));
	return;
}*/

if ( victim->client->pers.localClient ) {
	CP(va("print \"Cannot kick host player.\n\""));
	return;
}

if ( victim->r.svFlags & SVF_BOT ) {
	trap_DropClient( pid, "was kicked." );
	return;
}

if(trap_Argc() < 3) {
	CP(va("print \"Usage: xkick [name|slot#|allbots|all] [reason]\n\""));
	return;
}

trap_Argv(2, reason, sizeof(reason));

if(Q_stricmp(reason, "none") || reason[0]) {
	trap_DropClient( pid, va("%s",reason") );
} else {
	trap_DropClient( pid, "was kicked." );
}
}

Link to comment
Share on other sites

Wow! I'm rather pleased with myself! I managed to create Partial name detection all on my own! :D Weee!

 

BOO OK I didn't... no Matter what name I enter it always kills me :S.

Anyhelp?

 

int G_ClientNumberFromPartialName(char *partial)
{
int clientnumber = 0;
gentity_t *tent;
gentity_t *final;
char *tempname = "";
char *partialname = "";	
char *name;
int i;
int y = 0;
int x;	
int matches[MAX_CLIENTS];	
int finalmatch = 0;
//char finalname[1024];
int max_value = 0;
int max_index = -1;

//SanitizeString2(partial, partialname);
partialname = partial;

//First client pass
for(i = 0; i < MAX_CLIENTS; i++)
{
	tent = &g_entities[i];
	name = tent->client->pers.netname; 
	tempname = name;
	//SanitizeString2(name, tempname);

	if(!tent->client)
	{
		break; //if the client doesn't exist move on to the next one.
	}
	//Second Name pass
	//We compare each letter in the partial name ot the name of the client we are checking
	//And note down any matches
	for(x = 0; x < sizeof(tempname); x++)
	{
		if(partialname[y] == tempname[x])
		{
			matches[i]++; //Increase the number of matches for this client
			y++; //Move on to the next letter in the partial name
		}
		else
		{
			 continue; //If they don't match just try the next letter
		}
	}
}

//Check which client has the most amount of matches
for(x = 0 ; x < MAX_CLIENTS ; x++)
{
	if(matches[x] > max_value)
	{		
		max_value = matches[x];
		finalmatch = x;
	}

	//If there is more than one final match just quit the function
	if(matches[x] == max_value)
	{
		return -1; //The calling function will knwo this means More than one match
	}
}	

final = &g_entities[finalmatch];	
clientnumber = G_ClientNumberFromStrippedName(final->client->pers.netname);

return clientnumber;

}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...