Add time_from_last_punch to Lua API
authorPerttu Ahola <celeron55@gmail.com>
Fri, 2 Dec 2011 09:51:41 +0000 (11:51 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Fri, 2 Dec 2011 09:51:41 +0000 (11:51 +0200)
data/mods/default/init.lua
src/content_sao.cpp
src/scriptapi.cpp
src/scriptapi.h

index c6c679b631089604ea173e38c1584a18666fb248..6788defa2aaf044798363d9349dec7713140dc3c 100644 (file)
 -- - getpos() -> {x=num, y=num, z=num}
 -- - setpos(pos); pos={x=num, y=num, z=num}
 -- - moveto(pos, continuous=false): interpolated move
--- - punch(puncher); puncher = an another ObjectRef
+-- - punch(puncher, time_from_last_punch)
+--   ^ puncher = an another ObjectRef,
+--   ^ time_from_last_punch = time since last punch action of the puncher
 -- - right_click(clicker); clicker = an another ObjectRef
 -- - get_wield_digging_properties() -> digging property table
 -- - add_to_inventory_later(itemstring): like above, but after callback returns (only allowed for craftitem callbacks)
index e0f230bbcae1dc2286e55d37afa1037b7fbf95e5..171e315af87ea40791c48da49603440eb8a3e9e6 100644 (file)
@@ -1678,7 +1678,7 @@ void LuaEntitySAO::punch(ServerActiveObject *puncher, float time_from_last_punch
        if(!m_registered)
                return;
        lua_State *L = m_env->getLua();
-       scriptapi_luaentity_punch(L, m_id, puncher);
+       scriptapi_luaentity_punch(L, m_id, puncher, time_from_last_punch);
 }
 
 void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
index 951ff6f83b89eda8e6ebbd5e6674493c78d1d501..dce454ea4aa40500eccce5cda2c709a540ff07c4 100644 (file)
@@ -3208,9 +3208,9 @@ void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime)
                script_error(L, "error running function 'on_step': %s\n", lua_tostring(L, -1));
 }
 
-// Calls entity:on_punch(ObjectRef puncher)
+// Calls entity:on_punch(ObjectRef puncher, time_from_last_punch)
 void scriptapi_luaentity_punch(lua_State *L, u16 id,
-               ServerActiveObject *puncher)
+               ServerActiveObject *puncher, float time_from_last_punch)
 {
        realitycheck(L);
        assert(lua_checkstack(L, 20));
@@ -3228,8 +3228,9 @@ void scriptapi_luaentity_punch(lua_State *L, u16 id,
        luaL_checktype(L, -1, LUA_TFUNCTION);
        lua_pushvalue(L, object); // self
        objectref_get_or_create(L, puncher); // Clicker reference
+       lua_pushnumber(L, time_from_last_punch);
        // Call with 2 arguments, 0 results
-       if(lua_pcall(L, 2, 0, 0))
+       if(lua_pcall(L, 3, 0, 0))
                script_error(L, "error running function 'on_punch': %s\n", lua_tostring(L, -1));
 }
 
index fe9329d75bb4746d41cd38aee41ffb632f55f40f..2baf6f8361d8cfbb9076aea05d60b4e099cc2ab4 100644 (file)
@@ -83,7 +83,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
                LuaEntityProperties *prop);
 void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime);
 void scriptapi_luaentity_punch(lua_State *L, u16 id,
-               ServerActiveObject *puncher);
+               ServerActiveObject *puncher, float time_from_last_punch);
 void scriptapi_luaentity_rightclick(lua_State *L, u16 id,
                ServerActiveObject *clicker);