diff options
author | sfan5 <sfan5@live.de> | 2019-07-16 14:00:42 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2019-08-10 19:44:27 +0200 |
commit | cf64054390970f3cf974afb2b174340a3e1da382 (patch) | |
tree | 9f3a62d3f935ae76f00fb1c0002f9ba59e59f219 /src/script/lua_api/l_object.cpp | |
parent | b19400aa74f30ef61ba0c1bb4a25a978e7cf4125 (diff) | |
download | minetest-cf64054390970f3cf974afb2b174340a3e1da382.tar.gz minetest-cf64054390970f3cf974afb2b174340a3e1da382.tar.bz2 minetest-cf64054390970f3cf974afb2b174340a3e1da382.zip |
Implement adding velocity to player from Lua
The intended usecase is knockback, but there's potential for more.
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r-- | src/script/lua_api/l_object.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 5dba63159..be2172f1b 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1092,6 +1092,27 @@ int ObjectRef::l_get_player_velocity(lua_State *L) 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); + + RemotePlayer *player = getplayer(ref); + PlayerSAO *co = getplayersao(ref); + if (!player || !co) + return 0; + + session_t peer_id = player->getPeerId(); + if (peer_id == PEER_ID_INEXISTENT) + return 0; + // Do it + co->setMaxSpeedOverride(vel); + getServer(L)->SendPlayerSpeed(peer_id, vel); + return 0; +} + // get_look_dir(self) int ObjectRef::l_get_look_dir(lua_State *L) { @@ -1931,6 +1952,7 @@ luaL_Reg ObjectRef::methods[] = { 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), |