mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
**NEW!** hook_SeenPlayer
This commit is contained in:
parent
cd1cc9a222
commit
1c048275da
3 changed files with 60 additions and 4 deletions
|
@ -53,6 +53,7 @@ enum hook {
|
|||
hook_IntermissionThinker,
|
||||
hook_TeamSwitch,
|
||||
hook_ViewpointSwitch,
|
||||
hook_SeenPlayer,
|
||||
|
||||
hook_MAX // last hook
|
||||
};
|
||||
|
@ -97,5 +98,8 @@ 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 tryingautobalance, boolean tryingscramble); // Hook for team switching in... uh....
|
||||
UINT8 LUAh_ViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean forced); // Hook for spy mode
|
||||
#ifdef SEENAMES
|
||||
boolean LUAh_SeenPlayer(player_t *player, player_t *seenplayer); // Hook for MT_NAMECHECK
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,7 @@ const char *const hookNames[hook_MAX+1] = {
|
|||
"IntermissionThinker",
|
||||
"TeamSwitch",
|
||||
"ViewpointSwitch",
|
||||
"SeenPlayer",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -207,6 +208,7 @@ static int lib_addHook(lua_State *L)
|
|||
case hook_PlayerCanDamage:
|
||||
case hook_TeamSwitch:
|
||||
case hook_ViewpointSwitch:
|
||||
case hook_SeenPlayer:
|
||||
case hook_ShieldSpawn:
|
||||
case hook_ShieldSpecial:
|
||||
lastp = &playerhooks;
|
||||
|
@ -1412,7 +1414,7 @@ UINT8 LUAh_ViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean
|
|||
return 0;
|
||||
|
||||
lua_settop(gL, 0);
|
||||
hud_running = true;
|
||||
hud_running = true; // local hook
|
||||
|
||||
for (hookp = playerhooks; hookp; hookp = hookp->next)
|
||||
{
|
||||
|
@ -1453,4 +1455,49 @@ UINT8 LUAh_ViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean
|
|||
return canSwitchView;
|
||||
}
|
||||
|
||||
// Hook for MT_NAMECHECK
|
||||
#ifdef SEENAMES
|
||||
boolean LUAh_SeenPlayer(player_t *player, player_t *seenplayer)
|
||||
{
|
||||
hook_p hookp;
|
||||
boolean hasSeenPlayer = true;
|
||||
if (!gL || !(hooksAvailable[hook_SeenPlayer/8] & (1<<(hook_SeenPlayer%8))))
|
||||
return 0;
|
||||
|
||||
lua_settop(gL, 0);
|
||||
hud_running = true; // local hook
|
||||
|
||||
for (hookp = playerhooks; hookp; hookp = hookp->next)
|
||||
{
|
||||
if (hookp->type != hook_SeenPlayer)
|
||||
continue;
|
||||
|
||||
if (lua_gettop(gL) == 0)
|
||||
{
|
||||
LUA_PushUserdata(gL, player, META_PLAYER);
|
||||
LUA_PushUserdata(gL, seenplayer, META_PLAYER);
|
||||
}
|
||||
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||
lua_pushvalue(gL, -3);
|
||||
lua_pushvalue(gL, -3);
|
||||
if (lua_pcall(gL, 2, 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))
|
||||
hasSeenPlayer = false; // Hasn't seen player
|
||||
lua_pop(gL, 1);
|
||||
}
|
||||
|
||||
lua_settop(gL, 0);
|
||||
hud_running = false;
|
||||
|
||||
return hasSeenPlayer;
|
||||
}
|
||||
#endif // SEENAMES
|
||||
|
||||
#endif
|
||||
|
|
|
@ -746,8 +746,7 @@ static boolean PIT_CheckThing(mobj_t *thing)
|
|||
if (tmthing->type == MT_NAMECHECK)
|
||||
{
|
||||
// Ignore things that aren't players, ignore spectators, ignore yourself.
|
||||
// (also don't bother to check that tmthing->target->player is non-NULL because we're not actually using it here.)
|
||||
if (!thing->player || thing->player->spectator || (tmthing->target && thing->player == tmthing->target->player))
|
||||
if (!thing->player || !(tmthing->target && tmthing->target->player) || thing->player->spectator || (tmthing->target && thing->player == tmthing->target->player))
|
||||
return true;
|
||||
|
||||
// Now check that you actually hit them.
|
||||
|
@ -760,6 +759,12 @@ static boolean PIT_CheckThing(mobj_t *thing)
|
|||
if (tmthing->z + tmthing->height < thing->z)
|
||||
return true; // underneath
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
// REX HAS SEEN YOU
|
||||
if (!LUAh_SeenPlayer(tmthing->target->player, thing->player))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
seenplayer = thing->player;
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue