mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-03-24 11:42:03 +00:00
Amendment to G_RemovePlayer to preserve lua error handlers
This commit is contained in:
parent
22f42efb61
commit
95359fef51
1 changed files with 11 additions and 6 deletions
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue