diff options
author | MirceaKitsune <sonichedgehog_hyperblast00@yahoo.com> | 2012-11-22 21:01:31 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-11-25 19:14:24 +0200 |
commit | 3d1c481f0bdf03b59871237d810685278e87613b (patch) | |
tree | fe49c10e926b1e452e4f98561a148e2f145c27e9 /src/scriptapi.cpp | |
parent | 756db8174aa6a05eb998cfcec8eb5127053c5ea9 (diff) | |
download | minetest-3d1c481f0bdf03b59871237d810685278e87613b.tar.gz minetest-3d1c481f0bdf03b59871237d810685278e87613b.tar.bz2 minetest-3d1c481f0bdf03b59871237d810685278e87613b.zip |
RealBadAngel's patch which allows the lua api to read pressed player keys. This should make it possible to change the player's animation based on what he is doing
Correct lua api version number
Always update animations and attachments after the entity is added to scene client side. Fixes animations not being applied in client initialization for some reason. Attachments should be re-tested now just to be safe.
Fix a segmentation fault caused by reaching materials that didn't exist in a loop for setting texture
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r-- | src/scriptapi.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 2b2ccfcec..91100d311 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -3025,7 +3025,54 @@ private: lua_pushlstring(L, formspec.c_str(), formspec.size()); return 1; } - + + // get_player_control(self) + static int l_get_player_control(lua_State *L) + { + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if(player == NULL){ + lua_pushlstring(L, "", 0); + return 1; + } + // Do it + PlayerControl control = player->getPlayerControl(); + lua_newtable(L); + lua_pushboolean(L, control.up); + lua_setfield(L, -2, "up"); + lua_pushboolean(L, control.down); + lua_setfield(L, -2, "down"); + lua_pushboolean(L, control.left); + lua_setfield(L, -2, "left"); + lua_pushboolean(L, control.right); + lua_setfield(L, -2, "right"); + lua_pushboolean(L, control.jump); + lua_setfield(L, -2, "jump"); + lua_pushboolean(L, control.aux1); + lua_setfield(L, -2, "aux1"); + lua_pushboolean(L, control.sneak); + lua_setfield(L, -2, "sneak"); + lua_pushboolean(L, control.LMB); + lua_setfield(L, -2, "LMB"); + lua_pushboolean(L, control.RMB); + lua_setfield(L, -2, "RMB"); + return 1; + } + + // get_player_control_bits(self) + static int l_get_player_control_bits(lua_State *L) + { + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if(player == NULL){ + lua_pushlstring(L, "", 0); + return 1; + } + // Do it + lua_pushnumber(L, player->keyPressed); + return 1; + } + public: ObjectRef(ServerActiveObject *object): m_object(object) @@ -3128,6 +3175,8 @@ const luaL_reg ObjectRef::methods[] = { method(ObjectRef, get_look_yaw), method(ObjectRef, set_inventory_formspec), method(ObjectRef, get_inventory_formspec), + method(ObjectRef, get_player_control), + method(ObjectRef, get_player_control_bits), {0,0} }; |