Grand Prix Rank Points Hook

This commit is contained in:
Nep2Disk 2025-08-22 00:24:12 +00:00 committed by Eidolon
parent 294e60bf8d
commit 49c8ebceed
3 changed files with 29 additions and 0 deletions

View file

@ -21,6 +21,7 @@
#include "m_random.h"
#include "p_local.h"
#include "r_things.h"
#include "lua_hook.h" // LUA_HookGPRankPoints
struct grandprixinfo grandprixinfo;
@ -94,6 +95,8 @@ INT16 K_CalculateGPRankPoints(UINT8 position, UINT8 numplayers)
points = 0;
}
LUA_HookGPRankPoints(position, numplayers, &points);
return points;
}

View file

@ -79,6 +79,7 @@ automatically.
X (GameQuit),\
X (PlayerCmd),/* building the player's ticcmd struct */\
X (VoteThinker),/* Y_VoteTicker */\
X (GPRankPoints),/* K_CalculateGPRankPoints */\
#define STRING_HOOK_LIST(X) \
X (SpecialExecute),\
@ -146,6 +147,7 @@ void LUA_HookPlayerQuit(player_t *, kickreason_t);
int LUA_HookTeamSwitch(player_t *, int newteam, boolean fromspectators, boolean tryingautobalance, boolean tryingscramble);
int LUA_HookViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean forced);
int LUA_HookSeenPlayer(player_t *player, player_t *seenfriend);
int LUA_HookGPRankPoints(UINT8 position, UINT8 numplayers, INT16 *points);
#ifdef __cplusplus
} // extern "C"

View file

@ -1007,4 +1007,28 @@ int LUA_HookSeenPlayer(player_t *player, player_t *seenfriend)
return hook.status;
}
static void res_gprankpoints(Hook_State *hook)
{
if (!lua_isnil(gL, -1))
{
INT16 *points = (INT16*)hook->userdata;
*points = lua_tointeger(gL, -1);
hook->status = true;
}
}
int LUA_HookGPRankPoints(UINT8 position, UINT8 numplayers, INT16 *points)
{
Hook_State hook;
if (prepare_hook(&hook, 0, HOOK(GPRankPoints)))
{
hook.userdata = points;
lua_pushinteger(gL, position);
lua_pushinteger(gL, numplayers);
lua_pushinteger(gL, *points);
call_hooks(&hook, 1, res_gprankpoints);
}
return hook.status;
}
boolean hook_cmd_running = false;