1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Add reasons to on_dieplayer and on_hpchange

This commit is contained in:
Andrew Ward 2018-03-28 16:05:18 +01:00 committed by GitHub
parent 2323842dd3
commit dfc8198349
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 219 additions and 52 deletions

View file

@ -43,6 +43,7 @@ extern "C" {
#include <cstdio>
#include <cstdarg>
#include "script/common/c_content.h"
#include "content_sao.h"
#include <sstream>
@ -151,7 +152,7 @@ void ScriptApiBase::clientOpenLibs(lua_State *L)
{ LUA_JITLIBNAME, luaopen_jit },
#endif
};
for (const std::pair<std::string, lua_CFunction> &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<Server *>(m_gamedef);