IsPlayerAdmin support, since admin was removed

# Conflicts:
#	src/lua_baselib.c
This commit is contained in:
TehRealSalt 2018-11-07 18:07:34 -05:00 committed by wolfy852
parent b59718d3ad
commit c70cf5908d
2 changed files with 18 additions and 4 deletions

View file

@ -8269,10 +8269,10 @@ static inline int lib_getenum(lua_State *L)
return 0;
LUA_PushUserdata(L, &players[serverplayer], META_PLAYER);
return 1;
} else if (fastcmp(word,"admin")) {
//if (!playeringame[adminplayer] || IsPlayerAdmin(serverplayer))
//return 0;
//LUA_PushUserdata(L, &players[adminplayer], META_PLAYER);
} else if (fastcmp(word,"admin")) { // BACKWARDS COMPATIBILITY HACK: This was replaced with IsPlayerAdmin(), but some 2.1 Lua scripts still use the admin variable. It now points to the first admin player in the array.
if (!playeringame[adminplayers[0]] || IsPlayerAdmin(serverplayer))
return 0;
LUA_PushUserdata(L, &players[adminplayers[0]], META_PLAYER);
return 1;
} else if (fastcmp(word,"emeralds")) {
lua_pushinteger(L, emeralds);

View file

@ -20,6 +20,9 @@
#include "m_random.h"
#include "s_sound.h"
#include "g_game.h"
#include "hu_stuff.h"
#include "console.h"
#include "d_netcmd.h" // IsPlayerAdmin
#include "lua_script.h"
#include "lua_libs.h"
@ -93,6 +96,16 @@ static int lib_evalMath(lua_State *L)
return 1;
}
static int lib_isPlayerAdmin(lua_State *L)
{
player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
//HUDSAFE
if (!player)
return LUA_ErrInvalid(L, "player_t");
lua_pushboolean(L, IsPlayerAdmin(player-players));
return 1;
}
// M_RANDOM
//////////////
@ -1983,6 +1996,7 @@ static int lib_gTicsToMilliseconds(lua_State *L)
static luaL_Reg lib[] = {
{"print", lib_print},
{"EvalMath", lib_evalMath},
{"IsPlayerAdmin", lib_isPlayerAdmin},
// m_random
{"P_RandomFixed",lib_pRandomFixed},