Fix ObjectRef:punch()

master
Perttu Ahola 2012-09-09 12:05:38 +03:00
parent 9696ed31a4
commit ac628c9b0a
2 changed files with 12 additions and 6 deletions

View File

@ -1087,6 +1087,7 @@ methods:
- punch(puncher, time_from_last_punch, tool_capabilities, direction) - punch(puncher, time_from_last_punch, tool_capabilities, direction)
^ puncher = an another ObjectRef, ^ puncher = an another ObjectRef,
^ time_from_last_punch = time since last punch action of the puncher ^ time_from_last_punch = time since last punch action of the puncher
^ direction: can be nil
- right_click(clicker); clicker = an another ObjectRef - right_click(clicker); clicker = an another ObjectRef
- get_hp(): returns number of hitpoints (2 * number of hearts) - get_hp(): returns number of hitpoints (2 * number of hearts)
- set_hp(hp): set number of hitpoints (2 * number of hearts) - set_hp(hp): set number of hitpoints (2 * number of hearts)

View File

@ -2542,7 +2542,7 @@ private:
return 0; 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) static int l_punch(lua_State *L)
{ {
ObjectRef *ref = checkobject(L, 1); ObjectRef *ref = checkobject(L, 1);
@ -2551,13 +2551,18 @@ private:
ServerActiveObject *puncher = getobject(puncher_ref); ServerActiveObject *puncher = getobject(puncher_ref);
if(co == NULL) return 0; if(co == NULL) return 0;
if(puncher == NULL) return 0; if(puncher == NULL) return 0;
ToolCapabilities toolcap = read_tool_capabilities(L, 3); v3f dir;
v3f dir = read_v3f(L, 4); if(lua_type(L, 5) != LUA_TTABLE)
dir = co->getBasePosition() - puncher->getBasePosition();
else
dir = read_v3f(L, 5);
float time_from_last_punch = 1000000; float time_from_last_punch = 1000000;
if(lua_isnumber(L, 5)) if(lua_isnumber(L, 3))
time_from_last_punch = lua_tonumber(L, 5); time_from_last_punch = lua_tonumber(L, 3);
ToolCapabilities toolcap = read_tool_capabilities(L, 4);
dir.normalize();
// Do it // Do it
puncher->punch(dir, &toolcap, puncher, time_from_last_punch); co->punch(dir, &toolcap, puncher, time_from_last_punch);
return 0; return 0;
} }