aboutsummaryrefslogtreecommitdiff
path: root/src/scriptapi_object.cpp
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2013-05-05 01:44:55 +0200
committerPilzAdam <pilzadam@minetest.net>2013-05-20 01:18:45 +0200
commit55a97f4605a263f4b670b447cd4af9ffa1a8d472 (patch)
tree86b22a0d22480324c1732a883d71f34dbbc6506a /src/scriptapi_object.cpp
parent3e2efdf18ab95d3c88f66c7a1f6caf6b1c7231e5 (diff)
downloadminetest-55a97f4605a263f4b670b447cd4af9ffa1a8d472.tar.gz
minetest-55a97f4605a263f4b670b447cd4af9ffa1a8d472.tar.bz2
minetest-55a97f4605a263f4b670b447cd4af9ffa1a8d472.zip
Allow nil as puncher e.g. to do damage by tnt
Diffstat (limited to 'src/scriptapi_object.cpp')
-rw-r--r--src/scriptapi_object.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp
index 4dfdeb8c8..851f1761f 100644
--- a/src/scriptapi_object.cpp
+++ b/src/scriptapi_object.cpp
@@ -182,21 +182,30 @@ int ObjectRef::l_moveto(lua_State *L)
int ObjectRef::l_punch(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
- ObjectRef *puncher_ref = checkobject(L, 2);
ServerActiveObject *co = getobject(ref);
- ServerActiveObject *puncher = getobject(puncher_ref);
if(co == NULL) return 0;
- if(puncher == NULL) return 0;
- v3f dir;
- if(lua_type(L, 5) != LUA_TTABLE)
+
+ ServerActiveObject *puncher = 0;
+ v3f dir(0,0,0);
+
+ if (!lua_isnil(L,2)) {
+ ObjectRef *puncher_ref = checkobject(L, 2);
+ puncher = getobject(puncher_ref);
+ if(puncher == NULL) return 0;
+
dir = co->getBasePosition() - puncher->getBasePosition();
- else
- dir = read_v3f(L, 5);
+ }
+
float time_from_last_punch = 1000000;
if(lua_isnumber(L, 3))
time_from_last_punch = lua_tonumber(L, 3);
+
ToolCapabilities toolcap = read_tool_capabilities(L, 4);
+
+ if(lua_type(L, 5) == LUA_TTABLE)
+ dir = read_v3f(L, 5);
dir.normalize();
+
// Do it
co->punch(dir, &toolcap, puncher, time_from_last_punch);
return 0;