**NEW!** hook_SeenPlayer

This commit is contained in:
Jaime Passos 2019-12-31 14:37:45 -03:00
parent cd1cc9a222
commit 1c048275da
3 changed files with 60 additions and 4 deletions

View File

@ -53,6 +53,7 @@ enum hook {
hook_IntermissionThinker, hook_IntermissionThinker,
hook_TeamSwitch, hook_TeamSwitch,
hook_ViewpointSwitch, hook_ViewpointSwitch,
hook_SeenPlayer,
hook_MAX // last hook 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 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.... 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 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 #endif

View File

@ -64,6 +64,7 @@ const char *const hookNames[hook_MAX+1] = {
"IntermissionThinker", "IntermissionThinker",
"TeamSwitch", "TeamSwitch",
"ViewpointSwitch", "ViewpointSwitch",
"SeenPlayer",
NULL NULL
}; };
@ -207,6 +208,7 @@ static int lib_addHook(lua_State *L)
case hook_PlayerCanDamage: case hook_PlayerCanDamage:
case hook_TeamSwitch: case hook_TeamSwitch:
case hook_ViewpointSwitch: case hook_ViewpointSwitch:
case hook_SeenPlayer:
case hook_ShieldSpawn: case hook_ShieldSpawn:
case hook_ShieldSpecial: case hook_ShieldSpecial:
lastp = &playerhooks; lastp = &playerhooks;
@ -1412,7 +1414,7 @@ UINT8 LUAh_ViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean
return 0; return 0;
lua_settop(gL, 0); lua_settop(gL, 0);
hud_running = true; hud_running = true; // local hook
for (hookp = playerhooks; hookp; hookp = hookp->next) for (hookp = playerhooks; hookp; hookp = hookp->next)
{ {
@ -1453,4 +1455,49 @@ UINT8 LUAh_ViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean
return canSwitchView; 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 #endif

View File

@ -745,9 +745,8 @@ static boolean PIT_CheckThing(mobj_t *thing)
// So that NOTHING ELSE can see MT_NAMECHECK because it is client-side. // So that NOTHING ELSE can see MT_NAMECHECK because it is client-side.
if (tmthing->type == MT_NAMECHECK) if (tmthing->type == MT_NAMECHECK)
{ {
// Ignore things that aren't players, ignore spectators, ignore yourself. // 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 || !(tmthing->target && tmthing->target->player) || thing->player->spectator || (tmthing->target && thing->player == tmthing->target->player))
if (!thing->player || thing->player->spectator || (tmthing->target && thing->player == tmthing->target->player))
return true; return true;
// Now check that you actually hit them. // 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) if (tmthing->z + tmthing->height < thing->z)
return true; // underneath return true; // underneath
#ifdef HAVE_BLUA
// REX HAS SEEN YOU
if (!LUAh_SeenPlayer(tmthing->target->player, thing->player))
return false;
#endif
seenplayer = thing->player; seenplayer = thing->player;
return false; return false;
} }