diff options
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r-- | src/scriptapi.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index e87c35482..09900ce1f 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -2543,7 +2543,7 @@ private: return 0; } - // punch(self, puncher, tool_capabilities, direction, time_from_last_punch) + // punch(self, puncher, time_from_last_punch, tool_capabilities, dir) static int l_punch(lua_State *L) { ObjectRef *ref = checkobject(L, 1); @@ -2552,13 +2552,18 @@ private: ServerActiveObject *puncher = getobject(puncher_ref); if(co == NULL) return 0; if(puncher == NULL) return 0; - ToolCapabilities toolcap = read_tool_capabilities(L, 3); - v3f dir = read_v3f(L, 4); + v3f dir; + if(lua_type(L, 5) != LUA_TTABLE) + dir = co->getBasePosition() - puncher->getBasePosition(); + else + dir = read_v3f(L, 5); float time_from_last_punch = 1000000; - if(lua_isnumber(L, 5)) - time_from_last_punch = lua_tonumber(L, 5); + if(lua_isnumber(L, 3)) + time_from_last_punch = lua_tonumber(L, 3); + ToolCapabilities toolcap = read_tool_capabilities(L, 4); + dir.normalize(); // Do it - puncher->punch(dir, &toolcap, puncher, time_from_last_punch); + co->punch(dir, &toolcap, puncher, time_from_last_punch); return 0; } @@ -6479,7 +6484,7 @@ bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name) } void scriptapi_luaentity_activate(lua_State *L, u16 id, - const std::string &staticdata) + const std::string &staticdata, u32 dtime_s) { realitycheck(L); assert(lua_checkstack(L, 20)); @@ -6497,8 +6502,9 @@ void scriptapi_luaentity_activate(lua_State *L, u16 id, luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self lua_pushlstring(L, staticdata.c_str(), staticdata.size()); - // Call with 2 arguments, 0 results - if(lua_pcall(L, 2, 0, 0)) + lua_pushinteger(L, dtime_s); + // Call with 3 arguments, 0 results + if(lua_pcall(L, 3, 0, 0)) script_error(L, "error running function on_activate: %s\n", lua_tostring(L, -1)); } |