Predefined variables list
Client-side
Server-side
Shared
Lua Predefined variables
Section Lua Predefined variables_G -- returns a table of all global variablescoroutine -- returns a table containing functions for threadsdebug -- returns a table containing debug functionsmath -- returns a table that contains mathematical functionsstring -- returns a table containing functions for stringstable -- returns a table that contains functions for tables_VERSION -- returns a string of the version of lua in format "Lua 5.1"self -- used in methodsarg -- used in functions which use '...' as an argument (https://www.lua.org/pil/5.2.html)MTA Predefined variables
Section MTA Predefined variablesGlobal
Section Global shared
exports -- returns a table of resource names containing all export functionsresource -- returns a resource element of the resource the snippet was executed inresourceRoot -- returns a resource root element of the resource the snippet was executed inresourceName -- returns the name of the resource the snippet was executed inroot -- returns the root element of the server client
guiRoot -- returns the root element of all GUI elements.localPlayer -- returns the player element of the local player.Event Handlers
Section Event Handlers shared
source -- The player or element the event was attached tothis -- Element, which was attached function-handler.eventName -- the name of the event ("onResourceStart", "onPlayerWasted" etc.)sourceResource -- the resource that called the eventsourceResourceRoot -- the root of the resource that called the event server
client -- the client that called the eventPlease note, the above pre-defined variables may only be accessible in the relevant scope (i.e, an event handler callback function).
Further functions defined within that scope may not have access to these pre-defined variables at the time of their execution.
For this reason, you should always explicitly redefine pre-defined variables as local variables,
to ensure they are always available to new functions declared within that scope - for example:
function init() local player = source -- source is a pre-defined variable for this event, containing the player element
local func = function() print(source) -- prints 'nil', source isn't available anymore print(player) -- prints player element end
setTimer(func, 1000, 1) -- run above function after 1 secondendaddEventHandler("onPlayerResourceStart", root, init)Timer callbacks
Section Timer callbacks shared
sourceTimer -- current timer in callback function.HTTP
Section HTTPList Predefined variables available in the HTTP files (more info about it).
requestHeaders -- table, contains all HTTP headlines current page.form -- table, contains all POST and GET settings, transferred current page.cookies -- table, contains all COOKIE, transferred current page.hostname -- string, contains IP or name host, which requested current page.url -- string, URL current page.user -- element, account user, which requested current page.