diff --git a/src/k_grandprix.c b/src/k_grandprix.c index 4f10d4e29..a2d942e54 100644 --- a/src/k_grandprix.c +++ b/src/k_grandprix.c @@ -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; } diff --git a/src/lua_hook.h b/src/lua_hook.h index 24e2ebf25..3a7b2a3a7 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -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" diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index ad6254a7b..f77722b43 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -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;