Skip to content

Commit e51ad53

Browse files
committedDec 3, 2013
Use a table in set_physics_override()
1 parent 15be265 commit e51ad53

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed
 

‎doc/lua_api.txt

+7-5
Original file line numberDiff line numberDiff line change
@@ -1706,11 +1706,13 @@ Player-only: (no-op for other objects)
17061706
{jump=bool,right=bool,left=bool,LMB=bool,RMB=bool,sneak=bool,aux1=bool,down=bool,up=bool}
17071707
- get_player_control_bits(): returns integer with bit packed player pressed keys
17081708
bit nr/meaning: 0/up ,1/down ,2/left ,3/right ,4/jump ,5/aux1 ,6/sneak ,7/LMB ,8/RMB
1709-
- set_physics_override(speed, jump, gravity, sneak, sneak_glitch)
1710-
modifies per-player walking speed, jump height, and gravity.
1711-
Values default to 1 and act as offsets to the physics settings
1712-
in minetest.conf. nil will keep the current setting.
1713-
sneak and sneak_glitch are booleans, default is true
1709+
- set_physics_override({
1710+
speed = 1.0, -- multiplier to default value
1711+
jump = 1.0, -- multiplier to default value
1712+
gravity = 1.0, -- multiplier to default value
1713+
sneak = true, -- whether player can sneak
1714+
sneak_glitch = true, -- whether player can use the sneak glitch
1715+
})
17141716
- hud_add(hud definition): add a HUD element described by HUD def, returns ID number on success
17151717
- hud_remove(id): remove the HUD element of the specified id
17161718
- hud_change(id, stat, value): change a value of a previously added HUD element

‎src/script/lua_api/l_object.cpp

+20-18
Original file line numberDiff line numberDiff line change
@@ -357,25 +357,27 @@ int ObjectRef::l_set_physics_override(lua_State *L)
357357
PlayerSAO *co = (PlayerSAO *) getobject(ref);
358358
if(co == NULL) return 0;
359359
// Do it
360-
if(!lua_isnil(L, 2)){
361-
co->m_physics_override_speed = lua_tonumber(L, 2);
362-
co->m_physics_override_sent = false;
363-
}
364-
if(!lua_isnil(L, 3)){
365-
co->m_physics_override_jump = lua_tonumber(L, 3);
366-
co->m_physics_override_sent = false;
367-
}
368-
if(!lua_isnil(L, 4)){
369-
co->m_physics_override_gravity = lua_tonumber(L, 4);
370-
co->m_physics_override_sent = false;
371-
}
372-
if (lua_isboolean(L, 5)) {
373-
co->m_physics_override_sneak = lua_toboolean(L, 5);
374-
co->m_physics_override_sent = false;
375-
}
376-
if (lua_isboolean(L, 6)) {
377-
co->m_physics_override_sneak_glitch = lua_toboolean(L, 6);
360+
if (lua_istable(L, 2)) {
361+
co->m_physics_override_speed = getfloatfield_default(L, 2, "speed", co->m_physics_override_speed);
362+
co->m_physics_override_jump = getfloatfield_default(L, 2, "jump", co->m_physics_override_jump);
363+
co->m_physics_override_gravity = getfloatfield_default(L, 2, "gravity", co->m_physics_override_gravity);
364+
co->m_physics_override_sneak = getboolfield_default(L, 2, "sneak", co->m_physics_override_sneak);
365+
co->m_physics_override_sneak_glitch = getboolfield_default(L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
378366
co->m_physics_override_sent = false;
367+
} else {
368+
// old, non-table format
369+
if(!lua_isnil(L, 2)){
370+
co->m_physics_override_speed = lua_tonumber(L, 2);
371+
co->m_physics_override_sent = false;
372+
}
373+
if(!lua_isnil(L, 3)){
374+
co->m_physics_override_jump = lua_tonumber(L, 3);
375+
co->m_physics_override_sent = false;
376+
}
377+
if(!lua_isnil(L, 4)){
378+
co->m_physics_override_gravity = lua_tonumber(L, 4);
379+
co->m_physics_override_sent = false;
380+
}
379381
}
380382
return 0;
381383
}

0 commit comments

Comments
 (0)
Please sign in to comment.