Player attrs: permits to remove an attribute by setting value to nil (#5716)
* Player attrs: permits to remove an attribute by setting value to nil When doing player:set_attribute("attr", nil) remove attribute Also remove a useless check on C++ API part (already done by checkplayer) Fix #5709
This commit is contained in:
parent
698e5b2ff1
commit
86253bb961
@ -3028,7 +3028,9 @@ This is basically a reference to a C++ `ServerActiveObject`
|
|||||||
* `0`: player is drowning,
|
* `0`: player is drowning,
|
||||||
* `1`-`10`: remaining number of bubbles
|
* `1`-`10`: remaining number of bubbles
|
||||||
* `11`: bubbles bar is not shown
|
* `11`: bubbles bar is not shown
|
||||||
* `set_attribute(attribute, value)`: sets an extra attribute with value on player
|
* `set_attribute(attribute, value)`:
|
||||||
|
* Sets an extra attribute with value on player.
|
||||||
|
* If value is nil, remove attribute from player.
|
||||||
* `get_attribute(attribute)`: returns value for extra attribute. Returns nil if no attribute found.
|
* `get_attribute(attribute)`: returns value for extra attribute. Returns nil if no attribute found.
|
||||||
* `set_inventory_formspec(formspec)`
|
* `set_inventory_formspec(formspec)`
|
||||||
* Redefine player's inventory form
|
* Redefine player's inventory form
|
||||||
|
@ -277,6 +277,16 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void removeExtendedAttribute(const std::string &attr)
|
||||||
|
{
|
||||||
|
PlayerAttributes::iterator it = m_extra_attributes.find(attr);
|
||||||
|
if (it == m_extra_attributes.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_extra_attributes.erase(it);
|
||||||
|
m_extended_attributes_modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
inline const PlayerAttributes &getExtendedAttributes()
|
inline const PlayerAttributes &getExtendedAttributes()
|
||||||
{
|
{
|
||||||
return m_extra_attributes;
|
return m_extra_attributes;
|
||||||
|
@ -1202,9 +1202,10 @@ int ObjectRef::l_set_attribute(lua_State *L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string attr = luaL_checkstring(L, 2);
|
std::string attr = luaL_checkstring(L, 2);
|
||||||
std::string value = luaL_checkstring(L, 3);
|
if (lua_isnil(L, 3)) {
|
||||||
|
co->removeExtendedAttribute(attr);
|
||||||
if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
|
} else {
|
||||||
|
std::string value = luaL_checkstring(L, 3);
|
||||||
co->setExtendedAttribute(attr, value);
|
co->setExtendedAttribute(attr, value);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user