diff --git a/src/events.cpp b/src/events.cpp index 5481dd871..60e678365 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -449,6 +449,12 @@ void E_PlayerEntered(int num, bool fromhub) handler->PlayerEntered(num, fromhub); } +void E_PlayerSpawned(int num) +{ + for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) + handler->PlayerSpawned(num); +} + void E_PlayerRespawned(int num) { for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) @@ -1024,6 +1030,18 @@ void DStaticEventHandler::PlayerEntered(int num, bool fromhub) } } +void DStaticEventHandler::PlayerSpawned(int num) +{ + IFVIRTUAL(DStaticEventHandler, PlayerSpawned) + { + // don't create excessive DObjects if not going to be processed anyway + if (isEmpty(func)) return; + FPlayerEvent e = { num, false }; + VMValue params[2] = { (DStaticEventHandler*)this, &e }; + VMCall(func, params, 2, nullptr, 0); + } +} + void DStaticEventHandler::PlayerRespawned(int num) { IFVIRTUAL(DStaticEventHandler, PlayerRespawned) diff --git a/src/events.h b/src/events.h index 736749547..6e83fe356 100755 --- a/src/events.h +++ b/src/events.h @@ -70,6 +70,8 @@ void E_RenderOverlay(EHudState state); void E_RenderUnderlay(EHudState state); // this executes when a player enters the level (once). PlayerEnter+inhub = RETURN void E_PlayerEntered(int num, bool fromhub); +// this executes at the same time as ENTER scripts +void E_PlayerSpawned(int num); // this executes when a player respawns. includes resurrect cheat. void E_PlayerRespawned(int num); // this executes when a player dies (partially duplicating worldthingdied, but whatever) @@ -177,6 +179,7 @@ public: // void PlayerEntered(int num, bool fromhub); + void PlayerSpawned(int num); void PlayerRespawned(int num); void PlayerDied(int num); void PlayerDisconnected(int num); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index b9adba1d4..9c1bd943a 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -5047,6 +5047,15 @@ void PlayerSpawnPickClass (int playernum) } } +int PlayerNum(player_t *player) +{ + for (int i = 0; i < MAXPLAYERS; i++) + { + if (player == &players[i]) return i; + } + return -1; +} + AActor *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags) { player_t *p; @@ -5264,6 +5273,7 @@ AActor *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags) if (state == PST_ENTER || (state == PST_LIVE && !savegamerestore)) { FBehavior::StaticStartTypedScripts (SCRIPT_Enter, p->mo, true); + E_PlayerSpawned(PlayerNum(p)); } else if (state == PST_REBORN) { diff --git a/wadsrc/static/zscript/events.zs b/wadsrc/static/zscript/events.zs index acb28b0e1..7406cdbc2 100644 --- a/wadsrc/static/zscript/events.zs +++ b/wadsrc/static/zscript/events.zs @@ -345,6 +345,7 @@ class StaticEventHandler : Object native play version("2.4") // virtual void PlayerEntered(PlayerEvent e) {} + virtual void PlayerSpawned(PlayerEvent e) {} virtual void PlayerRespawned(PlayerEvent e) {} virtual void PlayerDied(PlayerEvent e) {} virtual void PlayerDisconnected(PlayerEvent e) {}