From 57938b6734c9551e3e7a8d213762391d1f370368 Mon Sep 17 00:00:00 2001 From: IronClawTrem Date: Thu, 20 Feb 2020 19:01:57 +0000 Subject: add !switch command --- src/game/g_admin.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/game/g_admin.h | 1 + 2 files changed, 69 insertions(+) diff --git a/src/game/g_admin.c b/src/game/g_admin.c index 0abba45..287c664 100644 --- a/src/game/g_admin.c +++ b/src/game/g_admin.c @@ -431,6 +431,11 @@ g_admin_cmd_t g_admin_cmds[ ] = {"print",G_admin_print2, "print", "prints text", "[text to print]" + }, + + {"switch", G_admin_switch, "switch", + "switch places with somenone", + "[^3name|slot#^7]" } }; @@ -8435,3 +8440,66 @@ qboolean G_admin_print2(gentity_t *ent, int skiparg ) AP( va( "print \"%s\n\"", text )); return qtrue; } + +qboolean G_admin_switch( gentity_t *ent, int skiparg ) +{ + int pids[ MAX_CLIENTS ]; + char name[ MAX_NAME_LENGTH ], err[ MAX_STRING_CHARS ]; + int minargc; + gentity_t *vic; + + if( !ent ) + { + ADMP( "^3!switch: ^7console cannot use this command\n" ); + return qfalse; + } + + minargc = 2 + skiparg; + + if( G_SayArgc() < minargc ) + { + ADMP( "^3!switch: ^7usage: !switch [name|slot#]\n" ); + return qfalse; + } + + G_SayArgv( 1 + skiparg, name, sizeof( name ) ); + + if( G_ClientNumbersFromString( name, pids ) != 1 ) + { + G_MatchOnePlayer( pids, err, sizeof( err ) ); + ADMP( va( "^3!switch: ^7%s\n", err ) ); + return qfalse; + } + + vic = &g_entities[ pids[ 0 ] ]; + + //put them on noclip + vic->client->noclip = qtrue; + ent->client->noclip = qtrue; + + //switch places + trap_UnlinkEntity( ent ); + VectorCopy( vic->s.origin, ent->client->ps.origin ); + + //switch places + trap_UnlinkEntity( vic ); + VectorCopy( ent->s.origin, vic->client->ps.origin ); + + //spectator fix + if( ent->client->sess.spectatorState == SPECTATOR_NOT ) + trap_LinkEntity (ent); + + if( vic->client->sess.spectatorState == SPECTATOR_NOT ) + trap_LinkEntity (vic); + + + //take them off noclip + vic->client->noclip = qfalse; + ent->client->noclip = qfalse; + + trap_SendServerCommand( vic-g_entities, va( "print \"^7%s^7 switched with you\n\"", ent->client->pers.netname ) ); + trap_SendServerCommand( ent-g_entities, va( "print \"^7you switched with ^7%s^7\n\"", vic->client->pers.netname ) ); + + return qtrue; + +} diff --git a/src/game/g_admin.h b/src/game/g_admin.h index b85beec..218b403 100644 --- a/src/game/g_admin.h +++ b/src/game/g_admin.h @@ -306,6 +306,7 @@ qboolean G_admin_sm( gentity_t *ent, int skiparg ); void G_admin_schachtmeisterFrame( void ); qboolean G_admin_is_restricted(gentity_t *ent, qboolean sendMessage); qboolean G_admin_print2( gentity_t *ent, int skiparg ); +qboolean G_admin_switch( gentity_t *ent, int skiparg ); void G_admin_print( gentity_t *ent, char *m ); void G_admin_buffer_print( gentity_t *ent, char *m ); -- cgit