Fix core.get_player_by_name() returning unusable ObjectRef

Followup to the previous commit.
master
sfan5 2020-03-03 21:14:47 +01:00
parent 1761d7d0f8
commit 6d8e2d2483
1 changed files with 4 additions and 8 deletions

View 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;