aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-04-18 17:21:58 +0200
committerGitHub <noreply@github.com>2020-04-18 17:21:58 +0200
commit87829cd7446dd13d1dfd27d96e0b4aeb2f234e33 (patch)
tree58938f6852c33fa61f8ca9d78d7f8e1e812bc4ed /src/script/lua_api
parent4fb6b6afa7329676166bbbccb897bd625155d038 (diff)
downloadminetest-87829cd7446dd13d1dfd27d96e0b4aeb2f234e33.tar.gz
minetest-87829cd7446dd13d1dfd27d96e0b4aeb2f234e33.tar.bz2
minetest-87829cd7446dd13d1dfd27d96e0b4aeb2f234e33.zip
script: Move SAO usability check so that it covers all functions (#9698)
see also 91eef646a59575bd9ae792e257bb6ad12fafc0b1
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_object.cpp16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index bb1456ac9..d7afb84da 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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
@@ -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
@@ -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;
}