Allow nil as puncher e.g. to do damage by tnt
parent
3e2efdf18a
commit
55a97f4605
|
@ -673,8 +673,14 @@ int LuaEntitySAO::punch(v3f dir,
|
||||||
{
|
{
|
||||||
setHP(getHP() - result.damage);
|
setHP(getHP() - result.damage);
|
||||||
|
|
||||||
|
|
||||||
|
std::string punchername = "nil";
|
||||||
|
|
||||||
|
if ( puncher != 0 )
|
||||||
|
punchername = puncher->getDescription();
|
||||||
|
|
||||||
actionstream<<getDescription()<<" punched by "
|
actionstream<<getDescription()<<" punched by "
|
||||||
<<puncher->getDescription()<<", damage "<<result.damage
|
<<punchername<<", damage "<<result.damage
|
||||||
<<" hp, health now "<<getHP()<<" hp"<<std::endl;
|
<<" hp, health now "<<getHP()<<" hp"<<std::endl;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -1307,8 +1313,13 @@ int PlayerSAO::punch(v3f dir,
|
||||||
HitParams hitparams = getHitParams(m_armor_groups, toolcap,
|
HitParams hitparams = getHitParams(m_armor_groups, toolcap,
|
||||||
time_from_last_punch);
|
time_from_last_punch);
|
||||||
|
|
||||||
|
std::string punchername = "nil";
|
||||||
|
|
||||||
|
if ( puncher != 0 )
|
||||||
|
punchername = puncher->getDescription();
|
||||||
|
|
||||||
actionstream<<"Player "<<m_player->getName()<<" punched by "
|
actionstream<<"Player "<<m_player->getName()<<" punched by "
|
||||||
<<puncher->getDescription()<<", damage "<<hitparams.hp
|
<<punchername<<", damage "<<hitparams.hp
|
||||||
<<" HP"<<std::endl;
|
<<" HP"<<std::endl;
|
||||||
|
|
||||||
setHP(getHP() - hitparams.hp);
|
setHP(getHP() - hitparams.hp);
|
||||||
|
|
|
@ -182,21 +182,30 @@ int ObjectRef::l_moveto(lua_State *L)
|
||||||
int ObjectRef::l_punch(lua_State *L)
|
int ObjectRef::l_punch(lua_State *L)
|
||||||
{
|
{
|
||||||
ObjectRef *ref = checkobject(L, 1);
|
ObjectRef *ref = checkobject(L, 1);
|
||||||
ObjectRef *puncher_ref = checkobject(L, 2);
|
|
||||||
ServerActiveObject *co = getobject(ref);
|
ServerActiveObject *co = getobject(ref);
|
||||||
ServerActiveObject *puncher = getobject(puncher_ref);
|
|
||||||
if(co == NULL) return 0;
|
if(co == NULL) return 0;
|
||||||
if(puncher == NULL) return 0;
|
|
||||||
v3f dir;
|
ServerActiveObject *puncher = 0;
|
||||||
if(lua_type(L, 5) != LUA_TTABLE)
|
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();
|
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, 3))
|
if(lua_isnumber(L, 3))
|
||||||
time_from_last_punch = lua_tonumber(L, 3);
|
time_from_last_punch = lua_tonumber(L, 3);
|
||||||
|
|
||||||
ToolCapabilities toolcap = read_tool_capabilities(L, 4);
|
ToolCapabilities toolcap = read_tool_capabilities(L, 4);
|
||||||
|
|
||||||
|
if(lua_type(L, 5) == LUA_TTABLE)
|
||||||
|
dir = read_v3f(L, 5);
|
||||||
dir.normalize();
|
dir.normalize();
|
||||||
|
|
||||||
// Do it
|
// Do it
|
||||||
co->punch(dir, &toolcap, puncher, time_from_last_punch);
|
co->punch(dir, &toolcap, puncher, time_from_last_punch);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue