Use a table in set_physics_override()
authorPilzAdam <pilzadam@minetest.net>
Tue, 3 Dec 2013 21:26:40 +0000 (22:26 +0100)
committerPilzAdam <pilzadam@minetest.net>
Tue, 3 Dec 2013 22:20:00 +0000 (23:20 +0100)
doc/lua_api.txt
src/script/lua_api/l_object.cpp

index 410998cc61fc2074e4dc9817ab7100e9fe956d2b..3505b463541b4eb6a51437fbb2f5679ed44e83e9 100644 (file)
@@ -1706,11 +1706,13 @@ Player-only: (no-op for other objects)
     {jump=bool,right=bool,left=bool,LMB=bool,RMB=bool,sneak=bool,aux1=bool,down=bool,up=bool}
 - get_player_control_bits(): returns integer with bit packed player pressed keys
     bit nr/meaning: 0/up ,1/down ,2/left ,3/right ,4/jump ,5/aux1 ,6/sneak ,7/LMB ,8/RMB
-- set_physics_override(speed, jump, gravity, sneak, sneak_glitch)
-    modifies per-player walking speed, jump height, and gravity.
-    Values default to 1 and act as offsets to the physics settings 
-    in minetest.conf. nil will keep the current setting.
-    sneak and sneak_glitch are booleans, default is true
+- set_physics_override({
+    speed = 1.0, -- multiplier to default value
+    jump = 1.0, -- multiplier to default value
+    gravity = 1.0, -- multiplier to default value
+    sneak = true, -- whether player can sneak
+    sneak_glitch = true, -- whether player can use the sneak glitch
+  })
 - hud_add(hud definition): add a HUD element described by HUD def, returns ID number on success
 - hud_remove(id): remove the HUD element of the specified id
 - hud_change(id, stat, value): change a value of a previously added HUD element
index 5e1517e46cf38c622f92ce9ac000ca49d427b657..3a990887b2b9bd76e44c966c6b9df735aaf68c95 100644 (file)
@@ -357,25 +357,27 @@ int ObjectRef::l_set_physics_override(lua_State *L)
        PlayerSAO *co = (PlayerSAO *) getobject(ref);
        if(co == NULL) return 0;
        // Do it
-       if(!lua_isnil(L, 2)){
-               co->m_physics_override_speed = lua_tonumber(L, 2);
-               co->m_physics_override_sent = false;
-       }
-       if(!lua_isnil(L, 3)){
-               co->m_physics_override_jump = lua_tonumber(L, 3);
-               co->m_physics_override_sent = false;
-       }
-       if(!lua_isnil(L, 4)){
-               co->m_physics_override_gravity = lua_tonumber(L, 4);
-               co->m_physics_override_sent = false;
-       }
-       if (lua_isboolean(L, 5)) {
-               co->m_physics_override_sneak = lua_toboolean(L, 5);
-               co->m_physics_override_sent = false;
-       }
-       if (lua_isboolean(L, 6)) {
-               co->m_physics_override_sneak_glitch = lua_toboolean(L, 6);
+       if (lua_istable(L, 2)) {
+               co->m_physics_override_speed = getfloatfield_default(L, 2, "speed", co->m_physics_override_speed);
+               co->m_physics_override_jump = getfloatfield_default(L, 2, "jump", co->m_physics_override_jump);
+               co->m_physics_override_gravity = getfloatfield_default(L, 2, "gravity", co->m_physics_override_gravity);
+               co->m_physics_override_sneak = getboolfield_default(L, 2, "sneak", co->m_physics_override_sneak);
+               co->m_physics_override_sneak_glitch = getboolfield_default(L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
                co->m_physics_override_sent = false;
+       } else {
+               // old, non-table format
+               if(!lua_isnil(L, 2)){
+                       co->m_physics_override_speed = lua_tonumber(L, 2);
+                       co->m_physics_override_sent = false;
+               }
+               if(!lua_isnil(L, 3)){
+                       co->m_physics_override_jump = lua_tonumber(L, 3);
+                       co->m_physics_override_sent = false;
+               }
+               if(!lua_isnil(L, 4)){
+                       co->m_physics_override_gravity = lua_tonumber(L, 4);
+                       co->m_physics_override_sent = false;
+               }
        }
        return 0;
 }