/*-------------------------------------------------------------------------------------------------------------------------
| ULX ExLua for ULX SVN/ULib SVN by LuaTenshi
| Steam: [url]http://steamcommunity.com/profiles/76561198096713277[/url]
| Email: luatenshi@gmail.com
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.exlua( calling_ply, str )
local tab, out, s, p, err = {}, "", ""
local ply = calling_ply
if string.Trim(str) == "" or string.Trim(str) == "Lua Code" then ULib.tsayError( ply, "ExLua:1: Please enter some code to run." ) return end
if string.len(str) <= 3 then ULib.tsayError( ply, "ExLua:1: The string you entered is too short." ) return end
for v in string.gmatch(str, "%S+:") do v = string.Replace(v,":","") table.insert(tab, v) end
for k,v in pairs(tab) do
s = tostring(tab[k])
p,err = ULib.getUser(s,true,ply)
if p and not err then
out = string.Replace(str, s, "Entity(" .. tostring(p:EntIndex()) .. ")")
elseif p and err then
ULib.tsayError( ply, err )
end
end
local func = CompileString( out, "ExLua", false )
if type(func) == "function" and func and not err then
if Entity(p:EntIndex()) and IsValid(Entity(p:EntIndex())) then
local succ, err = pcall(func)
if err then ULib.tsayError( ply, err ) return end
if succ then
ulx.fancyLogAdmin( calling_ply, true, "#A ran some code." )
else
ulx.fancyLogAdmin( calling_ply, true, "#A attempted to run code." )
ULib.tsayError( ply, "ExLua:1: pcall returned false." )
end
else
ULib.tsayError( ply, "ExLua:1: The target entity has vanished." )
end
elseif func then
ULib.tsayError( ply, tostring(func) )
else
ULib.tsayError( ply, "ExLua:1: No callback found. This should not happen." )
end
end
local exlua = ulx.command( "Extra Utility", "ulx exlua", ulx.exlua, "!l" )
exlua:addParam{ type=ULib.cmds.StringArg, hint="Lua Code", ULib.cmds.takeRestOfLine }
exlua:defaultAccess( ULib.ACCESS_SUPERADMIN )
exlua:help( [[Run a lua script on the server.
Excepts player arguments such as a players name or the ULX keywords.
Accepted Keywords: ^, @, $10 ]] )