Fix core.get_player_by_name() returning unusable ObjectRef
authorsfan5 <sfan5@live.de>
Tue, 3 Mar 2020 20:14:47 +0000 (21:14 +0100)
committersfan5 <sfan5@live.de>
Tue, 3 Mar 2020 20:21:41 +0000 (21:21 +0100)
Followup to the previous commit.

src/script/lua_api/l_env.cpp

index 6e67e547bf9792720d30740a0a8d3b946acc36df..a175569d8bfea347e724852b89e211b11ed43f19 100644 (file)
@@ -667,15 +667,11 @@ int ModApiEnvMod::l_get_player_by_name(lua_State *L)
        // Do it
        const char *name = luaL_checkstring(L, 1);
        RemotePlayer *player = env->getPlayer(name);
-       if (player == NULL){
-               lua_pushnil(L);
-               return 1;
-       }
+       if (!player || player->getPeerId() == PEER_ID_INEXISTENT)
+               return 0;
        PlayerSAO *sao = player->getPlayerSAO();
-       if(sao == NULL){
-               lua_pushnil(L);
-               return 1;
-       }
+       if (!sao || sao->isGone())
+               return 0;
        // Put player on stack
        getScriptApiBase(L)->objectrefGetOrCreate(L, sao);
        return 1;