1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement adding velocity to player from Lua

The intended usecase is knockback, but there's potential for more.
This commit is contained in:
sfan5 2019-07-16 14:00:42 +02:00
parent b19400aa74
commit cf64054390
14 changed files with 105 additions and 2 deletions

View file

@ -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),