VoteThinker Hook for Lua

This commit is contained in:
Latapostrophe 2020-03-10 18:58:44 +01:00
parent 63eadaf83c
commit 5202a4f0fd
3 changed files with 28 additions and 0 deletions

View File

@ -52,6 +52,7 @@ enum hook {
hook_PlayerSquish, //SRB2KART
hook_PlayerCmd, //SRB2KART
hook_IntermissionThinker, //SRB2KART
hook_VoteThinker, //SRB2KART
hook_MAX // last hook
};
@ -101,5 +102,6 @@ boolean LUAh_PlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source);
boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd); // Allows to write to player cmd before the game does anything with them.
void LUAh_IntermissionThinker(void); // Hook for Y_Ticker
void LUAh_VoteThinker(void); // Hook for Y_VoteTicker
#endif

View File

@ -63,6 +63,7 @@ const char *const hookNames[hook_MAX+1] = {
"PlayerSquish",
"PlayerCmd",
"IntermissionThinker",
"VoteThinker",
NULL
};
@ -442,6 +443,27 @@ void LUAh_IntermissionThinker(void)
}
}
// Hook for Y_VoteTicker
void LUAh_VoteThinker(void)
{
hook_p hookp;
if (!gL || !(hooksAvailable[hook_VoteThinker/8] & (1<<(hook_VoteThinker%8))))
return;
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_VoteThinker)
{
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
lua_gettable(gL, LUA_REGISTRYINDEX);
if (lua_pcall(gL, 0, 0, 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;
}
}
}
// Hook for mobj collisions
UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which)

View File

@ -1251,6 +1251,10 @@ void Y_VoteTicker(void)
if (paused || P_AutoPause() || !voteclient.loaded)
return;
#ifdef HAVE_BLUA
LUAh_VoteThinker();
#endif
votetic++;
if (votetic == voteendtic)