]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
lua api: add set/get_pitch
authorcorarona <email@example.com>
Tue, 27 Oct 2020 14:36:07 +0000 (15:36 +0100)
committercorarona <email@example.com>
Tue, 27 Oct 2020 14:36:07 +0000 (15:36 +0100)
src/script/lua_api/l_localplayer.cpp
src/script/lua_api/l_localplayer.h

index 8057802a43dca1614b8f71bdbbf9421bb224cec7..1d04e62db3a82aec131ed22aa59111e7583647c5 100644 (file)
@@ -95,6 +95,30 @@ int LuaLocalPlayer::l_set_yaw(lua_State *L)
        return 0;
 }
 
+int LuaLocalPlayer::l_get_pitch(lua_State *L)
+{
+       LocalPlayer *player = getobject(L, 1);
+
+       lua_pushinteger(L, player->getPitch());
+       return 1;
+}
+
+
+int LuaLocalPlayer::l_set_pitch(lua_State *L)
+{
+       LocalPlayer *player = getobject(L, 1);
+
+       if (lua_isnumber(L, 2)) {
+               int pitch = lua_tonumber(L, 2);
+               player->setPitch(pitch);
+               g_game->cam_view.camera_pitch = pitch;
+               g_game->cam_view_target.camera_pitch = pitch;
+       }
+       
+       return 0;
+}
+
+
 int LuaLocalPlayer::l_get_hp(lua_State *L)
 {
        LocalPlayer *player = getobject(L, 1);
@@ -527,6 +551,8 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
                luamethod(LuaLocalPlayer, set_velocity),
                luamethod(LuaLocalPlayer, get_yaw),
                luamethod(LuaLocalPlayer, set_yaw),
+               luamethod(LuaLocalPlayer, get_pitch),
+               luamethod(LuaLocalPlayer, set_pitch),
                luamethod(LuaLocalPlayer, get_hp),
                luamethod(LuaLocalPlayer, get_name),
                luamethod(LuaLocalPlayer, get_wield_index),
index 8daa901e01abb09fa7499957260af1b749aab0e1..1d7f9fcbd505e395e0ad0c6038a5cbe6cb9c7a53 100644 (file)
@@ -44,6 +44,12 @@ class LuaLocalPlayer : public ModApiBase
        // set_yaw(self, yaw)
        static int l_set_yaw(lua_State *L);
 
+        // get_pitch(self)
+        static int l_get_pitch(lua_State *L);
+
+        // set_pitch(self,pitch)
+        static int l_set_pitch(lua_State *L);
+
        // get_hp(self)
        static int l_get_hp(lua_State *L);