From c0ab09af747fc431dfb459ede30788cb9cd1c56b Mon Sep 17 00:00:00 2001 From: BlockMen Date: Fri, 11 Apr 2014 15:32:46 +0200 Subject: Add player:set_eye_offset() by @MirceaKitsune and clean up --- src/script/lua_api/l_object.cpp | 33 ++++++++++++++++++++++++++++++++- src/script/lua_api/l_object.h | 5 ++++- 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src/script/lua_api') diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index e801ddd5f..8f2bde036 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -406,7 +406,7 @@ int ObjectRef::l_set_animation(lua_State *L) return 0; } -// set_local_animation(self, {stand/ilde}, {walk}, {dig}, {walk+dig}, frame_speed) +// set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed) int ObjectRef::l_set_local_animation(lua_State *L) { //NO_MAP_LOCK_REQUIRED; @@ -431,6 +431,36 @@ int ObjectRef::l_set_local_animation(lua_State *L) return 0; } +// set_eye_offset(self, v3f first pv, v3f third pv) +int ObjectRef::l_set_eye_offset(lua_State *L) +{ + //NO_MAP_LOCK_REQUIRED; + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + // Do it + v3f offset_first = v3f(0, 0, 0); + v3f offset_third = v3f(0, 0, 0); + + if(!lua_isnil(L, 2)) + offset_first = read_v3f(L, 2); + if(!lua_isnil(L, 3)) + offset_third = read_v3f(L, 3); + + // Prevent abuse of offset values (keep player always visible) + offset_third.X = rangelim(offset_third.X,-10,10); + offset_third.Z = rangelim(offset_third.Z,-5,5); + /* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */ + offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS + + if (!getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third)) + return 0; + + lua_pushboolean(L, true); + return 0; +} + // set_bone_position(self, std::string bone, v3f position, v3f rotation) int ObjectRef::l_set_bone_position(lua_State *L) { @@ -1296,5 +1326,6 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, set_sky), luamethod(ObjectRef, override_day_night_ratio), luamethod(ObjectRef, set_local_animation), + luamethod(ObjectRef, set_eye_offset), {0,0} }; diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index be1068c14..f6070585d 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -231,9 +231,12 @@ private: // override_day_night_ratio(self, type, list) static int l_override_day_night_ratio(lua_State *L); - // set_local_animation(self, {stand/ilde}, {walk}, {dig}, {walk+dig}, frame_speed) + // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed) static int l_set_local_animation(lua_State *L); + // set_eye_offset(self, v3f first pv, v3f third pv) + static int l_set_eye_offset(lua_State *L); + public: ObjectRef(ServerActiveObject *object); -- cgit v1.2.3