<?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=Warlord</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=Warlord"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Warlord"/>
	<updated>2026-04-17T20:02:59Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Hibakeres%C3%A9s&amp;diff=31443</id>
		<title>Hibakeresés</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Hibakeres%C3%A9s&amp;diff=31443"/>
		<updated>2012-06-16T23:56:49Z</updated>

		<summary type="html">&lt;p&gt;Warlord: /* Add debugmessages to check the value of a variable */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;While scripting you will often come across problems that are not immediately apparent. This page tries to point out some basic strategies to locate the error.&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. You can open it by typing ''debugscript x'' in console, while ''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;
Thus, by typing ''debugscript 3'' all messages are visible, that or level 2 are recommended for most occasions. You should have debugscript enabled most of the time you are testing your scripts, this will help you detect typos or other simple issues and solve them easily.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
This example snippet has two errors:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&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;
&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: C:\&amp;lt;server path&amp;gt;\mods\deathmatch\resources\myResource\script.lua:15: 'then' expected near ´outputChatbox'}}&lt;br /&gt;
This means the script could not be parsed, because there was a syntax error. It shows the path of the script, so you can also see what resource it is in ('myResource' in this case) and of course the name of the script. After the filename it shows the line number and again after that what was wrong. Easy to solve now, we just forgot the 'then' keyword:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&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;
&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' enters this section of the script. Then, debugscript will output:&lt;br /&gt;
:{{Debug error|C:\&amp;lt;server path&amp;gt;\mods\deathmatch\resources\d\script.lua:15: attempt to call global 'outputChatbox' (a nil value)}}&lt;br /&gt;
This means the called function does not exist, which can be easily explained since the functions' name is ''outputChatBox'' (with a capital ''B''):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&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;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is of course just an example, there are plenty of other messages and scenarios, but you should get the 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; shortcut in the main menu of MTA. This is a quick, easy, and temporary way of starting servers 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 independently of the client for long-term hosting.&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 of course. Most of them include outputting debug messages, with differing information depending on the situtation.&lt;br /&gt;
&lt;br /&gt;
===Useful functions===&lt;br /&gt;
First of all some functions that may come in handy for debugging.&lt;br /&gt;
* [[outputDebugString]] or [[outputChatBox]] for outputting any information&lt;br /&gt;
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] on a variable to turn it into a string, for example when it contains a boolean value&lt;br /&gt;
* [[getElementType]] to check an MTA Element for its type&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;entered if&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 variables' value can be put together as a string, even if it's a boolean value for example.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Imagine you created a colshape (collision shape) somewhere and you want a player to stay 10 seconds in it, then perform some action.&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;,getRootElement(),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;,getRootElement(),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. In the example above, this is done when storing the timer id in the table. We need to add a check if the table exists and if not create it.&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;,getRootElement(),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;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we still get 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 check the ''player'' variable that '''should''' contain 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, the other one a vehicle element. Since we only want to react when a player enters the colshape, we add an ''if'' that will end the execution of the function if it's '''not''' an player element.&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 will still output the warning mentioned above. This happens because the timer we try to kill when a player leaves the colshape will not exist anymore when it reached the 10 seconds and is executed. There are different ways to get rid of that warning (since you know that the timer might not exist anymore and you only want to kill it if it is there). One way would be to check if the timer referenced in the table really exists. To do this, we need 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 cause using a great tool that comes with MTA SA server, performancebrowser. Make sure that its started with &amp;quot;start performancebrowser&amp;quot; if it doesn't exist then get it from the default resources that come with the server. 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 -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 &amp;quot;general.HTTP&amp;quot; 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;/div&gt;</summary>
		<author><name>Warlord</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetPedAnimation&amp;diff=31353</id>
		<title>SetPedAnimation</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetPedAnimation&amp;diff=31353"/>
		<updated>2012-06-10T07:38:37Z</updated>

		<summary type="html">&lt;p&gt;Warlord: /* Example2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Server client function}}&lt;br /&gt;
&lt;br /&gt;
Sets the current animation of a player or ped.  Not specifying the type of animation will automatically cancel the current one.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool setPedAnimation ( ped thePed [, string block=nil, string anim=nil, int time=-1, bool loop=true, bool updatePosition=true, bool interruptable=true, bool freezeLastFrame = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''thePed:''' the player or ped you want to apply an animation to.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
{{OptionalArg}}&lt;br /&gt;
*'''block:''' the [[Animations|animation]] block's name.&lt;br /&gt;
*'''anim:''' the name of the [[Animations|animation]] within the block.&lt;br /&gt;
*'''time:''' how long the animation will run for in milliseconds.&lt;br /&gt;
*'''loop:''' indicates whether or not the animation will loop.&lt;br /&gt;
*'''updatePosition:''' will change the actual coordinates of the ped according to the animation. Use this for e.g. walking animations.&lt;br /&gt;
*'''interruptable:''' if set to 'false' other tasks wont be able to interupt the animation.&lt;br /&gt;
*'''freezeLastFrame:''' ... (From 1.1 onwards).&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if succesful, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
==Example1== &lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example creates a ped, rotates him, and makes him walk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function makePed()&lt;br /&gt;
   ped1 = createPed(56, 1, 1, 4)&lt;br /&gt;
   setPedRotation(ped1, 315)&lt;br /&gt;
   setPedAnimation( ped1, &amp;quot;ped&amp;quot;, &amp;quot;WOMAN_walknorm&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler(&amp;quot;makemyped&amp;quot;, makePed)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example2==&lt;br /&gt;
This example makes the player dance when he uses command /dance and stop when he uses the same command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onClientPreRender&amp;quot;,root,&lt;br /&gt;
  function ()&lt;br /&gt;
    daBlock, daAnim = getPedAnimation(getLocalPlayer())&lt;br /&gt;
    setElementData(root,&amp;quot;blockz&amp;quot;,daBlock)&lt;br /&gt;
    setElementData(root,&amp;quot;animz&amp;quot;,daAnim)&lt;br /&gt;
  end )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function dance (source)&lt;br /&gt;
	daBlockz = getElementData(root,&amp;quot;blockz&amp;quot;)&lt;br /&gt;
	daAnimz = getElementData(root,&amp;quot;animz&amp;quot;)&lt;br /&gt;
		if daBlockz == &amp;quot;dancing&amp;quot; and daAnimz == &amp;quot;dnce_m_b&amp;quot; then&lt;br /&gt;
			setPedAnimation(source,false)&lt;br /&gt;
		else&lt;br /&gt;
			setPedAnimation ( source, &amp;quot;DANCING&amp;quot;, &amp;quot;dnce_m_b&amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
addCommandHandler(&amp;quot;dance&amp;quot;,dance)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Ped_functions}}&lt;br /&gt;
[[ru:setPedAnimation]]&lt;/div&gt;</summary>
		<author><name>Warlord</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetPedAnimation&amp;diff=31352</id>
		<title>SetPedAnimation</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetPedAnimation&amp;diff=31352"/>
		<updated>2012-06-10T07:34:54Z</updated>

		<summary type="html">&lt;p&gt;Warlord: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Server client function}}&lt;br /&gt;
&lt;br /&gt;
Sets the current animation of a player or ped.  Not specifying the type of animation will automatically cancel the current one.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool setPedAnimation ( ped thePed [, string block=nil, string anim=nil, int time=-1, bool loop=true, bool updatePosition=true, bool interruptable=true, bool freezeLastFrame = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''thePed:''' the player or ped you want to apply an animation to.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
{{OptionalArg}}&lt;br /&gt;
*'''block:''' the [[Animations|animation]] block's name.&lt;br /&gt;
*'''anim:''' the name of the [[Animations|animation]] within the block.&lt;br /&gt;
*'''time:''' how long the animation will run for in milliseconds.&lt;br /&gt;
*'''loop:''' indicates whether or not the animation will loop.&lt;br /&gt;
*'''updatePosition:''' will change the actual coordinates of the ped according to the animation. Use this for e.g. walking animations.&lt;br /&gt;
*'''interruptable:''' if set to 'false' other tasks wont be able to interupt the animation.&lt;br /&gt;
*'''freezeLastFrame:''' ... (From 1.1 onwards).&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if succesful, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
==Example1== &lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example creates a ped, rotates him, and makes him walk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function makePed()&lt;br /&gt;
   ped1 = createPed(56, 1, 1, 4)&lt;br /&gt;
   setPedRotation(ped1, 315)&lt;br /&gt;
   setPedAnimation( ped1, &amp;quot;ped&amp;quot;, &amp;quot;WOMAN_walknorm&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler(&amp;quot;makemyped&amp;quot;, makePed)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example2==&lt;br /&gt;
This example makes the local player dance when he uses command /dance and stop when he uses the same command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onClientPreRender&amp;quot;,root,&lt;br /&gt;
  function ()&lt;br /&gt;
    daBlock, daAnim = getPedAnimation(getLocalPlayer())&lt;br /&gt;
    setElementData(root,&amp;quot;blockz&amp;quot;,daBlock)&lt;br /&gt;
    setElementData(root,&amp;quot;animz&amp;quot;,daAnim)&lt;br /&gt;
  end )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function dance (source)&lt;br /&gt;
	daBlockz = getElementData(root,&amp;quot;blockz&amp;quot;)&lt;br /&gt;
	daAnimz = getElementData(root,&amp;quot;animz&amp;quot;)&lt;br /&gt;
		if daBlockz == &amp;quot;dancing&amp;quot; and daAnimz == &amp;quot;dnce_m_b&amp;quot; then&lt;br /&gt;
			setPedAnimation(source,false)&lt;br /&gt;
		else&lt;br /&gt;
			setPedAnimation ( source, &amp;quot;DANCING&amp;quot;, &amp;quot;dnce_m_b&amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
addCommandHandler(&amp;quot;dance&amp;quot;,dance)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Ped_functions}}&lt;br /&gt;
[[ru:setPedAnimation]]&lt;/div&gt;</summary>
		<author><name>Warlord</name></author>
	</entry>
</feed>