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:
parent
dc21924f31
commit
f2c66b9ceb
6 changed files with 66 additions and 4 deletions
|
@ -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}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue