<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kevin</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kevin"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Kevin"/>
	<updated>2026-04-25T17:04:15Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=HU/Resource_Web_Access&amp;diff=50737</id>
		<title>HU/Resource Web Access</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HU/Resource_Web_Access&amp;diff=50737"/>
		<updated>2017-04-18T06:06:59Z</updated>

		<summary type="html">&lt;p&gt;Kevin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Pages==&lt;br /&gt;
===Specifying a file in the meta===&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;html src=&amp;quot;filename.ext&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can then access this file from your web browser by visiting: http://host:port/resourcename/filename.ext&amp;lt;br/&amp;gt;&lt;br /&gt;
For example, on a locally hosted server using default http port with webmap started: http://127.0.0.1:22005/webmap/map.htm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binary files===&lt;br /&gt;
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=&amp;quot;true&amp;quot;'' to the ''html'' node. This means that the files are not preprocessed before being sent to the web browser.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;html src=&amp;quot;image.gif&amp;quot; raw=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Parsed files===&lt;br /&gt;
If a file is not specified in the meta file as &amp;quot;raw&amp;quot;, 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.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
        This resource is called &amp;lt;* httpWrite( getResourceName(getThisResource()) ) *&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is a shorthand (in common with PHP and ASP) for this code, meaning that you can also write the above code as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
        This resource is called &amp;lt;* = getResourceName(getThisResource()) *&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Aside from HTTP functions, embedded Lua has access to the following environment variables that contain information about how the page was requested:&lt;br /&gt;
* table '''requestHeaders''': This is a table containing all the headers that were requested with the page. You can set returned headers using [[httpSetResponseHeader]]. &lt;br /&gt;
* 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.&lt;br /&gt;
* table '''cookies''': This is a table of all the cookies. You can modify cookies using [[httpSetResponseCookie]].&lt;br /&gt;
* string '''hostname''': This is a string containing the IP address or hostname that requested the page.&lt;br /&gt;
* string '''url''': This is the URL of the page.&lt;br /&gt;
* account '''user''': This is the account of the current user.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Calls==&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
To specify an exported http-accessible function, add the following to your meta.xml file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;export function='functionName' http='true' /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Protocol===&lt;br /&gt;
{{note_box|You don't need to know this unless you're writing your own HTTP request code. You can just use one of the [[#SDK|SDKs listed below]].}}&lt;br /&gt;
&lt;br /&gt;
Calls are done by requesting ''&amp;lt;nowiki&amp;gt;http://&amp;lt;your IP&amp;gt;:&amp;lt;your port&amp;gt;/&amp;lt;resource_name&amp;gt;/call/&amp;lt;exported_function_name&amp;gt;&amp;lt;/nowiki&amp;gt;'' using HTTP POST. The body of the request should be a JSON array of the arguments for the function.&lt;br /&gt;
&lt;br /&gt;
The request will return a JSON array of the value(s) returned from the function as the HTTP response.&lt;br /&gt;
&lt;br /&gt;
The server supports HTTP Basic authentication and you can configure access via the ACL and the built-in accounts system.&lt;br /&gt;
&lt;br /&gt;
===Calls from the HTTP web interface===&lt;br /&gt;
Using calls is probably easiest from the web interface and can be done almost seamlessly.&lt;br /&gt;
&lt;br /&gt;
First, add this to your meta.xml file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;include resource=&amp;quot;ajax&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Secondly, add the following to the &amp;lt;head&amp;gt; section of the page you want to call from:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;* = exports.ajax:start(getResourceName(getThisResource())) *&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here's a simple example.&lt;br /&gt;
&lt;br /&gt;
'''meta.xml'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
   &amp;lt;include resource=&amp;quot;ajax&amp;quot; /&amp;gt;&lt;br /&gt;
   &amp;lt;script src='code.lua' /&amp;gt;&lt;br /&gt;
   &amp;lt;html src='page.htm' default='true' /&amp;gt;&lt;br /&gt;
   &amp;lt;export function='showChatMessage' http='true' /&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''code.lua'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function showChatMessage ( message )&lt;br /&gt;
    outputChatBox ( message )&lt;br /&gt;
    return 5;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''page.htm'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
    &amp;lt;head&amp;gt;&lt;br /&gt;
        &amp;lt;* = exports.ajax:start(getResourceName(getThisResource())) *&amp;gt;&lt;br /&gt;
        &amp;lt;script type='text/javascript'&amp;gt;&lt;br /&gt;
            function say() {&lt;br /&gt;
                var message = document.getElementById('message')&lt;br /&gt;
                showChatMessage ( message.value, &lt;br /&gt;
                    function ( number ) {&lt;br /&gt;
                        // the function has been called and returned something&lt;br /&gt;
                        message.value = &amp;quot;The function returned &amp;quot; + number;&lt;br /&gt;
                    }&lt;br /&gt;
                );&lt;br /&gt;
            }&lt;br /&gt;
        &amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;lt;/head&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
        &amp;lt;input type='text' id='message' /&amp;gt;&amp;lt;input type='button' value='say' onclick='say();' /&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can see (fairly complex) examples of how this can be done in the resources ''resourcebrowser'', ''resourcemanager'' and ''webadmin''.&lt;br /&gt;
&lt;br /&gt;
==Securing the web interface==&lt;br /&gt;
The [[ACL]] has a number of rights that can affect what files can be accessed.&lt;br /&gt;
{{Deprecated feature|3.0139|1.3.1|&lt;br /&gt;
* general.http: If disabled, none of the http files can be accessed (except by game clients)&lt;br /&gt;
** '''Important Note''': ''If 'general.http' is enabled, http access to all resources (for that ACL) is enabled by default. To disable http access you have to explicitly block access to resources that contain exported http functions.''&lt;br /&gt;
** '''Important Note''': ''If 'general.http' is enabled on an ACL which has a user with no password (i.e. user.* or user.guest or user.http_guest), it is essential that you explicitly block access to resources that contain exported http functions.''&lt;br /&gt;
* resource.'''ResourceName''': If disabled, none of the files in the resource can be accessed&lt;br /&gt;
* resource.'''ResourceName'''.file.'''FileName''': If disabled, the file named cannot be accessed&lt;br /&gt;
* resource.'''ResourceName'''.function.'''FunctionName''': If disabled, the function cannot be called&lt;br /&gt;
These work as with other ACL rights - you can disable them for normal users and just enable them for Admin users, or any other group of users you wish.&lt;br /&gt;
}}&lt;br /&gt;
{{New_feature|3.0139|1.3.1|&lt;br /&gt;
* '''resource.ResourceName.http''': If enabled, the resource will be accessible from http://server_ip:22005/ResourceName/&lt;br /&gt;
This works as with other ACL rights - You can enable it just for Admin users, or any other group of users you wish.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==SDK==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
* [[JavaSDK|Java SDK]]&lt;br /&gt;
* [[Javascript SDK]]&lt;br /&gt;
* [[Perl SDK]]&lt;br /&gt;
* [[PHP SDK]]&lt;br /&gt;
* [[CSharp SDK|C# SDK]]&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
[[callRemote]] - Allows game servers to call functions on PHP pages (with the PHP SDK) and on other game servers.&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;br /&gt;
[[ru:Resource Web Access]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=HU/Resources&amp;diff=50736</id>
		<title>HU/Resources</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HU/Resources&amp;diff=50736"/>
		<updated>2017-04-18T06:06:22Z</updated>

		<summary type="html">&lt;p&gt;Kevin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Resources are a key part of MTA. A resource is essentially a folder or zip file that contains a collection of files - including script files, plus a ''meta'' file that describes how the resource should be loaded. A resource can be seen as being partly equivalent to a program running in an operating system - it can be started and stopped, and multiple resources can run at once. Its worth remember though, that unlike programs on an operating system, there is no multi-tasking between resources.&lt;br /&gt;
&lt;br /&gt;
==Terminology==&lt;br /&gt;
* '''Resource''' - A zip file or folder containing a meta.xml file and a number of resource items. These are placed in the ''mods/deathmatch/resources'' folder in the server directory.&lt;br /&gt;
* '''Resource item''' - A file contained within a resource, currently this can be a map, script, images etc.&lt;br /&gt;
&lt;br /&gt;
==The Meta File==&lt;br /&gt;
''See main article [[Meta.xml]] for details''&lt;br /&gt;
&lt;br /&gt;
The Meta file is the core of each the resource. It describes exactly what files in the resource should be used, and how. The following is an example that covers every option there is, your meta files can have as many or as few of these tags as you require:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info author=&amp;quot;eAi&amp;quot; description=&amp;quot;This is a basic CTF script&amp;quot; version=&amp;quot;4&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;include resource=&amp;quot;radarblips&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;include resource=&amp;quot;markermanagement&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;script src=&amp;quot;ctf.lua&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;script src=&amp;quot;flag.lua&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;script src=&amp;quot;ctf_client.lua&amp;quot; type=&amp;quot;client&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;file src=&amp;quot;model.dff&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;file src=&amp;quot;quitbutton.png&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;file src=&amp;quot;killed.png&amp;quot;  /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;html src=&amp;quot;test.htm&amp;quot; default=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;html src=&amp;quot;logo.png&amp;quot; raw=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;export function=&amp;quot;multiply&amp;quot; http=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;export function=&amp;quot;getPlayerList&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;export function=&amp;quot;getElementOwner&amp;quot; type=&amp;quot;client&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;config src=&amp;quot;vehicle-list.xml&amp;quot; type=&amp;quot;client&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;config src=&amp;quot;markerconfig.xml&amp;quot; type=&amp;quot;server&amp;quot;  /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;map src=&amp;quot;somestuff.map&amp;quot; dimension=&amp;quot;99&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
While a CTF map may have a meta.xml that looks like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;include resource=&amp;quot;ctf&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;map src=&amp;quot;myuberl33tctfmap.map&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;info author=&amp;quot;Tom&amp;quot; instructions=&amp;quot;this is uber l33t !!!!!1111111&amp;quot; type=&amp;quot;map&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Script/type, Config/type and File/type attributes specify if the script/resource should be sent to clients or not, and defaults to &amp;quot;server&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The include tag specifies other resources that should be started before this resoucre is started.  In other words, if your resource is dependent on another, you can include it so that the other resource is started first,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each resource has its own virtual machine (VM). This contains every script in the resource.  This means that variables are not shared with other resources.  The best way to communictate with other resources is by using the ''export'' tag and exporting a function.  This will enable other resources to fire this function using the [[call]] scripting function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scripts sent to clients are started as soon as all the scripts have been downloaded.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scripts are able to read and write to their own resource folder with functions such as [[xmlCreateFile]] and [[fileCreate]]. They can also read and write to other resources, but must have [[Access_Control_List|ACL]] access. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each resource can only be loaded once, the server will ensure this. If a resource is included more than once, the same instance will be used by each resource that includes it.&lt;br /&gt;
&lt;br /&gt;
==File storage==&lt;br /&gt;
Resource files can either be stored in a zip or a directory. This is located in:&lt;br /&gt;
&lt;br /&gt;
server/mods/deathmatch/resources/ (if you've installed your server with the client)&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
mods/deathmatch/resources/ (for dedicated server installations)&lt;br /&gt;
&lt;br /&gt;
Each resource can have a zip file, a directory or both. In the case of both existing, the directory has precedence over the zip file, as such files can be placed in the directory to over-ride the files in the zip file. This allows directories to be used for testing and developing of maps/scripts while zip files used by end-users.&lt;br /&gt;
&lt;br /&gt;
==Other things to note==&lt;br /&gt;
*Resource names can't have dots in.&lt;br /&gt;
*If the resource does any file saving, the file names used should not be listed in the meta.xml&lt;br /&gt;
*Files listed in the meta.xml should be considered read only by your scripts. Do not modify them with xmlSaveFile, FileSave etc.&lt;br /&gt;
*When making a zip file of your resource, do not include save files. If your resource uses save files, they must be created by your resource when needed.&lt;br /&gt;
*When making a zip file of your resource, only include files that are listed in the meta.xml. Do not include 'example' save files, otherwise bad things will happen.&lt;br /&gt;
*We recommend avoiding spaces and exotic characters from resources names.&lt;br /&gt;
&lt;br /&gt;
==Script functions==&lt;br /&gt;
The resource system can be manipulated by script. As such, the following Serverside scripting functions are provided:&lt;br /&gt;
{{Resource functions}}&lt;br /&gt;
&lt;br /&gt;
The following events are also provided:&lt;br /&gt;
{{Resource_events}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[it:Introduzione alle Risorse]]&lt;br /&gt;
[[pt-br:Recursos]]&lt;br /&gt;
[[ru:Resources]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Talk:HU/Hibakeres%C3%A9s&amp;diff=50735</id>
		<title>Talk:HU/Hibakeresés</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Talk:HU/Hibakeres%C3%A9s&amp;diff=50735"/>
		<updated>2017-04-18T06:05:45Z</updated>

		<summary type="html">&lt;p&gt;Kevin: Created page with &amp;quot;A szkriptekben gyakran előfordulnak kisebb nagyobb problémák, amelyeket nem veszünk észre!Ez a leírás segít abban hogy gyorsan megtaláld őket!  ==Hibakereső konzol=...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A szkriptekben gyakran előfordulnak kisebb nagyobb problémák, amelyeket nem veszünk észre!Ez a leírás segít abban hogy gyorsan megtaláld őket!&lt;br /&gt;
&lt;br /&gt;
==Hibakereső konzol==&lt;br /&gt;
Az MTA tartalmaz beépített hibakereső konzolt!Hasznos mivel ha elgépelünk valamit és nem vesszük észre ő segítségünkre lehet.Ahhoz hogy tudjuk aktiválni ezt a jogusultságot Adminisztrátor rangot kell viselnünk{ACL}.Ha ez rendben van akkor a &amp;quot;debugscript x&amp;quot; parancsal tudjuk változtatni a visszajelzési szintet!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Lehetőségek:&lt;br /&gt;
* '''1:''' Csak a '''Hibákat''' jelzi&lt;br /&gt;
* '''2:''' A '''Hibákat''' és a '''Figyelmeztetéseket''' is jelzi&lt;br /&gt;
* '''3:''' A '''Hibákat''' és a '''Figyelmeztetéseket''' is jelzi illetve az '''Információkat''' amelyeket elrejtünk a szkriptekben!&lt;br /&gt;
Ha begépeljük a &amp;quot;debugscript 3&amp;quot; parancsot akkor a fent leírt paramétereket fogja megmutatni.Ez a legcélszerűbb funkció, sokkal egyszerűbb vele a fejlesztés&lt;br /&gt;
&lt;br /&gt;
===Példa===&lt;br /&gt;
Ebben a kódban elrejtettünk két darab hibát:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;)&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ha ezt a kódot lefuttatjuk akkor ezt a hibaüzenetet fogjuk kapni:&lt;br /&gt;
:{{Debug info|Loading script failed: myResource\script.lua:2: 'then' expected near ´outputChatbox'}}[Ezt nem fordítom le]&lt;br /&gt;
Itt láthatjuk a hiba pozícióját!(heyle,hibás sor, hiba)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;) then&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ezzel nincs semmi gond, működik annak rendje és módja szerint DE ha a játékos neve nem &amp;quot;Józsika&amp;quot; akkor ezt láthatjuk:&lt;br /&gt;
:{{Debug error|myResource\script.lua:2: attempt to call global 'outputChatbox' (a nil value)}}&lt;br /&gt;
This error means that the function '''outputChatbox''' is a nil value, that is - it doesn't exist! This is because the function is actually called [[outputChatBox]], not [[outputChatbox]] - take care of that capital B.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;) then&lt;br /&gt;
        outputChatBox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ez csak egy kis része a rendszernek.Nagyon sokoldalú illetve érdekes visszajelzéseket tud adni vissza nekünk.&lt;br /&gt;
&lt;br /&gt;
==Szerver &amp;amp; Cliens hibakeresési napló=&lt;br /&gt;
====Szerver====&lt;br /&gt;
Menj be a: ''(MTA mappa)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch'' mappába&lt;br /&gt;
&lt;br /&gt;
Van itt két majdnem azonos fájl.&lt;br /&gt;
&lt;br /&gt;
* A local.conf a beállításokat tartalmazza a „host játék” menüpont beállításait a főmenübe. Ez egy gyors módja a szerver indításának. Ha a host lecsatlakozik akkor a szerver is kikapcsol!&lt;br /&gt;
*A mtaserver.conf akkor használjuk, amikor „MTA SERVER.EXE” fájlal indítjuk a  szervert!(MTA mappája)&amp;gt; server. Ez a saját szerver  konzol, szóval ha a host lecsatlakozik akkor nem kapcsol le. Ez akkor lehet hasznos, ha érdekel a szerver hosting hosszabb ideig.&lt;br /&gt;
&lt;br /&gt;
Itt be lehet állítani a logok mentési helyét!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;!-- Itt beírhatja a log helyét!Ha üresen hagyod akkor a szerver megspórolja a helyet! --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebuglogfile&amp;gt;logs/scripts.log&amp;lt;/scriptdebuglogfile&amp;gt; &lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;!-- Itt lehet beállítani a debug szintjét! Lehetséges értékek: 0, 1, 2, 3. Ha nincs beállítva, akkor automatikusan 0.  --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebugloglevel&amp;gt;0&amp;lt;/scriptdebugloglevel&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Te biztos akarsz lenni hogy van egy file a megadott néven. Meg tudod határozni, hogy milyen szintű hibák kerüljene knaplózásra . Ha ez 0 akkor semmi nem lesz rögzítve. A szintek magyarázata a cikk tetején található. Ha a naplózási szint megváltozott 3-ra, akkor ebben az esetben minden „” „szerveroldalon” „” lévő szkripthibákat elnaplóz.&lt;br /&gt;
 (MTA mappa)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch&amp;gt;logs&amp;gt;scripts.log&lt;br /&gt;
&lt;br /&gt;
====Kliens====&lt;br /&gt;
Menj a: ''(MTA mappa)&amp;gt;server&amp;gt;clientscript.log''&lt;br /&gt;
&lt;br /&gt;
Ez a file az összes '''kliensoldali''' szkript hibákat naplózza. Ő alapértelmezés szerint fent van, nincs szükség telepítésre!&lt;br /&gt;
&lt;br /&gt;
==Hibakeresési stratégiák==&lt;br /&gt;
Számos stratégia létezik, amelyek támogatják a hibakeresést. Legtöbbjük közé tartozik a kimenő Hibaüzenetek, a különböző információktól függően helyezkednek el.&lt;br /&gt;
&lt;br /&gt;
===Hasznos funkciók===&lt;br /&gt;
Vannak olyan funkciók, amelyek jól jöhetnek a hibakereséshez.&lt;br /&gt;
* [[outputDebugString]] vagy [[outputChatBox]] ([[outputDebugString]] a műszaki kimenet)&lt;br /&gt;
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] Hasznos, ha az érték nem szám vagy string.&lt;br /&gt;
&lt;br /&gt;
* [[getElementType]] ellenőrizni, hogy milyen típusú az MTA elem.&lt;br /&gt;
* [[isElement]] ellenőrizni, hogy a MTA elem létezik.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check ''if'', ''when'' or ''how often'' a section of code is executed===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (variable1 == variable2) then&lt;br /&gt;
    outputDebugString(&amp;quot;variable1 is the same as variable2!&amp;quot;)&lt;br /&gt;
    -- do anything&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check the ''value'' of a variable===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
outputChatBox(&amp;quot;posX is: &amp;quot;..x..&amp;quot; posY is: &amp;quot;..y..&amp;quot; posZ is: &amp;quot;..z)&lt;br /&gt;
createMarker(x,y,z)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
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 values of the variables can be concatenated (put together) as a string, even if it's a boolean value.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Imagine you created a [[Colshape|collision shape]] somewhere and you want an action to perform after the player stays for ten seconds inside it, you would do this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;, root, colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
When a player enters the colshape, debugscript outputs the following message:&lt;br /&gt;
:{{Debug error|..[path]: attempt to index global 'colshapeTimer' (a nil value)}}&lt;br /&gt;
This means you tried to index a table that does not exist (because the table is a nil value, it doesn't 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 it does not exist we should create it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,root,colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we will still receive a warning when a player enters the colshape, waits for the message and leaves it again:&lt;br /&gt;
&lt;br /&gt;
:{{Debug warning|[..]: Bad argument @ 'killTimer' Line: ..}}&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===A more inconspicuous error===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit&amp;quot;)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave&amp;quot;)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 ensure that the ''player'' variable actually holds a reference to a player element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debug messages tell us that one of the ''player'' variables is a player and that the other one is 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the script should work as desired, but it 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 has reached the 10 seconds (and therefore executed after the 10th second has completed). 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 exists). One way would be to check if the timer referenced in the table really exists. To do this, we need to use [[isTimer]], which we will use when we kill the timer:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the complete working code would be:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
		killTimer(colshapeTimer[player])&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Debugging Performance Issues==&lt;br /&gt;
&lt;br /&gt;
If your server is using up more resources than it should or you just want to make sure your scripts are efficient, you can find the source of the issue by using a great tool that comes with the default resource package called [[Resource:Performancebrowser|performancebrowser]]. You can start it with ''''start performancebrowser''''. If it doesn't exist then you can get the latest resources from the [https://github.com/multitheftauto/mtasa-resources GitHub repository]. This tool provides an incredible amount of information for performance debugging. Memory leaks, element leaks and CPU intensive scripts are all easily findable via performancebrowser. If you use the ''''d'''' option in Lua timing you can see which functions are using up the CPU.&lt;br /&gt;
&lt;br /&gt;
To access performancebrowser you will need to go to your web browser and enter the address: http://serverIPHere:serverHTTPPortHere/performancebrowser/ Note that the / at the end is required. So for example: http://127.0.0.1:22005/performancebrowser/ You will then need to login with an in-game admin account or any account that has access to ''''resource.performancebrowser.http'''' and ''''resource.ajax.http''''. Most of the information you will need are in the categories Lua timing and Lua memory, look for values that are much higher than other values.&lt;br /&gt;
&lt;br /&gt;
===Examples of scripts that could cause performance problems===&lt;br /&gt;
&lt;br /&gt;
Adding data to a table but never removing it. This would take months/years before it causes a problem though.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local someData = {}&lt;br /&gt;
&lt;br /&gt;
function storeData()&lt;br /&gt;
    someData[source] = true&lt;br /&gt;
    -- There is no handling for when a player quits, this is considered a memory leak&lt;br /&gt;
    -- Using the Lua timing tab you can detect the RAM usage of each resource.&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, storeData)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Element leaking is possible if you use temporary colshapes for whatever reason and may not destroy them. This would cause bandwidth, CPU and memory performance issues over time.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function useTemporaryCol()&lt;br /&gt;
    local col = createColCircle(some code here)&lt;br /&gt;
    if (normally this should happen) then&lt;br /&gt;
        destroyElement(col)&lt;br /&gt;
    end&lt;br /&gt;
    -- But sometimes it didn't so the script ended but the collision area remained and over time&lt;br /&gt;
    -- you may end up with hundreds to thousands of pointless collision areas. &lt;br /&gt;
    -- The Lua timing tab allows you to see the amount of elements each script has created.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
High CPU usage resulting in the server FPS dropping so much that the server is unplayable. In under 24 hours this can create havoc on a very busy server. The amount of &amp;quot;refs&amp;quot; in the Lua timing detect this type of build up, surprisingly the Lua timing tab didn't help in this case but Lua memory did.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, function()&lt;br /&gt;
    -- Code for joiner&lt;br /&gt;
    addEventHandler(&amp;quot;onPlayerQuit&amp;quot;, root, function()&lt;br /&gt;
        -- Code for when they have quit&lt;br /&gt;
        -- See the problem? It's bound to root which the event handler is being added again and again and again&lt;br /&gt;
    end)&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A function uses up a lot of your CPU because whatever it does takes a long time. This is just some function that takes a long time to complete. Without performancebrowser you'd have no idea its the cause but with performancebrowser you can see that a resource is using lots of CPU in the Lua timing tab. If you then enter: ''''d'''' into the options edit box it will even tell you what file name and first line of the function that is using up so much CPU.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function someDodgyCode()&lt;br /&gt;
    for i=1, 100000 do&lt;br /&gt;
        -- some code&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Fordító==&lt;br /&gt;
&lt;br /&gt;
'''Fordította: Kevin'''&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;br /&gt;
[[en:Debugging]]&lt;br /&gt;
[[it:Guida al Debug]]&lt;br /&gt;
[[ru:Debugging]]&lt;br /&gt;
[[zh-cn:脚本调试教程]]&lt;br /&gt;
[[hu:Hibakeresés]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=HU/Debugging&amp;diff=50734</id>
		<title>HU/Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HU/Debugging&amp;diff=50734"/>
		<updated>2017-04-18T06:04:06Z</updated>

		<summary type="html">&lt;p&gt;Kevin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A szkriptekben gyakran előfordulnak kisebb nagyobb problémák, amelyeket nem veszünk észre!Ez a leírás segít abban hogy gyorsan megtaláld őket!&lt;br /&gt;
&lt;br /&gt;
==Hibakereső konzol==&lt;br /&gt;
Az MTA tartalmaz beépített hibakereső konzolt!Hasznos mivel ha elgépelünk valamit és nem vesszük észre ő segítségünkre lehet.Ahhoz hogy tudjuk aktiválni ezt a jogusultságot Adminisztrátor rangot kell viselnünk{ACL}.Ha ez rendben van akkor a &amp;quot;debugscript x&amp;quot; parancsal tudjuk változtatni a visszajelzési szintet!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Lehetőségek:&lt;br /&gt;
* '''1:''' Csak a '''Hibákat''' jelzi&lt;br /&gt;
* '''2:''' A '''Hibákat''' és a '''Figyelmeztetéseket''' is jelzi&lt;br /&gt;
* '''3:''' A '''Hibákat''' és a '''Figyelmeztetéseket''' is jelzi illetve az '''Információkat''' amelyeket elrejtünk a szkriptekben!&lt;br /&gt;
Ha begépeljük a &amp;quot;debugscript 3&amp;quot; parancsot akkor a fent leírt paramétereket fogja megmutatni.Ez a legcélszerűbb funkció, sokkal egyszerűbb vele a fejlesztés&lt;br /&gt;
&lt;br /&gt;
===Példa===&lt;br /&gt;
Ebben a kódban elrejtettünk két darab hibát:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;)&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ha ezt a kódot lefuttatjuk akkor ezt a hibaüzenetet fogjuk kapni:&lt;br /&gt;
:{{Debug info|Loading script failed: myResource\script.lua:2: 'then' expected near ´outputChatbox'}}[Ezt nem fordítom le]&lt;br /&gt;
Itt láthatjuk a hiba pozícióját!(heyle,hibás sor, hiba)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;) then&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ezzel nincs semmi gond, működik annak rendje és módja szerint DE ha a játékos neve nem &amp;quot;Józsika&amp;quot; akkor ezt láthatjuk:&lt;br /&gt;
:{{Debug error|myResource\script.lua:2: attempt to call global 'outputChatbox' (a nil value)}}&lt;br /&gt;
This error means that the function '''outputChatbox''' is a nil value, that is - it doesn't exist! This is because the function is actually called [[outputChatBox]], not [[outputChatbox]] - take care of that capital B.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;) then&lt;br /&gt;
        outputChatBox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ez csak egy kis része a rendszernek.Nagyon sokoldalú illetve érdekes visszajelzéseket tud adni vissza nekünk.&lt;br /&gt;
&lt;br /&gt;
==Szerver &amp;amp; Cliens hibakeresési napló=&lt;br /&gt;
====Szerver====&lt;br /&gt;
Menj be a: ''(MTA mappa)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch'' mappába&lt;br /&gt;
&lt;br /&gt;
Van itt két majdnem azonos fájl.&lt;br /&gt;
&lt;br /&gt;
* A local.conf a beállításokat tartalmazza a „host játék” menüpont beállításait a főmenübe. Ez egy gyors módja a szerver indításának. Ha a host lecsatlakozik akkor a szerver is kikapcsol!&lt;br /&gt;
*A mtaserver.conf akkor használjuk, amikor „MTA SERVER.EXE” fájlal indítjuk a  szervert!(MTA mappája)&amp;gt; server. Ez a saját szerver  konzol, szóval ha a host lecsatlakozik akkor nem kapcsol le. Ez akkor lehet hasznos, ha érdekel a szerver hosting hosszabb ideig.&lt;br /&gt;
&lt;br /&gt;
Itt be lehet állítani a logok mentési helyét!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;!-- Itt beírhatja a log helyét!Ha üresen hagyod akkor a szerver megspórolja a helyet! --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebuglogfile&amp;gt;logs/scripts.log&amp;lt;/scriptdebuglogfile&amp;gt; &lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;!-- Itt lehet beállítani a debug szintjét! Lehetséges értékek: 0, 1, 2, 3. Ha nincs beállítva, akkor automatikusan 0.  --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebugloglevel&amp;gt;0&amp;lt;/scriptdebugloglevel&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Te biztos akarsz lenni hogy van egy file a megadott néven. Meg tudod határozni, hogy milyen szintű hibák kerüljene knaplózásra . Ha ez 0 akkor semmi nem lesz rögzítve. A szintek magyarázata a cikk tetején található. Ha a naplózási szint megváltozott 3-ra, akkor ebben az esetben minden „” „szerveroldalon” „” lévő szkripthibákat elnaplóz.&lt;br /&gt;
 (MTA mappa)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch&amp;gt;logs&amp;gt;scripts.log&lt;br /&gt;
&lt;br /&gt;
====Kliens====&lt;br /&gt;
Menj a: ''(MTA mappa)&amp;gt;server&amp;gt;clientscript.log''&lt;br /&gt;
&lt;br /&gt;
Ez a file az összes '''kliensoldali''' szkript hibákat naplózza. Ő alapértelmezés szerint fent van, nincs szükség telepítésre!&lt;br /&gt;
&lt;br /&gt;
==Hibakeresési stratégiák==&lt;br /&gt;
Számos stratégia létezik, amelyek támogatják a hibakeresést. Legtöbbjük közé tartozik a kimenő Hibaüzenetek, a különböző információktól függően helyezkednek el.&lt;br /&gt;
&lt;br /&gt;
===Hasznos funkciók===&lt;br /&gt;
Vannak olyan funkciók, amelyek jól jöhetnek a hibakereséshez.&lt;br /&gt;
* [[outputDebugString]] vagy [[outputChatBox]] ([[outputDebugString]] a műszaki kimenet)&lt;br /&gt;
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] Hasznos, ha az érték nem szám vagy string.&lt;br /&gt;
&lt;br /&gt;
* [[getElementType]] ellenőrizni, hogy milyen típusú az MTA elem.&lt;br /&gt;
* [[isElement]] ellenőrizni, hogy a MTA elem létezik.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check ''if'', ''when'' or ''how often'' a section of code is executed===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (variable1 == variable2) then&lt;br /&gt;
    outputDebugString(&amp;quot;variable1 is the same as variable2!&amp;quot;)&lt;br /&gt;
    -- do anything&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check the ''value'' of a variable===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
outputChatBox(&amp;quot;posX is: &amp;quot;..x..&amp;quot; posY is: &amp;quot;..y..&amp;quot; posZ is: &amp;quot;..z)&lt;br /&gt;
createMarker(x,y,z)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
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 values of the variables can be concatenated (put together) as a string, even if it's a boolean value.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Imagine you created a [[Colshape|collision shape]] somewhere and you want an action to perform after the player stays for ten seconds inside it, you would do this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;, root, colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
When a player enters the colshape, debugscript outputs the following message:&lt;br /&gt;
:{{Debug error|..[path]: attempt to index global 'colshapeTimer' (a nil value)}}&lt;br /&gt;
This means you tried to index a table that does not exist (because the table is a nil value, it doesn't 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 it does not exist we should create it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,root,colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we will still receive a warning when a player enters the colshape, waits for the message and leaves it again:&lt;br /&gt;
&lt;br /&gt;
:{{Debug warning|[..]: Bad argument @ 'killTimer' Line: ..}}&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===A more inconspicuous error===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit&amp;quot;)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave&amp;quot;)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 ensure that the ''player'' variable actually holds a reference to a player element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debug messages tell us that one of the ''player'' variables is a player and that the other one is 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the script should work as desired, but it 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 has reached the 10 seconds (and therefore executed after the 10th second has completed). 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 exists). One way would be to check if the timer referenced in the table really exists. To do this, we need to use [[isTimer]], which we will use when we kill the timer:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the complete working code would be:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
		killTimer(colshapeTimer[player])&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Debugging Performance Issues==&lt;br /&gt;
&lt;br /&gt;
If your server is using up more resources than it should or you just want to make sure your scripts are efficient, you can find the source of the issue by using a great tool that comes with the default resource package called [[Resource:Performancebrowser|performancebrowser]]. You can start it with ''''start performancebrowser''''. If it doesn't exist then you can get the latest resources from the [https://github.com/multitheftauto/mtasa-resources GitHub repository]. This tool provides an incredible amount of information for performance debugging. Memory leaks, element leaks and CPU intensive scripts are all easily findable via performancebrowser. If you use the ''''d'''' option in Lua timing you can see which functions are using up the CPU.&lt;br /&gt;
&lt;br /&gt;
To access performancebrowser you will need to go to your web browser and enter the address: http://serverIPHere:serverHTTPPortHere/performancebrowser/ Note that the / at the end is required. So for example: http://127.0.0.1:22005/performancebrowser/ You will then need to login with an in-game admin account or any account that has access to ''''resource.performancebrowser.http'''' and ''''resource.ajax.http''''. Most of the information you will need are in the categories Lua timing and Lua memory, look for values that are much higher than other values.&lt;br /&gt;
&lt;br /&gt;
===Examples of scripts that could cause performance problems===&lt;br /&gt;
&lt;br /&gt;
Adding data to a table but never removing it. This would take months/years before it causes a problem though.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local someData = {}&lt;br /&gt;
&lt;br /&gt;
function storeData()&lt;br /&gt;
    someData[source] = true&lt;br /&gt;
    -- There is no handling for when a player quits, this is considered a memory leak&lt;br /&gt;
    -- Using the Lua timing tab you can detect the RAM usage of each resource.&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, storeData)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Element leaking is possible if you use temporary colshapes for whatever reason and may not destroy them. This would cause bandwidth, CPU and memory performance issues over time.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function useTemporaryCol()&lt;br /&gt;
    local col = createColCircle(some code here)&lt;br /&gt;
    if (normally this should happen) then&lt;br /&gt;
        destroyElement(col)&lt;br /&gt;
    end&lt;br /&gt;
    -- But sometimes it didn't so the script ended but the collision area remained and over time&lt;br /&gt;
    -- you may end up with hundreds to thousands of pointless collision areas. &lt;br /&gt;
    -- The Lua timing tab allows you to see the amount of elements each script has created.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
High CPU usage resulting in the server FPS dropping so much that the server is unplayable. In under 24 hours this can create havoc on a very busy server. The amount of &amp;quot;refs&amp;quot; in the Lua timing detect this type of build up, surprisingly the Lua timing tab didn't help in this case but Lua memory did.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, function()&lt;br /&gt;
    -- Code for joiner&lt;br /&gt;
    addEventHandler(&amp;quot;onPlayerQuit&amp;quot;, root, function()&lt;br /&gt;
        -- Code for when they have quit&lt;br /&gt;
        -- See the problem? It's bound to root which the event handler is being added again and again and again&lt;br /&gt;
    end)&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A function uses up a lot of your CPU because whatever it does takes a long time. This is just some function that takes a long time to complete. Without performancebrowser you'd have no idea its the cause but with performancebrowser you can see that a resource is using lots of CPU in the Lua timing tab. If you then enter: ''''d'''' into the options edit box it will even tell you what file name and first line of the function that is using up so much CPU.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function someDodgyCode()&lt;br /&gt;
    for i=1, 100000 do&lt;br /&gt;
        -- some code&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Fordító==&lt;br /&gt;
&lt;br /&gt;
'''Fordította: Kevin'''&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;br /&gt;
[[en:Debugging]]&lt;br /&gt;
[[it:Guida al Debug]]&lt;br /&gt;
[[ru:Debugging]]&lt;br /&gt;
[[zh-cn:脚本调试教程]]&lt;br /&gt;
[[hu:Hibakeresés]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=HU/Debugging&amp;diff=50733</id>
		<title>HU/Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HU/Debugging&amp;diff=50733"/>
		<updated>2017-04-17T16:54:11Z</updated>

		<summary type="html">&lt;p&gt;Kevin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A szkriptekben gyakran előfordulnak kisebb nagyobb problémák, amelyeket nem veszünk észre!Ez a leírás segít abban hogy gyorsan megtaláld őket!&lt;br /&gt;
&lt;br /&gt;
==Hibakereső konzol==&lt;br /&gt;
Az MTA tartalmaz beépített hibakereső konzolt!Hasznos mivel ha elgépelünk valamit és nem vesszük észre ő segítségünkre lehet.Ahhoz hogy tudjuk aktiválni ezt a jogusultságot Adminisztrátor rangot kell viselnünk{ACL}.Ha ez rendben van akkor a &amp;quot;debugscript x&amp;quot; parancsal tudjuk változtatni a visszajelzési szintet!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Lehetőségek:&lt;br /&gt;
* '''1:''' Csak a '''Hibákat''' jelzi&lt;br /&gt;
* '''2:''' A '''Hibákat''' és a '''Figyelmeztetéseket''' is jelzi&lt;br /&gt;
* '''3:''' A '''Hibákat''' és a '''Figyelmeztetéseket''' is jelzi illetve az '''Információkat''' amelyeket elrejtünk a szkriptekben!&lt;br /&gt;
Ha begépeljük a &amp;quot;debugscript 3&amp;quot; parancsot akkor a fent leírt paramétereket fogja megmutatni.Ez a legcélszerűbb funkció, sokkal egyszerűbb vele a fejlesztés&lt;br /&gt;
&lt;br /&gt;
===Példa===&lt;br /&gt;
Ebben a kódban elrejtettünk két darab hibát:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;)&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ha ezt a kódot lefuttatjuk akkor ezt a hibaüzenetet fogjuk kapni:&lt;br /&gt;
:{{Debug info|Loading script failed: myResource\script.lua:2: 'then' expected near ´outputChatbox'}}[Ezt nem fordítom le]&lt;br /&gt;
Itt láthatjuk a hiba pozícióját!(heyle,hibás sor, hiba)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;) then&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ezzel nincs semmi gond, működik annak rendje és módja szerint DE ha a játékos neve nem &amp;quot;Józsika&amp;quot; akkor ezt láthatjuk:&lt;br /&gt;
:{{Debug error|myResource\script.lua:2: attempt to call global 'outputChatbox' (a nil value)}}&lt;br /&gt;
This error means that the function '''outputChatbox''' is a nil value, that is - it doesn't exist! This is because the function is actually called [[outputChatBox]], not [[outputChatbox]] - take care of that capital B.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;) then&lt;br /&gt;
        outputChatBox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ez csak egy kis része a rendszernek.Nagyon sokoldalú illetve érdekes visszajelzéseket tud adni vissza nekünk.&lt;br /&gt;
&lt;br /&gt;
==Szerver &amp;amp; Cliens hibakeresési napló=&lt;br /&gt;
====Szerver====&lt;br /&gt;
Menj be a: ''(MTA mappa)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch'' mappába&lt;br /&gt;
&lt;br /&gt;
Van itt két majdnem azonos fájl.&lt;br /&gt;
&lt;br /&gt;
* A local.conf a beállításokat tartalmazza a „host játék” menüpont beállításait a főmenübe. Ez egy gyors módja a szerver indításának. Ha a host lecsatlakozik akkor a szerver is kikapcsol!&lt;br /&gt;
*A mtaserver.conf akkor használjuk, amikor „MTA SERVER.EXE” fájlal indítjuk a  szervert!(MTA mappája)&amp;gt; server. Ez a saját szerver  konzol, szóval ha a host lecsatlakozik akkor nem kapcsol le. Ez akkor lehet hasznos, ha érdekel a szerver hosting hosszabb ideig.&lt;br /&gt;
&lt;br /&gt;
Itt be lehet állítani a logok mentési helyét!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;!-- Itt beírhatja a log helyét!Ha üresen hagyod akkor a szerver megspórolja a helyet! --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebuglogfile&amp;gt;logs/scripts.log&amp;lt;/scriptdebuglogfile&amp;gt; &lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;!-- Specifies the level of the debugscript log file. Available values: 0, 1, 2, 3. When not set, defaults to 0. --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebugloglevel&amp;gt;0&amp;lt;/scriptdebugloglevel&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You want to make sure you have a log name specified. Also you want to specify what level of errors will be logged. If it is 0 nothing will be logged. The levels were explained at the top of this article. If the logging level was changed to 3, then in this case all '''serverside''' script errors log to (MTA root folder)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch&amp;gt;logs&amp;gt;scripts.log&lt;br /&gt;
&lt;br /&gt;
====Client====&lt;br /&gt;
Navigate to: ''(MTA root folder)&amp;gt;server&amp;gt;clientscript.log''&lt;br /&gt;
&lt;br /&gt;
This file logs all '''clientside''' script errors. This is set to log by default, no setup required.&lt;br /&gt;
&lt;br /&gt;
==Debug strategies==&lt;br /&gt;
There are several strategies that support finding errors, apart from going through the code. Most of them include outputting debug messages, with have different information depending on the situtation.&lt;br /&gt;
&lt;br /&gt;
===Useful functions===&lt;br /&gt;
There are some functions that may come in handy for debugging.&lt;br /&gt;
* [[outputDebugString]] or [[outputChatBox]] for outputting any information (use outputDebugString for technical output)&lt;br /&gt;
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] on a variable to turn the value into a string. Useful if the value is not a number or string.&lt;br /&gt;
* [[getElementType]] to check the type of the MTA element.&lt;br /&gt;
* [[isElement]] to check if the MTA element exists.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check ''if'', ''when'' or ''how often'' a section of code is executed===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (variable1 == variable2) then&lt;br /&gt;
    outputDebugString(&amp;quot;variable1 is the same as variable2!&amp;quot;)&lt;br /&gt;
    -- do anything&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check the ''value'' of a variable===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
outputChatBox(&amp;quot;posX is: &amp;quot;..x..&amp;quot; posY is: &amp;quot;..y..&amp;quot; posZ is: &amp;quot;..z)&lt;br /&gt;
createMarker(x,y,z)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
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 values of the variables can be concatenated (put together) as a string, even if it's a boolean value.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Imagine you created a [[Colshape|collision shape]] somewhere and you want an action to perform after the player stays for ten seconds inside it, you would do this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;, root, colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
When a player enters the colshape, debugscript outputs the following message:&lt;br /&gt;
:{{Debug error|..[path]: attempt to index global 'colshapeTimer' (a nil value)}}&lt;br /&gt;
This means you tried to index a table that does not exist (because the table is a nil value, it doesn't 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 it does not exist we should create it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,root,colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we will still receive a warning when a player enters the colshape, waits for the message and leaves it again:&lt;br /&gt;
&lt;br /&gt;
:{{Debug warning|[..]: Bad argument @ 'killTimer' Line: ..}}&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===A more inconspicuous error===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit&amp;quot;)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave&amp;quot;)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 ensure that the ''player'' variable actually holds a reference to a player element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debug messages tell us that one of the ''player'' variables is a player and that the other one is 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the script should work as desired, but it 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 has reached the 10 seconds (and therefore executed after the 10th second has completed). 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 exists). One way would be to check if the timer referenced in the table really exists. To do this, we need to use [[isTimer]], which we will use when we kill the timer:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the complete working code would be:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
		killTimer(colshapeTimer[player])&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Debugging Performance Issues==&lt;br /&gt;
&lt;br /&gt;
If your server is using up more resources than it should or you just want to make sure your scripts are efficient, you can find the source of the issue by using a great tool that comes with the default resource package called [[Resource:Performancebrowser|performancebrowser]]. You can start it with ''''start performancebrowser''''. If it doesn't exist then you can get the latest resources from the [https://github.com/multitheftauto/mtasa-resources GitHub repository]. This tool provides an incredible amount of information for performance debugging. Memory leaks, element leaks and CPU intensive scripts are all easily findable via performancebrowser. If you use the ''''d'''' option in Lua timing you can see which functions are using up the CPU.&lt;br /&gt;
&lt;br /&gt;
To access performancebrowser you will need to go to your web browser and enter the address: http://serverIPHere:serverHTTPPortHere/performancebrowser/ Note that the / at the end is required. So for example: http://127.0.0.1:22005/performancebrowser/ You will then need to login with an in-game admin account or any account that has access to ''''resource.performancebrowser.http'''' and ''''resource.ajax.http''''. Most of the information you will need are in the categories Lua timing and Lua memory, look for values that are much higher than other values.&lt;br /&gt;
&lt;br /&gt;
===Examples of scripts that could cause performance problems===&lt;br /&gt;
&lt;br /&gt;
Adding data to a table but never removing it. This would take months/years before it causes a problem though.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local someData = {}&lt;br /&gt;
&lt;br /&gt;
function storeData()&lt;br /&gt;
    someData[source] = true&lt;br /&gt;
    -- There is no handling for when a player quits, this is considered a memory leak&lt;br /&gt;
    -- Using the Lua timing tab you can detect the RAM usage of each resource.&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, storeData)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Element leaking is possible if you use temporary colshapes for whatever reason and may not destroy them. This would cause bandwidth, CPU and memory performance issues over time.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function useTemporaryCol()&lt;br /&gt;
    local col = createColCircle(some code here)&lt;br /&gt;
    if (normally this should happen) then&lt;br /&gt;
        destroyElement(col)&lt;br /&gt;
    end&lt;br /&gt;
    -- But sometimes it didn't so the script ended but the collision area remained and over time&lt;br /&gt;
    -- you may end up with hundreds to thousands of pointless collision areas. &lt;br /&gt;
    -- The Lua timing tab allows you to see the amount of elements each script has created.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
High CPU usage resulting in the server FPS dropping so much that the server is unplayable. In under 24 hours this can create havoc on a very busy server. The amount of &amp;quot;refs&amp;quot; in the Lua timing detect this type of build up, surprisingly the Lua timing tab didn't help in this case but Lua memory did.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, function()&lt;br /&gt;
    -- Code for joiner&lt;br /&gt;
    addEventHandler(&amp;quot;onPlayerQuit&amp;quot;, root, function()&lt;br /&gt;
        -- Code for when they have quit&lt;br /&gt;
        -- See the problem? It's bound to root which the event handler is being added again and again and again&lt;br /&gt;
    end)&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A function uses up a lot of your CPU because whatever it does takes a long time. This is just some function that takes a long time to complete. Without performancebrowser you'd have no idea its the cause but with performancebrowser you can see that a resource is using lots of CPU in the Lua timing tab. If you then enter: ''''d'''' into the options edit box it will even tell you what file name and first line of the function that is using up so much CPU.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function someDodgyCode()&lt;br /&gt;
    for i=1, 100000 do&lt;br /&gt;
        -- some code&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;br /&gt;
[[en:Debugging]]&lt;br /&gt;
[[it:Guida al Debug]]&lt;br /&gt;
[[ru:Debugging]]&lt;br /&gt;
[[zh-cn:脚本调试教程]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=HU/Debugging&amp;diff=50688</id>
		<title>HU/Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HU/Debugging&amp;diff=50688"/>
		<updated>2017-04-15T17:34:35Z</updated>

		<summary type="html">&lt;p&gt;Kevin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A szkriptekben gyakran előfordulnak kisebb nagyobb problémák, amelyeket nem veszünk észre!Ez a leírás segít abban hogy gyorsan megtaláld őket!&lt;br /&gt;
&lt;br /&gt;
==Hibakereső konzol==&lt;br /&gt;
Az MTA tartalmaz beépített hibakereső konzolt!Hasznos mivel ha elgépelünk valamit és nem vesszük észre ő segítségünkre lehet.Ahhoz hogy tudjuk aktiválni ezt a jogusultságot Adminisztrátor rangot kell viselnünk{ACL}.Ha ez rendben van akkor a &amp;quot;debugscript x&amp;quot; parancsal tudjuk változtatni a visszajelzési szintet!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Lehetőségek:&lt;br /&gt;
* '''1:''' Csak a '''Hibákat''' jelzi&lt;br /&gt;
* '''2:''' A '''hibákat''' és a '''Figyelmeztetéseket''' is jelzi&lt;br /&gt;
* '''3:''' A '''hibákat''' és a '''Figyelmeztetéseket''' is jelzi illetve az '''Információkat''' amelyeket elrejtünk a szkriptekben!&lt;br /&gt;
Ha begépeljük a &amp;quot;debugscript 3&amp;quot; parancsot akkor a fent leírt paramétereket fogja megmutatni.Ez a legcélszerűbb funkció, sokkal egyszerűbb vele a fejlesztés&lt;br /&gt;
&lt;br /&gt;
===Példa===&lt;br /&gt;
Ebben a kódban elrejtettünk két darab hibát:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;)&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ha ezt a kódot lefuttatjuk akkor ezt a hibaüzenetet fogjuk kapni:&lt;br /&gt;
:{{Debug info|Loading script failed: myResource\script.lua:2: 'then' expected near ´outputChatbox'}}[Ezt nem fordítom le]&lt;br /&gt;
Itt láthatjuk a hiba pozícióját!(heyle,hibás sor, hiba)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;) then&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ezzel nincs semmi gond, működik annak rendje és módja szerint DE ha a játékos neve nem &amp;quot;Józsika&amp;quot; akkor ezt láthatjuk:&lt;br /&gt;
:{{Debug error|myResource\script.lua:2: attempt to call global 'outputChatbox' (a nil value)}}&lt;br /&gt;
This error means that the function '''outputChatbox''' is a nil value, that is - it doesn't exist! This is because the function is actually called [[outputChatBox]], not [[outputChatbox]] - take care of that capital B.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;) then&lt;br /&gt;
        outputChatBox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, this is just an example and I've only skimmed the surface of error messages. There are plenty of other messages and scenarios, but you should get the general idea.&lt;br /&gt;
&lt;br /&gt;
==Server &amp;amp; client debug logging==&lt;br /&gt;
====Server====&lt;br /&gt;
Navigate to: ''(MTA root folder)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch''&lt;br /&gt;
&lt;br /&gt;
There are two nearly identical files:&lt;br /&gt;
&lt;br /&gt;
*The local.conf is the settings for the &amp;quot;host game&amp;quot; menu item in the main menu of MTA. This is a quick and easy way of starting a temporary server from inside the client. When the client is turned off the server will also turn off.&lt;br /&gt;
&lt;br /&gt;
*The mtaserver.conf is used when &amp;quot;MTA Server.exe&amp;quot; is executed from (MTA root folder)&amp;gt;server. This runs the server in its own console window which does not need the client to exist or to be run. This is can be useful if you're interested in hosting servers for a longer time period or if you want to experiment with a real world console.&lt;br /&gt;
&lt;br /&gt;
Depending on which way you host, you will want to edit those files. The settings in question are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;!-- Specifies the location and name of the debugscript log file. If left blank, server won't be saving this file. --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebuglogfile&amp;gt;logs/scripts.log&amp;lt;/scriptdebuglogfile&amp;gt; &lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;!-- Specifies the level of the debugscript log file. Available values: 0, 1, 2, 3. When not set, defaults to 0. --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebugloglevel&amp;gt;0&amp;lt;/scriptdebugloglevel&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You want to make sure you have a log name specified. Also you want to specify what level of errors will be logged. If it is 0 nothing will be logged. The levels were explained at the top of this article. If the logging level was changed to 3, then in this case all '''serverside''' script errors log to (MTA root folder)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch&amp;gt;logs&amp;gt;scripts.log&lt;br /&gt;
&lt;br /&gt;
====Client====&lt;br /&gt;
Navigate to: ''(MTA root folder)&amp;gt;server&amp;gt;clientscript.log''&lt;br /&gt;
&lt;br /&gt;
This file logs all '''clientside''' script errors. This is set to log by default, no setup required.&lt;br /&gt;
&lt;br /&gt;
==Debug strategies==&lt;br /&gt;
There are several strategies that support finding errors, apart from going through the code. Most of them include outputting debug messages, with have different information depending on the situtation.&lt;br /&gt;
&lt;br /&gt;
===Useful functions===&lt;br /&gt;
There are some functions that may come in handy for debugging.&lt;br /&gt;
* [[outputDebugString]] or [[outputChatBox]] for outputting any information (use outputDebugString for technical output)&lt;br /&gt;
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] on a variable to turn the value into a string. Useful if the value is not a number or string.&lt;br /&gt;
* [[getElementType]] to check the type of the MTA element.&lt;br /&gt;
* [[isElement]] to check if the MTA element exists.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check ''if'', ''when'' or ''how often'' a section of code is executed===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (variable1 == variable2) then&lt;br /&gt;
    outputDebugString(&amp;quot;variable1 is the same as variable2!&amp;quot;)&lt;br /&gt;
    -- do anything&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check the ''value'' of a variable===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
outputChatBox(&amp;quot;posX is: &amp;quot;..x..&amp;quot; posY is: &amp;quot;..y..&amp;quot; posZ is: &amp;quot;..z)&lt;br /&gt;
createMarker(x,y,z)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
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 values of the variables can be concatenated (put together) as a string, even if it's a boolean value.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Imagine you created a [[Colshape|collision shape]] somewhere and you want an action to perform after the player stays for ten seconds inside it, you would do this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;, root, colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
When a player enters the colshape, debugscript outputs the following message:&lt;br /&gt;
:{{Debug error|..[path]: attempt to index global 'colshapeTimer' (a nil value)}}&lt;br /&gt;
This means you tried to index a table that does not exist (because the table is a nil value, it doesn't 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 it does not exist we should create it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,root,colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we will still receive a warning when a player enters the colshape, waits for the message and leaves it again:&lt;br /&gt;
&lt;br /&gt;
:{{Debug warning|[..]: Bad argument @ 'killTimer' Line: ..}}&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===A more inconspicuous error===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit&amp;quot;)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave&amp;quot;)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 ensure that the ''player'' variable actually holds a reference to a player element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debug messages tell us that one of the ''player'' variables is a player and that the other one is 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the script should work as desired, but it 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 has reached the 10 seconds (and therefore executed after the 10th second has completed). 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 exists). One way would be to check if the timer referenced in the table really exists. To do this, we need to use [[isTimer]], which we will use when we kill the timer:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the complete working code would be:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
		killTimer(colshapeTimer[player])&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Debugging Performance Issues==&lt;br /&gt;
&lt;br /&gt;
If your server is using up more resources than it should or you just want to make sure your scripts are efficient, you can find the source of the issue by using a great tool that comes with the default resource package called [[Resource:Performancebrowser|performancebrowser]]. You can start it with ''''start performancebrowser''''. If it doesn't exist then you can get the latest resources from the [https://github.com/multitheftauto/mtasa-resources GitHub repository]. This tool provides an incredible amount of information for performance debugging. Memory leaks, element leaks and CPU intensive scripts are all easily findable via performancebrowser. If you use the ''''d'''' option in Lua timing you can see which functions are using up the CPU.&lt;br /&gt;
&lt;br /&gt;
To access performancebrowser you will need to go to your web browser and enter the address: http://serverIPHere:serverHTTPPortHere/performancebrowser/ Note that the / at the end is required. So for example: http://127.0.0.1:22005/performancebrowser/ You will then need to login with an in-game admin account or any account that has access to ''''resource.performancebrowser.http'''' and ''''resource.ajax.http''''. Most of the information you will need are in the categories Lua timing and Lua memory, look for values that are much higher than other values.&lt;br /&gt;
&lt;br /&gt;
===Examples of scripts that could cause performance problems===&lt;br /&gt;
&lt;br /&gt;
Adding data to a table but never removing it. This would take months/years before it causes a problem though.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local someData = {}&lt;br /&gt;
&lt;br /&gt;
function storeData()&lt;br /&gt;
    someData[source] = true&lt;br /&gt;
    -- There is no handling for when a player quits, this is considered a memory leak&lt;br /&gt;
    -- Using the Lua timing tab you can detect the RAM usage of each resource.&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, storeData)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Element leaking is possible if you use temporary colshapes for whatever reason and may not destroy them. This would cause bandwidth, CPU and memory performance issues over time.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function useTemporaryCol()&lt;br /&gt;
    local col = createColCircle(some code here)&lt;br /&gt;
    if (normally this should happen) then&lt;br /&gt;
        destroyElement(col)&lt;br /&gt;
    end&lt;br /&gt;
    -- But sometimes it didn't so the script ended but the collision area remained and over time&lt;br /&gt;
    -- you may end up with hundreds to thousands of pointless collision areas. &lt;br /&gt;
    -- The Lua timing tab allows you to see the amount of elements each script has created.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
High CPU usage resulting in the server FPS dropping so much that the server is unplayable. In under 24 hours this can create havoc on a very busy server. The amount of &amp;quot;refs&amp;quot; in the Lua timing detect this type of build up, surprisingly the Lua timing tab didn't help in this case but Lua memory did.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, function()&lt;br /&gt;
    -- Code for joiner&lt;br /&gt;
    addEventHandler(&amp;quot;onPlayerQuit&amp;quot;, root, function()&lt;br /&gt;
        -- Code for when they have quit&lt;br /&gt;
        -- See the problem? It's bound to root which the event handler is being added again and again and again&lt;br /&gt;
    end)&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A function uses up a lot of your CPU because whatever it does takes a long time. This is just some function that takes a long time to complete. Without performancebrowser you'd have no idea its the cause but with performancebrowser you can see that a resource is using lots of CPU in the Lua timing tab. If you then enter: ''''d'''' into the options edit box it will even tell you what file name and first line of the function that is using up so much CPU.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function someDodgyCode()&lt;br /&gt;
    for i=1, 100000 do&lt;br /&gt;
        -- some code&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;br /&gt;
[[en:Debugging]]&lt;br /&gt;
[[it:Guida al Debug]]&lt;br /&gt;
[[ru:Debugging]]&lt;br /&gt;
[[zh-cn:脚本调试教程]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=HU/Main_Page&amp;diff=50687</id>
		<title>HU/Main Page</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HU/Main_Page&amp;diff=50687"/>
		<updated>2017-04-15T17:28:17Z</updated>

		<summary type="html">&lt;p&gt;Kevin: Kevin moved page HU/Main Page to HU/Főoldal: Hungarian&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[HU/Főoldal]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=HU/F%C5%91oldal&amp;diff=50686</id>
		<title>HU/Főoldal</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HU/F%C5%91oldal&amp;diff=50686"/>
		<updated>2017-04-15T17:28:17Z</updated>

		<summary type="html">&lt;p&gt;Kevin: Kevin moved page HU/Main Page to HU/Főoldal: Hungarian&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; |&lt;br /&gt;
&amp;lt;div style=&amp;quot;/*border: 1px solid #D8D8D8;*/ padding-left: 15px; padding-right: 15px; height: 100%;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Mtalogo.png|left|100px|link=http://wiki.multitheftauto.com/]]'''Üdvözöllek a [[Multi Theft Auto]] wikin.''' Itt rengeteg információt találhatsz a Multi Theft Auto használatáról.&lt;br /&gt;
&lt;br /&gt;
Sok [[HU/How you can help|dologban segíthetsz Te is]], amivel fejleszted az MTAt - készíts pályákat, játékmódokat, írj leírást, példákat a függvényekhez, írj útmutatókat, vagy csak játssz, és jelezd a hibákat amiket találtál! &lt;br /&gt;
&lt;br /&gt;
Ha bármilyen kérdésed van a scripteléssel kapcsolatban, vedd fel velünk a kapcsolatot az [[HU/Places To Chat#IRC (Internet Relay Chat) |IRC csatornánkon.]]&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
|width=&amp;quot;50%&amp;quot; style=&amp;quot;vertical-align:top;&amp;quot; |&amp;lt;div style=&amp;quot;border: 1px solid #D8D8D8; padding:4px 8px 8px 8px; margin:10px; background: #FFFCF2;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right; width: 32px;&amp;quot;&amp;gt;[[File:Input-gaming.png‎|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Játék&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;background: #FFEEAA; border: 1px solid #FFCD19;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Go-down.png|link=http://mtasa.com/]] ''' [http://mtasa.com/ Töltsd le a Multi Theft Auto San Andreas {{Current Version|full}}-t!]'''&amp;lt;/div&amp;gt;&lt;br /&gt;
* [[HU/Client Manual | Kliens kézikönyv]]&lt;br /&gt;
&amp;lt;!-- * [[Changes_in_{{padleft:|3|{{Current Version|full}}}}| Changes in {{padleft:|3|{{Current Version|full}}}}]] --&amp;gt;&lt;br /&gt;
* [[HU/Changes_in_{{padleft:|5|{{Current Version|full}}}}| Változtatások az {{padleft:|5|{{Current Version|full}}}} verzióban]]&lt;br /&gt;
* [[HU/Known_Issues_-_FAQ|Ismert problémák]]&lt;br /&gt;
* [[HU/Upgrading_from_MTA:Race|MTA:Race frissítése MTA:SA {{padleft:|3|{{Current Version|full}}}} -ra ]]&lt;br /&gt;
* [[HU/Server Manual|Szerver kézikönyv]]&lt;br /&gt;
* [[HU/Map manager|Map Manager]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Map Editor&amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[HU/Resource:Editor|Kézikönyv]]&lt;br /&gt;
*[[HU/Resource:Editor/EDF|EDF (leírás) fájlok]]&lt;br /&gt;
*[[HU/Resource:Editor/Plugins|Pluginok]]&lt;br /&gt;
*[[HU/Resource:Editor#FAQ|Gyakran Ismételt Kérdések]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: 1px solid #D8D8D8; padding:4px 8px 8px 8px; margin:10px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right; width: 32px;&amp;quot;&amp;gt;[[File:Package-x-generic.png‎|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Adatbázisok&amp;lt;/h3&amp;gt;&lt;br /&gt;
Az alábbi oldalakból megtudhatod mire képes a Lua az MTA-ban.&lt;br /&gt;
* [[HU/:Category:Resource|Resource katalógus]] - Igazán jól működő scriptek készítéséhez érdemes áttanulmányozni őket&lt;br /&gt;
* [[HU/Client side scripts|Kliens oldali scriptek]] &lt;br /&gt;
* [[HU/Modules|Modulok]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: 1px solid #D8D8D8; padding:4px 8px 8px 8px; margin:10px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right; width: 32px;&amp;quot;&amp;gt;[[File:Applications-development.png‎‎‎|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;A Multi Theft Auto fejlesztése&amp;lt;/h3&amp;gt;&lt;br /&gt;
[[File:Go-down.png|link=http://nightly.mtasa.com/]] [http://nightly.mtasa.com/ Fejlesztői verzió]&lt;br /&gt;
* [[HU/Compiling_MTASA|MTA SA fordítása Windowson]]&lt;br /&gt;
* [[HU/Building_MTASA_Server_on_Mac_OS_X|MTA SA fordítása Linuxon]]&lt;br /&gt;
* [[HU/Building_MTASA_Server_on_GNU_Linux|MTA SA fordítása GNU/Linux rendszeren]]&lt;br /&gt;
* [[HU/Coding guidelines|Kódolási útmutató]]&lt;br /&gt;
* [http://code.google.com/p/mtasa-blue Google Code SVN]&lt;br /&gt;
* [[HU/Roadmap|Tervezet]]&lt;br /&gt;
* [http://bugs.mtasa.com/ Hibák]&lt;br /&gt;
* [[HU/Branches|Fejlesztési ágazatok]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: 1px solid #D8D8D8; padding:4px 8px 8px 8px; margin:10px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right; width: 32px;&amp;quot;&amp;gt;[[File:Applications-office.png|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Wiki - Hogyan segíthetsz&amp;lt;/h3&amp;gt;&lt;br /&gt;
* EGészítsd ki a [[HU/:Category:Incomplete|függvények hiányos leírású oldalát]].&lt;br /&gt;
* [[HU/:Category:Needs_Example |Írj példákat függvények használatára]].&lt;br /&gt;
* Ellenőrizd az [[HU/:Category:Needs Checking|ellenőrzésre váró lapokat]].&lt;br /&gt;
* Írj útmutatókat&lt;br /&gt;
* Fordíts wiki lapokat&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: 1px solid #D8D8D8; padding:4px 8px 8px 8px; margin:10px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right; width: 32px;&amp;quot;&amp;gt;[[File:Internet-group-chat.png‎|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Közösség&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [http://forum.multitheftauto.com/ Fórum]&lt;br /&gt;
* IRC: [irc://irc.multitheftauto.com/mta irc.multitheftauto.com #mta]&lt;br /&gt;
* [http://community.mtasa.com/ MTA Community] - Ossz meg és tölts le resourceokat!&lt;br /&gt;
* [http://twitter.com/#!/MTAQA/ Twitter] - [http://www.youtube.com/user/MTAQA Youtube] - [http://plus.google.com/102014133442331779727/ Google+] - [http://www.moddb.com/mods/multi-theft-auto-san-andreas ModDB]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; style=&amp;quot;vertical-align:top;&amp;quot; |&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: 1px solid #D8D8D8; padding:4px 8px 8px 8px; margin:10px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right; width: 32px;&amp;quot;&amp;gt;[[File:Accessories-text-editor.png|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Scriptelés&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[HU/Scripting Introduction|Bevezetés a scriptelésbe]]&lt;br /&gt;
* [[HU/Introduction to Scripting the GUI|Bevezetés a GUI készítésébe]]&lt;br /&gt;
* [[HU/Debugging|Hibakeresés]] - Találd meg a hibát a kódodban&lt;br /&gt;
* [[HU/Resources|Bevezetés a Resourceokba]]&lt;br /&gt;
** [[HU/Resource Web Access|Resource Web Hozzáférés]] - Internet elérése&lt;br /&gt;
** [[HU/:Category:Resource|Resource katalógus]]&lt;br /&gt;
** [[HU/Meta.xml|Meta.xml]] - Minden resource alapja&lt;br /&gt;
** [[HU/ACL]] - A megfelelő jogok meghatározása az összetettebb kódokhoz elengedhetetlen&lt;br /&gt;
* [[HU/Writing_Gamemodes|Játékmódok írása]]&lt;br /&gt;
* [[HU/Useful_Functions|Hasznos függvények]]&lt;br /&gt;
* [http://forum.mtasa.com/viewtopic.php?f=13&amp;amp;t=29363 Offline Wiki Másolatok]&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right; width: 32px;&amp;quot;&amp;gt;[[File:start-here.png|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Általános Lua Segítség&amp;lt;/h3&amp;gt;&lt;br /&gt;
Oldalak a Lua megértésehez:&lt;br /&gt;
*[http://www.lua.org/pil/index.html &amp;quot;Lua Programozás&amp;quot; Kézikönyv]&lt;br /&gt;
**[http://www.lua.org/manual/5.1/#index Lua belső/beépített függvények]&lt;br /&gt;
*[http://lua-users.org/wiki/TutorialDirectory Lua Wiki]&lt;br /&gt;
*[http://nixstaller.berlios.de/manual/0.2/nixstaller_9.html Nixstaller Lua útmutatója]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: 1px solid #D8D8D8; padding:4px 8px 8px 8px; margin:10px; background:#F2F2FF;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right; width: 32px;&amp;quot;&amp;gt;[[File:Preferences-system.png|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Referenciák&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[HU/Client Scripting Functions|Kliens-oldali függvények]]&lt;br /&gt;
* [[HU/Client Scripting Events|Kliens-oldali események]]&lt;br /&gt;
* [[HU/Server Scripting Functions|Szerver-oldali függvények]]&lt;br /&gt;
* [[HU/Server Scripting Events|Szerver-oldali események]]&lt;br /&gt;
&amp;lt;!-- Incomplete * [[Module functions|Server-side external module scripting functions list]] --&amp;gt;&lt;br /&gt;
* [[HU/MTA Classes|MTA Osztályok]] - MTA osztályok részletes leírása&lt;br /&gt;
** [[HU/Element|MTA Elemek]] / [[HU/Element tree|Element ágak]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: 1px solid #D8D8D8; padding:4px 8px 8px 8px; margin:10px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right; width: 32px;&amp;quot;&amp;gt;[[File:System-file-manager.png|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;[[HU/Id|ID Lista]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[HU/Animations|Animációk]]&lt;br /&gt;
*[[HU/Character Skins|Karakter skinek]]&lt;br /&gt;
*[[HU/CJ_Clothes|CJ Ruhái]]&lt;br /&gt;
*[[HU/Garage|Garázs ID lista]]&lt;br /&gt;
*[[HU/Interior IDs|Interiorok]]&lt;br /&gt;
*[[HU/Material IDs|Material]]&lt;br /&gt;
*[[HU/Projectiles|Lövedékek]]&lt;br /&gt;
*[[HU/Radar Blips|Radar jelzések]]&lt;br /&gt;
*[[HU/Sounds|Hang]]&lt;br /&gt;
*[[HU/Vehicle IDs|Járművek]]&lt;br /&gt;
*[[HU/Vehicle Colors|Jármű színek]]&lt;br /&gt;
*[[HU/Vehicle Upgrades|Jármű fejlesztések]]&lt;br /&gt;
*[[HU/Vehicle variants|Járművek egyedi tulajdonságai]]&lt;br /&gt;
*[[HU/Vehicle component manipulation|Jármű komponens változtatások]]&lt;br /&gt;
*[[HU/Weapons|Fegyverek]]&lt;br /&gt;
*[[HU/Weather|Időjárás]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding:4px 8px 8px 8px; margin:10px;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Osi symbol.png|75px|link=http://opensource.org/|left]]&lt;br /&gt;
A '''Multi Theft Auto''' '''nyílt forráskódú'''. &lt;br /&gt;
&amp;lt;br/&amp;gt;Ez azt jelenti, hogy a játékot bárki jobbá teheti!&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; |&lt;br /&gt;
|}&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; |&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding-left: 15px; padding-right: 15px;&amp;quot; class=&amp;quot;plainlinks&amp;quot;&amp;gt;&lt;br /&gt;
[[File:MTALogo_8ball.png|left|85px|link=Archive]]&lt;br /&gt;
&amp;lt;ul style=&amp;quot;list-style: none; width: 200px; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;'''A [[Multi Theft Auto]] - ról'''&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;[[Archive|Archívum]]&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;[[Press Coverage|Sajtó]]&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;[http://code.google.com/p/mtasa-blue/people/list Fejlesztők]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul style=&amp;quot;list-style: none; width: 200px; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;'''Multi Theft Auto 0.5'''&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;[[Archive#Multi_Theft_Auto_0.5|Letöltés]]&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;[[MTA 0.5r2 Known Issues|Ismert hibák]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul style=&amp;quot;list-style: none; width: 200px; float: left;&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;'''Wiki Statisztikák'''&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;{{NUMBEROFARTICLES}} cikk&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;{{NUMBEROFPAGES}} oldal&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;{{NUMBEROFUSERS}} regisztrált felhasználó&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
__NOEDITSECTION__&lt;br /&gt;
{{Languages list|en}}&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=HU/Debugging&amp;diff=50678</id>
		<title>HU/Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HU/Debugging&amp;diff=50678"/>
		<updated>2017-04-15T14:22:22Z</updated>

		<summary type="html">&lt;p&gt;Kevin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A szkriptekben gyakran előfordulnak kisebb nagyobb problémák, amelyeket nem veszünk észre!Ez a leírás segít abban hogy gyorsan megtaláld őket!&lt;br /&gt;
&lt;br /&gt;
==Hibakereső konzol==&lt;br /&gt;
Az MTA tartalmaz beépített hibakereső konzolt!Hasznos mivel ha elgépelünk valamit és nem vesszük észre ő segítségünkre lehet.Ahhoz hogy tudjuk aktiválni ezt a jogusultságot Adminisztrátor rangot kell viselnünk{ACL}.Ha ez rendben van akkor a &amp;quot;debugscript x&amp;quot; parancsal tudjuk változtatni a visszajelzési szintet!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Lehetőségek:&lt;br /&gt;
* '''1:''' Csak a '''Hibákat''' jelzi&lt;br /&gt;
* '''2:''' A '''hibákat''' és a '''Figyelmeztetéseket''' is jelzi&lt;br /&gt;
* '''3:''' A '''hibákat''' és a '''Figyelmeztetéseket''' is jelzi illetve az '''Információkat''' amelyeket elrejtünk a szkriptekben!&lt;br /&gt;
Ha begépeljük a &amp;quot;debugscript 3&amp;quot; parancsot akkor a fent leírt paramétereket fogja megmutatni.Ez a legcélszerűbb funkció, sokkal egyszerűbb vele a fejlesztés&lt;br /&gt;
&lt;br /&gt;
===Példa===&lt;br /&gt;
Ebben a kódban elrejtettünk két darab hibát:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;)&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ha ezt a kódot lefuttatjuk akkor ezt a hibaüzenetet fogjuk kapni:&lt;br /&gt;
:{{Debug info|Loading script failed: myResource\script.lua:2: 'then' expected near ´outputChatbox'}}[Ezt nem fordítom le]&lt;br /&gt;
This means the script could not be parsed because there was a syntax error. It shows the script path relative to the resource directory so you can identify to script where the error originated from. After the filename it shows a colon and a number, this number presents the line number - this is so you can find out where in your script the error is - it is very helpful for large scripts. After that is the error message, which varies depending on the error made. Looking at the error message, we can easily determine that the error originated from the resource '''myResource''' and line two of the script file '''script.lua'''. The error message is very clear, we forgot the &amp;quot;then&amp;quot;! We can easily fix that!&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;) then&lt;br /&gt;
        outputChatbox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Now the script will load fine and won't output any errors until a player with the name 'Fedor' says something in the chat. At that moment, the debug console will output:&lt;br /&gt;
:{{Debug error|myResource\script.lua:2: attempt to call global 'outputChatbox' (a nil value)}}&lt;br /&gt;
This error means that the function '''outputChatbox''' is a nil value, that is - it doesn't exist! This is because the function is actually called [[outputChatBox]], not [[outputChatbox]] - take care of that capital B.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;) then&lt;br /&gt;
        outputChatBox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, this is just an example and I've only skimmed the surface of error messages. There are plenty of other messages and scenarios, but you should get the general idea.&lt;br /&gt;
&lt;br /&gt;
==Server &amp;amp; client debug logging==&lt;br /&gt;
====Server====&lt;br /&gt;
Navigate to: ''(MTA root folder)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch''&lt;br /&gt;
&lt;br /&gt;
There are two nearly identical files:&lt;br /&gt;
&lt;br /&gt;
*The local.conf is the settings for the &amp;quot;host game&amp;quot; menu item in the main menu of MTA. This is a quick and easy way of starting a temporary server from inside the client. When the client is turned off the server will also turn off.&lt;br /&gt;
&lt;br /&gt;
*The mtaserver.conf is used when &amp;quot;MTA Server.exe&amp;quot; is executed from (MTA root folder)&amp;gt;server. This runs the server in its own console window which does not need the client to exist or to be run. This is can be useful if you're interested in hosting servers for a longer time period or if you want to experiment with a real world console.&lt;br /&gt;
&lt;br /&gt;
Depending on which way you host, you will want to edit those files. The settings in question are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;!-- Specifies the location and name of the debugscript log file. If left blank, server won't be saving this file. --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebuglogfile&amp;gt;logs/scripts.log&amp;lt;/scriptdebuglogfile&amp;gt; &lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;!-- Specifies the level of the debugscript log file. Available values: 0, 1, 2, 3. When not set, defaults to 0. --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebugloglevel&amp;gt;0&amp;lt;/scriptdebugloglevel&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You want to make sure you have a log name specified. Also you want to specify what level of errors will be logged. If it is 0 nothing will be logged. The levels were explained at the top of this article. If the logging level was changed to 3, then in this case all '''serverside''' script errors log to (MTA root folder)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch&amp;gt;logs&amp;gt;scripts.log&lt;br /&gt;
&lt;br /&gt;
====Client====&lt;br /&gt;
Navigate to: ''(MTA root folder)&amp;gt;server&amp;gt;clientscript.log''&lt;br /&gt;
&lt;br /&gt;
This file logs all '''clientside''' script errors. This is set to log by default, no setup required.&lt;br /&gt;
&lt;br /&gt;
==Debug strategies==&lt;br /&gt;
There are several strategies that support finding errors, apart from going through the code. Most of them include outputting debug messages, with have different information depending on the situtation.&lt;br /&gt;
&lt;br /&gt;
===Useful functions===&lt;br /&gt;
There are some functions that may come in handy for debugging.&lt;br /&gt;
* [[outputDebugString]] or [[outputChatBox]] for outputting any information (use outputDebugString for technical output)&lt;br /&gt;
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] on a variable to turn the value into a string. Useful if the value is not a number or string.&lt;br /&gt;
* [[getElementType]] to check the type of the MTA element.&lt;br /&gt;
* [[isElement]] to check if the MTA element exists.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check ''if'', ''when'' or ''how often'' a section of code is executed===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (variable1 == variable2) then&lt;br /&gt;
    outputDebugString(&amp;quot;variable1 is the same as variable2!&amp;quot;)&lt;br /&gt;
    -- do anything&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check the ''value'' of a variable===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
outputChatBox(&amp;quot;posX is: &amp;quot;..x..&amp;quot; posY is: &amp;quot;..y..&amp;quot; posZ is: &amp;quot;..z)&lt;br /&gt;
createMarker(x,y,z)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
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 values of the variables can be concatenated (put together) as a string, even if it's a boolean value.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Imagine you created a [[Colshape|collision shape]] somewhere and you want an action to perform after the player stays for ten seconds inside it, you would do this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;, root, colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
When a player enters the colshape, debugscript outputs the following message:&lt;br /&gt;
:{{Debug error|..[path]: attempt to index global 'colshapeTimer' (a nil value)}}&lt;br /&gt;
This means you tried to index a table that does not exist (because the table is a nil value, it doesn't 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 it does not exist we should create it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,root,colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we will still receive a warning when a player enters the colshape, waits for the message and leaves it again:&lt;br /&gt;
&lt;br /&gt;
:{{Debug warning|[..]: Bad argument @ 'killTimer' Line: ..}}&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===A more inconspicuous error===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit&amp;quot;)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave&amp;quot;)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 ensure that the ''player'' variable actually holds a reference to a player element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debug messages tell us that one of the ''player'' variables is a player and that the other one is 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the script should work as desired, but it 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 has reached the 10 seconds (and therefore executed after the 10th second has completed). 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 exists). One way would be to check if the timer referenced in the table really exists. To do this, we need to use [[isTimer]], which we will use when we kill the timer:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the complete working code would be:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
		killTimer(colshapeTimer[player])&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Debugging Performance Issues==&lt;br /&gt;
&lt;br /&gt;
If your server is using up more resources than it should or you just want to make sure your scripts are efficient, you can find the source of the issue by using a great tool that comes with the default resource package called [[Resource:Performancebrowser|performancebrowser]]. You can start it with ''''start performancebrowser''''. If it doesn't exist then you can get the latest resources from the [https://github.com/multitheftauto/mtasa-resources GitHub repository]. This tool provides an incredible amount of information for performance debugging. Memory leaks, element leaks and CPU intensive scripts are all easily findable via performancebrowser. If you use the ''''d'''' option in Lua timing you can see which functions are using up the CPU.&lt;br /&gt;
&lt;br /&gt;
To access performancebrowser you will need to go to your web browser and enter the address: http://serverIPHere:serverHTTPPortHere/performancebrowser/ Note that the / at the end is required. So for example: http://127.0.0.1:22005/performancebrowser/ You will then need to login with an in-game admin account or any account that has access to ''''resource.performancebrowser.http'''' and ''''resource.ajax.http''''. Most of the information you will need are in the categories Lua timing and Lua memory, look for values that are much higher than other values.&lt;br /&gt;
&lt;br /&gt;
===Examples of scripts that could cause performance problems===&lt;br /&gt;
&lt;br /&gt;
Adding data to a table but never removing it. This would take months/years before it causes a problem though.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local someData = {}&lt;br /&gt;
&lt;br /&gt;
function storeData()&lt;br /&gt;
    someData[source] = true&lt;br /&gt;
    -- There is no handling for when a player quits, this is considered a memory leak&lt;br /&gt;
    -- Using the Lua timing tab you can detect the RAM usage of each resource.&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, storeData)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Element leaking is possible if you use temporary colshapes for whatever reason and may not destroy them. This would cause bandwidth, CPU and memory performance issues over time.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function useTemporaryCol()&lt;br /&gt;
    local col = createColCircle(some code here)&lt;br /&gt;
    if (normally this should happen) then&lt;br /&gt;
        destroyElement(col)&lt;br /&gt;
    end&lt;br /&gt;
    -- But sometimes it didn't so the script ended but the collision area remained and over time&lt;br /&gt;
    -- you may end up with hundreds to thousands of pointless collision areas. &lt;br /&gt;
    -- The Lua timing tab allows you to see the amount of elements each script has created.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
High CPU usage resulting in the server FPS dropping so much that the server is unplayable. In under 24 hours this can create havoc on a very busy server. The amount of &amp;quot;refs&amp;quot; in the Lua timing detect this type of build up, surprisingly the Lua timing tab didn't help in this case but Lua memory did.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, function()&lt;br /&gt;
    -- Code for joiner&lt;br /&gt;
    addEventHandler(&amp;quot;onPlayerQuit&amp;quot;, root, function()&lt;br /&gt;
        -- Code for when they have quit&lt;br /&gt;
        -- See the problem? It's bound to root which the event handler is being added again and again and again&lt;br /&gt;
    end)&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A function uses up a lot of your CPU because whatever it does takes a long time. This is just some function that takes a long time to complete. Without performancebrowser you'd have no idea its the cause but with performancebrowser you can see that a resource is using lots of CPU in the Lua timing tab. If you then enter: ''''d'''' into the options edit box it will even tell you what file name and first line of the function that is using up so much CPU.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function someDodgyCode()&lt;br /&gt;
    for i=1, 100000 do&lt;br /&gt;
        -- some code&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[it:Guida al Debug]]&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;br /&gt;
[[ru:Debugging]]&lt;br /&gt;
[[zh-cn:脚本调试教程]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Hibakeres%C3%A9s&amp;diff=50677</id>
		<title>Hibakeresés</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Hibakeres%C3%A9s&amp;diff=50677"/>
		<updated>2017-04-15T14:20:04Z</updated>

		<summary type="html">&lt;p&gt;Kevin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A szkriptekben gyakran előfordulnak kisebb nagyobb problémák, amelyeket nem veszünk észre!Ez a leírás segít abban hogy gyorsan megtaláld őket!&lt;br /&gt;
&lt;br /&gt;
==Hibakereső konzol==&lt;br /&gt;
Az MTA tartalmaz beépített hibakereső konzolt!Hasznos mivel ha elgépelünk valamit és nem vesszük észre ő segítségünkre lehet.Ahhoz hogy tudjuk aktiválni ezt a jogusultságot Adminisztrátor rangot kell viselnünk{ACL}.Ha ez rendben van akkor a &amp;quot;debugscript x&amp;quot; parancsal tudjuk változtatni a visszajelzési szintet!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Lehetőségek:&lt;br /&gt;
* '''1:''' Csak a '''Hibákat''' jelzi&lt;br /&gt;
* '''2:''' A '''hibákat''' és a '''Figyelmeztetéseket''' is jelzi&lt;br /&gt;
* '''3:''' A '''hibákat''' és a '''Figyelmeztetéseket''' is jelzi illetve az '''Információkat''' amelyeket elrejtünk a szkriptekben!&lt;br /&gt;
Ha begépeljük a &amp;quot;debugscript 3&amp;quot; parancsot akkor a fent leírt paramétereket fogja megmutatni.Ez a legcélszerűbb funkció, sokkal egyszerűbb vele a fejlesztés&lt;br /&gt;
&lt;br /&gt;
===Példa===&lt;br /&gt;
Ebben a kódban elrejtettünk két darab hibát:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Koszones(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Józsika&amp;quot;)&lt;br /&gt;
        outputChatbox(&amp;quot;Szia Józsika&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, Koszones)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ha ezt a kódot lefuttatjuk akkor ezt a hibaüzenetet fogjuk kapni:&lt;br /&gt;
:{{Debug info|Loading script failed: myResource\script.lua:2: 'then' expected near ´outputChatbox'}}[Ezt nem fordítom le]&lt;br /&gt;
This means the script could not be parsed because there was a syntax error. It shows the script path relative to the resource directory so you can identify to script where the error originated from. After the filename it shows a colon and a number, this number presents the line number - this is so you can find out where in your script the error is - it is very helpful for large scripts. After that is the error message, which varies depending on the error made. Looking at the error message, we can easily determine that the error originated from the resource '''myResource''' and line two of the script file '''script.lua'''. The error message is very clear, we forgot the &amp;quot;then&amp;quot;! We can easily fix that!&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;) then&lt;br /&gt;
        outputChatbox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Now the script will load fine and won't output any errors until a player with the name 'Fedor' says something in the chat. At that moment, the debug console will output:&lt;br /&gt;
:{{Debug error|myResource\script.lua:2: attempt to call global 'outputChatbox' (a nil value)}}&lt;br /&gt;
This error means that the function '''outputChatbox''' is a nil value, that is - it doesn't exist! This is because the function is actually called [[outputChatBox]], not [[outputChatbox]] - take care of that capital B.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;) then&lt;br /&gt;
        outputChatBox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, this is just an example and I've only skimmed the surface of error messages. There are plenty of other messages and scenarios, but you should get the general idea.&lt;br /&gt;
&lt;br /&gt;
==Server &amp;amp; client debug logging==&lt;br /&gt;
====Server====&lt;br /&gt;
Navigate to: ''(MTA root folder)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch''&lt;br /&gt;
&lt;br /&gt;
There are two nearly identical files:&lt;br /&gt;
&lt;br /&gt;
*The local.conf is the settings for the &amp;quot;host game&amp;quot; menu item in the main menu of MTA. This is a quick and easy way of starting a temporary server from inside the client. When the client is turned off the server will also turn off.&lt;br /&gt;
&lt;br /&gt;
*The mtaserver.conf is used when &amp;quot;MTA Server.exe&amp;quot; is executed from (MTA root folder)&amp;gt;server. This runs the server in its own console window which does not need the client to exist or to be run. This is can be useful if you're interested in hosting servers for a longer time period or if you want to experiment with a real world console.&lt;br /&gt;
&lt;br /&gt;
Depending on which way you host, you will want to edit those files. The settings in question are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;!-- Specifies the location and name of the debugscript log file. If left blank, server won't be saving this file. --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebuglogfile&amp;gt;logs/scripts.log&amp;lt;/scriptdebuglogfile&amp;gt; &lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;!-- Specifies the level of the debugscript log file. Available values: 0, 1, 2, 3. When not set, defaults to 0. --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebugloglevel&amp;gt;0&amp;lt;/scriptdebugloglevel&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You want to make sure you have a log name specified. Also you want to specify what level of errors will be logged. If it is 0 nothing will be logged. The levels were explained at the top of this article. If the logging level was changed to 3, then in this case all '''serverside''' script errors log to (MTA root folder)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch&amp;gt;logs&amp;gt;scripts.log&lt;br /&gt;
&lt;br /&gt;
====Client====&lt;br /&gt;
Navigate to: ''(MTA root folder)&amp;gt;server&amp;gt;clientscript.log''&lt;br /&gt;
&lt;br /&gt;
This file logs all '''clientside''' script errors. This is set to log by default, no setup required.&lt;br /&gt;
&lt;br /&gt;
==Debug strategies==&lt;br /&gt;
There are several strategies that support finding errors, apart from going through the code. Most of them include outputting debug messages, with have different information depending on the situtation.&lt;br /&gt;
&lt;br /&gt;
===Useful functions===&lt;br /&gt;
There are some functions that may come in handy for debugging.&lt;br /&gt;
* [[outputDebugString]] or [[outputChatBox]] for outputting any information (use outputDebugString for technical output)&lt;br /&gt;
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] on a variable to turn the value into a string. Useful if the value is not a number or string.&lt;br /&gt;
* [[getElementType]] to check the type of the MTA element.&lt;br /&gt;
* [[isElement]] to check if the MTA element exists.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check ''if'', ''when'' or ''how often'' a section of code is executed===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (variable1 == variable2) then&lt;br /&gt;
    outputDebugString(&amp;quot;variable1 is the same as variable2!&amp;quot;)&lt;br /&gt;
    -- do anything&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check the ''value'' of a variable===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
outputChatBox(&amp;quot;posX is: &amp;quot;..x..&amp;quot; posY is: &amp;quot;..y..&amp;quot; posZ is: &amp;quot;..z)&lt;br /&gt;
createMarker(x,y,z)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
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 values of the variables can be concatenated (put together) as a string, even if it's a boolean value.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Imagine you created a [[Colshape|collision shape]] somewhere and you want an action to perform after the player stays for ten seconds inside it, you would do this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;, root, colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
When a player enters the colshape, debugscript outputs the following message:&lt;br /&gt;
:{{Debug error|..[path]: attempt to index global 'colshapeTimer' (a nil value)}}&lt;br /&gt;
This means you tried to index a table that does not exist (because the table is a nil value, it doesn't 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 it does not exist we should create it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,root,colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we will still receive a warning when a player enters the colshape, waits for the message and leaves it again:&lt;br /&gt;
&lt;br /&gt;
:{{Debug warning|[..]: Bad argument @ 'killTimer' Line: ..}}&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===A more inconspicuous error===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit&amp;quot;)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave&amp;quot;)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 ensure that the ''player'' variable actually holds a reference to a player element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debug messages tell us that one of the ''player'' variables is a player and that the other one is 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the script should work as desired, but it 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 has reached the 10 seconds (and therefore executed after the 10th second has completed). 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 exists). One way would be to check if the timer referenced in the table really exists. To do this, we need to use [[isTimer]], which we will use when we kill the timer:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the complete working code would be:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
		killTimer(colshapeTimer[player])&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Debugging Performance Issues==&lt;br /&gt;
&lt;br /&gt;
If your server is using up more resources than it should or you just want to make sure your scripts are efficient, you can find the source of the issue by using a great tool that comes with the default resource package called [[Resource:Performancebrowser|performancebrowser]]. You can start it with ''''start performancebrowser''''. If it doesn't exist then you can get the latest resources from the [https://github.com/multitheftauto/mtasa-resources GitHub repository]. This tool provides an incredible amount of information for performance debugging. Memory leaks, element leaks and CPU intensive scripts are all easily findable via performancebrowser. If you use the ''''d'''' option in Lua timing you can see which functions are using up the CPU.&lt;br /&gt;
&lt;br /&gt;
To access performancebrowser you will need to go to your web browser and enter the address: http://serverIPHere:serverHTTPPortHere/performancebrowser/ Note that the / at the end is required. So for example: http://127.0.0.1:22005/performancebrowser/ You will then need to login with an in-game admin account or any account that has access to ''''resource.performancebrowser.http'''' and ''''resource.ajax.http''''. Most of the information you will need are in the categories Lua timing and Lua memory, look for values that are much higher than other values.&lt;br /&gt;
&lt;br /&gt;
===Examples of scripts that could cause performance problems===&lt;br /&gt;
&lt;br /&gt;
Adding data to a table but never removing it. This would take months/years before it causes a problem though.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local someData = {}&lt;br /&gt;
&lt;br /&gt;
function storeData()&lt;br /&gt;
    someData[source] = true&lt;br /&gt;
    -- There is no handling for when a player quits, this is considered a memory leak&lt;br /&gt;
    -- Using the Lua timing tab you can detect the RAM usage of each resource.&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, storeData)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Element leaking is possible if you use temporary colshapes for whatever reason and may not destroy them. This would cause bandwidth, CPU and memory performance issues over time.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function useTemporaryCol()&lt;br /&gt;
    local col = createColCircle(some code here)&lt;br /&gt;
    if (normally this should happen) then&lt;br /&gt;
        destroyElement(col)&lt;br /&gt;
    end&lt;br /&gt;
    -- But sometimes it didn't so the script ended but the collision area remained and over time&lt;br /&gt;
    -- you may end up with hundreds to thousands of pointless collision areas. &lt;br /&gt;
    -- The Lua timing tab allows you to see the amount of elements each script has created.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
High CPU usage resulting in the server FPS dropping so much that the server is unplayable. In under 24 hours this can create havoc on a very busy server. The amount of &amp;quot;refs&amp;quot; in the Lua timing detect this type of build up, surprisingly the Lua timing tab didn't help in this case but Lua memory did.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, function()&lt;br /&gt;
    -- Code for joiner&lt;br /&gt;
    addEventHandler(&amp;quot;onPlayerQuit&amp;quot;, root, function()&lt;br /&gt;
        -- Code for when they have quit&lt;br /&gt;
        -- See the problem? It's bound to root which the event handler is being added again and again and again&lt;br /&gt;
    end)&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A function uses up a lot of your CPU because whatever it does takes a long time. This is just some function that takes a long time to complete. Without performancebrowser you'd have no idea its the cause but with performancebrowser you can see that a resource is using lots of CPU in the Lua timing tab. If you then enter: ''''d'''' into the options edit box it will even tell you what file name and first line of the function that is using up so much CPU.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function someDodgyCode()&lt;br /&gt;
    for i=1, 100000 do&lt;br /&gt;
        -- some code&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[it:Guida al Debug]]&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;br /&gt;
[[ru:Debugging]]&lt;br /&gt;
[[zh-cn:脚本调试教程]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Talk:Debugging&amp;diff=50676</id>
		<title>Talk:Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Talk:Debugging&amp;diff=50676"/>
		<updated>2017-04-15T13:59:47Z</updated>

		<summary type="html">&lt;p&gt;Kevin: Kevin moved page Talk:Debugging to Talk:Hibakeresés&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:Hibakeresés]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Talk:Hibakeres%C3%A9s&amp;diff=50675</id>
		<title>Talk:Hibakeresés</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Talk:Hibakeres%C3%A9s&amp;diff=50675"/>
		<updated>2017-04-15T13:59:47Z</updated>

		<summary type="html">&lt;p&gt;Kevin: Kevin moved page Talk:Debugging to Talk:Hibakeresés&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Isn't isTimer already MTA function?&lt;br /&gt;
http://wiki.mtasa.com/wiki/IsTimer&lt;br /&gt;
Also, is this really the way MTA isTimer works? If having a lot of timers, better method would be to remove the table key in the function setTimer references to. And onColShapeLeave just check if the key exists.&lt;br /&gt;
 --Madis&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Debugging&amp;diff=50674</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Debugging&amp;diff=50674"/>
		<updated>2017-04-15T13:59:47Z</updated>

		<summary type="html">&lt;p&gt;Kevin: Kevin moved page Debugging to Hibakeresés&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Hibakeresés]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Hibakeres%C3%A9s&amp;diff=50673</id>
		<title>Hibakeresés</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Hibakeres%C3%A9s&amp;diff=50673"/>
		<updated>2017-04-15T13:59:47Z</updated>

		<summary type="html">&lt;p&gt;Kevin: Kevin moved page Debugging to Hibakeresés&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;When 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.&lt;br /&gt;
&lt;br /&gt;
==Debug console==&lt;br /&gt;
MTA features a built-in debug console that shows debug messages output from MTA functions or from scripts. Keeping it mind that you should have administrator access (unless you modify the ACL to change this), you can open the debug console by typing ''debugscript *x*'' in the console, where ''x'' is the debug level:&lt;br /&gt;
* '''1:''' only errors&lt;br /&gt;
* '''2:''' errors and warnings&lt;br /&gt;
* '''3:''' errors, warnings and info messages&lt;br /&gt;
By typing ''debugscript 3'' all messages are visible. Level 3 and level 2 are recommended for most occasions. You should have ''debugscript'' enabled whenever you are testing your scripts as it will help you easily detect and solve typos and other issues.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
This example code has two errors:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;)&lt;br /&gt;
        outputChatbox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
When the script this piece of code is in is tried to be loaded, debugscript will output something similiar to this:&lt;br /&gt;
:{{Debug info|Loading script failed: myResource\script.lua:2: 'then' expected near ´outputChatbox'}}&lt;br /&gt;
This means the script could not be parsed because there was a syntax error. It shows the script path relative to the resource directory so you can identify to script where the error originated from. After the filename it shows a colon and a number, this number presents the line number - this is so you can find out where in your script the error is - it is very helpful for large scripts. After that is the error message, which varies depending on the error made. Looking at the error message, we can easily determine that the error originated from the resource '''myResource''' and line two of the script file '''script.lua'''. The error message is very clear, we forgot the &amp;quot;then&amp;quot;! We can easily fix that!&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;) then&lt;br /&gt;
        outputChatbox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Now the script will load fine and won't output any errors until a player with the name 'Fedor' says something in the chat. At that moment, the debug console will output:&lt;br /&gt;
:{{Debug error|myResource\script.lua:2: attempt to call global 'outputChatbox' (a nil value)}}&lt;br /&gt;
This error means that the function '''outputChatbox''' is a nil value, that is - it doesn't exist! This is because the function is actually called [[outputChatBox]], not [[outputChatbox]] - take care of that capital B.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function SayHello(message, player)&lt;br /&gt;
    if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;) then&lt;br /&gt;
        outputChatBox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onChatMessage&amp;quot;, root, SayHello)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, this is just an example and I've only skimmed the surface of error messages. There are plenty of other messages and scenarios, but you should get the general idea.&lt;br /&gt;
&lt;br /&gt;
==Server &amp;amp; client debug logging==&lt;br /&gt;
====Server====&lt;br /&gt;
Navigate to: ''(MTA root folder)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch''&lt;br /&gt;
&lt;br /&gt;
There are two nearly identical files:&lt;br /&gt;
&lt;br /&gt;
*The local.conf is the settings for the &amp;quot;host game&amp;quot; menu item in the main menu of MTA. This is a quick and easy way of starting a temporary server from inside the client. When the client is turned off the server will also turn off.&lt;br /&gt;
&lt;br /&gt;
*The mtaserver.conf is used when &amp;quot;MTA Server.exe&amp;quot; is executed from (MTA root folder)&amp;gt;server. This runs the server in its own console window which does not need the client to exist or to be run. This is can be useful if you're interested in hosting servers for a longer time period or if you want to experiment with a real world console.&lt;br /&gt;
&lt;br /&gt;
Depending on which way you host, you will want to edit those files. The settings in question are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;!-- Specifies the location and name of the debugscript log file. If left blank, server won't be saving this file. --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebuglogfile&amp;gt;logs/scripts.log&amp;lt;/scriptdebuglogfile&amp;gt; &lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;!-- Specifies the level of the debugscript log file. Available values: 0, 1, 2, 3. When not set, defaults to 0. --&amp;gt;&lt;br /&gt;
	&amp;lt;scriptdebugloglevel&amp;gt;0&amp;lt;/scriptdebugloglevel&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You want to make sure you have a log name specified. Also you want to specify what level of errors will be logged. If it is 0 nothing will be logged. The levels were explained at the top of this article. If the logging level was changed to 3, then in this case all '''serverside''' script errors log to (MTA root folder)&amp;gt;server&amp;gt;mods&amp;gt;deathmatch&amp;gt;logs&amp;gt;scripts.log&lt;br /&gt;
&lt;br /&gt;
====Client====&lt;br /&gt;
Navigate to: ''(MTA root folder)&amp;gt;server&amp;gt;clientscript.log''&lt;br /&gt;
&lt;br /&gt;
This file logs all '''clientside''' script errors. This is set to log by default, no setup required.&lt;br /&gt;
&lt;br /&gt;
==Debug strategies==&lt;br /&gt;
There are several strategies that support finding errors, apart from going through the code. Most of them include outputting debug messages, with have different information depending on the situtation.&lt;br /&gt;
&lt;br /&gt;
===Useful functions===&lt;br /&gt;
There are some functions that may come in handy for debugging.&lt;br /&gt;
* [[outputDebugString]] or [[outputChatBox]] for outputting any information (use outputDebugString for technical output)&lt;br /&gt;
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] on a variable to turn the value into a string. Useful if the value is not a number or string.&lt;br /&gt;
* [[getElementType]] to check the type of the MTA element.&lt;br /&gt;
* [[isElement]] to check if the MTA element exists.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check ''if'', ''when'' or ''how often'' a section of code is executed===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (variable1 == variable2) then&lt;br /&gt;
    outputDebugString(&amp;quot;variable1 is the same as variable2!&amp;quot;)&lt;br /&gt;
    -- do anything&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Add debugmessages to check the ''value'' of a variable===&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
outputChatBox(&amp;quot;posX is: &amp;quot;..x..&amp;quot; posY is: &amp;quot;..y..&amp;quot; posZ is: &amp;quot;..z)&lt;br /&gt;
createMarker(x,y,z)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
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 values of the variables can be concatenated (put together) as a string, even if it's a boolean value.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Imagine you created a [[Colshape|collision shape]] somewhere and you want an action to perform after the player stays for ten seconds inside it, you would do this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;, root, colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
When a player enters the colshape, debugscript outputs the following message:&lt;br /&gt;
:{{Debug error|..[path]: attempt to index global 'colshapeTimer' (a nil value)}}&lt;br /&gt;
This means you tried to index a table that does not exist (because the table is a nil value, it doesn't 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 it does not exist we should create it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;, root, colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,root,colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we will still receive a warning when a player enters the colshape, waits for the message and leaves it again:&lt;br /&gt;
&lt;br /&gt;
:{{Debug warning|[..]: Bad argument @ 'killTimer' Line: ..}}&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===A more inconspicuous error===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit&amp;quot;)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave&amp;quot;)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 ensure that the ''player'' variable actually holds a reference to a player element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debug messages tell us that one of the ''player'' variables is a player and that the other one is 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the script should work as desired, but it 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 has reached the 10 seconds (and therefore executed after the 10th second has completed). 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 exists). One way would be to check if the timer referenced in the table really exists. To do this, we need to use [[isTimer]], which we will use when we kill the timer:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the complete working code would be:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
		killTimer(colshapeTimer[player])&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Debugging Performance Issues==&lt;br /&gt;
&lt;br /&gt;
If your server is using up more resources than it should or you just want to make sure your scripts are efficient, you can find the source of the issue by using a great tool that comes with the default resource package called [[Resource:Performancebrowser|performancebrowser]]. You can start it with ''''start performancebrowser''''. If it doesn't exist then you can get the latest resources from the [https://github.com/multitheftauto/mtasa-resources GitHub repository]. This tool provides an incredible amount of information for performance debugging. Memory leaks, element leaks and CPU intensive scripts are all easily findable via performancebrowser. If you use the ''''d'''' option in Lua timing you can see which functions are using up the CPU.&lt;br /&gt;
&lt;br /&gt;
To access performancebrowser you will need to go to your web browser and enter the address: http://serverIPHere:serverHTTPPortHere/performancebrowser/ Note that the / at the end is required. So for example: http://127.0.0.1:22005/performancebrowser/ You will then need to login with an in-game admin account or any account that has access to ''''resource.performancebrowser.http'''' and ''''resource.ajax.http''''. Most of the information you will need are in the categories Lua timing and Lua memory, look for values that are much higher than other values.&lt;br /&gt;
&lt;br /&gt;
===Examples of scripts that could cause performance problems===&lt;br /&gt;
&lt;br /&gt;
Adding data to a table but never removing it. This would take months/years before it causes a problem though.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local someData = {}&lt;br /&gt;
&lt;br /&gt;
function storeData()&lt;br /&gt;
    someData[source] = true&lt;br /&gt;
    -- There is no handling for when a player quits, this is considered a memory leak&lt;br /&gt;
    -- Using the Lua timing tab you can detect the RAM usage of each resource.&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, storeData)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Element leaking is possible if you use temporary colshapes for whatever reason and may not destroy them. This would cause bandwidth, CPU and memory performance issues over time.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function useTemporaryCol()&lt;br /&gt;
    local col = createColCircle(some code here)&lt;br /&gt;
    if (normally this should happen) then&lt;br /&gt;
        destroyElement(col)&lt;br /&gt;
    end&lt;br /&gt;
    -- But sometimes it didn't so the script ended but the collision area remained and over time&lt;br /&gt;
    -- you may end up with hundreds to thousands of pointless collision areas. &lt;br /&gt;
    -- The Lua timing tab allows you to see the amount of elements each script has created.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
High CPU usage resulting in the server FPS dropping so much that the server is unplayable. In under 24 hours this can create havoc on a very busy server. The amount of &amp;quot;refs&amp;quot; in the Lua timing detect this type of build up, surprisingly the Lua timing tab didn't help in this case but Lua memory did.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, root, function()&lt;br /&gt;
    -- Code for joiner&lt;br /&gt;
    addEventHandler(&amp;quot;onPlayerQuit&amp;quot;, root, function()&lt;br /&gt;
        -- Code for when they have quit&lt;br /&gt;
        -- See the problem? It's bound to root which the event handler is being added again and again and again&lt;br /&gt;
    end)&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A function uses up a lot of your CPU because whatever it does takes a long time. This is just some function that takes a long time to complete. Without performancebrowser you'd have no idea its the cause but with performancebrowser you can see that a resource is using lots of CPU in the Lua timing tab. If you then enter: ''''d'''' into the options edit box it will even tell you what file name and first line of the function that is using up so much CPU.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function someDodgyCode()&lt;br /&gt;
    for i=1, 100000 do&lt;br /&gt;
        -- some code&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[it:Guida al Debug]]&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;br /&gt;
[[ru:Debugging]]&lt;br /&gt;
[[zh-cn:脚本调试教程]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Kevin</name></author>
	</entry>
</feed>