Skip to content

Commit 55a97f4

Browse files
sapierPilzAdam
sapier
authored andcommittedMay 19, 2013
Allow nil as puncher e.g. to do damage by tnt
1 parent 3e2efdf commit 55a97f4

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed
 

‎src/content_sao.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,14 @@ int LuaEntitySAO::punch(v3f dir,
673673
{
674674
setHP(getHP() - result.damage);
675675

676+
677+
std::string punchername = "nil";
678+
679+
if ( puncher != 0 )
680+
punchername = puncher->getDescription();
681+
676682
actionstream<<getDescription()<<" punched by "
677-
<<puncher->getDescription()<<", damage "<<result.damage
683+
<<punchername<<", damage "<<result.damage
678684
<<" hp, health now "<<getHP()<<" hp"<<std::endl;
679685

680686
{
@@ -1307,8 +1313,13 @@ int PlayerSAO::punch(v3f dir,
13071313
HitParams hitparams = getHitParams(m_armor_groups, toolcap,
13081314
time_from_last_punch);
13091315

1316+
std::string punchername = "nil";
1317+
1318+
if ( puncher != 0 )
1319+
punchername = puncher->getDescription();
1320+
13101321
actionstream<<"Player "<<m_player->getName()<<" punched by "
1311-
<<puncher->getDescription()<<", damage "<<hitparams.hp
1322+
<<punchername<<", damage "<<hitparams.hp
13121323
<<" HP"<<std::endl;
13131324

13141325
setHP(getHP() - hitparams.hp);

‎src/scriptapi_object.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,30 @@ int ObjectRef::l_moveto(lua_State *L)
182182
int ObjectRef::l_punch(lua_State *L)
183183
{
184184
ObjectRef *ref = checkobject(L, 1);
185-
ObjectRef *puncher_ref = checkobject(L, 2);
186185
ServerActiveObject *co = getobject(ref);
187-
ServerActiveObject *puncher = getobject(puncher_ref);
188186
if(co == NULL) return 0;
189-
if(puncher == NULL) return 0;
190-
v3f dir;
191-
if(lua_type(L, 5) != LUA_TTABLE)
187+
188+
ServerActiveObject *puncher = 0;
189+
v3f dir(0,0,0);
190+
191+
if (!lua_isnil(L,2)) {
192+
ObjectRef *puncher_ref = checkobject(L, 2);
193+
puncher = getobject(puncher_ref);
194+
if(puncher == NULL) return 0;
195+
192196
dir = co->getBasePosition() - puncher->getBasePosition();
193-
else
194-
dir = read_v3f(L, 5);
197+
}
198+
195199
float time_from_last_punch = 1000000;
196200
if(lua_isnumber(L, 3))
197201
time_from_last_punch = lua_tonumber(L, 3);
202+
198203
ToolCapabilities toolcap = read_tool_capabilities(L, 4);
204+
205+
if(lua_type(L, 5) == LUA_TTABLE)
206+
dir = read_v3f(L, 5);
199207
dir.normalize();
208+
200209
// Do it
201210
co->punch(dir, &toolcap, puncher, time_from_last_punch);
202211
return 0;

0 commit comments

Comments
 (0)
Please sign in to comment.