Index: src/game/g_cmds.c =================================================================== --- src/game/g_cmds.c (revision 829) +++ src/game/g_cmds.c (working copy) @@ -2585,7 +2585,163 @@ ent->client->lastPoisonClient = ent;*/ } +/* +================= +Cmd_Share_f +================= +*/ +void Cmd_Share_f( gentity_t *ent ) +{ + int i, clientNum = 0, creds = 0; + int clientNums[ MAX_CLIENTS ] = { -1 }; + char arg1[ MAX_STRING_TOKENS ]; + char arg2[ MAX_STRING_TOKENS ]; + pTeam_t team; + if( !ent || !ent->client || ( ent->client->pers.teamSelection == PTE_NONE ) ) + { + return; + } + + team = ent->client->pers.teamSelection; + trap_Argv( 1, arg1, sizeof( arg1 ) ); + trap_Argv( 2, arg2, sizeof( arg2 ) ); + + if( arg1[0] && !strchr( arg1, ';' ) ) // target player name is in arg1 + { + //check arg1 is a number + for( i = 0; arg1[ i ]; i++ ) + { + if( arg1[ i ] < '0' || arg1[ i ] > '9' ) + { + clientNum = -1; + break; + } + } + + if( clientNum >= 0 ) + { + clientNum = atoi( arg1 ); + } + else if( G_ClientNumbersFromString( arg1, clientNums ) == 1 ) + { + // there was one partial name match name was clientNum + clientNum = clientNums[ 0 ]; + } + else + { + // look for an exact name match before bailing out + clientNum = G_ClientNumberFromString( ent, arg1 ); + if( clientNum == -1 ) + { + trap_SendServerCommand( ent-g_entities, + "print \"share: invalid player\n\"" ); + return; + } + } + } + else // arg1 not set + { + vec3_t forward, end; + trace_t tr; + gentity_t *traceEnt; + + + // trace a teammate + AngleVectors( ent->client->ps.viewangles, forward, NULL, NULL ); + VectorMA( ent->client->ps.origin, 8192 * 16, forward, end ); + + trap_Trace( &tr, ent->client->ps.origin, NULL, NULL, end, ent->s.number, MASK_PLAYERSOLID ); + traceEnt = &g_entities[ tr.entityNum ]; + + if( tr.fraction < 1.0f && traceEnt->client && + ( traceEnt->client->pers.teamSelection == team ) ) + { + clientNum = traceEnt - g_entities; + } + else + { + trap_SendServerCommand( ent-g_entities, + "print \"share: no player to transfer credits to found.\n\"" ); + return; + } + } + + // verify target player team + if( ( clientNum < 0 ) || ( clientNum >= level.maxclients ) || + ( level.clients[ clientNum ].pers.teamSelection != team ) ) + { + trap_SendServerCommand( ent-g_entities, + "print \"share: not a valid player on your team.\n\"" ); + return; + } + + if( !arg1[0] || strchr( arg1, ';' ) || !arg2[0] || strchr( arg2, ';' ) ) + { + // default credit count + if( team == PTE_HUMANS ) + { + creds = FREEKILL_HUMAN; + } + else if( team == PTE_ALIENS ) + { + creds = FREEKILL_ALIEN; + } + } + else + { + //check arg2 is a number + for( i = 0; arg2[ i ]; i++ ) + { + if( arg2[ i ] < '0' || arg2[ i ] > '9' ) + { + trap_SendServerCommand( ent-g_entities, + "print \"Usage: share (name|slot#) (amount)\n\"" ); + break; + } + } + + // credit count from parameter + creds = atoi( arg2 ); + } + + // transfer only credits the player really has + if( creds > ent->client->ps.persistant[ PERS_CREDIT ] ) + { + creds = ent->client->ps.persistant[ PERS_CREDIT ]; + } + + // allow transfers only up to the credit/evo limit + if( ( team == PTE_HUMANS ) && + ( creds > HUMAN_MAX_CREDITS - level.clients[ clientNum ].ps.persistant[ PERS_CREDIT ] ) ) + { + creds = HUMAN_MAX_CREDITS - level.clients[ clientNum ].ps.persistant[ PERS_CREDIT ]; + } + else if( ( team == PTE_ALIENS ) && + ( creds > ALIEN_MAX_KILLS - level.clients[ clientNum ].ps.persistant[ PERS_CREDIT ] ) ) + { + creds = ALIEN_MAX_KILLS - level.clients[ clientNum ].ps.persistant[ PERS_CREDIT ]; + } + + if( creds <= 0 ) + { + trap_SendServerCommand( ent-g_entities, + "print \"share: no credits to transfer.\n\"" ); + return; + } + + // transfer credits + ent->client->ps.persistant[ PERS_CREDIT ] -= creds; + trap_SendServerCommand( ent-g_entities, + va( "print \"share: transfering %d credits to %s.\n\"", creds, + level.clients[ clientNum ].pers.netname ) ); + level.clients[ clientNum ].ps.persistant[ PERS_CREDIT ] += creds; + trap_SendServerCommand( clientNum, + va( "print \"You have received %d credits from %s.\n\"", creds, + ent->client->pers.netname) ); +} + + /* ================= ClientCommand @@ -2693,6 +2849,8 @@ Cmd_PTRCRestore_f( ent ); else if( Q_stricmp( cmd, "test" ) == 0 ) Cmd_Test_f( ent ); + else if( Q_stricmp( cmd, "share" ) == 0 ) + Cmd_Share_f( ent ); else trap_SendServerCommand( clientNum, va( "print \"unknown cmd %s\n\"", cmd ) ); }