diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/common/c_content.cpp | 4 | ||||
-rw-r--r-- | src/script/lua_api/l_clientobject.cpp | 11 | ||||
-rw-r--r-- | src/script/lua_api/l_clientobject.h | 5 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index eeaf69da1..8543b70ce 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -200,7 +200,7 @@ void read_object_properties(lua_State *L, int index, if (getintfield(L, -1, "hp_max", hp_max)) { prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX); - if (prop->hp_max < sao->getHP()) { + if (sao && prop->hp_max < sao->getHP()) { PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP); sao->setHP(prop->hp_max, reason); if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) @@ -209,7 +209,7 @@ void read_object_properties(lua_State *L, int index, } if (getintfield(L, -1, "breath_max", prop->breath_max)) { - if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + if (sao && sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) { PlayerSAO *player = (PlayerSAO *)sao; if (prop->breath_max < player->getBreath()) player->setBreath(prop->breath_max); diff --git a/src/script/lua_api/l_clientobject.cpp b/src/script/lua_api/l_clientobject.cpp index 7b9c4c3fa..0147fd48b 100644 --- a/src/script/lua_api/l_clientobject.cpp +++ b/src/script/lua_api/l_clientobject.cpp @@ -160,6 +160,16 @@ int ClientObjectRef::l_get_properties(lua_State *L) return 1; } +int ClientObjectRef::l_set_properties(lua_State *L) +{ + ClientObjectRef *ref = checkobject(L, 1); + GenericCAO *gcao = get_generic_cao(ref, L); + ObjectProperties prop = *gcao->getProperties(); + read_object_properties(L, 2, nullptr, &prop, getClient(L)->idef()); + gcao->setProperties(prop); + return 1; +} + int ClientObjectRef::l_get_hp(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); @@ -259,6 +269,7 @@ luaL_Reg ClientObjectRef::methods[] = {luamethod(ClientObjectRef, get_pos), luamethod(ClientObjectRef, get_nametag), luamethod(ClientObjectRef, get_item_textures), luamethod(ClientObjectRef, get_properties), + luamethod(ClientObjectRef, set_properties), luamethod(ClientObjectRef, get_hp), luamethod(ClientObjectRef, get_max_hp), luamethod(ClientObjectRef, punch), luamethod(ClientObjectRef, rightclick), {0, 0}}; diff --git a/src/script/lua_api/l_clientobject.h b/src/script/lua_api/l_clientobject.h index 160b6c4fe..22d2f4a1c 100644 --- a/src/script/lua_api/l_clientobject.h +++ b/src/script/lua_api/l_clientobject.h @@ -75,12 +75,15 @@ private: // get_nametag(self) static int l_get_nametag(lua_State *L); - // get_textures(self) + // get_item_textures(self) static int l_get_item_textures(lua_State *L); // get_properties(self) static int l_get_properties(lua_State *L); + // set_properties(self, properties) + static int l_set_properties(lua_State *L); + // get_hp(self) static int l_get_hp(lua_State *L); |