Amendment to G_RemovePlayer to preserve lua error handlers

This commit is contained in:
CobaltBW 2021-07-15 15:19:47 -07:00
parent 22f42efb61
commit 95359fef51

View file

@ -3482,20 +3482,25 @@ static int lib_gAddPlayer(lua_State *L)
static int lib_gRemovePlayer(lua_State *L)
{
UINT8 pnum = -1;
if (!lua_isnoneornil(L, 1))
pnum = luaL_checkinteger(L, 1);
if (&players[pnum])
else // No argument
return luaL_error(L, "argument #1 not given (expected number)");
if (pnum >= MAXPLAYERS) // Out of range
return luaL_error(L, "playernum %d out of range (0 - %d)", pnum, MAXPLAYERS-1);
if (playeringame[pnum]) // Found player
{
if (players[pnum].bot != BOT_NONE && players[pnum].removing == false)
if (players[pnum].bot == BOT_NONE) // Can't remove clients.
return luaL_error(L, "G_RemovePlayer can only be used on players with a bot value other than BOT_NONE.");
else
{
players[pnum].removing = true; // This function can be run in players.iterate(), which isn't equipped to deal with players being removed mid-process. Instead we'll remove the player at the beginning of the next ticframe.
players[pnum].removing = true;
lua_pushboolean(L, true);
return 1;
}
}
lua_pushboolean(L, false);
return 1;
// Fell through. Invalid player
return LUA_ErrInvalid(L, "player_t");
}