From db3797fd35da9dfde3dcef754b48ac47d9ea602d Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Sun, 14 Feb 2016 05:19:40 -0600 Subject: [PATCH 1/4] Add PlayerSpawn hook --- src/lua_hook.h | 2 ++ src/lua_hooklib.c | 1 + src/p_mobj.c | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/src/lua_hook.h b/src/lua_hook.h index da2dcdc3..f3af7f30 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -42,6 +42,7 @@ enum hook { hook_LinedefExecute, hook_PlayerMsg, hook_HurtMsg, + hook_PlayerSpawn, hook_MAX // last hook }; @@ -75,5 +76,6 @@ boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd); // Hook for B_B boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook for linedef executors boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg); // Hook for chat messages boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source); // Hook for hurt messages +#define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for P_SpawnPlayer #endif diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 0415d23e..dfd6d703 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -53,6 +53,7 @@ const char *const hookNames[hook_MAX+1] = { "LinedefExecute", "PlayerMsg", "HurtMsg", + "PlayerSpawn", NULL }; diff --git a/src/p_mobj.c b/src/p_mobj.c index 25ae8815..4916dbfd 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -8294,6 +8294,12 @@ void P_SpawnPlayer(INT32 playernum) // Spawn with a pity shield if necessary. P_DoPityCheck(p); + +#ifdef HAVE_BLUA + if (LUAh_PlayerSpawn(p)) // Lua hook for player spawning :) + ; +#endif + } void P_AfterPlayerSpawn(INT32 playernum) From 000ec9ac67c47c1c16489f35987fe2c87caaab81 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Sun, 14 Feb 2016 15:22:13 -0600 Subject: [PATCH 2/4] Call LUAh_PlayerSpawn instead of checking for it --- src/p_mobj.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 4916dbfd..367a3a7d 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -8296,8 +8296,7 @@ void P_SpawnPlayer(INT32 playernum) P_DoPityCheck(p); #ifdef HAVE_BLUA - if (LUAh_PlayerSpawn(p)) // Lua hook for player spawning :) - ; + LUAh_PlayerSpawn(p); // Lua hook for player spawning :) #endif } From 5c9aaf2fe4ae3d93dfe50028634e0b70d4ac598f Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Thu, 25 Feb 2016 22:28:19 -0600 Subject: [PATCH 3/4] Move hook into G_SpawnPlayer --- src/g_game.c | 6 ++++++ src/lua_hook.h | 2 +- src/p_mobj.c | 5 ----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 72cfe4a5..3329e8ef 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2328,6 +2328,12 @@ void G_SpawnPlayer(INT32 playernum, boolean starpost) } } P_MovePlayerToSpawn(playernum, spawnpoint); + +#ifdef HAVE_BLUA + player_t *p = &players[playernum]; + LUAh_PlayerSpawn(p); // Lua hook for player spawning :) +#endif + } mapthing_t *G_FindCTFStart(INT32 playernum) diff --git a/src/lua_hook.h b/src/lua_hook.h index f3af7f30..4eb08378 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -76,6 +76,6 @@ boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd); // Hook for B_B boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook for linedef executors boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg); // Hook for chat messages boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source); // Hook for hurt messages -#define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for P_SpawnPlayer +#define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for G_SpawnPlayer #endif diff --git a/src/p_mobj.c b/src/p_mobj.c index 367a3a7d..25ae8815 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -8294,11 +8294,6 @@ void P_SpawnPlayer(INT32 playernum) // Spawn with a pity shield if necessary. P_DoPityCheck(p); - -#ifdef HAVE_BLUA - LUAh_PlayerSpawn(p); // Lua hook for player spawning :) -#endif - } void P_AfterPlayerSpawn(INT32 playernum) From 8f0abb267edd493b58e875a08083af9c36ea3870 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Thu, 25 Feb 2016 22:47:52 -0600 Subject: [PATCH 4/4] Don't mix declarations and code --- src/g_game.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 3329e8ef..219b276e 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2330,8 +2330,7 @@ void G_SpawnPlayer(INT32 playernum, boolean starpost) P_MovePlayerToSpawn(playernum, spawnpoint); #ifdef HAVE_BLUA - player_t *p = &players[playernum]; - LUAh_PlayerSpawn(p); // Lua hook for player spawning :) + LUAh_PlayerSpawn(&players[playernum]); // Lua hook for player spawning :) #endif }