https://wiki.multitheftauto.com/api.php?action=feedcontributions&user=Borov&feedformat=atomMulti Theft Auto: Wiki - User contributions [en]2024-03-19T04:03:53ZUser contributionsMediaWiki 1.39.3https://wiki.multitheftauto.com/index.php?title=GuiSetEnabled&diff=16913GuiSetEnabled2008-05-27T02:14:05Z<p>Borov: New page: --place holder--</p>
<hr />
<div>--place holder--</div>Borovhttps://wiki.multitheftauto.com/index.php?title=AddEventHandler&diff=16828AddEventHandler2008-05-23T21:05:17Z<p>Borov: /* Optional Arguments */</p>
<hr />
<div>__NOTOC__ <br />
{{Server client function}}<br />
{{Note_box|It is strongly advised that you do not use the same name for your handler function as the event name, as this can lead to confusion if multiple handler functions are used.}}<br />
This function will add an [[event]] handler. An event handler is a function that will be called when the event it's attached to is triggered. See [[event system]] for more information on how the event system works.<br />
<br />
Event handlers are functions that are called when a particular event happens. Each event specifies a specific set of variables that are passed to the event handler and can be read by your function. The following global variables are available for use in handler functions:<br />
*'''source''': the element that triggered the event<br />
*'''this''': the element that the event handler is attached to<br />
*'''sourceResource''': the resource that triggered the event<br />
*'''sourceResourceRoot''': the root element of the resource that triggered the event<br />
*'''client''': the client that triggered the event using [[triggerServerEvent]]. Not set if the event was not triggered from a client.<br />
<br />
It is important to remember that events pass up and down the element tree. An event triggered on the root element is triggered on every element in the tree. An event triggered on any other element is triggered on its ancestors (its parent element and its parent's parent etc) and its children, grandchildren and great-grandchildren. You can use the ''getPropagated'' argument to specify if you wish your handler to receive events that have propagated up or down the tree.<br />
<br />
The order in which event handlers are triggered is undefined, you should not rely on one event handler being executed before another.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool addEventHandler ( string eventName, element attachedTo, function handlerFunction, [bool getPropagated = true] ) <br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''eventName:''' The name of the [[event]] you want to attach the handler function to.<br />
*'''attachedTo:''' The [[element]] you wish to attach the handler to. The handler will only be called when the event it is attached to is triggered for this element, or one of its children. Often, this can be the root element (meaning the handler will be called when the event is triggered for ''any'' element).<br />
*'''handlerFunction:''' The handler function you wish to call when the event is triggered. This function will be passed all of the event's parameters as arguments, but it isn't required that it takes all of them.<br />
<br />
===Optional Arguments===<br />
*'''getPropagated:''' A boolean representing whether the handler will be triggered if the event was propagated down the tree (starting from the source), and not triggered directly on attachedTo (that is, handlers attached with this argument set to ''false'' will only be triggered if ''source == this'').<br />
<br />
===Returns===<br />
Returns ''true'' if the event handler was attached successfully. Returns ''false'' if the specified event could not be found or any parameters were invalid.<br />
<br />
==Example==<br />
<section name="Server" class="server" show="true"><br />
This serverside example sends a message to everyone in the server when a player spawns.<br />
<syntaxhighlight lang="lua"><br />
-- get the root element<br />
rootElement = getRootElement()<br />
-- define our handler function<br />
function onSpawnpointUseHandler ( thePlayer )<br />
-- get the player's name<br />
local playerName = getClientName( thePlayer )<br />
-- output in the chat box that they've spawned<br />
outputChatBox ( playerName .. " has spawned!" )<br />
end<br />
-- add the defined onSpawnpointUseHandler function as a handler to the onSpawnPointUse event (triggered when any player spawns at a spawnpoint)<br />
addEventHandler( "onSpawnpointUse", rootElement, onSpawnpointUseHandler )<br />
</syntaxhighlight><br />
</section><br />
<br />
==See Also==<br />
{{Event_functions}}</div>Borovhttps://wiki.multitheftauto.com/index.php?title=AddEventHandler&diff=16827AddEventHandler2008-05-23T21:01:24Z<p>Borov: /* Optional Arguments */</p>
<hr />
<div>__NOTOC__ <br />
{{Server client function}}<br />
{{Note_box|It is strongly advised that you do not use the same name for your handler function as the event name, as this can lead to confusion if multiple handler functions are used.}}<br />
This function will add an [[event]] handler. An event handler is a function that will be called when the event it's attached to is triggered. See [[event system]] for more information on how the event system works.<br />
<br />
Event handlers are functions that are called when a particular event happens. Each event specifies a specific set of variables that are passed to the event handler and can be read by your function. The following global variables are available for use in handler functions:<br />
*'''source''': the element that triggered the event<br />
*'''this''': the element that the event handler is attached to<br />
*'''sourceResource''': the resource that triggered the event<br />
*'''sourceResourceRoot''': the root element of the resource that triggered the event<br />
*'''client''': the client that triggered the event using [[triggerServerEvent]]. Not set if the event was not triggered from a client.<br />
<br />
It is important to remember that events pass up and down the element tree. An event triggered on the root element is triggered on every element in the tree. An event triggered on any other element is triggered on its ancestors (its parent element and its parent's parent etc) and its children, grandchildren and great-grandchildren. You can use the ''getPropagated'' argument to specify if you wish your handler to receive events that have propagated up or down the tree.<br />
<br />
The order in which event handlers are triggered is undefined, you should not rely on one event handler being executed before another.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool addEventHandler ( string eventName, element attachedTo, function handlerFunction, [bool getPropagated = true] ) <br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''eventName:''' The name of the [[event]] you want to attach the handler function to.<br />
*'''attachedTo:''' The [[element]] you wish to attach the handler to. The handler will only be called when the event it is attached to is triggered for this element, or one of its children. Often, this can be the root element (meaning the handler will be called when the event is triggered for ''any'' element).<br />
*'''handlerFunction:''' The handler function you wish to call when the event is triggered. This function will be passed all of the event's parameters as arguments, but it isn't required that it takes all of them.<br />
<br />
===Optional Arguments===<br />
*'''getPropagated:''' A boolean representing whether the handler will be triggered if the event was propagated down the tree starting from source, and not triggered directly on attachedTo (that is, handlers attached with this argument set to ''false'' will only be triggered if ''source == this'').<br />
<br />
===Returns===<br />
Returns ''true'' if the event handler was attached successfully. Returns ''false'' if the specified event could not be found or any parameters were invalid.<br />
<br />
==Example==<br />
<section name="Server" class="server" show="true"><br />
This serverside example sends a message to everyone in the server when a player spawns.<br />
<syntaxhighlight lang="lua"><br />
-- get the root element<br />
rootElement = getRootElement()<br />
-- define our handler function<br />
function onSpawnpointUseHandler ( thePlayer )<br />
-- get the player's name<br />
local playerName = getClientName( thePlayer )<br />
-- output in the chat box that they've spawned<br />
outputChatBox ( playerName .. " has spawned!" )<br />
end<br />
-- add the defined onSpawnpointUseHandler function as a handler to the onSpawnPointUse event (triggered when any player spawns at a spawnpoint)<br />
addEventHandler( "onSpawnpointUse", rootElement, onSpawnpointUseHandler )<br />
</syntaxhighlight><br />
</section><br />
<br />
==See Also==<br />
{{Event_functions}}</div>Borovhttps://wiki.multitheftauto.com/index.php?title=AddEventHandler&diff=16826AddEventHandler2008-05-23T20:54:41Z<p>Borov: /* Optional Arguments */</p>
<hr />
<div>__NOTOC__ <br />
{{Server client function}}<br />
{{Note_box|It is strongly advised that you do not use the same name for your handler function as the event name, as this can lead to confusion if multiple handler functions are used.}}<br />
This function will add an [[event]] handler. An event handler is a function that will be called when the event it's attached to is triggered. See [[event system]] for more information on how the event system works.<br />
<br />
Event handlers are functions that are called when a particular event happens. Each event specifies a specific set of variables that are passed to the event handler and can be read by your function. The following global variables are available for use in handler functions:<br />
*'''source''': the element that triggered the event<br />
*'''this''': the element that the event handler is attached to<br />
*'''sourceResource''': the resource that triggered the event<br />
*'''sourceResourceRoot''': the root element of the resource that triggered the event<br />
*'''client''': the client that triggered the event using [[triggerServerEvent]]. Not set if the event was not triggered from a client.<br />
<br />
It is important to remember that events pass up and down the element tree. An event triggered on the root element is triggered on every element in the tree. An event triggered on any other element is triggered on its ancestors (its parent element and its parent's parent etc) and its children, grandchildren and great-grandchildren. You can use the ''getPropagated'' argument to specify if you wish your handler to receive events that have propagated up or down the tree.<br />
<br />
The order in which event handlers are triggered is undefined, you should not rely on one event handler being executed before another.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
bool addEventHandler ( string eventName, element attachedTo, function handlerFunction, [bool getPropagated = true] ) <br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''eventName:''' The name of the [[event]] you want to attach the handler function to.<br />
*'''attachedTo:''' The [[element]] you wish to attach the handler to. The handler will only be called when the event it is attached to is triggered for this element, or one of its children. Often, this can be the root element (meaning the handler will be called when the event is triggered for ''any'' element).<br />
*'''handlerFunction:''' The handler function you wish to call when the event is triggered. This function will be passed all of the event's parameters as arguments, but it isn't required that it takes all of them.<br />
<br />
===Optional Arguments===<br />
*'''getPropagated:''' A boolean representing whether the handler will be triggered if the event was not triggered directly on attachedTo (that is, handlers attached with this argument set to ''false'' will only be triggered if ''source == this'').<br />
<br />
===Returns===<br />
Returns ''true'' if the event handler was attached successfully. Returns ''false'' if the specified event could not be found or any parameters were invalid.<br />
<br />
==Example==<br />
<section name="Server" class="server" show="true"><br />
This serverside example sends a message to everyone in the server when a player spawns.<br />
<syntaxhighlight lang="lua"><br />
-- get the root element<br />
rootElement = getRootElement()<br />
-- define our handler function<br />
function onSpawnpointUseHandler ( thePlayer )<br />
-- get the player's name<br />
local playerName = getClientName( thePlayer )<br />
-- output in the chat box that they've spawned<br />
outputChatBox ( playerName .. " has spawned!" )<br />
end<br />
-- add the defined onSpawnpointUseHandler function as a handler to the onSpawnPointUse event (triggered when any player spawns at a spawnpoint)<br />
addEventHandler( "onSpawnpointUse", rootElement, onSpawnpointUseHandler )<br />
</syntaxhighlight><br />
</section><br />
<br />
==See Also==<br />
{{Event_functions}}</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element/Collision_shape&diff=16812Element/Collision shape2008-05-21T21:24:55Z<p>Borov: /* XML syntax */</p>
<hr />
<div>__NOTOC__<br />
The collision shape class represents invisible collision detection shapes that can be created in the GTA world. Collision shapes are typically used to detect physical entities moving through them and perform actions when they do.<br />
<br />
The element types for this class are '''colcube''', '''colcube''', '''colrectangle''', '''colcuboid''' and '''colcircle'''.<br />
<br />
Colshapes cannot have their corners/radius specified via XML currently, which makes their xml representation essentially useless.<br />
<br />
==XML syntax==<br />
<syntaxhighlight lang="xml"><br />
<colcube posX="1024.768" posY="1248.1024" posZ="800.600" width="100" height="100" depth="100"/><br />
<colsphere posX="1024.768" posY="1248.1024" posZ="800.600" radius="100"/><br />
<coltube posX="1024.768" posY="1248.1024" posZ="800.600" radius="30" height="15"/><br />
<colrectangle posX="1024.768" posY="1248.1024" posZ="800.600" width="100" depth="61.8"/><br />
<colcircle posX="1024.768" posY="1248.1024" posZ="800.600" radius="30"/><br />
</syntaxhighlight><br />
<br />
===Required Attributes===<br />
* '''posX''': A float representing the X position of the vehicle.<br />
* '''posY''': A float representing the Y position of the vehicle.<br />
* '''posZ''': A float representing the Z position of the vehicle.<br />
<br />
===Optional Attributes===<br />
* '''dimension''': The dimension the colshape is in<br />
<br />
==Related scripting functions==<br />
{{Collision shape functions}}<br />
[[Category:Element Types]]<br />
<br />
[[it:Elemento Collision shape]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element/Collision_shape&diff=16811Element/Collision shape2008-05-21T21:17:14Z<p>Borov: /* XML syntax */</p>
<hr />
<div>__NOTOC__<br />
The collision shape class represents invisible collision detection shapes that can be created in the GTA world. Collision shapes are typically used to detect physical entities moving through them and perform actions when they do.<br />
<br />
The element types for this class are '''colcube''', '''colcube''', '''colrectangle''', '''colcuboid''' and '''colcircle'''.<br />
<br />
Colshapes cannot have their corners/radius specified via XML currently, which makes their xml representation essentially useless.<br />
<br />
==XML syntax==<br />
<syntaxhighlight lang="xml"><br />
<colcube posX="1024.768" posY="1248.1024" posZ="800.600" .../><br />
</syntaxhighlight><br />
<br />
===Required Attributes===<br />
* '''posX''': A float representing the X position of the vehicle.<br />
* '''posY''': A float representing the Y position of the vehicle.<br />
* '''posZ''': A float representing the Z position of the vehicle.<br />
<br />
===Optional Attributes===<br />
* '''dimension''': The dimension the colshape is in<br />
<br />
==Related scripting functions==<br />
{{Collision shape functions}}<br />
[[Category:Element Types]]<br />
<br />
[[it:Elemento Collision shape]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element/Collision_shape&diff=16810Element/Collision shape2008-05-21T21:12:50Z<p>Borov: /* XML syntax */</p>
<hr />
<div>__NOTOC__<br />
The collision shape class represents invisible collision detection shapes that can be created in the GTA world. Collision shapes are typically used to detect physical entities moving through them and perform actions when they do.<br />
<br />
The element types for this class are '''colcube''', '''colcube''', '''colrectangle''', '''colcuboid''' and '''colcircle'''.<br />
<br />
Colshapes cannot have their corners/radius specified via XML currently, which makes their xml representation essentially useless.<br />
<br />
==XML syntax==<br />
<syntaxhighlight lang="xml"><br />
<colshape posX="1024.768" posY="1248.1024" posZ="800.600" /><br />
</syntaxhighlight><br />
<br />
===Required Attributes===<br />
* '''posX''': A float representing the X position of the vehicle.<br />
* '''posY''': A float representing the Y position of the vehicle.<br />
* '''posZ''': A float representing the Z position of the vehicle.<br />
<br />
===Optional Attributes===<br />
* '''dimension''': The dimension the colshape is in<br />
<br />
==Related scripting functions==<br />
{{Collision shape functions}}<br />
[[Category:Element Types]]<br />
<br />
[[it:Elemento Collision shape]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=GetPlayerTotalAmmo&diff=16754GetPlayerTotalAmmo2008-05-12T10:47:11Z<p>Borov: /* Syntax */</p>
<hr />
<div>__NOTOC__<br />
{{Server client function}}<br />
This function returns an integer that contains the total ammo in a specified [[player]]'s weapon. See [[weapon|Weapon Info]]<br />
<br />
==Syntax==<br />
<section name="Server" class="server" show="true"><br />
<syntaxhighlight lang="lua"><br />
int getPlayerTotalAmmo ( player thePlayer )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''thePlayer''': The [[player]] whose ammo you want to check.<br />
<br />
===Returns===<br />
Returns an [[int]] containing the total amount of ammo for the player's current weapon.<br />
</section><br />
<section name="Client" class="client" show="true"><br />
<syntaxhighlight lang="lua"><br />
int getPlayerTotalAmmo ( player thePlayer , int weaponSlot )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''thePlayer''': The [[player]] whose ammo you want to check.<br />
<br />
*'''weaponSlot''': an integer representing the weapon slot (set to the players current slot if not given)<br />
<br />
===Returns===<br />
Returns an [[int]] containing the total amount of ammo for the specified player's weapon, or 0 if the player specified is invalid.<br />
</section><br />
<br />
==Example==<br />
This example outputs the total amount of ammo a player called ''Someguy'' has for his weapon.<br />
<syntaxhighlight lang="lua"><br />
-- Find the player called 'Someguy'<br />
myPlayer = getPlayerFromNick ( "Someguy" )<br />
-- If a player called 'Someguy' was found then<br />
if ( myPlayer ) then<br />
-- Retrieve the total amount of ammo for that player, and store it in a variable called 'ammo'<br />
ammo = getPlayerTotalAmmo ( myPlayer )<br />
-- Tell all the players how much ammo 'Someguy' has<br />
outputChatBox ( "Someguy's current total ammo: " .. ammo .. "." )<br />
end<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Player functions}}</div>Borovhttps://wiki.multitheftauto.com/index.php?title=GetPlayerTotalAmmo&diff=16753GetPlayerTotalAmmo2008-05-12T10:46:50Z<p>Borov: /* Syntax */</p>
<hr />
<div>__NOTOC__<br />
{{Server client function}}<br />
This function returns an integer that contains the total ammo in a specified [[player]]'s weapon. See [[weapon|Weapon Info]]<br />
<br />
==Syntax==<br />
<section name="Server" class="server" show="true"><br />
<syntaxhighlight lang="lua"><br />
int getPlayerTotalAmmo ( player thePlayer )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''thePlayer''': The [[player]] whose ammo you want to check.<br />
<br />
===Returns===<br />
Returns an [[int]] containing the total amount of ammo for the player's current weapon.<br />
</section><br />
<section name="Client" class="client" show="true"><br />
<syntaxhighlight lang="lua"><br />
int getPlayerTotalAmmo ( player thePlayer , int weaponSlot = current )<br />
</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''thePlayer''': The [[player]] whose ammo you want to check.<br />
<br />
*'''weaponSlot''': an integer representing the weapon slot (set to the players current slot if not given)<br />
<br />
===Returns===<br />
Returns an [[int]] containing the total amount of ammo for the specified player's weapon, or 0 if the player specified is invalid.<br />
</section><br />
<br />
==Example==<br />
This example outputs the total amount of ammo a player called ''Someguy'' has for his weapon.<br />
<syntaxhighlight lang="lua"><br />
-- Find the player called 'Someguy'<br />
myPlayer = getPlayerFromNick ( "Someguy" )<br />
-- If a player called 'Someguy' was found then<br />
if ( myPlayer ) then<br />
-- Retrieve the total amount of ammo for that player, and store it in a variable called 'ammo'<br />
ammo = getPlayerTotalAmmo ( myPlayer )<br />
-- Tell all the players how much ammo 'Someguy' has<br />
outputChatBox ( "Someguy's current total ammo: " .. ammo .. "." )<br />
end<br />
</syntaxhighlight><br />
<br />
==See Also==<br />
{{Player functions}}</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Resource&diff=16746Resource2008-05-08T16:46:17Z<p>Borov: </p>
<hr />
<div>A [[resource]] object refers to a resource that is loaded in the server.<br />
<br />
A name, state, root element, base directory path are associated to a [[resource]], among other attributes.<br />
<br />
==Related scripting functions==<br />
===Server===<br />
{{Resource functions}}<br />
===Client===<br />
{{Client resource functions}}<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Community_Resources&diff=16745Community Resources2008-05-08T16:45:38Z<p>Borov: </p>
<hr />
<div>==Community calls documentation==<br />
using callRemote<br />
<br />
==community.mtasa.com/mta/verify.php==<br />
<br />
'''Calls:'''<br />
<br />
User validation:<br />
<syntaxhighlight lang="lua"><br />
player thePlayer, string Username, string Serial<br />
</syntaxhighlight> <br />
'''Returns:''' an integer, 1 if user is valid, 0 otherwise<br />
<br />
<br />
==community.mtasa.com/mta/groups.php==<br />
<br />
'''Calls:'''<br />
<br />
Info:<br />
<syntaxhighlight lang="lua"><br />
string "info", int groupID<br />
</syntaxhighlight> <br />
'''Returns 5 values:'''<br /><br />
1. Group name<br /><br />
2. Owner username<br /><br />
3. Number of members<br /><br />
4. Public. Integer: 1 if the group is public, 0 otherwise<br /><br />
5. Registration time<br /><br />
<br />
<br />
Members list:<br />
<syntaxhighlight lang="lua"><br />
string "members", int groupID<br />
</syntaxhighlight> <br />
'''Returns:''' a table of usernames in the group<br />
<br />
<br />
==community.mtasa.com/mta/resources.php==<br />
<br />
'''Calls:'''<br />
<br />
Latest resource version:<br />
<syntaxhighlight lang="lua"><br />
string "version", string resourceName<br />
</syntaxhighlight> <br />
'''Returns:''' an integer, resource version. 0 if an error has occured<br />
<br />
<br />
==Example==<br />
<syntaxhighlight lang="lua"><br />
addEventHandler ( "onPlayerJoin", getRootElement(), function()<br />
local username = getPlayerUserName ( source )<br />
local serial = getPlayerSerial ( source )<br />
callRemote ( "http://community.mtasa.com/mta/verify.php", validatePlayer, source, username, serial )<br />
end )<br />
<br />
function validatePlayer ( player, result )<br />
local valid = "invalid"<br />
if ( result == 1 ) then valid = "valid" end<br />
outputChatBox ( getClientName ( player ).."'s username is "..valid )<br />
end<br />
</syntaxhighlight><br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Resource_Web_Access&diff=16744Resource Web Access2008-05-08T16:45:00Z<p>Borov: </p>
<hr />
<div>The Multi Theft Auto Server provides a web interface that resources can use in a variety of ways. This document's purpose is to explain what these ways are and how to go about using them.<br />
<br />
==Overview==<br />
There are two key parts that make up this system. The first is a standard web server that allows web browsers to request pages and files you have in a resource. The second is a system for allowing web browsers to call functions you have exported from your resource.<br />
<br />
==Pages==<br />
===Specifying a file in the meta===<br />
You can specify in your resource's meta file that certain files are accessible through the web server. To do this, you add a line:<br />
<syntaxhighlight lang="xml"><br />
<html src="filename" /><br />
</syntaxhighlight><br />
You can then access this file from your web browser by visiting:<br />
http://host:port/resourcename/filename<br />
<br />
===Binary files===<br />
Despite the misleading name, files specified using the html node can be of any type. If they are binary files (like images, zip files) then you need to specify this in the meta file, by adding ''raw="true"'' to the ''html'' node. This means that the files are not preprocessed before being sent to the web browser.<br />
<br />
For example:<br />
<syntaxhighlight lang="xml"><br />
<html src="image.gif" raw="true" /><br />
</syntaxhighlight><br />
<br />
===Parsed files===<br />
If a file is not specified in the meta file as "raw", then it is passed through a pre-processor before it is returned to the client. This pre-processor works much like PHP or ASP, but uses LUA. You can embed standard MTA scripts within HTML pages, controlling the output. Almost all standard MTA functions work, plus a number of special [[Template:HTTP functions|HTTP Functions]], such as [[httpWrite]], a function that outputs text to the buffer.<br />
<br />
For example:<br />
<syntaxhighlight lang="lua">[html]<br />
<html><br />
<body><br />
This resource is called <* httpWrite( getResourceName(getThisResource()) ) *><br />
</body><br />
<html><br />
</syntaxhighlight><br />
<br />
There is a shorthand (in common with PHP and ASP) for this code, meaning that you can also write the above code as:<br />
<br />
<syntaxhighlight lang="lua">[html]<br />
<html><br />
<body><br />
This resource is called <* = getResourceName(getThisResource()) *><br />
</body><br />
<html><br />
</syntaxhighlight><br />
<br />
Aside from HTTP functions, embedded Lua has access to the following environment variables that contain information about how the page was requested:<br />
* table '''requestHeaders''': This is a table containing all the headers that were requested with the page. You can set returned headers using [[httpSetResponseHeader]]. <br />
* table '''form''': This is a table containing all the form data submitted to the page using HTTP POST combined with any variables passed in the querystring with HTTP GET.<br />
* table '''cookies''': This is a table of all the cookies. You can modify cookies using [[httpSetResponseCookie]].<br />
* string '''hostname''': This is a string containing the IP address or hostname that requested the page.<br />
* string '''url''': This is the URL of the page.<br />
* account '''user''': This is the account of the current user.<br />
<br />
It's important to note that parsed files are run in a separate virtual machine from the rest of your resource's code. As such, if you want to call a function in your resource's main code, you need to export the function and use the [[call]] function from your parsed file.<br />
<br />
==Calls==<br />
You can specify that certain exported functions in your resource are able to be called from the HTTP interface. All the SDKs (listed below) allow you to call these functions from a remote location. <br />
<br />
To specify an exported http-accessible function, add the following to your meta.xml file:<br />
<syntaxhighlight lang="xml"><br />
<export function='functionName' http='true' /><br />
</syntaxhighlight><br />
<br />
You can code your function just as you would any normal function, returning as many values as you want, including tables and resources and most importantly elements. You ''cannot'' however return other 'userdata' values such as [[xmlnode|xmlnodes]] or functions.<br />
<br />
===Calls from the HTTP web interface===<br />
Using calls is probably easiest from the web interface and can be done almost seamlessly.<br />
<br />
First, add this to your meta.xml file:<br />
<syntaxhighlight lang="xml"><br />
<include resource="ajax" /><br />
</syntaxhighlight><br />
<br />
Secondly, add the following to the <head> section of the page you want to call from:<br />
<syntaxhighlight lang="lua"><br />
<* = call ( getResourceFromName("ajax"), "start", getResourceName(getThisResource()) ) *><br />
</syntaxhighlight><br />
<br />
Finally, you can create a javascript block in your page and call your functions almost as if they were local. The only difference is that the calls are aysnchronous - you should specify a callback function as the last argument for your call. This is called when the function returns.<br />
<br />
Here's a simple example.<br />
<br />
'''meta.xml'''<br />
<syntaxhighlight lang="xml"><br />
<meta><br />
<include resource="ajax" /><br />
<script src='code.lua' /><br />
<html src='page.htm' default='true' /><br />
<export function='showChatMessage' http='true' /><br />
</meta><br />
</syntaxhighlight><br />
<br />
'''code.lua'''<br />
<syntaxhighlight lang="lua"><br />
function showChatMessage ( message )<br />
outputChatBox ( message )<br />
return 5;<br />
end<br />
</syntaxhighlight><br />
<br />
'''page.htm'''<br />
<syntaxhighlight lang="lua">[html]<br />
<html><br />
<head><br />
<* = call ( getResourceFromName("ajax"), "start", getResourceName(getThisResource()) ) *><br />
<script type='text/javascript'><br />
function say() {<br />
var message = document.getElementById('message')<br />
showChatMessage ( message.value, <br />
function ( number ) {<br />
// the function has been called and returned something<br />
message.value = "The function returned " + number;<br />
}<br />
);<br />
}<br />
</script><br />
</head><br />
<body><br />
<input type='text' id='message' /><input type='button' value='say' onclick='say();' /><br />
</body><br />
</html><br />
</syntaxhighlight><br />
<br />
You can see (fairly complex) examples of how this can be done in the resources ''resourcebrowser'', ''resourcemanager'' and ''webadmin''.<br />
<br />
==SDK==<br />
There are a number of so-called 'SDKs' available that allow you to interface with the server from other programming languages. With these you could (in theory) write whole gamemodes. In practice this is probably a bad idea, but it is useful for statistics and administration. The PHP SDK is the most developed version. Feel free to modify or create your own SDKs - if you do please send us a copy.<br />
<br />
* [[Java SDK]]<br />
* [[Javascript SDK]]<br />
* [[Perl SDK]]<br />
* [[PHP SDK]]<br />
<br />
==See Also==<br />
[[callRemote]] - Allows game servers to call functions on PHP pages (with the PHP SDK) and on other game servers.<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Optional_Arguments&diff=16743Optional Arguments2008-05-08T16:44:13Z<p>Borov: </p>
<hr />
<div>[[Optional Arguments]] are arguments that are passed to a function but are not required for the function to run. Often, if you do not specify them, default values will be used instead.<br />
<br />
When looking at the Syntax for an argument, Optional arguments are always enclosed in Square brackets.<br />
<br />
Example:<br />
<br />
<syntaxhighlight lang="lua">vehicle = createVehicle ( model, x, y, z, [rx, ry, rz] )</syntaxhighlight><br />
<br />
In this example, '''rx''', '''ry''', and '''rz''' are [[Optional Arguments]].<br />
<br />
==Using Optional Arguments==<br />
<br />
[[Optional Arguments]] have one limitation. You cannot use any optional arguments unless ''all previous arguments are also supplied.''<br />
<br />
This means that in the previous example, if you wanted to supply '''rz''', you would also need to supply '''rx''', and '''ry''' ''in order.''<br />
<br />
[[pl:Argumenty opcjonalne]]<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Nil&diff=16742Nil2008-05-08T16:43:58Z<p>Borov: </p>
<hr />
<div>Nil is a type with a single value, ''nil'', whose main property is to be different from any other value. A global variable has a ''nil'' value by default, before a first assignment, and you can assign ''nil'' to a global variable to delete it. Lua uses ''nil'' as a kind of non-value, to represent the absence of a useful value.<br />
<br />
==See Also==<br />
*[http://www.lua.org/pil/2.1.html Nil in Programming in Lua]<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Key_names&diff=16741Key names2008-05-08T16:43:35Z<p>Borov: </p>
<hr />
<div>This page lists all the key names. These can be used by the console commands ''bind'' and ''unbind'' as well as the script functions [[bindKey]] and [[unbindKey]].<br />
<br />
<div style="border:3px solid green;margin-bottom:3px;"><div style="float:right;padding-right:5px;font-weight:bold;">MOUSE</div><br />
* '''mouse1'''<br />
* '''mouse2'''<br />
* '''mouse3 (middle)'''<br />
* '''mouse4'''<br />
* '''mouse5'''<br />
* '''mouse_wheel_up'''<br />
* '''mouse_wheel_down'''<br />
</div><br />
<div style="border:3px solid red;margin-bottom:3px;"><div style="float:right;padding-right:5px;font-weight:bold;">ARROW KEYS</div><br />
* '''arrow_l'''<br />
* '''arrow_u'''<br />
* '''arrow_r'''<br />
* '''arrow_d'''<br />
</div><br />
<div style="border:3px solid blue;margin-bottom:3px;"><div style="float:right;padding-right:5px;font-weight:bold;">NUMBERS</div><br />
* '''0'''<br />
* '''1'''<br />
* '''2'''<br />
* '''3'''<br />
* '''4'''<br />
* '''5'''<br />
* '''6'''<br />
* '''7'''<br />
* '''8'''<br />
* '''9'''<br />
</div><br />
<div style="border:3px solid orange;margin-bottom:3px;"><div style="float:right;padding-right:5px;font-weight:bold;">LETTERS</div><br />
* '''a'''<br />
* '''b'''<br />
* '''c'''<br />
* '''d'''<br />
* '''e'''<br />
* '''f'''<br />
* '''g'''<br />
* '''h'''<br />
* '''i'''<br />
* '''j'''<br />
* '''k'''<br />
* '''l'''<br />
* '''m'''<br />
* '''n'''<br />
* '''o'''<br />
* '''p'''<br />
* '''q'''<br />
* '''r'''<br />
* '''s'''<br />
* '''t'''<br />
* '''u'''<br />
* '''v'''<br />
* '''w'''<br />
* '''x'''<br />
* '''y'''<br />
* '''z'''<br />
</div><br />
<div style="border:3px solid yellow;margin-bottom:3px;"><div style="float:right;padding-right:5px;font-weight:bold;">NUMERIC KEYPAD</div><br />
* '''num_0'''<br />
* '''num_1'''<br />
* '''num_2'''<br />
* '''num_3'''<br />
* '''num_4'''<br />
* '''num_5'''<br />
* '''num_6'''<br />
* '''num_7'''<br />
* '''num_8'''<br />
* '''num_9'''<br />
* '''num_mul'''<br />
* '''num_add'''<br />
* '''num_sep'''<br />
* '''num_sub'''<br />
* '''num_div'''<br />
* '''num_dec'''<br />
</div><br />
<div style="border:3px solid pink;margin-bottom:3px;"><div style="float:right;padding-right:5px;font-weight:bold;">FUNCTION KEYS</div><br />
* '''F1'''<br />
* '''F2'''<br />
* '''F3'''<br />
* '''F4'''<br />
* '''F5'''<br />
* '''F6'''<br />
* '''F7'''<br />
* '''F8'''<br />
* '''F9'''<br />
* '''F10'''<br />
* '''F11'''<br />
* '''F12'''<br />
</div><br />
<div style="border:3px solid purple;margin-bottom:3px;"><div style="float:right;padding-right:5px;font-weight:bold;">OTHER</div><br />
* '''backspace'''<br />
* '''tab'''<br />
* '''lalt'''<br />
* '''ralt'''<br />
* '''enter'''<br />
* '''space'''<br />
* '''pgup'''<br />
* '''pgdn'''<br />
* '''end'''<br />
* '''home'''<br />
* '''insert'''<br />
* '''delete'''<br />
* '''lshift'''<br />
* '''rshift'''<br />
* '''lctrl'''<br />
* '''rctrl'''<br />
* '''['''<br />
* ''']'''<br />
* '''pause'''<br />
* '''capslock'''<br />
* '''scroll'''<br />
* ''';'''<br />
* ''','''<br />
* '''-'''<br />
* '''.'''<br />
* '''/'''<br />
* '''#'''<br />
* '''\'''<br />
* '''='''<br />
<br />
</div><br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=JSON&diff=16740JSON2008-05-08T16:43:18Z<p>Borov: </p>
<hr />
<div>JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.<br />
<br />
MTA uses JSON in a number of places, most significantly it is used for communication over HTTP. See [[Resource Web Access]]. You can encode JSON strings in the server using [[toJSON]] and decode them using [[fromJSON]].<br />
<br />
For more general information about JSON, see http://www.json.org.<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Int&diff=16739Int2008-05-08T16:43:04Z<p>Borov: </p>
<hr />
<div>An integer is any whole number. It can be positive, zero, or negative. Examples: 1 0 -1<br />
<br />
A number with decimals is referred to as a [[float]] number<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=IRC_Channel&diff=16738IRC Channel2008-05-08T16:42:52Z<p>Borov: </p>
<hr />
<div>There is an IRC Channel available for help with MTA Scripting. You can find it at #mta.scripting on GTAnet.<br />
==How to get help==<br />
* Try to find your Answer on the [[Main Page]], especially the ''Getting Started'' section<br />
* Ask your question once and only repeat it after a reasonable amount of time, given the channel is busy and people just coming online won't see your question else (like 10 minutes). NOT after 10 seconds.<br />
* Your question should at least contain:<br />
** What are you trying to do.<br />
** What have you done so far.<br />
** What exactly doesn't work/is your problem. What errors are occuring.<br />
** Maybe a code snippet with an explanation using [http://mta.pastebin.com mta.pastebin.com] (''code snippet means the relevant parts, NOT the whole script'')<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Float&diff=16737Float2008-05-08T16:42:04Z<p>Borov: </p>
<hr />
<div>Float is an abreviation of 'Floating Point Number'. A floating point number is one with a decimal point, i.e. it can contain values such as 5.5 or 3.142. An [[int]] on the other hand can only hold whole numbers.<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Entity&diff=16736Entity2008-05-08T16:41:47Z<p>Borov: </p>
<hr />
<div>An entity is an element that has a position and a physical representation in the world. The following elements are entities:<br />
{{Entities}}<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Hibakeres%C3%A9s&diff=16735Hibakeresés2008-05-08T16:41:24Z<p>Borov: </p>
<hr />
<div>While scripting you will often come across problems that are not immediately apparent. This page tries to point out some basic strategies to locate the error.<br />
<br />
==Debug console==<br />
MTA features a built-in debug console that shows debug messages output from MTA functions or from scripts. You can open it by typing ''debugscript x'' in console, while ''x'' is the debug level:<br />
* '''1:''' only errors<br />
* '''2:''' errors and warnings<br />
* '''3:''' errors, warnings and info messages<br />
Thus, by typing ''debugscript 3'' all messages are visible, that or level 2 are recommended for most occasions. You should have debugscript enabled most of the time you are testing your scripts, this will help you detect typos or other simple issues and solve them easily.<br />
<br />
===Example===<br />
This example snippet has two errors:<br />
<syntaxhighlight lang="lua"><br />
if (getClientName(player) == "Fedor")<br />
outputChatbox("Hello Fedor")<br />
end<br />
</syntaxhighlight><br />
When the script this piece of code is in is tried to be loaded, debugscript will output something similiar to this:<br />
{{Debug info|Loading script failed: C:\<server path>\mods\deathmatch\resources\myResource\script.lua:15: 'then' expected near ´outputChatbox'}}<br />
This means the script could not be parsed, because there was a syntax error. It shows the path of the script, so you can also see what resource it is in ('myResource' in this case) and of course the name of the script. After the filename it shows the line number and again after that what was wrong. Easy to solve now, we just forgot the 'then' keyword:<br />
<syntaxhighlight lang="lua"><br />
if (getClientName(player) == "Fedor") then<br />
outputChatbox("Hello Fedor")<br />
end<br />
</syntaxhighlight><br />
Now the script will load fine and won't output any errors, until a player with the name 'Fedor' enters this section of the script. Then, debugscript will output:<br />
{{Debug error|C:\<server path>\mods\deathmatch\resources\d\script.lua:15: attempt to call global 'outputChatbox' (a nil value)}}<br />
This means the called function does not exist, which can be easily explained since the functions' name is ''outputChatBox'' (with a capital ''B''):<br />
<syntaxhighlight lang="lua"><br />
if (getClientName(player) == "Fedor") then<br />
outputChatBox("Hello Fedor")<br />
end<br />
</syntaxhighlight><br />
<br />
This is of course just an example, there are plenty of other messages and scenarios, but you should get the idea.<br />
<br />
==Debug logging==<br />
You can also turn debug message logging on by editing ''coreconfig.xml'' in your GTA\MTA folder. You should find the following tag:<br />
<syntaxhighlight lang="xml"><debugfile/></syntaxhighlight><br />
<br />
Replace that with a tag specifying the file you want to log messages to (file path is relative from the GTA folder):<br />
<syntaxhighlight lang="xml"><debugfile>MTA\debugscript.log</debugfile></syntaxhighlight><br />
<br />
All debug messages will be appended to the specified file from now on. To turn logging off, replace that line with an empty tag again.<br />
<br />
==Debug strategies==<br />
There are several strategies that support finding errors, apart from going through the code of course. Most of them include outputting debug messages, with differing information depending on the situtation.<br />
<br />
===Useful functions===<br />
First of all some functions that may come in handy for debugging.<br />
* [[outputDebugString]] or [[outputChatBox]] for outputting any information<br />
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] on a variable to turn it into a string, for example when it contains a boolean value<br />
* [[getElementType]] to check an MTA Element for its type<br />
<br />
===Add debugmessages to check ''if'', ''when'' or ''how often'' a section of code is executed===<br />
A typical example would be verify whether an ''if''-section is executed or not. To do that, just add any message you will recognize later within the ''if''-section.<br />
<syntaxhighlight lang="lua"><br />
if (variable1 == variable2) then<br />
outputDebugString("entered if")<br />
-- do anything<br />
end<br />
</syntaxhighlight><br />
<br />
Another application would be to check when variable values are modified. First search for all occurences of the variable being edited and add a message just beside it.<br />
<br />
===Add debugmessages to check the ''value'' of a variable===<br />
Let's say you want to create a marker, but it doesn't appear at the position you expect it to be. The first thing you might want to do is check if the [[createMarker]] function is executed. But while doing this, you can also check the values being used in the [[createMarker]] function in one run.<br />
<syntaxhighlight lang="lua"><br />
outputChatBox(tostring(x).." "..tostring(y).." "..tostring(z))<br />
createMarker(x,y,z)<br />
</syntaxhighlight><br />
This would output all three variables that are used as coordinates for the marker. Assuming you read those from a map file, you can now compare the debug output to the desired values. The [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] will ensure that the variables' value can be put together as a string, even if it's a boolean value for example.<br />
<br />
==Example==<br />
Imagine you created a colshape (collision shape) somewhere and you want a player to stay 10 seconds in it, then perform some action.<br />
<syntaxhighlight lang="lua"><br />
function colShapeHit(player)<br />
-- set a timer to output a message (could as well execute another function)<br />
-- store the timer id in a table, using the player as index<br />
colshapeTimer[player] = setTimer(outputChatBox,10000,1,"The player stayed 10 seconds in the colshape!")<br />
end<br />
addEventHandler("onColShapeHit",getRootElement(),colShapeHit)<br />
<br />
function colShapeLeave(player)<br />
-- kill the timer when the player leaves the colshape<br />
killTimer(colshapeTimer[player])<br />
end<br />
addEventHandler("onColShapeLeave",getRootElement(),colShapeLeave)<br />
</syntaxhighlight><br />
When a player enters the colshape, debugscript outputs the following message:<br />
{{Debug error|..[path]: attempt to index global 'colshapeTimer' (a nil value)}}<br />
This means you tried to index a table that does not exist. In the example above, this is done when storing the timer id in the table. We need to add a check if the table exists and if not create it.<br />
<br />
<syntaxhighlight lang="lua"><br />
function colShapeHit(player)<br />
if (colshapeTimer == nil) then<br />
colshapeTimer = {}<br />
end<br />
-- set a timer to output a message (could as well execute another function)<br />
-- store the timer id in a table, using the player as index<br />
colshapeTimer[player] = setTimer(outputChatBox,10000,1,"The player stayed 10 seconds in the colshape!")<br />
end<br />
addEventHandler("onColShapeHit",getRootElement(),colShapeHit)<br />
<br />
function colShapeLeave(player)<br />
-- kill the timer when the player leaves the colshape<br />
killTimer(colshapeTimer[player])<br />
end<br />
addEventHandler("onColShapeLeave",getRootElement(),colShapeLeave)<br />
</syntaxhighlight><br />
<br />
Now we still get a warning when a player enters the colshape, waits for the message and leaves it again:<br />
<br />
{{Debug warning|[..]: Bad argument @ 'killTimer' Line: ..}}<br />
<br />
Except for that (we will talk about that later) everything seems to work fine. A player enters the colshape, the timer is started, if he stays the message occurs, if he leaves the timer is killed.<br />
<br />
===A more inconspicuous error===<br />
But for some reason the message gets outputted twice when you stay in the colcircle while in a vehicle. Since it would appear some code is executed twice, we add debug messages to check this.<br />
<br />
<syntaxhighlight lang="lua"><br />
function colShapeHit(player)<br />
if (colshapeTimer == nil) then<br />
colshapeTimer = {}<br />
end<br />
-- add a debug message<br />
outputDebugString("colShapeHit")<br />
-- set a timer to output a message (could as well execute another function)<br />
-- store the timer id in a table, using the player as index<br />
colshapeTimer[player] = setTimer(outputChatBox,10000,1,"The player stayed 10 seconds in the colshape!")<br />
end<br />
addEventHandler("onColShapeHit",getRootElement(),colShapeHit)<br />
<br />
function colShapeLeave(player)<br />
-- add a debug message<br />
outputDebugString("colShapeLeave")<br />
-- kill the timer when the player leaves the colshape<br />
killTimer(colshapeTimer[player])<br />
end<br />
addEventHandler("onColShapeLeave",getRootElement(),colShapeLeave)<br />
</syntaxhighlight><br />
<br />
Now we notice that both handler functions get executed twice when we are in a vehicle, but only once when we are on-foot. It would appear the vehicle triggers the colshape as well. To confirm this theory, we check the ''player'' variable that '''should''' contain a player element.<br />
<br />
<syntaxhighlight lang="lua"><br />
function colShapeHit(player)<br />
if (colshapeTimer == nil) then<br />
colshapeTimer = {}<br />
end<br />
-- add a debug message, with the element type<br />
outputDebugString("colShapeHit "..getElementType(player))<br />
-- set a timer to output a message (could as well execute another function)<br />
-- store the timer id in a table, using the player as index<br />
colshapeTimer[player] = setTimer(outputChatBox,10000,1,"The player stayed 10 seconds in the colshape!")<br />
end<br />
addEventHandler("onColShapeHit",getRootElement(),colShapeHit)<br />
<br />
function colShapeLeave(player)<br />
-- add a debug message, with the element type<br />
outputDebugString("colShapeLeave "..getElementType(player))<br />
-- kill the timer when the player leaves the colshape<br />
killTimer(colshapeTimer[player])<br />
end<br />
addEventHandler("onColShapeLeave",getRootElement(),colShapeLeave)<br />
</syntaxhighlight><br />
<br />
The debug messages tell us that one of the ''player'' variables is a player, the other one a vehicle element. Since we only want to react when a player enters the colshape, we add an ''if'' that will end the execution of the function if it's '''not''' an player element.<br />
<br />
<syntaxhighlight lang="lua"><br />
function colShapeHit(player)<br />
if (colshapeTimer == nil) then<br />
colshapeTimer = {}<br />
end<br />
-- add a check for the element type<br />
if (getElementType(player) ~= "player") then return end<br />
-- add a debug message, with the element type<br />
outputDebugString("colShapeHit "..getElementType(player))<br />
-- set a timer to output a message (could as well execute another function)<br />
-- store the timer id in a table, using the player as index<br />
colshapeTimer[player] = setTimer(outputChatBox,10000,1,"The player stayed 10 seconds in the colshape!")<br />
end<br />
addEventHandler("onColShapeHit",getRootElement(),colShapeHit)<br />
<br />
function colShapeLeave(player)<br />
-- add a check for the element type<br />
if (getElementType(player) ~= "player") then return end<br />
-- add a debug message, with the element type<br />
outputDebugString("colShapeLeave "..getElementType(player))<br />
-- kill the timer when the player leaves the colshape<br />
killTimer(colshapeTimer[player])<br />
end<br />
addEventHandler("onColShapeLeave",getRootElement(),colShapeLeave)<br />
</syntaxhighlight><br />
<br />
Now the script should work as desired, but will still output the warning mentioned above. This happens because the timer we try to kill when a player leaves the colshape will not exist anymore when it reached the 10 seconds and is executed. There are different ways to get rid of that warning (since you know that the timer might not exist anymore and you only want to kill it if it is there). One way would be to check if the timer referenced in the table really exists. To do this, we need a little help function:<br />
<syntaxhighlight lang="lua"><br />
function isTimer(timer)<br />
local timers = getTimers()<br />
for k,v in ipairs(timers) do<br />
if (v == timer) then<br />
return true<br />
end<br />
end<br />
return false<br />
end<br />
</syntaxhighlight><br />
Which we will use when we kill the timer:<br />
<syntaxhighlight lang="lua"><br />
if (isTimer(colshapeTimer[player])) then<br />
killTimer(colshapeTimer[player])<br />
end<br />
</syntaxhighlight><br />
<br />
So the complete working code would be:<br />
<syntaxhighlight lang="lua"><br />
function colShapeHit(player)<br />
if (colshapeTimer == nil) then<br />
colshapeTimer = {}<br />
end<br />
-- add a check for the element type<br />
if (getElementType(player) ~= "player") then return end<br />
-- add a debug message, with the element type<br />
outputDebugString("colShapeHit "..getElementType(player))<br />
-- set a timer to output a message (could as well execute another function)<br />
-- store the timer id in a table, using the player as index<br />
colshapeTimer[player] = setTimer(outputChatBox,10000,1,"The player stayed 10 seconds in the colshape!")<br />
end<br />
addEventHandler("onColShapeHit",getRootElement(),colShapeHit)<br />
<br />
function colShapeLeave(player)<br />
-- add a check for the element type<br />
if (getElementType(player) ~= "player") then return end<br />
-- add a debug message, with the element type<br />
outputDebugString("colShapeLeave "..getElementType(player))<br />
-- kill the timer when the player leaves the colshape<br />
if (isTimer(colshapeTimer[player])) then<br />
killTimer(colshapeTimer[player])<br />
end<br />
end<br />
addEventHandler("onColShapeLeave",getRootElement(),colShapeLeave)<br />
<br />
function isTimer(timer)<br />
local timers = getTimers()<br />
for k,v in ipairs(timers) do<br />
if (v == timer) then<br />
return true<br />
end<br />
end<br />
return false<br />
end<br />
</syntaxhighlight><br />
<br />
[[it:Guida al Debug]]<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Client&diff=16734Client2008-05-08T16:41:05Z<p>Borov: </p>
<hr />
<div>__NOTOC__<br />
The client class represents any client that has connected to the server. This can be a [[player]] or a [[Element/Admin|remote administrator]].<br />
<br />
All client functions can operate on both player and admin elements.<br />
<br />
==Related scripting functions==<br />
===Server===<br />
{{Client functions}}<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=CJ_Clothes&diff=16733CJ Clothes2008-05-08T16:40:45Z<p>Borov: </p>
<hr />
<div>These pages contain clothing images and details for all of CJ's apparel.<br />
<br />
*[[CJ Clothes\Shirt (0)|Type 0 - Shirt]]<br />
*[[CJ Clothes\Head (1)|Type 1 - Head]]<br />
*[[CJ Clothes\Trousers (2)|Type 2 - Trousers]]<br />
*[[CJ Clothes\Shoes (3)|Type 3 - Shoes]]<br />
*[[CJ Clothes\Tattoos: Left Upper Arm (4)|Type 4 - Tattoos: Left Upper Arm]]<br />
*[[CJ Clothes\Tattoos: Left Lower Arm (5)|Type 5 - Tattoos: Left Lower Arm]]<br />
*[[CJ Clothes\Tattoos: Right Upper Arm (6)|Type 6 - Tattoos: Right Upper Arm]]<br />
*[[CJ Clothes\Tattoos: Right Lower Arm (7)|Type 7 - Tattoos: Right Lower Arm]]<br />
*[[CJ Clothes\Tattoos: Back (8)|Type 8 - Tattoos: Back]]<br />
*[[CJ Clothes\Tattoos: Left Chest (9)|Type 9 - Tattoos: Left Chest]]<br />
*[[CJ Clothes\Tattoos: Right Chest (10)|Type 10 - Tattoos: Right Chest]]<br />
*[[CJ Clothes\Tattoos: Stomach (11)|Type 11 - Tattoos: Stomach]]<br />
*[[CJ Clothes\Tattoos: Lower Back (12)|Type 12 - Tattoos: Lower Back]]<br />
*[[CJ Clothes\Necklace (13)|Type 13 - Necklace]]<br />
*[[CJ Clothes\Watches (14)|Type 14 - Watches]]<br />
*[[CJ Clothes\Glasses (15)|Type 15 - Glasses]]<br />
*[[CJ Clothes\Hats (16)|Type 16 - Hats]]<br />
*[[CJ Clothes\Extra (17)|Type 17 - Extra]]<br />
<br />
[[it:Vestiti di CJ]]<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Modules/MySQL/MysqlQuery&diff=16732Modules/MySQL/MysqlQuery2008-05-08T16:39:35Z<p>Borov: </p>
<hr />
<div>__NOTOC__<br />
{{ModuleFunction|MySQL}}<br />
<br />
This functions queries the MySQL server through the MySQL connection that has been opened by [[Modules/MySQL/MysqlOpen|mysqlOpen]]. The result of the query is then passed to the script by calling callback_function. It's syntax and functionality is similar to that of [[executeSQLSelect]].<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua">bool mysqlQuery ( mysql db, string callback_function, string query )</syntaxhighlight><br />
<br />
===Required Arguments===<br />
*'''db''' : A ''mysql'' object created by [[Modules/MySQL/MysqlCreate|mysqlCreate]]<br />
*'''callback_function''' : The function that is called if the operation is done (see below)<br />
*'''query''' : The MySQL query that is sent<br />
<br />
===Callback Arguments===<br />
Your callback function has to accept the following arguments.<br />
<br />
On success:<br />
<br />
*'''table:''' The 2-dimensional table where the results are stored in: table [row_index] [column_index].<br />
<br />
On failure:<br />
<br />
*'''boolean:''' False, when no rows are found or an error occured.<br />
<br />
===Optional Arguments===<br />
<br />
''None''<br />
<br />
==Example==<br />
<syntaxhighlight lang="lua"><br />
function onMySQLResult ( table )<br />
outputServerLog ( "Printing some test results" )<br />
outputServerLog ( table[1][1] )<br />
outputServerLog ( table[1][2] )<br />
end<br />
<br />
function onMySQLOpen ( result )<br />
if ( result ) then<br />
outputServerLog ( "MySQL connection established." )<br />
mysqlQuery ( db, "onMySQLResult", "SELECT * FROM test" )<br />
else<br />
outputServerLog ( "MySQL connection failed." )<br />
end<br />
end<br />
<br />
function mysqltest ()<br />
db = mysqlCreate ()<br />
mysqlOpen ( db, "onMySQLOpen", "localhost", "bastage", "bastage_pw", "test", 3306 )<br />
end<br />
</syntaxhighlight><br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Modules&diff=16731Modules2008-05-08T16:38:51Z<p>Borov: </p>
<hr />
<div>Modules are extensions for MTA's lua to provide new external functions that aren't available in the self core. All modules listed here are not included with the MTA distributions and if you want to use them for your development, you must download and install them in your server.<br />
<br />
==Module listing==<br />
You can access the listing of all documented modules in this wiki in the following link: [[:Category:Modules]]<br />
<br />
==Modules SDK==<br />
To be able to create your own module for MTA servers, you must make use of the Modules SDK. You can download it from [http://mtasa.com/files/ml_devkit.tar.gz here].<br />
<br />
===SDK functions===<br />
The SDK functions explained.<br />
<br />
[[Category:Scripting Concepts]]<br />
[[Category:Incomplete]]<br />
[[Category:Modules]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Interior_IDs&diff=16730Interior IDs2008-05-08T16:37:56Z<p>Borov: </p>
<hr />
<div>San Andreas Interior ID list.<br />
<br><br />
<br><br />
*'''ID 0:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Normal world''' || <br />
|-<br />
|}<br />
<br><br />
*'''ID 1:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Ammu-nation 1''' || 289.7870 || -35.7190 || 1003.5160<br />
|-<br />
| '''Burglary House''' || <br />
|-<br />
| '''Cafe shop (Catalina?)''' || 681.65 || -452.86 || -25.62<br />
|-<br />
| '''Restaurant 1''' || 446.6941 || -9.7977 || 1000.7340<br />
|-<br />
| '''Caligulas Casino''' || 2235.2524 || 1708.5146 || 1010.6129<br />
|-<br />
| '''Denise's Place''' || 244.0892 || 304.8456 || 999.1484<br />
|-<br />
| '''Shamal cabin''' || 1.6127 || 34.7411 || 1199.0<br />
|-<br />
| '''Liberty City''' || -750.80 || 491.00 || 1371.70<br />
|-<br />
| '''Sweet's House''' || 2525.0420 || -1679.1150 || 1015.4990<br />
|-<br />
| '''Transfender''' || 621.7850 || -12.5417 || 1000.9220<br />
|-<br />
| '''Safe House 4''' || 2216.5400 || -1076.2900 || 1050.4840<br />
|-<br />
| '''Trials Stadium''' || <br />
|-<br />
| '''Warehouse 1''' || 1405.3120 || -8.2928 || 1000.9130<br />
|-<br />
| '''Doherty Garage''' || -172.0020 || 6.9900 || 28.8350<br />
|-<br />
| '''Sindacco Abatoir''' || 963.6078 || 2108.3970 || 1011.0300<br />
|-<br />
| '''Sub Urban''' || 203.8173 || -46.5385 || 1001.8050<br />
|-<br />
| '''Wu Zi Mu's Betting place''' || -2159.9260 || 641.4587 || 1052.3820<br />
|-<br />
|}<br />
<br><br />
*'''ID 2:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Ryder's House''' || 2464.2110 || -1697.9520 || 1013.5080<br />
|-<br />
| '''Angel Pine Trailer''' || 0.3440 || -0.5140 || 1000.5490¨<br />
|-<br />
| '''The Pig Pen''' || 1213.4330 ||-6.6830 || 1000.9220<br />
|-<br />
| '''BDups Crack Palace''' || 1523.7510 || -46.0458 || 1002.1310<br />
|-<br />
| '''Big Smoke's Crack Palace''' || 2543.6610 || -1303.9320 || 1025.0700<br />
|-<br />
| '''Burglary House 2''' || <br />
|-<br />
| '''Burglary House 9''' || <br />
|-<br />
| '''Burglary House 10''' || <br />
|-<br />
| '''Katie's Place''' || 267.2290 || 304.7100 || 999.1480<br />
|-<br />
| '''Loco Low Co.''' || 612.5910 || -75.6370 || 997.9920<br />
|-<br />
| '''Reece's Barbershop''' || 612.5910 || -75.6370 || 997.9920<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 3:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Jizzy's Pleasure Domes''' || -2636.7190 || 1402.9170 || 906.4609<br />
|-<br />
| '''Brothel''' || 940.6520 || -18.4860 || 1000.9300<br />
|-<br />
| '''Brothel 2''' || 967.5334 || -53.0245 || 1001.1250<br />
|-<br />
| '''BDups Apartment''' || 1527.38 || -11.02 || 1002.10 <br />
|-<br />
| '''Bike School''' || 1494.3350 || 1305.6510 || 1093.2890<br />
|-<br />
| '''Big Spread Ranch''' || 1210.2570 || -29.2986 || 1000.8790<br />
|-<br />
| '''LV Tattoo Parlour''' || -204.4390 || -43.6520 || 1002.2990<br />
|-<br />
| '''LVPD HQ''' || 289.7703 || 171.7460 || 1007.1790<br />
|-<br />
| '''OG Loc's House''' || 516.8890 || -18.4120 || 1001.5650<br />
|-<br />
| '''Pro-Laps''' || 207.3560 || -138.0029 || 1003.3130<br />
|-<br />
| '''Las Venturas Planning Dep.''' || -348.1399 || 161.0369 || 1024.7860<br />
|-<br />
| '''Record Label Hallway''' || 1038.2190 || 6.9905 || 1001.2840<br />
|-<br />
| '''Driving School''' || -2027.9200 || -105.1830 || 1035.1720<br />
|-<br />
| '''Johnson House''' || 2496.0500 || -1693.9260 || 1014.7420<br />
|-<br />
| '''Budget Inn Motel Room''' || <br />
|-<br />
| '''Burglary House 1''' || <br />
|-<br />
| '''Gay Gordo's Barbershop''' || 418.6530 || -82.6390 || 1001.8050<br />
|-<br />
| '''Helena's Place''' || 292.4459 || 308.7790 || 999.1484<br />
|-<br />
| '''Inside Track Betting''' || 826.8863 || 5.5091 || 1004.4830<br />
|-<br />
| '''Sex Shop''' || -106.7268 || -19.6444 || 1000.7190<br />
|-<br />
| '''Wheel Arch Angels''' || 614.3889 || -124.0991 || 997.9950<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 4:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''24/7 shop 1''' || -27.3769 || -27.6416 || 1003.5570<br />
|-<br />
| '''Ammu-Nation 2''' || 285.8000 || -84.5470 || 1001.5390<br />
|-<br />
| '''Burglary House 12''' || <br />
|-<br />
| '''Burglary House 13''' || <br />
|-<br />
| '''Burglary House 15''' || <br />
|-<br />
| '''Diner 2''' || <br />
|-<br />
| '''Dirtbike Stadium''' || -1435.8690 || -662.2505 || 1052.4650<br />
|-<br />
| '''Michelle's Place''' || 302.6404 || 304.8048 || 999.1484<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 5:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Madd Dogg's Mansion''' || 1272.9116 || -768.9028 || 1090.5097<br />
|-<br />
| '''Well Stacked Pizza Co.''' || 377.7758 || -126.2766 || 1001.4920<br />
|-<br />
| '''Victim''' || 221.3310 || -6.6169 || 1005.1977<br />
|-<br />
| '''Burning Desire House''' || 2351.1540 || -1180.5770 || 1027.9770<br />
|-<br />
| '''Barbara's Place''' || <br />
|-<br />
| '''Burglary House 11''' || <br />
|-<br />
| '''Burglary House 16''' || <br />
|-<br />
| '''Burglary House 17''' || <br />
|-<br />
| '''The Crack Den''' || 322.1117 || 1119.3270 || 1083.8830<br />
|-<br />
| '''Police Station (unused)''' || 322.72 || 306.43 || 999.15<br />
|-<br />
| '''Diner place''' || 448.7435 || -110.0457 || 1000.0772<br />
|-<br />
| '''Ganton Gym''' || 768.0793 || 5.8606 || 1000.7160<br />
|-<br />
| '''Vank Hoff Hotel ''' || 2232.8210 || -1110.0180 || 1050.8830<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 6:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Ammu-Nation 3''' || 297.4460 || -109.9680 || 1001.5160<br />
|-<br />
| '''Ammu-Nation 4''' || 317.2380 || -168.0520 || 999.5930<br />
|-<br />
| '''LSPD HQ ''' || 246.4510 || 65.5860 ||1003.6410<br />
|-<br />
| '''Safe House 3''' || 2333.0330 || -1073.9600 || 1049.0230<br />
|-<br />
| '''Safe House 5''' || 2194.2910 || -1204.0150 || 1049.0230<br />
|-<br />
| '''Safe House 6''' || 2308.8710 || -1210.7170 || 1049.0230<br />
|-<br />
| '''Cobra Marital Arts Gym''' || 774.0870 ||-47.9830 || 1000.5860<br />
|-<br />
| '''24/7 shop 2''' || -26.7180 || -55.9860 || 1003.5470<br />
|-<br />
| '''Millie's Bedroom''' || 344.5200 || 304.8210 || 999.1480<br />
|-<br />
| '''Fanny Batter's Brothel''' || 744.2710 || 1437.2530 || 1102.7030<br />
|-<br />
| '''Restaurant 2''' || 443.9810 || -65.2190 || 1050.0000<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 7:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Ammu-Nation 5 (2 Floors)''' || 315.3850 || -142.2420 || 999.6010<br />
|-<br />
| '''8-Track Stadium''' || -1417.8720 || -276.4260 || 1051.1910<br />
|-<br />
| '''Burglary House 4''' || <br />
|-<br />
| '''Below the Belt Gym''' || 774.2430 || -76.0090 || 1000.6540<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 8:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Safe house 2''' || <br />
|-<br />
| '''Colonel Fuhrberger's House''' || 2807.8990 || -1172.9210 || 1025.5700<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 9:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Onbekend safe house''' || 2253.1740 || -1139.0100 || 1050.6330<br />
|-<br />
| '''Andromada Gargo hold''' || 315.48 || 984.13 || 1959.11<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 10:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Four Dragons Casino''' || 2009.4140 || 1017.8990 || 994.4680<br />
|-<br />
| '''RC Zero's Battlefield''' || -975.5766 || 1061.1312 || 1345.6719<br />
|-<br />
| '''Burger Shot''' || 366.4220 ||-73.4700 || 1001.5080<br />
|-<br />
| '''Burglary House 14''' || <br />
|-<br />
| '''Janitor room''' || 1891.3960 ||1018.1260 || 31.8820<br />
|-<br />
| '''Safe House 1''' || <br />
|-<br />
| '''Hashbury safe house''' || 2264.5231 || -1210.5229 || 1049.0234<br />
|-<br />
| '''24/7 shop 3''' || 6.0780 || -28.6330 || 1003.5490<br />
|-<br />
| '''Abandoned AC Tower''' || 419.6140 || 2536.6030 || 10.0000<br />
|-<br />
| '''SFPD HQ''' || 246.4410 || 112.1640 || 1003.2190<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 11:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''The Four Dragons Office''' || 2011.6030 || 1017.0230 || 39.0910<br />
|-<br />
| '''Los Santos safe house''' || <br />
|-<br />
| '''Ten Green Bottles Bar''' || 502.3310 || -70.6820 || 998.7570<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 12:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Budget Inn Motel Room''' || <br />
|-<br />
| '''The Casino''' || 1132.9450 || -8.6750 || 1000.6800<br />
|-<br />
| '''Macisla's Barbershop''' || 411.6410 || -51.8460 || 1001.8980<br />
|-<br />
| '''Safe house 7''' || 2237.2970 || -1077.9250 || 1049.0230<br />
|-<br />
| '''Modern safe house''' || 2324.4990 || -1147.0710 || 1050.7100<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 13:'''<br />
<br><br />
*'''ID 14:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Kickstart Stadium''' || -1464.5360 || 1557.6900 || 1052.5310<br />
|-<br />
| '''Didier Sachs''' || 204.1789 || -165.8740 || 1000.5230<br />
|-<br />
| '''Francis Int. Airport (Front ext.)''' || -1827.1473 || 7.2074 || 1061.1435<br />
|-<br />
| '''Francis Int. Airport (Baggage Claim/Ticket Sales)''' || -1855.5687 || 41.2631 || 1061.1435<br />
|-<br />
| '''Wardrobe''' || 255.7190 || -41.1370 || 1002.0230<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 15:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Binco''' || 207.5430 || -109.0040 || 1005.1330<br />
|-<br />
| '''Blood Bowl Stadium''' || -1394.20 || 987.62 || 1023.96<br />
|-<br />
| '''Jefferson Motel''' || 2217.6250 || -1150.6580 || 1025.7970<br />
|-<br />
| '''Burglary House 5''' || <br />
|-<br />
| '''Burglary House 6''' || <br />
|-<br />
| '''Burglary House 7''' || <br />
|-<br />
| '''Burglary House 8''' || <br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 16:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''24/7 shop 4''' || -25.3730 || -139.6540 || 1003.5470<br />
|-<br />
| '''LS Tattoo Parlour''' || -204.5580 || -25.6970 || 1002.2730<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 17:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''24/7 shop 5''' || -25.3930 || -185.9110 || 1003.5470<br />
|-<br />
| '''Club''' || 493.4687 || -23.0080 || 1000.6796<br />
|-<br />
| '''Rusty Brown's - Ring Donuts''' || 377.0030 || -192.5070 || 1000.6330<br />
|-<br />
| '''The Sherman's Dam Generator Hall''' || -942.1320 || 1849.1420 || 5.0050<br />
|-<br />
| '''Hemlock Tattoo''' || 377.0030 || -192.5070 || 1000.6330<br />
|-<br />
|}<br />
<br />
<br><br />
*'''ID 18:'''<br />
{| class="prettytable" style="width:50%;"<br />
|-<br />
| '''Lil Probe Inn''' || -227.0280 || 1401.2290 || 27.7690<br />
|-<br />
| '''24/7 shop 6''' || -30.9460 || -89.6090 || 1003.5490<br />
|-<br />
| '''Atrium''' || 1726.1370 || -1645.2300 || 20.2260<br />
|-<br />
| '''Warehouse 2''' || 1296.6310 || 0.5920 || 1001.0230<br />
|-<br />
| '''Zip''' || 161.4620 || -91.3940 || 1001.8050<br />
|-<br />
|}<br />
<br />
<br><br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Resource:Admin&diff=16727Resource:Admin2008-05-08T16:33:59Z<p>Borov: </p>
<hr />
<div>{{Resource page}}<br />
A quick tutorial on how to get admin rights and install admin resource.<br />
<br />
'''Note:''' Server should not be running when you are editing the files below<br />
<br />
At first, open the '''accounts.xml''' file located in '''server\mods\deathmatch\''' and add a line with your account details, like on the following example.<br />
<br />
[[Image:admin_accounts.png]]<br />
<br />
<br />
Then you open the '''acl.xml''' file located in the same folder and add yourself as an object to the Admin group by using the 'user.*' syntax, where * would be your account name.<br />
<br />
[[Image:admin_acl.png]]<br />
<br />
<br />
Now open your '''mtaserver.conf''' file and scroll to the bottom, make sure the admin resource is added to the ones that start with the server (note: protected="1" means that it can not be stopped).<br />
<br />
[[Image:admin_mtaserver.png]]<br />
<br />
<br />
Now that you're done with server files, you can you can finally start it. Connect to the server itself and login with your account details: use 'login [username] <password>'. If it tells you to press 'p' you have done everything right, congratulations! If not, do this from the very beginning.<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Account&diff=16726Account2008-05-08T16:33:30Z<p>Borov: </p>
<hr />
<div>The [[account]] class represents a [[client]]'s server account. You can get the [[account]] object associated to any client using [[getClientAccount]].<br />
<br />
Accounts are unique to each client and can be used to store information that is persistent across map changes and user sessions. Clients that join without an account are given a temporary 'guest' account. This can store information like any other account, but isn't saved across sessions.<br />
<br />
When a user logs in or out, the account object assigned to them will change. As such, you must not assume that the account attached to a client remains constant during their session.<br />
<br />
==Related scripting functions==<br />
===Server===<br />
{{Account functions}}<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element/Blip&diff=16725Element/Blip2008-05-08T16:31:42Z<p>Borov: </p>
<hr />
<div>__NOTOC__<br />
The blip class represents small icons or blips that can be shown on a player's radar.<br />
<br />
The element type of this class is '''"blip"'''.<br />
<br />
==XML syntax==<br />
<syntaxhighlight lang="xml"><br />
<blip posX="" posY="" posZ="" icon="" color="" dimension="" ordering=""/><br />
</syntaxhighlight><br />
<br />
===Required Attributes===<br />
* '''posX''': A float representing the X position of the vehicle.<br />
* '''posY''': A float representing the Y position of the vehicle.<br />
* '''posZ''': A float representing the Z position of the vehicle.<br />
<br />
===Optional Attributes===<br />
* '''color:''' The color of the icon in HTML-style format (i.e. #RRGGBB). Defaults to blue if not specified.<br />
* '''icon:''' The icon of the blip. Defaults to 0 if not specified.<br />
* '''dimension:''' The dimension of the blip. Defaults to 0 if not specified.<br />
* '''ordering:''' The Z-level ordering of the blip. Defaults to 0 if not specified.<br />
<br />
==Related scripting functions==<br />
===Client===<br />
{{Client_blip_functions}}<br />
===Server===<br />
{{Blip_functions}}<br />
==Blip Icon References==<br />
{{Blip Icons}}<br />
[[Category:Element Types]]<br />
<br />
[[it: Elemento Blip]]<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=MTA_Classes&diff=16723MTA Classes2008-05-08T16:27:01Z<p>Borov: </p>
<hr />
<div>In order to perform operations on MTA objects via scripting, pointers to internal classes are exported to scripts as Lua userdata. Each of these classes has a number of exported scripting functions associated to them.<br />
<br />
The complete list of classes to be found in scripts follows:<br />
<br />
* [[account|Account]]<br />
* [[element|Element]]<br />
<ul>{{Elements}}</ul><br />
* [[resource|Resource]]<br />
* [[textdisplay|Text display]]<br />
* [[textitem|Text item]]<br />
* [[timer|Timer]]<br />
* [[xmlnode|XML node]]<br />
* [[acl|ACL]]<br />
* [[aclgroup|ACL group]]<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Java_SDK&diff=16722Java SDK2008-05-08T16:26:25Z<p>Borov: </p>
<hr />
<div>This SDK allows you to call exported MTA functions from Java over HTTP.<br />
<br />
==Getting Started==<br />
To use it, you need to make sure you need to have the following packages:<br />
* ''com.multitheftauto''<br />
* ''org.json.simple''<br />
* ''org.json.simple.parser''<br />
These are all included in the zip file below.<br />
<br />
To get started, import com.multitheftauto.MTARPC.<br />
<br />
==Syntax==<br />
This class has one public static function, ''callFunction''. The syntax is as follows:<br />
<syntaxhighlight lang="lua">[java5]<br />
Object[] callFunction ( String serverHTTPAddress, String resourceName, String functionName, Object[] args )<br />
</syntaxhighlight><br />
* '''serverHTTPAddress:''' The server's HTTP address, in the form hostname:port (without "http://" prefixed)<br />
* '''resourceName:''' The name of the resource that has exported the function you want to call<br />
* '''functionName:''' The name of the function you want to call<br />
* '''args:''' An array of arguments you wish to pass. Most basic types are accepted - String, Integer, Double, Boolean, null etc, as well as the special classes com.multitheftauto.Element and com.multitheftauto.Resource.<br />
<br />
==Examples==<br />
This tests the resource functions exported from the 'echobot' resource:<br />
<syntaxhighlight lang="lua">[java5]<br />
Object[] ret = MTARPC.callFunction ( SERVER_HTTP_ADDRESS, "echobot", "getThisResource", null );<br />
Resource resource = (Resource)ret[0];<br />
Object[] arguments = {resource};<br />
ret = MTARPC.callFunction ( SERVER_HTTP_ADDRESS, "echobot", "getResourceName", arguments );<br />
String resourceName = (String)ret[0];<br />
System.out.println("Resource name: " + resourceName );<br />
</syntaxhighlight><br />
<br />
This example tests the element functions exported from the 'echobot' resource: <br />
<syntaxhighlight lang="lua">[java5]<br />
// call getRootElement<br />
Object[] ret = MTARPC.callFunction ( SERVER_HTTP_ADDRESS, "echobot", "getRootElement", null );<br />
Element rootElement = (Element)ret[0];<br />
<br />
// call getElementType<br />
Object[] arguments = {rootElement};<br />
ret = MTARPC.callFunction ( SERVER_HTTP_ADDRESS, "echobot", "getElementType", arguments );<br />
String rootElementType = (String)ret[0];<br />
<br />
System.out.println("Root element type: " + rootElementType );<br />
</syntaxhighlight><br />
<br />
==More complex example==<br />
[[Image:Mta java sdk example.png]]<br />
<br />
The zip file contains an example program (MTAJavaTest.java) that implements a console that allows you to see events on a server and chat to the players there. This allows you to see how you can handle multiple returns.<br />
<br />
==Caveats==<br />
* You cannot currently compare two Resource or Element objects that you expect to be identical - you need to do a "deep compare", comparing either the "id" fields or the "name" fields.<br />
<br />
==Download==<br />
* [http://misc.opencoding.net/mta/mtajavasdk_0.1.zip Download Version 0.1]<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Standard_GUI_Font_Names&diff=16721Standard GUI Font Names2008-05-08T16:22:06Z<p>Borov: </p>
<hr />
<div>These are the available CGUI fonts that are used in Multi Theft Auto and can be accessed with the GUI scripting functions [[guiGetFont]] and [[guiSetFont]].<br />
<br />
<br />
<gallery heights="48" widths="236" perrow="3" caption="Available font properties and previews"><br />
Image:mta-font_default-normal.gif|<div style="font-weight: bold">default-normal</div>Tahoma regular, 9px<br />
Image:mta-font_default-small.gif|<div style="font-weight: bold">default-small</div>Tahoma regular, 7px<br />
Image:mta-font_default-bold-small.gif|<div style="font-weight: bold">default-bold-small</div>Tahoma bold, 8px<br />
Image:mta-font_clear-normal.gif|<div style="font-weight: bold">clear-normal</div>Verdana regular, 9px<br />
Image:mta-font_sa-header.gif|<div style="font-weight: bold">sa-header</div>Diploma regular, 26px auto-scaled<br />
Image:mta-font_sa-gothic.gif|<div style="font-weight: bold">sa-gothic</div>Beckett regular, 47px auto-scaled<br />
</gallery><br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Event_system&diff=16720Event system2008-05-08T16:21:25Z<p>Borov: </p>
<hr />
<div>The event system is at the core of MTA scripting. Events work closely in conjunction with the element tree. Events are triggered when something happens - a player enters a marker, an element is clicked on etc. Each event has a source element, this is the element that performed the action.<br />
<br />
==Event handlers==<br />
To use the event system, you attach event handlers to elements in the element tree using addEventHandler. When you do this, your function will get triggered for all the events triggered on that element, it's parents (and their parents, etc.) and it's children (and their children). As such, an event handler attached to the ''root'' element will be triggered when an event occurs for any element. As a consequence you should generally use as specific a handler as you can. If you wish to just see when the player enters a specific marker, just attach the event handler to that marker.<br />
<br />
Each event handler has two 'hidden' variables:<br />
* '''source''': This is the element that the event originated from.<br />
* '''this''': This is the element that the handler is being triggered on (i.e. the one you attached it to with addEventHandler).<br />
<br />
The ''source'' variable is the most important one for most handlers. You almost always will want to reference this variable to tell what element triggered the event. The ''this'' variable has some uses for ensuring that an event was emitted by the element that you attached the handler to.<br />
<br />
It is ''important'' to note that events follow the element hierachy. All events are initially triggered on the ''source'' element, followed by all the parent and children elements. This has few important implications:<br />
<br />
* An event triggered on the root element will be triggered on every element in the element tree. This should be avoided where possible.<br />
* All events anywhere in the element tree will be triggered on the root element. This means you can easily catch every event of a type by attaching a handler to the root element. Only do this if you genuinely want every event of that type, otherwise attach it somewhere more specific in the element tree.<br />
* You can attach an event handler to your resource's root element to get all the events triggered by elements your resource contains.<br />
<br />
==Built in events==<br />
MTA has a number of built in events. These are listed on the pages [[Client Scripting Events]] and [[Scripting Events]].<br />
<br />
==Custom events==<br />
You can create your own events that can be triggered across all resources. This is an important way to communicate with other resources and allow them to hook into your code. To add your own custom event, just call the [[addEvent]] function. You can then use the [[triggerEvent]] function to trigger that event any time you want - either using a timer, or based on a more general event. <br />
<br />
For example, you could be making a Capture the Flag game mode and want to trigger an event when a player captures the flag. You could do this by attaching a event handler to the standard MTA [[onMarkerHit]] event and checking that the player entering the marker has the flag. if they do, you can then trigger your more specific ''onFlagCaptured'' event and other resources could handle this as they please.<br />
<br />
==Canceling==<br />
Events can be canceled with [[cancelEvent]]. This can have a variety of effects, but in general this means that the server will not perform whatever action it would usually do. For example, canceling [[onPickupUse]] would prevent a player being given what they tried to pick up, canceling [[onVehicleStartEnter]] would prevent the player entering the vehicle. You can check if the currently active event has been canceled using [[wasEventCanceled]]. It's important to note that canceling event ''does not'' prevent other event handlers being triggered.<br />
<br />
[[Category:Scripting Concepts]]<br />
[[Category:Incomplete Summaries]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Dictionary&diff=16719Dictionary2008-05-08T16:20:51Z<p>Borov: </p>
<hr />
<div>Over the years MTA's community has come across some new terms and words. They are most often used in IRC and on the forums but some are also featered in the game. What follows is an alphabetical list.<br />
<hr /><br /><br />
<br />
* Bitchpack (verb)<br />
Use of the lack of enter vehicle animation in MTA 0.x in order to get unlimited players into a <br />
vehicle<br />
<br />
* Johnline (being a ..) (noun)<br />
acting immature, using a lot of sexual related insults hoping to make you look cool/mature.<br />
<br />
* MAD_BOY (noun)<br />
When something is refered to as old or outdated<br />
<br />
* Ransom<br />
GTANet's resident bastard operator from hell<br />
<br />
* RIFK<br />
A common typographical error of "rofl", has also come to be known as an acronym <br />
for "rolling in fucking kitchens." Though first pioneered in #mta by Jani, it is most<br />
frequently used by BrophY and Johnline<br />
<br />
* Robpol86 (verb)/(noun)<br />
-Consistent use of mushrooms in order to grow and the ability to jump incredibly high<br />
-Also a mythical creature with a mustache of supernatural size and ability<br />
<br />
* YOIV<br />
-Your Opinion Is Void (aka "pulling a Luke")<br />
-Used to discribe a situation where an admin uses his powers to force his own opinion onto <br />
a person or a group of people.<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element/COL&diff=16718Element/COL2008-05-08T16:20:23Z<p>Borov: </p>
<hr />
<div>__NOTOC__<br />
The [[COL]] class represents a RenderWare Collision File (COL3) loaded by the client, which can be imported into a custom model to define its collisions.<br />
<br />
Collision data can also be embedded in DFF files. At the moment, vehicle collision replacement works with DFF embedded collisions only.<br />
<br />
==Related scripting functions==<br />
===Client===<br />
{{Engine_functions}}</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element_tree&diff=16717Element tree2008-05-08T16:19:48Z<p>Borov: </p>
<hr />
<div>MTA uses a so-called ''element tree'' to store all the elements that exist on the server and the client. This is directly related to the set of running [[resources]] and their map files' XML layout, although it can be changed at run-time by scripts.<br />
<br />
If you are familiar with the concept of ''trees'' in computer-science, this should be easy to understand. If you are not, think of it like a family tree - except everyone only has a single parent. Every [[element]] has a ''parent'' element.<br />
<br />
All elements that are created within scripts or from .map files are child elements of the resource they belong to. Thus, most elements (except for [[client]]s) exist only within resources and are also destroyed as soon as their resource is stopped.<br />
<br />
==Tree elements==<br />
* '''root''': This is at the very base of the tree - all elements are children (or descendants) of this element.<br />
* '''resource''': These are direct children of the root element - with one for each ''running'' resource. This element is called the ''resource root''. Its ID holds the name of the resource.<br />
* '''map''': Each resource element contains at least one map element, representing either a ".map" file in the resource or the one containing the elements created by scripts (this is called the ''dynamic'' map). Their IDs contain the maps' filenames, or ''dynamic'' for the dynamic map.<br />
** Map files can contain a number of other [[element]]s as well as an unlimited number of custom elements.<br />
<br />
==Example==<br />
This in an example of a serverside tree dumped to XML from a running server.<br />
''Please note that it is shortened on some places for the sake of overview.''<br />
<syntaxhighlight lang="xml"><br />
<root><br />
<console/><br />
<player dontRespawn="false"/><br />
<player dontRespawn="false" lastSpawnarea=""/><br />
<resource id="resourcebrowser"/><br />
<resource id="ajax"/><br />
<resource id="resourcemanager"/><br />
<resource id="spawnmanager"/><br />
<resource id="mapmanager"/><br />
<resource id="runcode"/><br />
<resource id="fr"><br />
<map id="dynamic"><br />
<vehicle/><br />
</map><br />
</resource><br />
<resource id="elementbrowser"/><br />
<resource id="assault"><br />
<map id="dynamic"><br />
<team/><br />
<team/><br />
<blip/><br />
<marker/><br />
<colshape/><br />
<blip/><br />
<blip/><br />
</map><br />
</resource><br />
<resource id="as-farm"><br />
<map id="dynamic"/><br />
<map id="as-farm.map"><br />
<meta><br />
<author/><br />
<version/><br />
<name/><br />
<description/><br />
</meta><br />
<spawngroup req="" type="attacker"><br />
<spawnarea posY="-8.3976354598999" posX="20.182683944702" skins="9" ... /><br />
</spawngroup><br />
<spawngroup req="" type="attacker"><br />
<spawnarea posY="32.166355133057" posX="-46.90763092041" skins="9" ... /><br />
</spawngroup><br />
<spawngroup req="" type="attacker"><br />
<spawnarea posY="35.214984893799" posX="-33.486911773682" skins="9" ... /><br />
</spawngroup><br />
<spawngroup req="" type="attacker"><br />
<spawnarea posY="35.214984893799" posX="-33.486911773682" skins="9" ... /><br />
</spawngroup><br />
<objective id="first" type="checkpoint" description="Breach into the farm" ... /><br />
<pickup type="weapon" ... /><br />
</map><br />
</resource><br />
</root><br />
</syntaxhighlight><br />
===Explanation===<br />
This tree consists of a number of resource root elements, the [[Element/Console|server console]] and two [[player]] elements, that are direct children of the '''root''' element. All these resources have a ''dynamic map'' as child element (it is just not shown for most of them). These contain the elements that are created dynamically by this resource using scripts, for example a [[vehicle]]. If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.<br />
<br />
Let's have a closer look at the '''assault''' resource: This contains just one ''dynamic'' map that has 2 teams, 3 blips, 1 marker and 1 colshape as child elements. These are the elements that are created by the script, for example the marker, the colshape and one of the blips are probably used for the objective.<br />
<br />
The '''as-farm''' resource's function on the contrary is to be a map for the '''assault''' gamemode. The dynamic map is empty (it could contain elements if there was a script in it though), while there is a map called 'as-farm.map', that contains a number of elements. These are mostly custom elements (like spawngroup, spawnarea, objective) but also a few elements that MTA creates automactically after loading the map (like pickup). In the brackets after the element type, you can see the element data it contains. These are identical with the attributes the .map file contains within these elements, while you can also set and get element data for any other elements (e.g. players) with [[setElementData]] and [[getElementData]].<br />
<br />
==Pratical application==<br />
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.<br />
<br />
===Setting data for elements===<br />
If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).<br />
<br />
So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to ''2.5''.<br />
<syntaxhighlight lang="lua"><br />
setMarkerSize ( getRootElement(), 2.5 )<br />
</syntaxhighlight><br />
<br />
The same can be done on any element, it is not restricted to the root element.<br />
<br />
===Map manager===<br />
The [[#Example|example above]] shows the way the [[map manager]] uses different resources. The 'assault' resource is the gamemode, that manages what happens on the server using scripts and thus by creating elements in the tree dynamically. When a map resource is started, the gamemode receives a [[resource|resource pointer]] referring to the started resource - in this case ''as-farm'' - from which you can retrieve and store the resource root element. Using this element in conjunction with functions like [[getElementsByType]], [[getElementData]] and various others, you can access any of the information that was loaded into the tree from the 'as-farm.map'-file through scripts in the gamemode resource.<br />
<br />
Another thing that has to be considered related to the tree of elements is the fact that when you change the map, you don't have to remove any elements you created within the map resource, while you '''do''' have to remove elements that are created within the gamemode resource, '''if''' they are specific to the map (which will be probably the case for those items you create based on information read from the map resource's .map files).<br />
<br />
==Element browser==<br />
You can start the resource ''elementbrowser'' to see a live view of the element tree on your server. Just start the resource and browser to your server's web page and choose the ''Element browser'' option in the sidebar (firefox only currently).<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element/COL&diff=16716Element/COL2008-05-08T16:18:23Z<p>Borov: </p>
<hr />
<div>__NOTOC__<br />
The [[COL]] class represents a RenderWare Collision File (COL3) loaded by the client, which can be imported into a custom model to define its collisions.<br />
<br />
Collision data can also be embedded in DFF files. At the moment, vehicle collision replacement works with DFF embedded collisions only.<br />
<br />
==Related scripting functions==<br />
===Client===<br />
{{Engine_functions}}<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Boolean&diff=16715Boolean2008-05-08T16:17:52Z<p>Borov: </p>
<hr />
<div>A ''boolean'' or ''bool'' is a datatype whose value can be either ''true'' or ''false''. These are often returned by functions to indicate whether the operation was successful or not.<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element/Blip&diff=16714Element/Blip2008-05-08T16:17:33Z<p>Borov: </p>
<hr />
<div>__NOTOC__<br />
The blip class represents small icons or blips that can be shown on a player's radar.<br />
<br />
The element type of this class is '''"blip"'''.<br />
<br />
==XML syntax==<br />
<syntaxhighlight lang="xml"><br />
<blip posX="" posY="" posZ="" icon="" color="" dimension="" ordering=""/><br />
</syntaxhighlight><br />
<br />
===Required Attributes===<br />
* '''posX''': A float representing the X position of the vehicle.<br />
* '''posY''': A float representing the Y position of the vehicle.<br />
* '''posZ''': A float representing the Z position of the vehicle.<br />
<br />
===Optional Attributes===<br />
* '''color:''' The color of the icon in HTML-style format (i.e. #RRGGBB). Defaults to blue if not specified.<br />
* '''icon:''' The icon of the blip. Defaults to 0 if not specified.<br />
* '''dimension:''' The dimension of the blip. Defaults to 0 if not specified.<br />
* '''ordering:''' The Z-level ordering of the blip. Defaults to 0 if not specified.<br />
<br />
==Related scripting functions==<br />
===Client===<br />
{{Client_blip_functions}}<br />
===Server===<br />
{{Blip_functions}}<br />
==Blip Icon References==<br />
{{Blip Icons}}<br />
[[Category:Element Types]]<br />
<br />
[[it: Elemento Blip]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element/Blip&diff=16713Element/Blip2008-05-08T16:16:44Z<p>Borov: </p>
<hr />
<div>__NOTOC__<br />
The blip class represents small icons or blips that can be shown on a player's radar.<br />
<br />
The element type of this class is '''"blip"'''.<br />
<br />
==XML syntax==<br />
<syntaxhighlight lang="xml"><br />
<blip posX="" posY="" posZ="" icon="" color="" dimension="" ordering=""/><br />
</syntaxhighlight><br />
<br />
===Required Attributes===<br />
* '''posX''': A float representing the X position of the vehicle.<br />
* '''posY''': A float representing the Y position of the vehicle.<br />
* '''posZ''': A float representing the Z position of the vehicle.<br />
<br />
===Optional Attributes===<br />
* '''color:''' The color of the icon in HTML-style format (i.e. #RRGGBB). Defaults to blue if not specified.<br />
* '''icon:''' The icon of the blip. Defaults to 0 if not specified.<br />
* '''dimension:''' The dimension of the blip. Defaults to 0 if not specified.<br />
* '''ordering:''' The Z-level ordering of the blip. Defaults to 0 if not specified.<br />
<br />
==Related scripting functions==<br />
===Client===<br />
{{Client_blip_functions}}<br />
===Server===<br />
{{Blip_functions}}<br />
==Blip Icon References==<br />
{{Blip Icons}}<br />
[[Category:Element Types]]<br />
<br />
[[it: Elemento Blip]]<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Element/Blip&diff=16712Element/Blip2008-05-08T16:15:59Z<p>Borov: </p>
<hr />
<div>__NOTOC__<br />
The blip class represents small icons or blips that can be shown on a player's radar.<br />
<br />
The element type of this class is '''"blip"'''.<br />
<br />
==XML syntax==<br />
<syntaxhighlight lang="xml"><br />
<blip posX="" posY="" posZ="" icon="" color="" dimension="" ordering=""/><br />
</syntaxhighlight><br />
<br />
===Required Attributes===<br />
* '''posX''': A float representing the X position of the vehicle.<br />
* '''posY''': A float representing the Y position of the vehicle.<br />
* '''posZ''': A float representing the Z position of the vehicle.<br />
<br />
===Optional Attributes===<br />
* '''color:''' The color of the icon in HTML-style format (i.e. #RRGGBB). Defaults to blue if not specified.<br />
* '''icon:''' The icon of the blip. Defaults to 0 if not specified.<br />
* '''dimension:''' The dimension of the blip. Defaults to 0 if not specified.<br />
* '''ordering:''' The Z-level ordering of the blip. Defaults to 0 if not specified.<br />
<br />
==Related scripting functions==<br />
===Client===<br />
{{Client_blip_functions}}<br />
===Server===<br />
{{Blip_functions}}<br />
==Blip Icon References==<br />
{{Blip Icons}}<br />
[[Category:Element Types]]<br />
<br />
[[it: Elemento Blip]]<br />
[[category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=ASCII&diff=16709ASCII2008-05-08T15:25:59Z<p>Borov: </p>
<hr />
<div>{| class="wikitable" style="text-align: center; float:left;"<br />
|-<br />
!Dec !! Glyph<br />
|-<br />
|style="background:#CCFFFF;"| 32 || Space<br />
|-<br />
|style="background:#CCFFFF;"| 33 || !<br />
|-<br />
|style="background:#CCFFFF;"| 34 || "<br />
|-<br />
|style="background:#CCFFFF;"| 35 || #<br />
|-<br />
|style="background:#CCFFFF;"| 36 || $<br />
|-<br />
|style="background:#CCFFFF;"| 37 || %<br />
|-<br />
|style="background:#CCFFFF;"| 38 || &<br />
|-<br />
|style="background:#CCFFFF;"| 39 || '<br />
|-<br />
|style="background:#CCFFFF;"| 40 || (<br />
|-<br />
|style="background:#CCFFFF;"| 41 || )<br />
|-<br />
|style="background:#CCFFFF;"| 42 || *<br />
|-<br />
|style="background:#CCFFFF;"| 43 || +<br />
|-<br />
|style="background:#CCFFFF;"| 44 || ,<br />
|-<br />
|style="background:#CCFFFF;"| 45 || -<br />
|-<br />
|style="background:#CCFFFF;"| 46 || .<br />
|-<br />
|style="background:#CCFFFF;"| 47 || /<br />
|-<br />
|style="background:#CCFFFF;"| 48 || 0<br />
|-<br />
|style="background:#CCFFFF;"| 49 || 1<br />
|-<br />
|style="background:#CCFFFF;"| 50 || 2<br />
|-<br />
|style="background:#CCFFFF;"| 51 || 3<br />
|-<br />
|style="background:#CCFFFF;"| 52 || 4<br />
|-<br />
|style="background:#CCFFFF;"| 53 || 5<br />
|-<br />
|style="background:#CCFFFF;"| 54 || 6<br />
|-<br />
|style="background:#CCFFFF;"| 55 || 7<br />
|-<br />
|style="background:#CCFFFF;"| 56 || 8<br />
|-<br />
|style="background:#CCFFFF;"| 57 || 9<br />
|-<br />
|style="background:#CCFFFF;"| 58 || :<br />
|-<br />
|style="background:#CCFFFF;"| 59 || ;<br />
|-<br />
|style="background:#CCFFFF;"| 60 || <<br />
|-<br />
|style="background:#CCFFFF;"| 61 || =<br />
|-<br />
|style="background:#CCFFFF;"| 62 || ><br />
|-<br />
|style="background:#CCFFFF;"| 63 || ?<br />
|}<br />
<br />
{| class="wikitable" style="text-align:center; float:left;"<br />
|- valign="bottom"<br />
! Dec !! Glyph<br />
|-<br />
|style="background:#CCFFFF;"| 64 || @<br />
|-<br />
|style="background:#CCFFFF;"| 65 || A<br />
|-<br />
|style="background:#CCFFFF;"| 66 || B<br />
|-<br />
|style="background:#CCFFFF;"| 67 || C<br />
|-<br />
|style="background:#CCFFFF;"| 68 || D<br />
|-<br />
|style="background:#CCFFFF;"| 69 || E<br />
|-<br />
|style="background:#CCFFFF;"| 70 || F<br />
|-<br />
|style="background:#CCFFFF;"| 71 || G<br />
|-<br />
|style="background:#CCFFFF;"| 72 || H<br />
|-<br />
|style="background:#CCFFFF;"| 73 || I<br />
|-<br />
|style="background:#CCFFFF;"| 74 || J<br />
|-<br />
|style="background:#CCFFFF;"| 75 || K<br />
|-<br />
|style="background:#CCFFFF;"| 76 || L<br />
|-<br />
|style="background:#CCFFFF;"| 77 || M<br />
|-<br />
|style="background:#CCFFFF;"| 78 || N<br />
|-<br />
|style="background:#CCFFFF;"| 79 || O<br />
|-<br />
|style="background:#CCFFFF;"| 80 || P<br />
|-<br />
|style="background:#CCFFFF;"| 81 || Q<br />
|-<br />
|style="background:#CCFFFF;"| 82 || R<br />
|-<br />
|style="background:#CCFFFF;"| 83 || S<br />
|-<br />
|style="background:#CCFFFF;"| 84 || T<br />
|-<br />
|style="background:#CCFFFF;"| 85 || U<br />
|-<br />
|style="background:#CCFFFF;"| 86 || V<br />
|-<br />
|style="background:#CCFFFF;"| 87 || W<br />
|-<br />
|style="background:#CCFFFF;"| 88 || X<br />
|-<br />
|style="background:#CCFFFF;"| 89 || Y<br />
|-<br />
|style="background:#CCFFFF;"| 90 || Z<br />
|-<br />
|style="background:#CCFFFF;"| 91 || <nowiki>[</nowiki><br />
|-<br />
|style="background:#CCFFFF;"| 92 || \<br />
|-<br />
|style="background:#CCFFFF;"| 93 || <nowiki>]</nowiki><br />
|-<br />
|style="background:#CCFFFF;"| 94 || ^<br />
|-<br />
|style="background:#CCFFFF;"| 95 || _<br />
|}<br />
<br />
{| class="wikitable" style="text-align:center; float:left;"<br />
|- valign="bottom"<br />
! Dec !! Glyph<br />
|-<br />
|style="background:#CCFFFF;"| 96 || `<br />
|-<br />
|style="background:#CCFFFF;"| 97 || a<br />
|-<br />
|style="background:#CCFFFF;"| 98 || b<br />
|-<br />
|style="background:#CCFFFF;"| 99 || c<br />
|-<br />
|style="background:#CCFFFF;"| 100 || d<br />
|-<br />
|style="background:#CCFFFF;"| 101 || e<br />
|-<br />
|style="background:#CCFFFF;"| 102 || f<br />
|-<br />
|style="background:#CCFFFF;"| 103 || g<br />
|-<br />
|style="background:#CCFFFF;"| 104 || h<br />
|-<br />
|style="background:#CCFFFF;"| 105 || i<br />
|-<br />
|style="background:#CCFFFF;"| 106 || j<br />
|-<br />
|style="background:#CCFFFF;"| 107 || k<br />
|-<br />
|style="background:#CCFFFF;"| 108 || l<br />
|-<br />
|style="background:#CCFFFF;"| 109 || m<br />
|-<br />
|style="background:#CCFFFF;"| 110 || n<br />
|-<br />
|style="background:#CCFFFF;"| 111 || o<br />
|-<br />
|style="background:#CCFFFF;"| 112 || p<br />
|-<br />
|style="background:#CCFFFF;"| 113 || q<br />
|-<br />
|style="background:#CCFFFF;"| 114 || r<br />
|-<br />
|style="background:#CCFFFF;"| 115 || s<br />
|-<br />
|style="background:#CCFFFF;"| 116 || t<br />
|-<br />
|style="background:#CCFFFF;"| 117 || u<br />
|-<br />
|style="background:#CCFFFF;"| 118 || v<br />
|-<br />
|style="background:#CCFFFF;"| 119 || w<br />
|-<br />
|style="background:#CCFFFF;"| 120 || x<br />
|-<br />
|style="background:#CCFFFF;"| 121 || y<br />
|-<br />
|style="background:#CCFFFF;"| 122 || z<br />
|-<br />
|style="background:#CCFFFF;"| 123 || &#123;<br />
|-<br />
|style="background:#CCFFFF;"| 124 || &#124;<br />
<br />
|-<br />
|style="background:#CCFFFF;"| 125 || &#125;<br />
|-<br />
|style="background:#CCFFFF;"| 126 || ~<br />
|}<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Category:Incomplete&diff=16708Category:Incomplete2008-05-08T15:25:44Z<p>Borov: </p>
<hr />
<div>This is a list of functions that need to be documented. To list a function as incomplete, add the following to the function's page: <br />
<br />
<nowiki>[[Category:Incomplete]]</nowiki></div>Borovhttps://wiki.multitheftauto.com/index.php?title=Category:Incomplete&diff=16707Category:Incomplete2008-05-08T15:24:26Z<p>Borov: </p>
<hr />
<div>This is a list of functions that need to be documented. To list a function as incomplete, add the following to the function's page: <br />
<br />
<nowiki>[[Category:Incomplete]]</nowiki><br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Access_Control_List&diff=16706Access Control List2008-05-08T15:23:33Z<p>Borov: </p>
<hr />
<div>MTA includes a complete Access Control List (ACL) that allows you to secure and limit access to the server, it's functions and resources in any number of ways.<br />
<br />
The key concept of MTA's ACL (and ACLs in general) is that you're giving a specific object a set of rights. In MTA's case objects are one of two things - resources or users. There are numerous ''rights'' available in MTA - these mainly focus on server-side scripting functions. <br />
<br />
What this essentially means is that the ACL allows you to choose exactly what functions a resource or user can perform. This can obviously be invaluable - for example preventing all your server's players from being able to ban each other, or preventing your new untested resources from doing the same. <br />
<br />
Of course, ''with great power comes great responsibility'' and it is very easily possible to completely break resources - for example, disabling [[spawnPlayer]] for all resources would be a Bad Thing. Of course, there are situations when you might want to do this - if you want to force all your resources to use a spawn manager resource for example, but even this is somewhat draconian.<br />
<br />
==How it works==<br />
There are three ways you can modify the ACL - how you do it depends who you are.<br />
<br />
===HTTP Interface===<br />
You can use the [[Resource/webadmin|webadmin]] http interface to modify the ACL in your web browser. This is by far the easiest way to do so. Just make sure the ''webadmin'' resource is started on your server and visit ''<nowiki>http://ServerIP:HttpPort/</nowiki>''. You can then use the two sections - ACLs and Groups. ACLs allows you to create your Access Control Lists - lists of rights. Groups allow you to group together collections of users and assign ACLs to them. For example, the ACLs section allows you to specify that the Admin ACL has access to the ''start'' console command. You can the go to the Groups section and create an Admin ''group'' that has access to your Admin ''acl''. You can then add users to your Admin ''group''.<br />
<br />
===XML file===<br />
You can modify the ACL.xml file manually. This has a fairly straightforward syntax, but it can get a bit confusing at times. If you do it while the server is running, don't forget to call [[aclReload]] so the new ACL is loaded. This also prevents your changes from being accidentally overwritten by the server.<br />
<br />
===Scripting functions===<br />
You can use a large number of ACL scripting functions to modify the ACL on the fly. Of course, you can (and really should!) limit access to the ACL functions with the ACL.<br />
<br />
{{ACL functions}}<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Tasks&diff=16705Tasks2008-05-08T15:21:27Z<p>Borov: </p>
<hr />
<div>The task system is a system that is built into Grand Theft Auto: San Andreas. It is a large system that manages everything to do with how players and pedestrians behave. Every action a player or pedestrian performs is a task of some type. Each player can have a number of primary and secondary tasks. Primary tasks tend to be the most interesting to us when making scripts. Primary tasks are divided up into 5 slots ordered by priority, while secondary tasks are divided up into 6 slots each with a different purpose. The slots are as follows:<br />
<br />
'''PRIMARY TASKS'''<br />
*'''0:''' TASK_PRIORITY_PHYSICAL_RESPONSE<br />
*'''1:''' TASK_PRIORITY_EVENT_RESPONSE_TEMP<br />
*'''2:''' TASK_PRIORITY_EVENT_RESPONSE_NONTEMP<br />
*'''3:''' TASK_PRIORITY_PRIMARY<br />
*'''4:''' TASK_PRIORITY_DEFAULT<br />
'''SECONDARY TASKS'''<br />
*'''0:''' TASK_SECONDARY_ATTACK<br />
*'''1:''' TASK_SECONDARY_DUCK<br />
*'''2:''' TASK_SECONDARY_SAY<br />
*'''3:''' TASK_SECONDARY_FACIAL_COMPLEX<br />
*'''4:''' TASK_SECONDARY_PARTIAL_ANIM<br />
*'''5:''' TASK_SECONDARY_IK<br />
Each slot can contain one task at a time, or be empty. <br />
<br />
There are two types of tasks - complex tasks and simple tasks. Simple tasks actually perform actions that affect the player, such as opening a car door, walking forwards etc. Complex tasks trigger off simple tasks in a sequence to perform more complex things, such as walking to a car, opening the door and getting in.<br />
<br />
If a complex task is in a slot, you can get what task that complex task is running using [[getPlayerTask]] and an index value of 1. If that itself has a child task, then you can retrieve that using an index value of 2 etc.<br />
<br />
You can see a complete list of tasks on the [[list of player tasks]] page.<br />
[[Category:Scripting Concepts]]</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Introduction_to_Scripting_the_GUI&diff=16701Introduction to Scripting the GUI2008-05-07T05:32:03Z<p>Borov: /* Scripting the button */</p>
<hr />
<div><!-- place holder --><br />
One important feature in MTA:DM is the ability to script customized GUI (Graphic User Interface). The GUI consists of windows, button, edit boxes, check boxes... Almost every standard form components in graphical environments. They can be displayed while the user is in game, and used for inputs and outpus in place of traditional commands. <br />
<br />
[[Image:AdminGUI.png|thumb|Admin Console GUI]]<br />
<br />
==A tutorial to make a login window==<br />
In this tutorial we'll make a simple login window, with two input boxes and a button. The window appears when the player joins the game, and once the button is clicked, the player is spawned. The tutorial will continue the gamemode we made in [[Scripting Introduction|Introduction to Scripting]]. We'll also take a look at client-side scripting. <br />
<br />
===Draw the window===<br />
All the GUI must be made client side. It is also a good practice to keep all the client scripts in a separate folder. Browse to /Your MTA Server/mods/deathmatch/resources/myserver/ directory, and create a folder named "client". Under /client/ directory, create a text file and name it "gui.lua", and in this file we will write a funtion that draws the window:<br />
<syntaxhighlight lang="lua"><br />
function CreateLoginWindow()<br />
local X = 0.375<br />
local Y = 0.375<br />
local Width = 0.25<br />
local Height = 0.25<br />
wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)<br />
end<br />
</syntaxhighlight><br />
You may click on the function's name to read its documentation. Note that the coordinates of the window is in ''percentage'' of the screen. It means that if the screen is labelled with 0 on the left end, and 1 on the right end, and if "X" is 0.5, it represents the middle of the screen. It applies to Y, window width, and window height as well (if "width" is 0.5, the window will be half as wide as the screen). Next we'll add the text labels (saying "username:" and "password:"), edit boxes and a button. Replace the function with its complete version:<br />
<syntaxhighlight lang="lua"><br />
function CreateLoginWindow()<br />
local X = 0.375<br />
local Y = 0.375<br />
local Width = 0.25<br />
local Height = 0.25<br />
wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)<br />
<br />
X = 0.0825<br />
Y = 0.2<br />
Width = 0.25<br />
Height = 0.25<br />
guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)<br />
Y = 0.5<br />
guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)<br />
<br />
X = 0.415<br />
Y = 0.2<br />
Width = 0.5<br />
Height = 0.15<br />
edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)<br />
Y = 0.5<br />
edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)<br />
guiEditSetMaxLength(edtUser, 50)<br />
guiEditSetMaxLength(edtPass, 50)<br />
<br />
X = 0.415<br />
Y = 0.7<br />
Width = 0.25<br />
Height = 0.2<br />
btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)<br />
<br />
guiSetVisible(wdwLogin, false)<br />
end<br />
</syntaxhighlight><br />
Note that every GUI component created is a child of the window, this is done by specifying the parent element (wdwLogin, in this case) when creating the component:<br />
<syntaxhighlight lang="lua"><br />
guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)<br />
</syntaxhighlight><br />
This is very useful because later when you need to control the entire set of GUI, you can just refer to the parent element. For example:<br />
<syntaxhighlight lang="lua"><br />
guiSetVisible(wdwLogin, false) --hides all the GUI we made so we can show them to the player at the appropriate moment. <br />
</syntaxhighlight><br />
<br />
===Using the function we wrote===<br />
The CreateLoginWindow function is done, but it won't do anything until we call it. It is recommended to create all GUI when the client resource starts, hide them, and show them to player later when needed. Therefore, we'll write an event handler for "[[onClientResourceStart]]" to create the window:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), <br />
function ()<br />
CreateLoginWindow()<br />
end<br />
) <br />
</syntaxhighlight><br />
We would like to show the window when the client joins the game, using the same event "[[onClientResourceStart]]". Now the event handler looks like:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), <br />
function ()<br />
CreateLoginWindow()<br />
<br />
outputChatBox("Welcome to My MTA DM Server, please log in. ")<br />
<br />
if (wdwLogin ~= nil) then<br />
guiSetVisible(wdwLogin, true)<br />
end <br />
<br />
showCursor(true)<br />
guiSetInputEnabled(true)<br />
end<br />
) <br />
</syntaxhighlight><br />
Note that we have a security check before making the window visible, so that in case the window had not been created, in which case wdwLogin is not a valid element, we don't get an error. The [[showCursor]] function gives control to your mouse, and [[guiSetInputEnabled]] makes sure when you type in the GUI, certain letters like "A", "S", "D", "W", "T" don't move your character or bring out the chatbox input. In the next step, we'll make the button work as desired.<br />
<br />
===Scripting the button===<br />
When the player clicks on any part of the GUI, the event "[[onClientGUIClick]]" will be triggered for the GUI component you clicked on. For instance, if you click on the button, you can add the event handler attached to the button:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientGUIClick", theButtonElement, theHandlerFunction, false)<br />
</syntaxhighlight><br />
In our script, we only need the event handler attached to the button. When it's clicked, the client will tell the server to spawn the player. Find the event handler code for "onClientResourceStart" from the previous section, and add the following line right AFTER CreateLoginWindow() is called:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false)<br />
</syntaxhighlight><br />
The event handler must be added here because it makes sure variable btnLogin contains the actual button. You cannot attach an event to an non-existant element. You should have noticed that we need the "clientSubmitLogin" function, as stated in the line above.<br />
<syntaxhighlight lang="lua"><br />
function clientSubmitLogin(button)<br />
if button == "left" then<br />
<br />
triggerServerEvent("SubmitLogin", g_root, guiGetText(edtUser), guiGetText(edtPass))<br />
guiSetInputEnabled(false)<br />
guiSetVisible(wdwLogin, false)<br />
showCursor(false)<br />
end<br />
end<br />
</syntaxhighlight><br />
The variable "button" is passed by the event handler, and it's a string with the name of the button (either "left" or "right"). Here we also hit a new concept, which is custom events. Custom events can be triggered by script from the same side (server to server, or client to client), or from the other side (server to client, or vice versa). Here we use the [[triggerServerEvent]] function to trigger a custom event on the server, "SubmitLogin".<br />
<br />
At this point we have all the code needed on the client side. On the server side, recall that we are spawning the player as soon as they join, as shown below: <br />
<syntaxhighlight lang="lua"><br />
function joinHandler()<br />
local x,y,z<br />
x = 1959.55<br />
y = -1714.46<br />
z = 10<br />
spawnPlayer(source, x, y, z)<br />
fadeCamera(source, true)<br />
outputChatBox("Welcome to My Server", source)<br />
end<br />
addEventHandler('onPlayerJoin', getRootElement(), joinHandler)<br />
</syntaxhighlight><br />
However, since we are going to spawn the player when the button is clicked, we must replace the "onPlayerJoin" event with the custom event triggered by the client script. Replace the above code with the following:<br />
<syntaxhighlight lang="lua"><br />
function joinHandler(username, password)<br />
local x,y,z<br />
x = 1959.55<br />
y = -1714.46<br />
z = 10<br />
if (client) then<br />
spawnPlayer(client, x, y, z)<br />
fadeCamera(client, true)<br />
outputChatBox("Welcome to My Server", client)<br />
end<br />
end<br />
<br />
addEvent("SubmitLogin", true)<br />
addEventHandler("SubmitLogin", getRootElement(), joinHandler)<br />
</syntaxhighlight><br />
Note that the second arguement of [[addEvent]] function (the one with value "true") specifies whether the event can be triggered by the other side, therefore we need to turn it on since the client is triggering it. Also note the variable "client", it's an internal variable used by MTA to identify the player who triggered the event. <br />
<br />
Finally, do not forget to include the new gui.lua file in the meta.xml of the main resource, and label it as a client script:<br />
<syntaxhighlight lang="xml"><br />
<script src="client/gui.lua" type="client" /><br />
</syntaxhighlight><br />
<br />
As to this point, we have a basic login window that spawns the player when the "login" button is clicked. You can also use the username and password submitted by the [[triggerServerEvent]] function to verify the player's identify before spawning him.</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Introduction_to_Scripting_the_GUI&diff=16700Introduction to Scripting the GUI2008-05-07T05:31:36Z<p>Borov: </p>
<hr />
<div><!-- place holder --><br />
One important feature in MTA:DM is the ability to script customized GUI (Graphic User Interface). The GUI consists of windows, button, edit boxes, check boxes... Almost every standard form components in graphical environments. They can be displayed while the user is in game, and used for inputs and outpus in place of traditional commands. <br />
<br />
[[Image:AdminGUI.png|thumb|Admin Console GUI]]<br />
<br />
==A tutorial to make a login window==<br />
In this tutorial we'll make a simple login window, with two input boxes and a button. The window appears when the player joins the game, and once the button is clicked, the player is spawned. The tutorial will continue the gamemode we made in [[Scripting Introduction|Introduction to Scripting]]. We'll also take a look at client-side scripting. <br />
<br />
===Draw the window===<br />
All the GUI must be made client side. It is also a good practice to keep all the client scripts in a separate folder. Browse to /Your MTA Server/mods/deathmatch/resources/myserver/ directory, and create a folder named "client". Under /client/ directory, create a text file and name it "gui.lua", and in this file we will write a funtion that draws the window:<br />
<syntaxhighlight lang="lua"><br />
function CreateLoginWindow()<br />
local X = 0.375<br />
local Y = 0.375<br />
local Width = 0.25<br />
local Height = 0.25<br />
wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)<br />
end<br />
</syntaxhighlight><br />
You may click on the function's name to read its documentation. Note that the coordinates of the window is in ''percentage'' of the screen. It means that if the screen is labelled with 0 on the left end, and 1 on the right end, and if "X" is 0.5, it represents the middle of the screen. It applies to Y, window width, and window height as well (if "width" is 0.5, the window will be half as wide as the screen). Next we'll add the text labels (saying "username:" and "password:"), edit boxes and a button. Replace the function with its complete version:<br />
<syntaxhighlight lang="lua"><br />
function CreateLoginWindow()<br />
local X = 0.375<br />
local Y = 0.375<br />
local Width = 0.25<br />
local Height = 0.25<br />
wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)<br />
<br />
X = 0.0825<br />
Y = 0.2<br />
Width = 0.25<br />
Height = 0.25<br />
guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)<br />
Y = 0.5<br />
guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)<br />
<br />
X = 0.415<br />
Y = 0.2<br />
Width = 0.5<br />
Height = 0.15<br />
edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)<br />
Y = 0.5<br />
edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)<br />
guiEditSetMaxLength(edtUser, 50)<br />
guiEditSetMaxLength(edtPass, 50)<br />
<br />
X = 0.415<br />
Y = 0.7<br />
Width = 0.25<br />
Height = 0.2<br />
btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)<br />
<br />
guiSetVisible(wdwLogin, false)<br />
end<br />
</syntaxhighlight><br />
Note that every GUI component created is a child of the window, this is done by specifying the parent element (wdwLogin, in this case) when creating the component:<br />
<syntaxhighlight lang="lua"><br />
guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)<br />
</syntaxhighlight><br />
This is very useful because later when you need to control the entire set of GUI, you can just refer to the parent element. For example:<br />
<syntaxhighlight lang="lua"><br />
guiSetVisible(wdwLogin, false) --hides all the GUI we made so we can show them to the player at the appropriate moment. <br />
</syntaxhighlight><br />
<br />
===Using the function we wrote===<br />
The CreateLoginWindow function is done, but it won't do anything until we call it. It is recommended to create all GUI when the client resource starts, hide them, and show them to player later when needed. Therefore, we'll write an event handler for "[[onClientResourceStart]]" to create the window:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), <br />
function ()<br />
CreateLoginWindow()<br />
end<br />
) <br />
</syntaxhighlight><br />
We would like to show the window when the client joins the game, using the same event "[[onClientResourceStart]]". Now the event handler looks like:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), <br />
function ()<br />
CreateLoginWindow()<br />
<br />
outputChatBox("Welcome to My MTA DM Server, please log in. ")<br />
<br />
if (wdwLogin ~= nil) then<br />
guiSetVisible(wdwLogin, true)<br />
end <br />
<br />
showCursor(true)<br />
guiSetInputEnabled(true)<br />
end<br />
) <br />
</syntaxhighlight><br />
Note that we have a security check before making the window visible, so that in case the window had not been created, in which case wdwLogin is not a valid element, we don't get an error. The [[showCursor]] function gives control to your mouse, and [[guiSetInputEnabled]] makes sure when you type in the GUI, certain letters like "A", "S", "D", "W", "T" don't move your character or bring out the chatbox input. In the next step, we'll make the button work as desired.<br />
<br />
===Scripting the button===<br />
When the player clicks on any part of the GUI, the event "[[onClientGUIClick]]" will be triggered for the GUI component you clicked on. For instance, if you click on the button, you can add the event handler attached to the button:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientGUIClick", theButtonElement, theHandlerFunction, false)<br />
</syntaxhighlight><br />
In our script, we only need the event handler attached to the button. When it's clicked, the client will tell the server to spawn the player. Find the event handler code for "onClientResourceStart" from the previous section, and add the following line right AFTER CreateLoginWindow() is called:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false)<br />
</syntaxhighlight><br />
The event handler must be added here because it makes sure variable btnLogin contains the actual button. You cannot attach an event to an non-existant element. You should have noticed that we need the "clientSubmitLogin" function, as stated in the line above.<br />
<syntaxhighlight lang="lua"><br />
function clientSubmitLogin(button)<br />
if button == "left" then<br />
<br />
triggerServerEvent("SubmitLogin", g_root, guiGetText(edtUser), guiGetText(edtPass))<br />
guiSetInputEnabled(false)<br />
guiSetVisible(wdwLogin, false)<br />
showCursor(false)<br />
end<br />
end<br />
</syntaxhighlight><br />
The variable "button" is passed by the event handler, and it's a string with the name of the button (either "left" or "right"). Here we also hit a new concept, which is custom events. Custom events can be triggered by script from the same side (server to server, or client to client), or from the other side (server to client, or vice versa). Here we use the [[triggerServerEvent]] function to trigger a custom event on the server, "SubmitLogin".<br />
<br />
At this point we have all the code needed on the client side. On the server side, recall that we are spawning the player as soon as they join, as shown below: <br />
<syntaxhighlight lang="lua"><br />
function joinHandler()<br />
local x,y,z<br />
x = 1959.55<br />
y = -1714.46<br />
z = 10<br />
spawnPlayer(source, x, y, z)<br />
fadeCamera(source, true)<br />
outputChatBox("Welcome to My Server", source)<br />
end<br />
addEventHandler('onPlayerJoin', getRootElement(), joinHandler)<br />
</syntaxhighlight><br />
However, since we are going to spawn the player when the button is clicked, we must replace the "onPlayerJoin" event with the custom event triggered by the client script. Replace the above code with the following:<br />
<syntaxhighlight lang="lua"><br />
function joinHandler(username, password)<br />
local x,y,z<br />
x = 1959.55<br />
y = -1714.46<br />
z = 10<br />
if (client) then<br />
spawnPlayer(client, x, y, z)<br />
fadeCamera(client, true)<br />
outputChatBox("Welcome to My Server", client)<br />
end<br />
end<br />
<br />
addEvent("SubmitLogin", true)<br />
addEventHandler("SubmitLogin", getElementRoot(), joinHandler)<br />
</syntaxhighlight><br />
Note that the second arguement of [[addEvent]] function (the one with value "true") specifies whether the event can be triggered by the other side, therefore we need to turn it on since the client is triggering it. Also note the variable "client", it's an internal variable used by MTA to identify the player who triggered the event. <br />
<br />
Finally, do not forget to include the new gui.lua file in the meta.xml of the main resource, and label it as a client script:<br />
<syntaxhighlight lang="xml"><br />
<script src="client/gui.lua" type="client" /><br />
</syntaxhighlight><br />
<br />
As to this point, we have a basic login window that spawns the player when the "login" button is clicked. You can also use the username and password submitted by the [[triggerServerEvent]] function to verify the player's identify before spawning him.</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Introduction_to_Scripting_the_GUI&diff=16699Introduction to Scripting the GUI2008-05-07T05:03:32Z<p>Borov: </p>
<hr />
<div><!-- place holder --><br />
One important feature in MTA:DM is the ability to script customized GUI (Graphic User Interface). The GUI consists of windows, button, edit boxes, check boxes... Almost every standard form components in graphical environments. They can be displayed while the user is in game, and used for inputs and outpus in place of traditional commands. <br />
<br />
[[Image:AdminGUI.png|thumb|Admin Console GUI]]<br />
<br />
==A tutorial to make a login window==<br />
In this tutorial we'll make a simple login window, with two input boxes and a button. The window appears when the player joins the game, and once the button is clicked, the player is spawned. The tutorial will continue the gamemode we made in [[Scripting Introduction|Introduction to Scripting]]. We'll also take a look at client-side scripting. <br />
<br />
===Draw the window===<br />
All the GUI must be made client side. It is also a good practice to keep all the client scripts in a separate folder. Browse to /Your MTA Server/mods/deathmatch/resources/myserver/ directory, and create a folder named "client". Under /client/ directory, create a text file and name it "gui.lua", and in this file we will write a funtion that draws the window:<br />
<syntaxhighlight lang="lua"><br />
function CreateLoginWindow()<br />
local X = 0.375<br />
local Y = 0.375<br />
local Width = 0.25<br />
local Height = 0.25<br />
wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)<br />
end<br />
</syntaxhighlight><br />
You may click on the function's name to read its documentation. Note that the coordinates of the window is in ''percentage'' of the screen. It means that if the screen is labelled with 0 on the left end, and 1 on the right end, and if "X" is 0.5, it represents the middle of the screen. It applies to Y, window width, and window height as well (if "width" is 0.5, the window will be half as wide as the screen). Next we'll add the text labels (saying "username:" and "password:"), edit boxes and a button. Replace the function with its complete version:<br />
<syntaxhighlight lang="lua"><br />
function CreateLoginWindow()<br />
local X = 0.375<br />
local Y = 0.375<br />
local Width = 0.25<br />
local Height = 0.25<br />
wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)<br />
<br />
X = 0.0825<br />
Y = 0.2<br />
Width = 0.25<br />
Height = 0.25<br />
guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)<br />
Y = 0.5<br />
guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)<br />
<br />
X = 0.415<br />
Y = 0.2<br />
Width = 0.5<br />
Height = 0.15<br />
edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)<br />
Y = 0.5<br />
edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)<br />
guiEditSetMaxLength(edtUser, 50)<br />
guiEditSetMaxLength(edtPass, 50)<br />
<br />
X = 0.415<br />
Y = 0.7<br />
Width = 0.25<br />
Height = 0.2<br />
btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)<br />
<br />
guiSetVisible(wdwLogin, false)<br />
end<br />
</syntaxhighlight><br />
Note that every GUI component created is a child of the window, this is done by specifying the parent element (wdwLogin, in this case) when creating the component:<br />
<syntaxhighlight lang="lua"><br />
guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)<br />
</syntaxhighlight><br />
This is very useful because later when you need to control the entire set of GUI, you can just refer to the parent element. For example:<br />
<syntaxhighlight lang="lua"><br />
guiSetVisible(wdwLogin, false) --hides all the GUI we made so we can show them to the player at the appropriate moment. <br />
</syntaxhighlight><br />
<br />
===Using the function we wrote===<br />
The CreateLoginWindow function is done, but it won't do anything until we call it. It is recommended to create all GUI when the client resource starts, hide them, and show them to player later when needed. Therefore, we'll write an event handler for "[[onClientResourceStart]]" to create the window:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), <br />
function ()<br />
CreateLoginWindow()<br />
end<br />
) <br />
</syntaxhighlight><br />
We would like to show the window when the client joins the game, using the same event "[[onClientResourceStart]]". Now the event handler looks like:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), <br />
function ()<br />
CreateLoginWindow()<br />
<br />
outputChatBox("Welcome to My MTA DM Server, please log in. ")<br />
<br />
if (wdwLogin ~= nil) then<br />
guiSetVisible(wdwLogin, true)<br />
end <br />
<br />
showCursor(true)<br />
guiSetInputEnabled(true)<br />
end<br />
) <br />
</syntaxhighlight><br />
Note that we have a security check before making the window visible, so that in case the window had not been created, in which case wdwLogin is not a valid element, we don't get an error. The [[showCursor]] function gives control to your mouse, and [[guiSetInputEnabled]] makes sure when you type in the GUI, certain letters like "A", "S", "D", "W", "T" don't move your character or bring out the chatbox input. In the next step, we'll make the button work as desired.<br />
<br />
===Scripting the button===<br />
When the player clicks on any part of the GUI, the event "[[onClientGUIClick]]" will be triggered for the GUI component you clicked on. For instance, if you click on the button, you can add the event handler attached to the button:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientGUIClick", theButtonElement, theHandlerFunction, false)<br />
</syntaxhighlight><br />
In our script, we only need the event handler attached to the button. When it's clicked, the client will tell the server to spawn the player. Find the event handler code for "onClientResourceStart" from the previous section, and add the following line right AFTER CreateLoginWindow() is called:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false)<br />
</syntaxhighlight><br />
The event handler must be added here because it makes sure variable btnLogin contains the actual button. You cannot attach an event to an non-existant element. You should have noticed that we need the "clientSubmitLogin" function, as stated in the line above.<br />
<syntaxhighlight lang="lua"><br />
function clientSubmitLogin(button)<br />
if button == "left" then<br />
<br />
triggerServerEvent("SubmitLogin", g_root, guiGetText(edtUser), guiGetText(edtPass))<br />
guiSetInputEnabled(false)<br />
guiSetVisible(wdwLogin, false)<br />
showCursor(false)<br />
end<br />
end<br />
</syntaxhighlight><br />
The variable "button" is passed by the event handler, and it's a string with the name of the button (either "left" or "right"). Here we also hit a new concept, which is custom events. Custom events can be triggered by script from the same side (server to server, or client to client), or from the other side (server to client, or vice versa). Here we use the [[triggerServerEvent]] function to trigger a custom event on the server, "SubmitLogin".<br />
<br />
At this point we have all the code needed on the client side. On the server side, recall that we are spawning the player as soon as they join, as shown below: <br />
<syntaxhighlight lang="lua"><br />
function joinHandler()<br />
local x,y,z<br />
x = 1959.55<br />
y = -1714.46<br />
z = 10<br />
spawnPlayer(source, x, y, z)<br />
fadeCamera(source, true)<br />
outputChatBox("Welcome to My Server", source)<br />
end<br />
addEventHandler('onPlayerJoin', getRootElement(), joinHandler)<br />
</syntaxhighlight><br />
However, since we are going to spawn the player when the button is clicked, we must replace the "onPlayerJoin" event with the custom event triggered by the client script. Replace the above code with the following:<br />
<syntaxhighlight lang="lua"><br />
function joinHandler(username, password)<br />
local x,y,z<br />
x = 1959.55<br />
y = -1714.46<br />
z = 10<br />
if (client) then<br />
spawnPlayer(client, x, y, z)<br />
fadeCamera(client, true)<br />
outputChatBox("Welcome to My Server", client)<br />
end<br />
end<br />
<br />
addEvent("SubmitLogin", true)<br />
addEventHandler("SubmitLogin", g_root, joinHandler)<br />
</syntaxhighlight><br />
Note that the second arguement of [[addEvent]] function (the one with value "true") specifies whether the event can be triggered by the other side, therefore we need to turn it on since the client is triggering it. Also note the variable "client", it's an internal variable used by MTA to identify the player who triggered the event. <br />
<br />
Finally, do not forget to include the new gui.lua file in the meta.xml of the main resource, and label it as a client script:<br />
<syntaxhighlight lang="xml"><br />
<script src="client/gui.lua" type="client" /><br />
</syntaxhighlight><br />
<br />
As to this point, we have a basic login window that spawns the player when the "login" button is clicked. You can also use the username and password submitted by the [[triggerServerEvent]] function to verify the player's identify before spawning him.</div>Borovhttps://wiki.multitheftauto.com/index.php?title=Introduction_to_Scripting_the_GUI&diff=16698Introduction to Scripting the GUI2008-05-07T05:01:47Z<p>Borov: </p>
<hr />
<div><!-- place holder --><br />
One important feature in MTA:DM is the ability to script customized GUI (Graphic User Interface). The GUI consists of windows, button, edit boxes, check boxes... Almost every standard form components in graphical environments. They can be displayed while the user is in game, and used for inputs and outpus in place of traditional commands. <br />
<br />
[[Image:AdminGUI.png|thumb|Admin Console GUI]]<br />
<br />
==A tutorial to make a login window==<br />
In this tutorial we'll make a simple login window, with two input boxes and a button. The window appears when the player joins the game, and once the button is clicked, the player is spawned. The tutorial will continue the gamemode we made in [[Scripting Introduction|Introduction to Scripting]]. We'll also take a look at client-side scripting. <br />
<br />
===Draw the window===<br />
All the GUI must be made client side. It is also a good practice to keep all the client scripts in a separate folder. Browse to /Your MTA Server/mods/deathmatch/resources/myserver/ directory, and create a folder named "client". Under /client/ directory, create a text file and name it "gui.lua", and in this file we will write a funtion that draws the window:<br />
<syntaxhighlight lang="lua"><br />
function CreateLoginWindow()<br />
local X = 0.375<br />
local Y = 0.375<br />
local Width = 0.25<br />
local Height = 0.25<br />
wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)<br />
end<br />
</syntaxhighlight><br />
You may click on the function's name to read its documentation. Note that the coordinates of the window is in ''percentage'' of the screen. It means that if the screen is labelled with 0 on the left end, and 1 on the right end, and if "X" is 0.5, it represents the middle of the screen. It applies to Y, window width, and window height as well (if "width" is 0.5, the window will be half as wide as the screen). Next we'll add the text labels (saying "username:" and "password:"), edit boxes and a button. Replace the function with its complete version:<br />
<syntaxhighlight lang="lua"><br />
function CreateLoginWindow()<br />
local X = 0.375<br />
local Y = 0.375<br />
local Width = 0.25<br />
local Height = 0.25<br />
wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)<br />
<br />
X = 0.0825<br />
Y = 0.2<br />
Width = 0.25<br />
Height = 0.25<br />
guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)<br />
Y = 0.5<br />
guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)<br />
<br />
X = 0.415<br />
Y = 0.2<br />
Width = 0.5<br />
Height = 0.15<br />
edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)<br />
Y = 0.5<br />
edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)<br />
guiEditSetMaxLength(edtUser, 50)<br />
guiEditSetMaxLength(edtPass, 50)<br />
<br />
X = 0.415<br />
Y = 0.7<br />
Width = 0.25<br />
Height = 0.2<br />
btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)<br />
<br />
guiSetVisible(wdwLogin, false)<br />
end<br />
</syntaxhighlight><br />
Note that every GUI component created is a child of the window, this is done by specifying the parent element (wdwLogin, in this case) when creating the component:<br />
<syntaxhighlight lang="lua"><br />
guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)<br />
</syntaxhighlight><br />
This is very useful because later when you need to control the entire set of GUI, you can just refer to the parent element. For example:<br />
<syntaxhighlight lang="lua"><br />
guiSetVisible(wdwLogin, false) --hides all the GUI we made so we can show them to the player at the appropriate moment. <br />
</syntaxhighlight><br />
<br />
===Using the function we wrote===<br />
The CreateLoginWindow function is done, but it won't do anything until we call it. It is recommended to create all GUI when the client resource starts, hide them, and show them to player later when needed. Therefore, we'll write an event handler for "[[onClientResourceStart]]" to create the window:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), <br />
function ()<br />
CreateLoginWindow()<br />
end<br />
) <br />
</syntaxhighlight><br />
We would like to show the window when the client joins the game, using the same event "[[onClientResourceStart]]". Now the event handler looks like:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), <br />
function ()<br />
CreateLoginWindow()<br />
<br />
outputChatBox("Welcome to My MTA DM Server, please log in. ")<br />
<br />
if (wdwLogin ~= nil) then<br />
guiSetVisible(wdwLogin, true)<br />
end <br />
<br />
showCursor(true)<br />
guiSetInputEnabled(true)<br />
end<br />
) <br />
</syntaxhighlight><br />
Note that we have a security check before making the window visible, so that in case the window had not been created, in which case wdwLogin is not a valid element, we don't get an error. The [[showCursor]] function gives control to your mouse, and [[guiSetInputEnabled]] makes sure when you type in the GUI, certain letters like "A", "S", "D", "W", "T" don't move your character or bring out the chatbox input. In the next step, we'll make the button work as desired.<br />
<br />
===Scripting the button===<br />
When the player clicks on any part of the GUI, the event "[[onClientGUIClick]]" will be triggered for the GUI component you clicked on. For instance, if you click on the button, you can add the event handler attached to the button:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientGUIClick", theButtonElement, theHandlerFunction, false)<br />
</syntaxhighlight><br />
In our script, we only need the event handler attached to the button. When it's clicked, the client will tell the server to spawn the player. Find the event handler code for "onClientResourceStart" from the previous section, and add the following line right AFTER CreateLoginWindow() is called:<br />
<syntaxhighlight lang="lua"><br />
addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false)<br />
</syntaxhighlight><br />
The event handler must be added here because it makes sure variable btnLogin contains the actual button. You cannot attach an event to an non-existant element. You should have noticed that we need the "clientSubmitLogin" function, as stated in the line above.<br />
<syntaxhighlight lang="lua"><br />
function clientSubmitLogin(button)<br />
if button == "left" then<br />
<br />
triggerServerEvent("SubmitLogin", g_root, guiGetText(edtUser), guiGetText(edtPass))<br />
guiSetInputEnabled(false)<br />
guiSetVisible(wdwLogin, false)<br />
showCursor(false)<br />
end<br />
end<br />
</syntaxhighlight><br />
The variable "button" is passed by the event handler, and it's a string with the name of the button (either "left" or "right"). Here we also hit a new concept, which is custom events. Custom events can be triggered by script from the same side (server to server, or client to client), or from the other side (server to client, or vice versa). Here we use the [[triggerServerEvent]] function to trigger a custom event on the server, "SubmitLogin".<br />
<br />
At this point we have all the code needed on the client side. On the server side, recall that we are spawning the player as soon as they join, as shown below: <br />
<syntaxhighlight lang="lua"><br />
function joinHandler()<br />
local x,y,z<br />
x = 1959.55<br />
y = -1714.46<br />
z = 10<br />
spawnPlayer(source, x, y, z)<br />
fadeCamera(source, true)<br />
outputChatBox("Welcome to My Server", source)<br />
end<br />
addEventHandler('onPlayerJoin', getRootElement(), joinHandler)<br />
</syntaxhighlight><br />
However, since we are going to spawn the player when the button is clicked, we must replace the "onPlayerJoin" event with the custom event triggered by the client script. Replace the above code with the following:<br />
<syntaxhighlight lang="lua"><br />
function joinHandler(username, password)<br />
local x,y,z<br />
x = 1959.55<br />
y = -1714.46<br />
z = 10<br />
if (client) then<br />
spawnPlayer(client, x, y, z)<br />
fadeCamera(client, true)<br />
outputChatBox("Welcome to My Server", client)<br />
end<br />
end<br />
<br />
addEvent("SubmitLogin", true)<br />
addEventHandler("SubmitLogin", g_root, joinHandler)<br />
</syntaxhighlight><br />
Note that the second arguement of [[addEvent]] function (the one with value "true") specifies whether the event can be triggered by the other side, therefore we need to turn it on since the client is triggering it. <br />
<br />
Finally, do not forget to include the new gui.lua file in the meta.xml of the main resource, and label it as a client script:<br />
<syntaxhighlight lang="xml"><br />
<script src="client/gui.lua" type="client" /><br />
</syntaxhighlight><br />
<br />
As to this point, we have a basic login window that spawns the player when the "login" button is clicked. You can also use the username and password submitted by the [[triggerServerEvent]] function to verify the player's identify before spawning him.</div>Borov