diff --git a/src/dehacked.c b/src/dehacked.c index 2d0176421..094329668 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -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); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index e8e8fd020..892974bdc 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -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},