//Func: Player:GetDuelingPartner() //Retn: nil if Player is not dueling, or Player:GetID() != self:GetID() due to lack of reliable information // Player object of the client Player is dueling static int JPLua_Player_GetDuelingPartner( lua_State *L ) { jplua_player_t *player = JPLua_CheckPlayer( L, 1 ); if ( !cg_entities[player->clientNum].currentState.bolt1 || player->clientNum != cg.clientNum ) lua_pushnil( L ); else JPLua_Player_CreateRef( L, cg.predictedPlayerState.duelIndex ); return 1; }
void JPLua_Event_SaberTouch( int victim, int attacker ) { #ifdef JPLUA for ( JPLua.currentPlugin = JPLua.plugins; JPLua.currentPlugin; JPLua.currentPlugin = JPLua.currentPlugin->next ) { if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_SABERTOUCH] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_SABERTOUCH] ); JPLua_Player_CreateRef( JPLua.state, victim ); JPLua_Player_CreateRef( JPLua.state, attacker ); JPLUACALL( JPLua.state, 2, 0 ); } } #endif // JPLUA }
void JPLua_Event_Pain( int target, int inflictor, int attacker, int health, int armor, uint32_t dflags, int mod ) { #ifdef JPLUA jplua_plugin_t *plugin = NULL; while ( JPLua_IteratePlugins( &plugin ) ) { if ( plugin->eventListeners[JPLUA_EVENT_PAIN] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, plugin->eventListeners[JPLUA_EVENT_PAIN] ); JPLua_Player_CreateRef( JPLua.state, target ); JPLua_Player_CreateRef( JPLua.state, inflictor ); JPLua_Player_CreateRef( JPLua.state, attacker ); lua_pushinteger( JPLua.state, health ); lua_pushinteger( JPLua.state, armor ); lua_pushinteger( JPLua.state, dflags ); lua_pushinteger( JPLua.state, mod ); JPLua_Call( JPLua.state, 7, 0 ); } } #endif // JPLUA }
void JPLua_Event_PlayerDeath( int clientNum, int mod, int inflictor ) { #ifdef JPLUA jplua_plugin_t *plugin = NULL; while ( JPLua_IteratePlugins( &plugin ) ) { if ( plugin->eventListeners[JPLUA_EVENT_PLAYERDEATH] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, plugin->eventListeners[JPLUA_EVENT_PLAYERDEATH] ); JPLua_Player_CreateRef( JPLua.state, clientNum ); // victim lua_pushinteger( JPLua.state, mod ); // method of death if ( inflictor >= MAX_CLIENTS || inflictor < 0 ) // -1 means inflictor is not a player lua_pushnil( JPLua.state ); // nil because not player else JPLua_Player_CreateRef( JPLua.state, inflictor ); JPLua_Call( JPLua.state, 3, 0 ); } } #endif // JPLUA }
void JPLua_Event_ClientSpawn( int clientNum, qboolean firstSpawn ) { #ifdef JPLUA jplua_plugin_t *plugin = NULL; while ( JPLua_IteratePlugins( &plugin ) ) { if ( plugin->eventListeners[JPLUA_EVENT_CLIENTSPAWN] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, plugin->eventListeners[JPLUA_EVENT_CLIENTSPAWN] ); JPLua_Player_CreateRef( JPLua.state, clientNum ); lua_pushboolean( JPLua.state, firstSpawn ); JPLua_Call( JPLua.state, 2, 0 ); } } #endif }
void JPLua_Event_ClientDisconnect( int clientNum ) { #ifdef JPLUA jplua_plugin_t *plugin = NULL; while ( JPLua_IteratePlugins( &plugin ) ) { if ( plugin->eventListeners[JPLUA_EVENT_CLIENTDISCONNECT] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, plugin->eventListeners[JPLUA_EVENT_CLIENTDISCONNECT] ); JPLua_Player_CreateRef( JPLua.state, clientNum ); JPLua_Call( JPLua.state, 1, 0 ); } } #endif }
void JPLua_Event_Pain( int clientNum, int health ) { #ifdef JPLUA jplua_plugin_t *plugin = NULL; while ( JPLua_IteratePlugins( &plugin ) ) { if ( plugin->eventListeners[JPLUA_EVENT_PAIN] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, plugin->eventListeners[JPLUA_EVENT_PAIN] ); JPLua_Player_CreateRef( JPLua.state, clientNum ); lua_pushinteger( JPLua.state, health ); JPLua_Call( JPLua.state, 2, 0 ); } } #endif // JPLUA }
//Func: Server:GetPlayers() //Retn: Indexed table of Player objects ordered by clientNum static int JPLua_Server_GetPlayers( lua_State *L ) { int top, i = 1, clientNum; lua_newtable( L ); top = lua_gettop( L ); for ( clientNum = 0; clientNum < MAX_CLIENTS; clientNum++ ) { if ( cgs.clientinfo[clientNum].infoValid ) { lua_pushnumber( L, i++ ); JPLua_Player_CreateRef( L, clientNum ); lua_settable( L, top ); } } return 1; }
//TODO: client-side version of this static int JPLua_Export_GetPlayers( lua_State *L ) { int top, i = 1, clNum; gentity_t *ent; lua_newtable( L ); top = lua_gettop( L ); for ( ent = g_entities, clNum = 0; clNum < level.maxclients; ent++, clNum++ ) { if ( !ent->inuse || ent->client->pers.connected == CON_DISCONNECTED ) continue; lua_pushnumber( L, i++ ); JPLua_Player_CreateRef( L, clNum ); lua_settable( L, top ); } return 1; }
void JPLua_Event_ClientConnect( int clientNum ) { #ifdef JPLUA for ( JPLua.currentPlugin = JPLua.plugins; JPLua.currentPlugin; JPLua.currentPlugin = JPLua.currentPlugin->next ) { if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_CLIENTCONNECT] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_CLIENTCONNECT] ); // Create a player instance for this client number and push on stack JPLua_Player_CreateRef( JPLua.state, clientNum ); JPLUACALL( JPLua.state, 1, 0 ); } } #endif // JPLUA }
void JPLua_Event_Pain( int clientNum, int damage ) { #ifdef JPLUA for ( JPLua.currentPlugin = JPLua.plugins; JPLua.currentPlugin; JPLua.currentPlugin = JPLua.currentPlugin->next ) { if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_PAIN] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_PAIN] ); // Create a player instance for this client number and push on stack JPLua_Player_CreateRef( JPLua.state, clientNum ); lua_pushinteger( JPLua.state, damage ); JPLUACALL( JPLua.state, 2, 0 ); } } #endif // JPLUA }
//Func: GetPlayer(clientNum) //Retn: Player object if their clientinfo is valid, and clientNum is between [0, MAX_CLIENTS-1] int JPLua_GetPlayer( lua_State *L ) { int num = -1; unsigned int clientsFound = 0; if ( lua_type( L, 1 ) == LUA_TNIL ) num = cg.clientNum; else if ( lua_type( L, 1 ) == LUA_TNUMBER ) num = lua_tointeger( L, 1 ); if ( lua_type( L, 1 ) == LUA_TSTRING ) { const char *name = lua_tostring( L, 1 ); int numFound = 0; int i=0; for ( i=0; i<cgs.maxclients; i++ ) { char nameClean[36] = {0}; char nameClean2[36] = {0}; if ( !cgs.clientinfo[i].infoValid ) continue; Q_strncpyz( nameClean, cgs.clientinfo[i].name, sizeof( nameClean ) ); Q_strncpyz( nameClean2, name, sizeof( nameClean2 ) ); Q_StripColor( nameClean ); Q_StripColor( nameClean2 ); if ( !Q_stricmp( nameClean, nameClean2 ) ) { num = i; clientsFound |= (1<<i); numFound++; } } if ( numFound > 1 ) { int top=0; lua_pushnil( L ); lua_pushstring( L, "Multiple matches" ); lua_newtable( L ); top = lua_gettop( L ); for ( i=0; i<cgs.maxclients; i++ ) { if ( clientsFound & (1<<i) ) { lua_pushnumber( L, i ); JPLua_Player_CreateRef( L, i ); lua_settable( L, top ); } } return 3; } else if ( !numFound ) { lua_pushnil( L ); return 1; } } JPLua_Player_CreateRef( L, num ); return 1; }
void JPLua_Event_ClientInfoUpdate( int clientNum, clientInfo_t *oldInfo, clientInfo_t *newInfo ) { #ifdef JPLUA jplua_plugin_t *plugin = NULL; while ( JPLua_IteratePlugins( &plugin ) ) { if ( plugin->eventListeners[JPLUA_EVENT_CLIENTINFO] ) { int top1, top2, i; lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, plugin->eventListeners[JPLUA_EVENT_CLIENTINFO] ); // Create a player instance for this client number and push on stack JPLua_Player_CreateRef( JPLua.state, clientNum ); for ( i = 0; i < 2; i++ ) { clientInfo_t *ci = i ? newInfo : oldInfo; lua_newtable( JPLua.state ); top1 = lua_gettop( JPLua.state ); lua_pushstring( JPLua.state, "colorOverride" ); lua_newtable( JPLua.state ); top2 = lua_gettop( JPLua.state ); lua_pushstring( JPLua.state, "r" ); lua_pushnumber( JPLua.state, ci->colorOverride.r ); lua_settable( JPLua.state, top2 ); lua_pushstring( JPLua.state, "g" ); lua_pushnumber( JPLua.state, ci->colorOverride.g ); lua_settable( JPLua.state, top2 ); lua_pushstring( JPLua.state, "b" ); lua_pushnumber( JPLua.state, ci->colorOverride.b ); lua_settable( JPLua.state, top2 ); lua_pushstring( JPLua.state, "a" ); lua_pushnumber( JPLua.state, ci->colorOverride.a ); lua_settable( JPLua.state, top2 ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "saberName" ); lua_pushstring( JPLua.state, ci->saberName ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "saber2Name" ); lua_pushstring( JPLua.state, ci->saber2Name ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "name" ); lua_pushstring( JPLua.state, ci->name ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "team" ); lua_pushnumber( JPLua.state, ci->team ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "duelTeam" ); lua_pushnumber( JPLua.state, ci->duelTeam ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "botSkill" ); lua_pushnumber( JPLua.state, ci->botSkill ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "color1" ); JPLua_Vector_CreateRef( JPLua.state, ci->color1.r, ci->color1.g, ci->color1.b ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "color2" ); JPLua_Vector_CreateRef( JPLua.state, ci->color2.r, ci->color2.g, ci->color2.b ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "rgb1" ); JPLua_Vector_CreateRef( JPLua.state, ci->rgb1.r, ci->rgb1.g, ci->rgb1.b ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "rgb2" ); JPLua_Vector_CreateRef( JPLua.state, ci->rgb2.r, ci->rgb2.g, ci->rgb2.b ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "icolor1" ); lua_pushnumber( JPLua.state, ci->icolor1 ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "icolor2" ); lua_pushnumber( JPLua.state, ci->icolor2 ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "score" ); lua_pushnumber( JPLua.state, ci->score ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "location" ); lua_pushnumber( JPLua.state, ci->location ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "health" ); lua_pushnumber( JPLua.state, ci->health ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "armor" ); lua_pushnumber( JPLua.state, ci->armor ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "curWeapon" ); lua_pushnumber( JPLua.state, ci->curWeapon ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "handicap" ); lua_pushnumber( JPLua.state, ci->handicap ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "wins" ); lua_pushnumber( JPLua.state, ci->wins ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "losses" ); lua_pushnumber( JPLua.state, ci->losses ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "teamTask" ); lua_pushnumber( JPLua.state, ci->teamTask ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "powerups" ); lua_pushnumber( JPLua.state, ci->powerups ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "modelName" ); lua_pushstring( JPLua.state, ci->saberName ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "skinName" ); lua_pushstring( JPLua.state, ci->saberName ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "forcePowers" ); lua_pushstring( JPLua.state, ci->forcePowers ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "teamName" ); lua_pushstring( JPLua.state, ci->teamName ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "deferred" ); lua_pushboolean( JPLua.state, ci->deferred ); lua_settable( JPLua.state, top1 ); lua_pushstring( JPLua.state, "gender" ); lua_pushnumber( JPLua.state, ci->gender ); lua_settable( JPLua.state, top1 ); } JPLua_Call( JPLua.state, 3, 0 ); } } #endif }
qboolean JPLua_Event_ClientCommand( int clientNum ) { qboolean ret = qfalse; #ifdef JPLUA jplua_plugin_t *plugin = NULL; while ( JPLua_IteratePlugins( &plugin ) ) { int top, i, numArgs = trap->Argc(); jplua_plugin_command_t *cmd; cmd = JPLua.currentPlugin->clientCmds; if ( plugin->eventListeners[JPLUA_EVENT_CLIENTCOMMAND] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, plugin->eventListeners[JPLUA_EVENT_CLIENTCOMMAND] ); JPLua_Player_CreateRef( JPLua.state, clientNum ); //Push table of arguments lua_newtable( JPLua.state ); top = lua_gettop( JPLua.state ); for ( i = 0; i < numArgs; i++ ) { char argN[MAX_TOKEN_CHARS]; trap->Argv( i, argN, sizeof(argN) ); lua_pushnumber( JPLua.state, i + 1 ); lua_pushstring( JPLua.state, argN ); lua_settable( JPLua.state, top ); } JPLua_Call( JPLua.state, 2, 0 ); } while ( cmd ) { char arg1[MAX_TOKEN_CHARS]; trap->Argv( 0, arg1, sizeof(arg1) ); if ( !Q_stricmp( arg1, cmd->command ) ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, cmd->handle ); JPLua_Player_CreateRef( JPLua.state, clientNum ); //Push table of arguments lua_newtable( JPLua.state ); top = lua_gettop( JPLua.state ); for ( i = 1; i < numArgs; i++ ) { char argN[MAX_TOKEN_CHARS]; trap->Argv( i, argN, sizeof(argN) ); lua_pushnumber( JPLua.state, i ); lua_pushstring( JPLua.state, argN ); lua_settable( JPLua.state, top ); } JPLua_Call( JPLua.state, 2, 0 ); if ( !ret ) ret = qtrue; } cmd = cmd->next; } } #endif // JPLUA return ret; }