diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/script/lua_api/l_base.cpp | 5 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 82 | ||||
-rw-r--r-- | src/script/lua_api/l_object.h | 6 |
3 files changed, 40 insertions, 53 deletions
diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index 2bee09436..03ef5447a 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -170,10 +170,11 @@ void ModApiBase::markAliasDeprecated(luaL_Reg *reg) m_deprecated_wrappers.emplace( std::pair<std::string, luaL_Reg>(reg->name, original_reg)); reg->func = l_deprecated_function; + } else { + last_func = reg->func; + last_name = reg->name; } - last_func = reg->func; - last_name = reg->name; ++reg; } } diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 24667e769..303b1175b 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -863,12 +863,21 @@ int ObjectRef::l_add_velocity(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - LuaEntitySAO *co = getluaobject(ref); - if (!co) + v3f vel = checkFloatPos(L, 2); + + ServerActiveObject *obj = getobject(ref); + if (obj == nullptr) return 0; - v3f pos = checkFloatPos(L, 2); - // Do it - co->addVelocity(pos); + + if (obj->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) { + LuaEntitySAO *co = dynamic_cast<LuaEntitySAO*>(obj); + co->addVelocity(vel); + } else if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + PlayerSAO *player = dynamic_cast<PlayerSAO*>(obj); + player->setMaxSpeedOverride(vel); + getServer(L)->SendPlayerSpeed(player->getPeerID(), vel); + } + return 0; } @@ -877,11 +886,23 @@ int ObjectRef::l_get_velocity(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->getVelocity(); - pushFloatPos(L, v); + + ServerActiveObject *obj = getobject(ref); + if (obj == nullptr) + return 0; + + if (obj->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) { + LuaEntitySAO *co = dynamic_cast<LuaEntitySAO*>(obj); + v3f v = co->getVelocity(); + pushFloatPos(L, v); + return 1; + } else if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + RemotePlayer *player = dynamic_cast<PlayerSAO*>(obj)->getPlayer(); + push_v3f(L, player->getSpeed() / BS); + return 1; + } + + lua_pushnil(L); return 1; } @@ -1082,38 +1103,6 @@ int ObjectRef::l_get_player_name(lua_State *L) return 1; } -// get_player_velocity(self) -int ObjectRef::l_get_player_velocity(lua_State *L) -{ - NO_MAP_LOCK_REQUIRED; - ObjectRef *ref = checkobject(L, 1); - RemotePlayer *player = getplayer(ref); - if (player == NULL) { - lua_pushnil(L); - return 1; - } - // Do it - push_v3f(L, player->getSpeed() / BS); - return 1; -} - -// add_player_velocity(self, {x=num, y=num, z=num}) -int ObjectRef::l_add_player_velocity(lua_State *L) -{ - NO_MAP_LOCK_REQUIRED; - ObjectRef *ref = checkobject(L, 1); - v3f vel = checkFloatPos(L, 2); - - PlayerSAO *co = getplayersao(ref); - if (!co) - return 0; - - // Do it - co->setMaxSpeedOverride(vel); - getServer(L)->SendPlayerSpeed(co->getPeerID(), vel); - return 0; -} - // get_look_dir(self) int ObjectRef::l_get_look_dir(lua_State *L) { @@ -2288,10 +2277,14 @@ luaL_Reg ObjectRef::methods[] = { luamethod(ObjectRef, get_properties), luamethod(ObjectRef, set_nametag_attributes), luamethod(ObjectRef, get_nametag_attributes), - // LuaEntitySAO-only + luamethod_aliased(ObjectRef, set_velocity, setvelocity), luamethod(ObjectRef, add_velocity), + {"add_player_velocity", ObjectRef::l_add_velocity}, luamethod_aliased(ObjectRef, get_velocity, getvelocity), + {"get_player_velocity", ObjectRef::l_get_velocity}, + + // LuaEntitySAO-only luamethod_aliased(ObjectRef, set_acceleration, setacceleration), luamethod_aliased(ObjectRef, get_acceleration, getacceleration), luamethod_aliased(ObjectRef, set_yaw, setyaw), @@ -2307,8 +2300,7 @@ luaL_Reg ObjectRef::methods[] = { luamethod(ObjectRef, is_player), luamethod(ObjectRef, is_player_connected), luamethod(ObjectRef, get_player_name), - luamethod(ObjectRef, get_player_velocity), - luamethod(ObjectRef, add_player_velocity), + luamethod(ObjectRef, get_look_dir), luamethod(ObjectRef, get_look_pitch), luamethod(ObjectRef, get_look_yaw), diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index a75c59fd9..126719b1f 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -209,12 +209,6 @@ private: // get_player_name(self) static int l_get_player_name(lua_State *L); - // get_player_velocity(self) - static int l_get_player_velocity(lua_State *L); - - // add_player_velocity(self, {x=num, y=num, z=num}) - static int l_add_player_velocity(lua_State *L); - // get_fov(self) static int l_get_fov(lua_State *L); |