Hey, I'm now trying to add the !allowoverride and !denyoverride command to a QVM.. And so far it's working properly. Though I'd like to make it so that you can't nadespam, or buy grenades at all for that matter, with !allowoverride. So what I'm trying to do is have !allowoverride also !denyweapon grenade the victim from using nades, as well as allow overriding them. The same goes for !denyoverride, I'd like that to also !allowweapon grenade the victim.
The two ideas I have on doing this so far are:
1.) Figuring out the trap_sendServerCommand() function to !denyweapon grenade the victim... But I don't understand how this function works, as all the other examples I can find throughout the QVM involve using !cp or !print, which just print strings to the screen.
2.) Duplicating the !denyweapon code and altering it to work with !allowoverride and only work for !denyweapon'ing grenades... The only thing about that is the code is messy and I can't even understand what it does, or how it does it.
Here's the code for !denyweapon:
qboolean G_admin_denyweapon( gentity_t *ent, int skiparg )
{
int pids[ MAX_CLIENTS ];
char name[ MAX_NAME_LENGTH ], err[ MAX_STRING_CHARS ];
char command[ MAX_ADMIN_CMD_LEN ], *cmd;
char buffer[ 32 ];
int weapon = WP_NONE;
int class = PCL_NONE;
char *realname;
gentity_t *vic;
int flag;
qboolean all = qfalse;
G_SayArgv( skiparg, command, sizeof( command ) );
cmd = command;
if( cmd && *cmd == '!' )
cmd++;
if( G_SayArgc() < 3 + skiparg )
{
ADMP( va( "^3!%s: ^7usage: !%s [name|slot#] [class|weapon]\n", cmd, cmd ) );
return qfalse;
}
G_SayArgv( 1 + skiparg, name, sizeof( name ) );
if( G_ClientNumbersFromString( name, pids ) != 1 )
{
G_MatchOnePlayer( pids, err, sizeof( err ) );
ADMP( va( "^3!%s: ^7%s\n", cmd, err ) );
return qfalse;
}
if( !admin_higher( ent, &g_entities[ pids[ 0 ] ] ) )
{
ADMP( va( "^3!%s: ^7sorry, but your intended victim has a higher admin"
" level than you\n", cmd ) );
return qfalse;
}
vic = &g_entities[ pids[ 0 ] ];
if( vic == ent &&
!Q_stricmp( cmd, "denyweapon" ) )
{
ADMP( va( "^3!%s: ^7sorry, you cannot %s yourself\n", cmd, cmd ) );
return qfalse;
}
G_SayArgv( 2 + skiparg, buffer, sizeof( buffer ) );
if( !Q_stricmp( buffer, "all" ) &&
!Q_stricmp( cmd, "allowweapon" ) )
{
if( vic->client->pers.denyHumanWeapons ||
vic->client->pers.denyAlienClasses )
{
vic->client->pers.denyHumanWeapons = 0;
vic->client->pers.denyAlienClasses = 0;
CPx( pids[ 0 ], "cp \"^1You've regained all weapon and class rights\"" );
AP( va( "print \"^3!%s: ^7all weapon and class rights for ^7%s^7 restored by %s\n\"",
cmd,
vic->client->pers.netname,
( ent ) ? ent->client->pers.netname : "console" ) );
}
else
{
ADMP( va( "^3!%s: ^7player already has all rights\n", cmd ) );
}
return qtrue;
}
if( !Q_stricmp( buffer, "all" ) &&
!Q_stricmp( cmd, "denyweapon" ) )
{
all = qtrue;
weapon = WP_NONE;
class = PCL_NONE;
if( vic->client->pers.denyHumanWeapons == 0xFFFFFF &&
vic->client->pers.denyAlienClasses == 0xFFFFFF )
{
ADMP( va( "^3!%s: ^7player already has no weapon or class rights\n", cmd ) );
return qtrue;
}
if( vic->client->pers.teamSelection == PTE_HUMANS )
{
weapon = vic->client->ps.weapon;
if( weapon < WP_PAIN_SAW || weapon > WP_GRENADE )
weapon = WP_NONE;
}
if( vic->client->pers.teamSelection == PTE_ALIENS )
{
class = vic->client->pers.classSelection;
if( class < PCL_ALIEN_LEVEL1 || class > PCL_ALIEN_LEVEL4 )
class = PCL_NONE;
}
vic->client->pers.denyHumanWeapons = 0xFFFFFF;
vic->client->pers.denyAlienClasses = 0xFFFFFF;
}
else
{
weapon = BG_FindWeaponNumForName( buffer );
if( weapon < WP_PAIN_SAW || weapon > WP_GRENADE )
class = BG_FindClassNumForName( buffer );
if( ( weapon < WP_PAIN_SAW || weapon > WP_GRENADE ) &&
( class < PCL_ALIEN_LEVEL1 || class > PCL_ALIEN_LEVEL4 ) )
{
{
ADMP( va( "^3!%s: ^7unknown weapon or class\n", cmd ) );
return qfalse;
}
}
}
if( class == PCL_NONE )
{
realname = BG_FindHumanNameForWeapon( weapon );
flag = 1 << (weapon - WP_BLASTER);
if( !Q_stricmp( cmd, "denyweapon" ) )
{
if( ( vic->client->pers.denyHumanWeapons & flag ) && !all )
{
ADMP( va( "^3!%s: ^7player already has no %s rights\n", cmd, realname ) );
return qtrue;
}
vic->client->pers.denyHumanWeapons |= flag;
if( vic->client->pers.teamSelection == PTE_HUMANS )
{
if( ( weapon == WP_GRENADE || all ) &&
BG_InventoryContainsUpgrade( UP_GRENADE, vic->client->ps.stats ) )
{
BG_RemoveUpgradeFromInventory( UP_GRENADE, vic->client->ps.stats );
G_AddCreditToClient( vic->client, (short)BG_FindPriceForUpgrade( UP_GRENADE ), qfalse );
}
if( BG_InventoryContainsWeapon( weapon, vic->client->ps.stats ) )
{
int maxAmmo, maxClips;
BG_RemoveWeaponFromInventory( weapon, vic->client->ps.stats );
G_AddCreditToClient( vic->client, (short)BG_FindPriceForWeapon( weapon ), qfalse );
BG_AddWeaponToInventory( WP_MACHINEGUN, vic->client->ps.stats );
BG_FindAmmoForWeapon( WP_MACHINEGUN, &maxAmmo, &maxClips );
BG_PackAmmoArray( WP_MACHINEGUN, vic->client->ps.ammo, vic->client->ps.powerups,
maxAmmo, maxClips );
G_ForceWeaponChange( vic, WP_MACHINEGUN );
vic->client->ps.stats[ STAT_MISC ] = 0;
ClientUserinfoChanged( pids[ 0 ], qtrue );
}
}
}
else
{
if( !( vic->client->pers.denyHumanWeapons & flag ) )
{
ADMP( va( "^3!%s: ^7player already has %s rights\n", cmd, realname ) );
return qtrue;
}
vic->client->pers.denyHumanWeapons &= ~flag;
}
}
else
{
realname = BG_FindHumanNameForClassNum( class );
flag = 1 << class;
if( !Q_stricmp( cmd, "denyweapon" ) )
{
if( ( vic->client->pers.denyAlienClasses & flag ) && !all )
{
ADMP( va( "^3!%s: ^7player already has no %s rights\n", cmd, realname ) );
return qtrue;
}
vic->client->pers.denyAlienClasses |= flag;
if( vic->client->pers.teamSelection == PTE_ALIENS &&
vic->client->pers.classSelection == class )
{
vec3_t infestOrigin;
short cost;
G_RoomForClassChange( vic, PCL_ALIEN_LEVEL0, infestOrigin );
vic->client->pers.evolveHealthFraction = (float)vic->client->ps.stats[ STAT_HEALTH ] /
(float)BG_FindHealthForClass( class );
if( vic->client->pers.evolveHealthFraction < 0.0f )
vic->client->pers.evolveHealthFraction = 0.0f;
else if( vic->client->pers.evolveHealthFraction > 1.0f )
vic->client->pers.evolveHealthFraction = 1.0f;
vic->client->pers.classSelection = PCL_ALIEN_LEVEL0;
cost = BG_ClassCanEvolveFromTo( PCL_ALIEN_LEVEL0, class, 9, 0 );
if( cost < 0 ) cost = 0;
G_AddCreditToClient( vic->client, cost, qfalse );
ClientUserinfoChanged( pids[ 0 ], qtrue );
VectorCopy( infestOrigin, vic->s.pos.trBase );
ClientSpawn( vic, vic, vic->s.pos.trBase, vic->s.apos.trBase );
}
}
else
{
if( !( vic->client->pers.denyAlienClasses & flag ) )
{
ADMP( va( "^3!%s: ^7player already has %s rights\n", cmd, realname ) );
return qtrue;
}
vic->client->pers.denyAlienClasses &= ~flag;
}
}
if( all )
realname = "weapon and class";
CPx( pids[ 0 ], va( "cp \"^1You've %s your %s rights\"",
( !Q_stricmp( cmd, "denyweapon" ) ) ? "lost" : "regained",
realname ) );
AP( va(
"print \"^3!%s: ^7%s rights for ^7%s^7 %s by %s\n\"",
cmd, realname,
vic->client->pers.netname,
( !Q_stricmp( cmd, "denyweapon" ) ) ? "revoked" : "restored",
( ent ) ? ent->client->pers.netname : "console" ) );
return qtrue;
}
And here's the code for !allowoverride:
qboolean G_admin_override( gentity_t *ent, int skiparg )
{ //this is all very similar to denybuild,
//it performs an essentially identical function
int i, j = 0, pids[ MAX_CLIENTS + 1 ];
char name[ MAX_NAME_LENGTH ], err[ MAX_STRING_CHARS ];
char command[ MAX_ADMIN_CMD_LEN ], *cmd;
qboolean targeted = qfalse;
//targeted is set to ensure we don't get spam when pausing everybody
gentity_t *vic;
G_SayArgv( skiparg, command, sizeof( command ) );
cmd = command;
if( cmd && *cmd == '!' )
cmd++;
if( G_SayArgc() == 1 + skiparg )
{
for( i = 0; i < MAX_CLIENTS; i++ )
{
vic = &g_entities[ i ];
if( vic && vic->client &&
vic->client->pers.connected == CON_CONNECTED )
{
pids[ j ] = i;
j++;
}
}
pids[ j ] = -1;
}
else if( G_SayArgc() == 2 + skiparg )
{
G_SayArgv( 1 + skiparg, name, sizeof( name ) );
if( G_ClientNumbersFromString( name, pids ) != 1 )
{
G_MatchOnePlayer( pids, err, sizeof( err ) );
ADMP( va( "^3!%s: ^7%s\n", cmd, err ) );
return qfalse;
}
targeted = qtrue;
}
else if( G_SayArgc() > 2 + skiparg )
{
ADMP( va( "^3!%s: ^7usage: ^3!%s ^7(^5name|slot^7)\n", cmd, cmd ) );
return qfalse;
}
for( i = 0; pids[ i ] >= 0; i++ )
{
vic = &g_entities[ pids[ i ] ];
if ( !vic || !vic->client ) continue;
if( !admin_higher( ent, vic ) )
{
if( targeted )
ADMP( va( "^3!%s: ^7sorry, but your intended victim has a higher admin"
" level than you\n", cmd ) );
continue;
}
if( vic->client->pers.override )
{
if( !Q_stricmp( cmd, "allowoverride" ) )
{
if( targeted )
ADMP( "^3!allowoverride: ^7player already allowed to override\n" );
continue;
}
vic->client->pers.override = qfalse;
CPx( pids[ i ], "cp \"^2You've been denied override\"" );
if( targeted )
AP( va( "print \"^3!denyoverride: ^7%s^7 override denied by %s\n\"",
vic->client->pers.netname,
( ent ) ? ent->client->pers.netname : "console" ) );
}
else
{
if( !Q_stricmp( cmd, "denyoverride" ) )
{
if( targeted )
ADMP( "^3!denyoverride: ^7player is already denied overide\n" );
continue;
}
vic->client->pers.override = qtrue;
CPx( pids[ i ], va( "cp \"^1You've been allowed to override by ^7%s\"",
( ent ) ? ent->client->pers.netname : "console" ) );
if( targeted )
AP( va( "print \"^3!allowoverride: ^7%s^7 allowed to override by %s\n\"",
vic->client->pers.netname,
( ent ) ? ent->client->pers.netname : "console" ) );
}
ClientUserinfoChanged( pids[ i ], qtrue );
}
G_admin_denyweapon( gentity_t *ent, int skiparg )
return qtrue;
}
Can anyone help? Thanks in advance :p.