diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index a3362181..cd94dd65 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -628,3 +628,7 @@ void Hud::setPause(bool pause) { darkOverlay->setVisible(pause); menu->setVisible(pause); } + +Player* Hud::getPlayer() const { + return frontend->getLevel()->player; +} diff --git a/src/frontend/hud.h b/src/frontend/hud.h index b591f4b6..aa7b2e9c 100644 --- a/src/frontend/hud.h +++ b/src/frontend/hud.h @@ -116,6 +116,8 @@ public: void add(HudElement element); void remove(HudElement& element); void remove(std::shared_ptr node); + + Player* getPlayer() const; }; #endif /* SRC_HUD_H_ */ diff --git a/src/logic/scripting/scripting_frontend.cpp b/src/logic/scripting/scripting_frontend.cpp index 5c2755d7..00923457 100644 --- a/src/logic/scripting/scripting_frontend.cpp +++ b/src/logic/scripting/scripting_frontend.cpp @@ -4,6 +4,8 @@ #include "lua/libhud.h" #include "lua/LuaState.h" +#include "../../frontend/hud.h" +#include "../../objects/Player.h" #include "../../files/files.h" #include "../../engine.h" @@ -21,7 +23,8 @@ void scripting::on_frontend_init(Hud* hud) { for (auto& pack : scripting::engine->getContentPacks()) { if (state->getglobal(pack.id+".hudopen")) { - state->callNoThrow(0); + state->pushinteger(hud->getPlayer()->getId()); + state->callNoThrow(1); } } } @@ -30,7 +33,8 @@ void scripting::on_frontend_close() { scripting::hud = nullptr; for (auto& pack : scripting::engine->getContentPacks()) { if (state->getglobal(pack.id+".hudclose")) { - state->callNoThrow(0); + state->pushinteger(hud->getPlayer()->getId()); + state->callNoThrow(1); } } } diff --git a/src/objects/Player.h b/src/objects/Player.h index 18f92e55..f49a9fc2 100644 --- a/src/objects/Player.h +++ b/src/objects/Player.h @@ -70,6 +70,10 @@ public: void deserialize(dynamic::Map *src) override; static void convert(dynamic::Map* data, const ContentLUT* lut); + + inline int getId() const { + return 1; + } }; #endif /* SRC_OBJECTS_PLAYER_H_ */