// get_luaentity(self) int ObjectRef::l_get_luaentity(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it luaentity_get(L, co->getId()); return 1; }
// get_texture_mod(self) int ObjectRef::l_get_texture_mod(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it std::string mod = co->getTextureMod(); lua_pushstring(L, mod.c_str()); return 1; }
// set_texture_mod(self, mod) int ObjectRef::l_set_texture_mod(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it std::string mod = luaL_checkstring(L, 2); co->setTextureMod(mod); return 0; }
// get_acceleration(self) int ObjectRef::l_get_acceleration(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it v3f v = co->getAcceleration(); pushFloatPos(L, v); return 1; }
// set_velocity(self, {x=num, y=num, z=num}) int ObjectRef::l_set_velocity(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; v3f pos = checkFloatPos(L, 2); // Do it co->setVelocity(pos); return 0; }
// getyaw(self) int ObjectRef::l_getyaw(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it float yaw = co->getYaw() * core::DEGTORAD; lua_pushnumber(L, yaw); return 1; }
// setyaw(self, radians) int ObjectRef::l_setyaw(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; float yaw = luaL_checknumber(L, 2) * core::RADTODEG; // Do it co->setYaw(yaw); return 0; }
// DEPRECATED // get_entity_name(self) int ObjectRef::l_get_entity_name(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if(co == NULL) return 0; // Do it std::string name = co->getName(); lua_pushstring(L, name.c_str()); return 1; }
// get_yaw(self) int ObjectRef::l_get_yaw(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (!co) return 0; float yaw = co->getRotation().Y * core::DEGTORAD; lua_pushnumber(L, yaw); return 1; }
// set_rotation(self, {x=num, y=num, z=num}) // Each 'num' is in radians int ObjectRef::l_set_rotation(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (!co) return 0; v3f rotation = check_v3f(L, 2) * core::RADTODEG; co->setRotation(rotation); return 0; }
// setacceleration(self, {x=num, y=num, z=num}) int ObjectRef::l_setacceleration(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // pos v3f pos = checkFloatPos(L, 2); // Do it co->setAcceleration(pos); return 0; }
// get_rotation(self) // returns: {x=num, y=num, z=num} // Each 'num' is in radians int ObjectRef::l_get_rotation(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (!co) return 0; lua_newtable(L); v3f rotation = co->getRotation() * core::DEGTORAD; push_v3f(L, rotation); return 1; }
// set_yaw(self, radians) int ObjectRef::l_set_yaw(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; if (isNaN(L, 2)) throw LuaError("ObjectRef::set_yaw: NaN value is not allowed."); float yaw = readParam<float>(L, 2) * core::RADTODEG; co->setRotation(v3f(0, yaw, 0)); return 0; }
// setvelocity(self, {x=num, y=num, z=num}) int ObjectRef::l_setvelocity(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); v3f pos = checkFloatPos(L, 2); PlayerSAO* ps = getplayersao(ref); if (ps) { ps->addSpeed(pos); return 0; } LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it co->setVelocity(pos); return 0; }
// getvelocity(self) int ObjectRef::l_getvelocity(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); { PlayerSAO* co = getplayersao(ref); if (co) { v3f v = co->getPlayer()->getSpeed(); pushFloatPos(L, v); return 1; } } LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it v3f v = co->getVelocity(); pushFloatPos(L, v); return 1; }
// set_sprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2, // select_horiz_by_yawpitch=false) int ObjectRef::l_set_sprite(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it v2s16 p(0,0); if (!lua_isnil(L, 2)) p = readParam<v2s16>(L, 2); int num_frames = 1; if (!lua_isnil(L, 3)) num_frames = lua_tonumber(L, 3); float framelength = 0.2; if (!lua_isnil(L, 4)) framelength = lua_tonumber(L, 4); bool select_horiz_by_yawpitch = false; if (!lua_isnil(L, 5)) select_horiz_by_yawpitch = readParam<bool>(L, 5); co->setSprite(p, num_frames, framelength, select_horiz_by_yawpitch); return 0; }