mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
TeamSwitch hook for Lua
This commit is contained in:
parent
b496cc0d62
commit
be5fd1a0db
4 changed files with 67 additions and 1 deletions
|
@ -2734,6 +2734,12 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum)
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
// Don't switch team, just go away, please, go awaayyyy, aaauuauugghhhghgh
|
||||
if (!LUAh_TeamSwitch(&players[playernum], NetPacket.packet.newteam, players[playernum].spectator, NetPacket.packet.autobalance, NetPacket.packet.scrambled))
|
||||
return;
|
||||
#endif
|
||||
|
||||
//no status changes after hidetime
|
||||
if ((gametyperules & GTR_HIDEFROZEN) && (leveltime >= (hidetime * TICRATE)))
|
||||
error = true;
|
||||
|
|
|
@ -51,6 +51,7 @@ enum hook {
|
|||
hook_PlayerCanDamage,
|
||||
hook_PlayerQuit,
|
||||
hook_IntermissionThinker,
|
||||
hook_TeamSwitch,
|
||||
hook_ViewpointSwitch,
|
||||
|
||||
hook_MAX // last hook
|
||||
|
@ -94,6 +95,7 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj); // Hook for P_PlayerAft
|
|||
UINT8 LUAh_PlayerCanDamage(player_t *player, mobj_t *mobj); // Hook for P_PlayerCanDamage
|
||||
void LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting
|
||||
void LUAh_IntermissionThinker(void); // Hook for Y_Ticker
|
||||
boolean LUAh_TeamSwitch(player_t *player, int newteam, boolean fromspectators, boolean autobalance, boolean scrambled); // Hook for team switching in... uh....
|
||||
UINT8 LUAh_ViewpointSwitch(player_t *player, player_t *newdisplayplayer); // Hook for spy mode in G_Responder
|
||||
|
||||
#endif
|
||||
|
|
|
@ -62,6 +62,7 @@ const char *const hookNames[hook_MAX+1] = {
|
|||
"PlayerCanDamage",
|
||||
"PlayerQuit",
|
||||
"IntermissionThinker",
|
||||
"TeamSwitch",
|
||||
"ViewpointSwitch",
|
||||
NULL
|
||||
};
|
||||
|
@ -204,6 +205,7 @@ static int lib_addHook(lua_State *L)
|
|||
case hook_PlayerSpawn:
|
||||
case hook_FollowMobj:
|
||||
case hook_PlayerCanDamage:
|
||||
case hook_TeamSwitch:
|
||||
case hook_ViewpointSwitch:
|
||||
case hook_ShieldSpawn:
|
||||
case hook_ShieldSpecial:
|
||||
|
@ -1348,6 +1350,53 @@ void LUAh_IntermissionThinker(void)
|
|||
}
|
||||
}
|
||||
|
||||
// Hook for team switching
|
||||
// It's just an edit of LUAh_ViewpointSwitch.
|
||||
boolean LUAh_TeamSwitch(player_t *player, int newteam, boolean fromspectators, boolean autobalance, boolean scrambled)
|
||||
{
|
||||
hook_p hookp;
|
||||
boolean canSwitchTeam = true;
|
||||
if (!gL || !(hooksAvailable[hook_TeamSwitch/8] & (1<<(hook_TeamSwitch%8))))
|
||||
return 0;
|
||||
|
||||
lua_settop(gL, 0);
|
||||
|
||||
for (hookp = playerhooks; hookp; hookp = hookp->next)
|
||||
{
|
||||
if (hookp->type != hook_TeamSwitch)
|
||||
continue;
|
||||
|
||||
if (lua_gettop(gL) == 0)
|
||||
{
|
||||
LUA_PushUserdata(gL, player, META_PLAYER);
|
||||
lua_pushinteger(gL, newteam);
|
||||
lua_pushboolean(gL, fromspectators);
|
||||
lua_pushboolean(gL, autobalance);
|
||||
lua_pushboolean(gL, scrambled);
|
||||
}
|
||||
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||
lua_pushvalue(gL, -6);
|
||||
lua_pushvalue(gL, -6);
|
||||
lua_pushvalue(gL, -6);
|
||||
lua_pushvalue(gL, -6);
|
||||
lua_pushvalue(gL, -6);
|
||||
if (lua_pcall(gL, 5, 1, 0)) {
|
||||
if (!hookp->error || cv_debug & DBG_LUA)
|
||||
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
||||
lua_pop(gL, 1);
|
||||
hookp->error = true;
|
||||
continue;
|
||||
}
|
||||
if (!lua_isnil(gL, -1) && !lua_toboolean(gL, -1))
|
||||
canSwitchTeam = false; // Can't switch team
|
||||
lua_pop(gL, 1);
|
||||
}
|
||||
|
||||
lua_settop(gL, 0);
|
||||
return canSwitchTeam;
|
||||
}
|
||||
|
||||
// Hook for spy mode in G_Responder
|
||||
UINT8 LUAh_ViewpointSwitch(player_t *player, player_t *newdisplayplayer)
|
||||
{
|
||||
|
|
11
src/p_user.c
11
src/p_user.c
|
@ -10364,6 +10364,11 @@ boolean P_SpectatorJoinGame(player_t *player)
|
|||
else
|
||||
changeto = (P_RandomFixed() & 1) + 1;
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
if (!LUAh_TeamSwitch(player, changeto, true, false, false))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if (player->mo)
|
||||
{
|
||||
P_RemoveMobj(player->mo);
|
||||
|
@ -10389,8 +10394,12 @@ boolean P_SpectatorJoinGame(player_t *player)
|
|||
{
|
||||
// Exception for hide and seek. Don't join a game when you simply
|
||||
// respawn in place and sit there for the rest of the round.
|
||||
if (!(gametype == GT_HIDEANDSEEK && leveltime > (hidetime * TICRATE)))
|
||||
if (!((gametyperules & GTR_HIDEFROZEN) && leveltime > (hidetime * TICRATE)))
|
||||
{
|
||||
#ifdef HAVE_BLUA
|
||||
if (!LUAh_TeamSwitch(player, 3, true, false, false))
|
||||
return false;
|
||||
#endif
|
||||
if (player->mo)
|
||||
{
|
||||
P_RemoveMobj(player->mo);
|
||||
|
|
Loading…
Reference in a new issue