summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorBlockMen <nmuelll@web.de>2014-04-11 15:32:46 +0200
committerBlockMen <nmuelll@web.de>2014-04-12 17:44:20 +0200
commitc0ab09af747fc431dfb459ede30788cb9cd1c56b (patch)
tree7355b0b349a6d188e6066c00c3b3ef9b0a76f33e /src/script
parenta1db9242ec491efdee70a7184aa61e861b17595a (diff)
downloadminetest-c0ab09af747fc431dfb459ede30788cb9cd1c56b.tar.gz
minetest-c0ab09af747fc431dfb459ede30788cb9cd1c56b.tar.bz2
minetest-c0ab09af747fc431dfb459ede30788cb9cd1c56b.zip
Add player:set_eye_offset() by @MirceaKitsune and clean up
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_object.cpp33
-rw-r--r--src/script/lua_api/l_object.h5
2 files changed, 36 insertions, 2 deletions
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);