|
|
 |
06-05-2006, 01:24 PM
|
#1
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
Two questions!
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:
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:
Code:
error C2143: syntax error : missing ')' before 'type'
For this line:
Code:
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?
|
|
you may:
quote & reply,
|
06-05-2006, 03:09 PM
|
#2
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
I have fixed the second problem but the first one still stands. the Saber is taken away but is immediatly gained again. How can I stop this?
Last edited by Dom_152; 06-05-2006 at 04:07 PM.
|
|
you may:
quote & reply,
|
06-05-2006, 03:49 PM
|
#3
|
|
The Stig
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,242
Current Game: Borderlands 2
|
Code:
victimnum = ClientNumberFromString( victim, arg); //Victims Client Number, the name is from the given arguments
|
|
you may:
quote & reply,
|
06-05-2006, 03:58 PM
|
#4
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
Yeah I fixed that problem. But what about the first one?
|
|
you may:
quote & reply,
|
06-05-2006, 05:33 PM
|
#5
|
|
The Stig
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,242
Current Game: Borderlands 2
|
show the whole cmd please would help.
|
|
you may:
quote & reply,
|
06-06-2006, 02:14 AM
|
#6
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
It's probably a bit bloated and some things could be done more effectivly because I'm new to this but here it is.
Code:
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));
}
}
|
|
you may:
quote & reply,
|
06-06-2006, 04:04 PM
|
#7
|
|
The Stig
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,242
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.
Last edited by ensiform; 06-06-2006 at 04:32 PM.
|
|
you may:
quote & reply,
|
06-06-2006, 04:44 PM
|
#8
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
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.
|
|
you may:
quote & reply,
|
06-06-2006, 04:58 PM
|
#9
|
|
The Stig
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,242
Current Game: Borderlands 2
|
uhm so you would like to teleport a player near the other?
do this:
TeleportPlayer( sendingplayer, toplayer->client->ps.origin, not sure what angles you want though... its vec3_t );
|
|
you may:
quote & reply,
|
06-07-2006, 10:34 AM
|
#10
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
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.
|
|
you may:
quote & reply,
|
06-07-2006, 12:17 PM
|
#11
|
|
The Stig
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,242
Current Game: Borderlands 2
|
hmm try this:
Code:
// 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." );
}
}
|
|
you may:
quote & reply,
|
06-08-2006, 01:05 PM
|
#12
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
Thanks. You're very helpful. How long have you been modding?
|
|
you may:
quote & reply,
|
06-09-2006, 02:54 AM
|
#13
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
Don't worry I'm an idiot 
|
|
you may:
quote & reply,
|
06-09-2006, 03:03 AM
|
#14
|
|
The Stig
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,242
Current Game: Borderlands 2
|
quite a while 
|
|
you may:
quote & reply,
|
06-09-2006, 03:04 AM
|
#15
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
OI! =D Yeah well I'm getting better slowly... and don't worry I'll be crediting you in my Mod.
|
|
you may:
quote & reply,
|
06-09-2006, 03:42 PM
|
#16
|
|
Rookie
Join Date: Jan 2006
Location: England
Posts: 150
|
Wow! I'm rather pleased with myself! I managed to create Partial name detection all on my own!  Weee!
BOO OK I didn't... no Matter what name I enter it always kills me :S.
Anyhelp?
Code:
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;
}
Last edited by Dom_152; 06-09-2006 at 04:14 PM.
|
|
you may:
quote & reply,
|
| Thread Tools |
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Forum Jump
|
|
|
|
|
|