1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add possibility to easier override HP and breath engine logic by Lua (#14179)

Co-authored-by: Lars Mueller <appgurulars@gmx.de>
This commit is contained in:
sfence 2024-08-21 20:24:43 +02:00 committed by GitHub
parent dc21924f31
commit f2c66b9ceb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 66 additions and 4 deletions

View file

@ -2688,6 +2688,41 @@ int ObjectRef::l_respawn(lua_State *L)
return 1;
}
// set_flags(self, flags)
int ObjectRef::l_set_flags(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkObject<ObjectRef>(L, 1);
auto *psao = getplayersao(ref);
if (psao == nullptr)
return 0;
if (!lua_istable(L, -1))
throw LuaError("expected a table of flags");
auto &flags = psao->m_flags;
flags.drowning = getboolfield_default(L, -1, "drowning", flags.drowning);
flags.breathing = getboolfield_default(L, -1, "breathing", flags.breathing);
flags.node_damage = getboolfield_default(L, -1, "node_damage", flags.node_damage);
return 0;
}
// get_flags(self)
int ObjectRef::l_get_flags(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkObject<ObjectRef>(L, 1);
const auto *psao = getplayersao(ref);
if (psao == nullptr)
return 0;
lua_createtable(L, 0, 3);
lua_pushboolean(L, psao->m_flags.drowning);
lua_setfield(L, -2, "drowning");
lua_pushboolean(L, psao->m_flags.breathing);
lua_setfield(L, -2, "breathing");
lua_pushboolean(L, psao->m_flags.node_damage);
lua_setfield(L, -2, "node_damage");
return 1;
}
ObjectRef::ObjectRef(ServerActiveObject *object):
m_object(object)
@ -2838,6 +2873,8 @@ luaL_Reg ObjectRef::methods[] = {
luamethod(ObjectRef, set_lighting),
luamethod(ObjectRef, get_lighting),
luamethod(ObjectRef, respawn),
luamethod(ObjectRef, set_flags),
luamethod(ObjectRef, get_flags),
{0,0}
};