51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "cpp_api/scriptapi.h"
-#include "common/c_converter.h"
-#include "common/c_content.h"
#include "lua_api/l_object.h"
-#include "common/c_internal.h"
+#include "lua_api/l_internal.h"
#include "lua_api/l_inventory.h"
#include "lua_api/l_item.h"
+#include "common/c_converter.h"
+#include "common/c_content.h"
#include "log.h"
#include "tool.h"
#include "serverobject.h"
{HUD_FLAG_HEALTHBAR_VISIBLE, "healthbar"},
{HUD_FLAG_CROSSHAIR_VISIBLE, "crosshair"},
{HUD_FLAG_WIELDITEM_VISIBLE, "wielditem"},
+ {HUD_FLAG_BREATHBAR_VISIBLE, "breathbar"},
{0, NULL},
};
if(co == NULL) return 0;
// Do it
InventoryLocation loc = co->getInventoryLocation();
- if(STACK_TO_SERVER(L)->getInventory(loc) != NULL)
+ if(getServer(L)->getInventory(loc) != NULL)
InvRef::create(L, loc);
else
lua_pushnil(L); // An object may have no inventory (nil)
ServerActiveObject *co = getobject(ref);
if(co == NULL) return 0;
// Do it
- ItemStack item = read_item(L, 2,STACK_TO_SERVER(L));
+ ItemStack item = read_item(L, 2, getServer(L));
bool success = co->setWieldedItem(item);
lua_pushboolean(L, success);
return 1;
return 1;
}
+// set_breath(self, breath)
+int ObjectRef::l_set_breath(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ PlayerSAO* co = getplayersao(ref);
+ if(co == NULL) return 0;
+ u16 breath = luaL_checknumber(L, 2);
+ // Do it
+ co->setBreath(breath);
+ co->m_breath_not_sent = true;
+ return 0;
+}
+
+// get_breath(self)
+int ObjectRef::l_get_breath(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ PlayerSAO* co = getplayersao(ref);
+ if(co == NULL) return 0;
+ // Do it
+ u16 breath = co->getBreath();
+ lua_pushinteger (L, breath);
+ return 1;
+}
+
// set_inventory_formspec(self, formspec)
int ObjectRef::l_set_inventory_formspec(lua_State *L)
{
std::string formspec = luaL_checkstring(L, 2);
player->inventory_formspec = formspec;
- STACK_TO_SERVER(L)->reportInventoryFormspecModified(player->getName());
+ getServer(L)->reportInventoryFormspecModified(player->getName());
lua_pushboolean(L, true);
return 1;
}
elem->offset = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
lua_pop(L, 1);
- u32 id = STACK_TO_SERVER(L)->hudAdd(player, elem);
+ u32 id = getServer(L)->hudAdd(player, elem);
if (id == (u32)-1) {
delete elem;
return 0;
if (!lua_isnil(L, 2))
id = lua_tonumber(L, 2);
- if (!STACK_TO_SERVER(L)->hudRemove(player, id))
+ if (!getServer(L)->hudRemove(player, id))
return 0;
lua_pushboolean(L, true);
value = &e->offset;
}
- STACK_TO_SERVER(L)->hudChange(player, id, stat, value);
+ getServer(L)->hudChange(player, id, stat, value);
lua_pushboolean(L, true);
return 1;
mask |= esp[i].num;
}
}
- if (!STACK_TO_SERVER(L)->hudSetFlags(player, flags, mask))
+ if (!getServer(L)->hudSetFlags(player, flags, mask))
+ return 0;
+
+ lua_pushboolean(L, true);
+ return 1;
+}
+
+// hud_set_hotbar_itemcount(self, hotbar_itemcount)
+int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
+{
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if (player == NULL)
+ return 0;
+
+ s32 hotbar_itemcount = lua_tonumber(L, 2);
+
+ if (!getServer(L)->hudSetHotbarItemcount(player, hotbar_itemcount))
return 0;
lua_pushboolean(L, true);
luamethod(ObjectRef, get_look_yaw),
luamethod(ObjectRef, set_look_yaw),
luamethod(ObjectRef, set_look_pitch),
+ luamethod(ObjectRef, get_breath),
+ luamethod(ObjectRef, set_breath),
luamethod(ObjectRef, set_inventory_formspec),
luamethod(ObjectRef, get_inventory_formspec),
luamethod(ObjectRef, get_player_control),
luamethod(ObjectRef, hud_change),
luamethod(ObjectRef, hud_get),
luamethod(ObjectRef, hud_set_flags),
+ luamethod(ObjectRef, hud_set_hotbar_itemcount),
{0,0}
};
-
-REGISTER_LUA_REF(ObjectRef)