// set_hp(self, hp) // hp = number of hitpoints (2 * number of hearts) // returns: nil int ObjectRef::l_set_hp(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); luaL_checknumber(L, 2); ServerActiveObject *co = getobject(ref); if(co == NULL) return 0; int hp = lua_tonumber(L, 2); /*infostream<<"ObjectRef::l_set_hp(): id="<<co->getId() <<" hp="<<hp<<std::endl;*/ // Do it co->setHP(hp); // Return return 0; }
// set_hp(self, hp) // hp = number of hitpoints (2 * number of hearts) // returns: nil int ObjectRef::l_set_hp(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); luaL_checknumber(L, 2); ServerActiveObject *co = getobject(ref); if (co == NULL) return 0; int hp = lua_tonumber(L, 2); /*infostream<<"ObjectRef::l_set_hp(): id="<<co->getId() <<" hp="<<hp<<std::endl;*/ // Do it co->setHP(hp); if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co); // Return return 0; }
// set_properties(self, properties) int ObjectRef::l_set_properties(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); if (co == NULL) return 0; ObjectProperties *prop = co->accessObjectProperties(); if (!prop) return 0; read_object_properties(L, 2, prop, getServer(L)->idef()); if (prop->hp_max < co->getHP()) { PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP); co->setHP(prop->hp_max, reason); if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co, reason); } co->notifyObjectPropertiesModified(); return 0; }
// set_hp(self, hp) // hp = number of hitpoints (2 * number of hearts) // returns: nil int ObjectRef::l_set_hp(lua_State *L) { NO_MAP_LOCK_REQUIRED; // Get Object ObjectRef *ref = checkobject(L, 1); luaL_checknumber(L, 2); ServerActiveObject *co = getobject(ref); if (co == NULL) return 0; // Get HP int hp = lua_tonumber(L, 2); // Get Reason PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP); reason.from_mod = true; if (lua_istable(L, 3)) { lua_pushvalue(L, 3); lua_getfield(L, -1, "type"); if (lua_isstring(L, -1) && !reason.setTypeFromString(readParam<std::string>(L, -1))) { errorstream << "Bad type given!" << std::endl; } lua_pop(L, 1); reason.lua_reference = luaL_ref(L, LUA_REGISTRYINDEX); } // Do it co->setHP(hp, reason); if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co, reason); if (reason.hasLuaReference()) luaL_unref(L, LUA_REGISTRYINDEX, reason.lua_reference); // Return return 0; }