forked from Mirrorlandia_minetest/minetest
Added get_player_velocity() method. Fixes #1176
This commit is contained in:
parent
7bbb9b066a
commit
5ebb4237e2
@ -2470,6 +2470,7 @@ This is basically a reference to a C++ `ServerActiveObject`
|
||||
|
||||
##### Player-only (no-op for other objects)
|
||||
* `get_player_name()`: returns `""` if is not a player
|
||||
* `get_player_velocity()`: returns `nil` if is not a player otherwise a table {x, y, z} representing the player's instantaneous velocity in nodes/s
|
||||
* `get_look_dir()`: get camera direction as a unit vector
|
||||
* `get_look_pitch()`: pitch in radians
|
||||
* `get_look_yaw()`: yaw in radians (wraps around pretty randomly as of now)
|
||||
|
@ -945,6 +945,21 @@ 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);
|
||||
Player *player = getplayer(ref);
|
||||
if (player == NULL) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
// Do it
|
||||
push_v3f(L, player->getSpeed() / BS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get_look_dir(self)
|
||||
int ObjectRef::l_get_look_dir(lua_State *L)
|
||||
{
|
||||
@ -1706,6 +1721,7 @@ const 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, get_look_dir),
|
||||
luamethod(ObjectRef, get_look_pitch),
|
||||
luamethod(ObjectRef, get_look_yaw),
|
||||
|
@ -183,6 +183,9 @@ 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);
|
||||
|
||||
// get_look_dir(self)
|
||||
static int l_get_look_dir(lua_State *L);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user