From dfc81983491417c5cd1c99d7db05e421c409379d Mon Sep 17 00:00:00 2001 From: Andrew Ward Date: Wed, 28 Mar 2018 16:05:18 +0100 Subject: Add reasons to on_dieplayer and on_hpchange --- src/script/cpp_api/s_base.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/script/cpp_api/s_base.cpp') diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index f451156bd..571bac611 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -43,6 +43,7 @@ extern "C" { #include #include #include "script/common/c_content.h" +#include "content_sao.h" #include @@ -151,7 +152,7 @@ void ScriptApiBase::clientOpenLibs(lua_State *L) { LUA_JITLIBNAME, luaopen_jit }, #endif }; - + for (const std::pair &lib : m_libs) { lua_pushcfunction(L, lib.second); lua_pushstring(L, lib.first.c_str()); @@ -381,6 +382,26 @@ void ScriptApiBase::objectrefGetOrCreate(lua_State *L, } } +void ScriptApiBase::pushPlayerHPChangeReason(lua_State *L, const PlayerHPChangeReason &reason) +{ + if (reason.lua_reference >= 0) { + lua_rawgeti(L, LUA_REGISTRYINDEX, reason.lua_reference); + luaL_unref(L, LUA_REGISTRYINDEX, reason.lua_reference); + } else + lua_newtable(L); + + lua_pushstring(L, reason.getTypeAsString().c_str()); + lua_setfield(L, -2, "type"); + + lua_pushstring(L, reason.from_mod ? "mod" : "engine"); + lua_setfield(L, -2, "from"); + + if (reason.object) { + objectrefGetOrCreate(L, reason.object); + lua_setfield(L, -2, "object"); + } +} + Server* ScriptApiBase::getServer() { return dynamic_cast(m_gamedef); -- cgit v1.2.3