Skip to content

Commit

Permalink
script: Move SAO usability check so that it covers all functions (min…
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Apr 18, 2020
1 parent 4fb6b6a commit 87829cd
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ ObjectRef* ObjectRef::checkobject(lua_State *L, int narg)
ServerActiveObject* ObjectRef::getobject(ObjectRef *ref)
{
ServerActiveObject *co = ref->m_object;
if (co && co->isGone())
return NULL;
return co;
}

Expand All @@ -60,8 +62,6 @@ LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref)
return NULL;
if (obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY)
return NULL;
if (obj->isGone())
return NULL;
return (LuaEntitySAO*)obj;
}

Expand All @@ -72,8 +72,6 @@ PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref)
return NULL;
if (obj->getType() != ACTIVEOBJECT_TYPE_PLAYER)
return NULL;
if (obj->isGone())
return NULL;
return (PlayerSAO*)obj;
}

Expand Down Expand Up @@ -132,7 +130,6 @@ int ObjectRef::l_set_pos(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
//LuaEntitySAO *co = getluaobject(ref);
ServerActiveObject *co = getobject(ref);
if (co == NULL) return 0;
// pos
Expand All @@ -147,7 +144,6 @@ int ObjectRef::l_move_to(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
//LuaEntitySAO *co = getluaobject(ref);
ServerActiveObject *co = getobject(ref);
if (co == NULL) return 0;
// pos
Expand Down Expand Up @@ -1102,17 +1098,13 @@ int ObjectRef::l_add_player_velocity(lua_State *L)
ObjectRef *ref = checkobject(L, 1);
v3f vel = checkFloatPos(L, 2);

RemotePlayer *player = getplayer(ref);
PlayerSAO *co = getplayersao(ref);
if (!player || !co)
if (!co)
return 0;

session_t peer_id = player->getPeerId();
if (peer_id == PEER_ID_INEXISTENT)
return 0;
// Do it
co->setMaxSpeedOverride(vel);
getServer(L)->SendPlayerSpeed(peer_id, vel);
getServer(L)->SendPlayerSpeed(co->getPeerID(), vel);
return 0;
}

Expand Down

0 comments on commit 87829cd

Please sign in to comment.