https://wiki.multitheftauto.com/api.php?action=feedcontributions&user=Renkon&feedformat=atomMulti Theft Auto: Wiki - User contributions [en]2024-03-28T09:35:47ZUser contributionsMediaWiki 1.39.3https://wiki.multitheftauto.com/index.php?title=User:Renkon&diff=53208User:Renkon2017-12-27T03:47:18Z<p>Renkon: /* Who am I */</p>
<hr />
<div>==Who am I==<br />
<br />
I'm a 22 year-old boy from Argentina who fancies playing Multi Theft Auto. I started playing SA-MP back in 2007 and moved to MTA in late 2009. Since then I have never left the community (although I got registered in 2010). I'm currently active in FFS Gaming community and the forum itself.<br />
<br />
==Feedback==<br />
<br />
*Alexs_Steel approves this guy</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=DxDrawDashedLine&diff=53207DxDrawDashedLine2017-12-27T00:45:00Z<p>Renkon: /* Optional Arguments */</p>
<hr />
<div>__NOTOC__<br />
{{Useful Function}}<br />
This function lets you draw a line with dashes or dots.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
dxDrawDashedLine ( int startX, int startY, int endX, int endY, int lengthLine, [ int lengthSpace = lengthLine, int color = 0xFFFFFFFF, int width = 1, bool postGUI = false ] )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''startX:''' An integer representing the absolute start X position of the line, represented by pixels on the screen.<br />
*'''startY:''' An integer representing the absolute start Y position of the line, represented by pixels on the screen.<br />
*'''endX:''' An integer representing the absolute end X position of the line, represented by pixels on the screen.<br />
*'''endY:''' An integer representing the absolute end Y position of the line, represented by pixels on the screen.<br />
*'''lengthLine:''' An integer representing the length of each dash.<br />
<br />
===Optional Arguments=== <br />
*'''lengthSpace:''' An integer representing the length of the empty space between the dashes.<br />
*'''color:''' An integer of the hex color, produced using [[tocolor]] or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).<br />
*'''width:''' The width/thickness of the line<br />
*'''postGUI:''' A bool representing whether the line should be drawn on top of or behind any ingame GUI (rendered by CEGUI).<br />
<br />
===Returns===<br />
This function does not return anything.<br />
<br />
==Code==<br />
<section name="Client-Side Script" class="client" show="true"><br />
<syntaxhighlight lang="lua"><br />
function dxDrawDashedLine(sX, sY, eX, eY, lengthLine, lengthSpace, color, width, postGUI)<br />
lengthSpace = lengthSpace or lengthLine;<br />
color = color or tocolor(255, 255, 255, 255);<br />
width = width or 1;<br />
postGUI = postGUI or false;<br />
local length = getDistanceBetweenPoints2D(sX, sY, eX, eY);<br />
local linePartLength = lengthLine + lengthSpace;<br />
local lineParts = length / linePartLength;<br />
local xToAdd = (eX - sX) / lineParts;<br />
local yToAdd = (eY - sY) / lineParts;<br />
local lineRatio = lengthSpace / lengthLine;<br />
while (length > 0) do<br />
if (lengthLine > length) then<br />
dxDrawLine(sX, sY, eX, eY, color, width, postGUI);<br />
length = 0;<br />
else<br />
dxDrawLine(sX, sY, sX + xToAdd - xToAdd * lineRatio, sY + yToAdd - yToAdd * lineRatio, color, width, postGUI);<br />
sX = sX + xToAdd;<br />
sY = sY + yToAdd;<br />
length = length - linePartLength;<br />
end<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows how to draw an X on the screen.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
addEventHandler("onClientRender", root, function()<br />
dxDrawDashedLine(100, 100, sW - 100, sH - 100, 10, 5, tocolor(255, 255, 255, 255), 2, false);<br />
dxDrawDashedLine(100, sH - 100, sW - 100, 100, 10, 5, tocolor(255, 255, 255, 255), 2, false);<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}<br />
[[:Category:Useful_Functions]]</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=DxDrawDashedLine&diff=53206DxDrawDashedLine2017-12-27T00:38:46Z<p>Renkon: /* Example */</p>
<hr />
<div>__NOTOC__<br />
{{Useful Function}}<br />
This function lets you draw a line with dashes or dots.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
dxDrawDashedLine ( int startX, int startY, int endX, int endY, int lengthLine, [ int lengthSpace = lengthLine, int color = 0xFFFFFFFF, int width = 1, bool postGUI = false ] )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''startX:''' An integer representing the absolute start X position of the line, represented by pixels on the screen.<br />
*'''startY:''' An integer representing the absolute start Y position of the line, represented by pixels on the screen.<br />
*'''endX:''' An integer representing the absolute end X position of the line, represented by pixels on the screen.<br />
*'''endY:''' An integer representing the absolute end Y position of the line, represented by pixels on the screen.<br />
*'''lengthLine:''' An integer representing the length of each dash.<br />
<br />
===Optional Arguments=== <br />
*'''lengthSpace:''' An integer representing the length of the empty space between the dashes.<br />
*'''color:''' An integer of the hex color, produced using [[tocolor]] or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).<br />
<br />
===Returns===<br />
This function does not return anything.<br />
<br />
==Code==<br />
<section name="Client-Side Script" class="client" show="true"><br />
<syntaxhighlight lang="lua"><br />
function dxDrawDashedLine(sX, sY, eX, eY, lengthLine, lengthSpace, color, width, postGUI)<br />
lengthSpace = lengthSpace or lengthLine;<br />
color = color or tocolor(255, 255, 255, 255);<br />
width = width or 1;<br />
postGUI = postGUI or false;<br />
local length = getDistanceBetweenPoints2D(sX, sY, eX, eY);<br />
local linePartLength = lengthLine + lengthSpace;<br />
local lineParts = length / linePartLength;<br />
local xToAdd = (eX - sX) / lineParts;<br />
local yToAdd = (eY - sY) / lineParts;<br />
local lineRatio = lengthSpace / lengthLine;<br />
while (length > 0) do<br />
if (lengthLine > length) then<br />
dxDrawLine(sX, sY, eX, eY, color, width, postGUI);<br />
length = 0;<br />
else<br />
dxDrawLine(sX, sY, sX + xToAdd - xToAdd * lineRatio, sY + yToAdd - yToAdd * lineRatio, color, width, postGUI);<br />
sX = sX + xToAdd;<br />
sY = sY + yToAdd;<br />
length = length - linePartLength;<br />
end<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows how to draw an X on the screen.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
addEventHandler("onClientRender", root, function()<br />
dxDrawDashedLine(100, 100, sW - 100, sH - 100, 10, 5, tocolor(255, 255, 255, 255), 2, false);<br />
dxDrawDashedLine(100, sH - 100, sW - 100, 100, 10, 5, tocolor(255, 255, 255, 255), 2, false);<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}<br />
[[:Category:Useful_Functions]]</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=DxDrawDashedLine&diff=53205DxDrawDashedLine2017-12-27T00:36:39Z<p>Renkon: Created page with "__NOTOC__ {{Useful Function}} This function lets you draw a line with dashes or dots. ==Syntax== <syntaxhighlight lang="lua"> dxDrawDashedLine ( int startX, int startY, int..."</p>
<hr />
<div>__NOTOC__<br />
{{Useful Function}}<br />
This function lets you draw a line with dashes or dots.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
dxDrawDashedLine ( int startX, int startY, int endX, int endY, int lengthLine, [ int lengthSpace = lengthLine, int color = 0xFFFFFFFF, int width = 1, bool postGUI = false ] )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''startX:''' An integer representing the absolute start X position of the line, represented by pixels on the screen.<br />
*'''startY:''' An integer representing the absolute start Y position of the line, represented by pixels on the screen.<br />
*'''endX:''' An integer representing the absolute end X position of the line, represented by pixels on the screen.<br />
*'''endY:''' An integer representing the absolute end Y position of the line, represented by pixels on the screen.<br />
*'''lengthLine:''' An integer representing the length of each dash.<br />
<br />
===Optional Arguments=== <br />
*'''lengthSpace:''' An integer representing the length of the empty space between the dashes.<br />
*'''color:''' An integer of the hex color, produced using [[tocolor]] or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).<br />
<br />
===Returns===<br />
This function does not return anything.<br />
<br />
==Code==<br />
<section name="Client-Side Script" class="client" show="true"><br />
<syntaxhighlight lang="lua"><br />
function dxDrawDashedLine(sX, sY, eX, eY, lengthLine, lengthSpace, color, width, postGUI)<br />
lengthSpace = lengthSpace or lengthLine;<br />
color = color or tocolor(255, 255, 255, 255);<br />
width = width or 1;<br />
postGUI = postGUI or false;<br />
local length = getDistanceBetweenPoints2D(sX, sY, eX, eY);<br />
local linePartLength = lengthLine + lengthSpace;<br />
local lineParts = length / linePartLength;<br />
local xToAdd = (eX - sX) / lineParts;<br />
local yToAdd = (eY - sY) / lineParts;<br />
local lineRatio = lengthSpace / lengthLine;<br />
while (length > 0) do<br />
if (lengthLine > length) then<br />
dxDrawLine(sX, sY, eX, eY, color, width, postGUI);<br />
length = 0;<br />
else<br />
dxDrawLine(sX, sY, sX + xToAdd - xToAdd * lineRatio, sY + yToAdd - yToAdd * lineRatio, color, width, postGUI);<br />
sX = sX + xToAdd;<br />
sY = sY + yToAdd;<br />
length = length - linePartLength;<br />
end<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows how to draw an X on the screen.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
addEventHandler("onClientRender", root, function()<br />
dxDrawDashedLine(100, 100, sW - 100, sH - 100, 10, 5, tocolor(255, 255, 255, 255), 2, false);<br />
dxDrawDashedLine(100, sW - 100, sH - 100, 100, 10, 5, tocolor(255, 255, 255, 255), 2, false);<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}<br />
[[:Category:Useful_Functions]]</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=Template:Useful_Functions&diff=53204Template:Useful Functions2017-12-27T00:24:30Z<p>Renkon: added dxDrawDashedLine</p>
<hr />
<div>=== ACL functions ===<br />
*[[aclGroupClone]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function clone a group to another group with/without ACLs and/or objects.</span><br />
*[[getPlayerAcls]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of all ACL groups on a player.</span><br />
*[[isPlayerInACL]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a player element is in an ACL group.</span><br />
*[[renameAclGroup]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gives an existing ACL group a new name.</span><br />
<br />
=== Account functions ===<br />
*[[setAccountName]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function is used to change an existing account's name.</span><br />
*[[removeAccountData]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function is used to remove data from account .</span><br />
<br />
=== Camera functions ===<br />
*[[smoothMoveCamera]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to create a cinematic camera flight.<br />
<br />
=== Cursor functions ===<br />
*[[getCursorMoveOn]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks in which way the cursor is currently moving.</span><br />
*[[getCursorMovedOn]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks in which way the cursor is currently moving.</span><br />
<br />
=== Drawing functions ===<br />
*[[dxDrawAnimWindow]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws an animated 2D window on the screen.</span><br />
*[[dxDrawCircle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a number of 2D lines in order to achieve a circle shape on the screen.</span><br />
*[[dxDrawDashedLine]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a line with dashes.</span><br />
*[[dxDrawOctagon3D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function creates a 3D Octagon</span><br />
*[[dxDrawTriangle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This is a function that will create a triangle with dx lines.</span><br />
*[[dxDrawLinedRectangle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This is a function that will create a rectangle outline with dx lines.</span><br />
*[[dxDrawBorderedRectangle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This is a function that will create a bordered rectangle .</span><br />
*[[dxDrawGifImage]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function simulates the effect of a GIF image by using image sprites in 2D.</span><br />
*[[dxDrawImage3D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a 3D image in GTA world.</span><br />
*[[dxDrawImageOnElement]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws an image on any element.</span><br />
*[[dxDrawLoading]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a loading bar on the screen.</span><br />
*[[dxDrawProgressBar]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function simulates a progress bar drawed using DirectDraw.</span><br />
*[[dxDrawRectangle3D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a 3D rectangle in GTA world.</span><br />
*[[dxDrawTextOnElement]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a text on any element.</span><br />
*[[dxGetFontSizeFromHeight]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function calculates the font size from given height.</span><br />
*[[dxGetRealFontHeight]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function calculates the height of a font.</span><br />
<br />
=== Effects functions ===<br />
*[[attachEffect]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you attach an effect to an element.</span><br />
<br />
=== Elements functions === <br />
*[[getElementSpeed]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the specified element's speed in m/s, km/h or mph.</span><br />
*[[getElementsInDimension]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of elements that are in the specified dimension.</span><br />
*[[getElementsWithinMarker]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of elements that are within a marker's collision shape.</span><br />
*[[isElementInPhotograph]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if an element is in the player's camera picture area.</span><br />
*[[isElementInRange]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to check if an element's range to a main point is within the maximum range.</span><br />
*[[isElementMoving]]<span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if an element is moving.</span><br />
*[[isElementWithinAColShape]]<span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if an element is within a collision shape element.</span><br />
*[[multi_check]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks one element to many, handy and clean.</span><br />
*[[setElementSpeed]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to set the speed of an element in kph or mph units.</span><br />
<br />
=== Events ===<br />
*[[onVehicleWeaponFire]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This code implements an event that is triggered when a player in a vehicle fires a vehicle's weapon.</span><br />
<br />
=== Input functions ===<br />
*[[bindControlKeys]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to bind each key bound to a control individually. Doing this bypasses a little MTA restriction.</span><br />
*[[getBoundControls]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of control names that are bound to the specified key.</span><br />
*[[unbindControlKeys]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to unbind each key bound to a control individually. Use this function with [[bindControlKeys]].</span><br />
<br />
=== Data functions === <br />
*[[Byte2human]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts an integer (number of bytes) into a human-readable unit.</span><br />
*[[capitalize]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function capitalizes a given string.</span><br />
*[[convertNumber]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts and formats large numbers.</span><br />
*[[convertServerTickToTimeStamp]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts server ticks to a unix timestamp.</span><br />
*[[convertTextToSpeech]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts the provided text to a speech in the provided language which players can hear.</span><br />
*[[findRotation]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function takes two points and returns the direction from point A to point B.</span><br />
*[[FormatDate]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function formats a date on the basis of a format string and returns it.</span><br />
*[[getRealMonthM]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gives you the real months name</span><br />
*[[getRealMonthH]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function convert english months to arabic months</span><br />
*[[generateString]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function generates a random string with any characters.</span><br />
*[[generateRandomASCIIString]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a random string which uses ASCII characters. </span><br />
*[[getAge]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function calculates the age of a given birthday.</span><br />
*[[getDistanceBetweenPointAndSegment2D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function takes point coordinates and line (a segment) starting and ending coordinates. It returns the shortest distance between the point and the line.</span><br />
*[[getEasterDate]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns easter date monthday and month for a given year.</span><br />
*[[getKeyFromValueInTable]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the key of the specified value in a table.</span><br />
*[[getOffsetFromXYZ]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to take an entity and a position and calculate the relative offset between them accounting for rotations.</span><br />
*[[getPointFromDistanceRotation]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function finds a point based on a starting point, direction and distance.</span><br />
*[[getRGColorFromPercentage]] <span style="color:gray; font-family:'Georgia', sans-serif; font-size:smaller;">»This function returns two integers representing red and green colors according to the specified percentage.</span><br />
*[[getScreenRotationFromWorldPosition]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a screen relative rotation to a world position.</span><br />
*[[getTimestamp]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the UNIX timestamp of a specified date and time.</span><br />
*[[isLeapYear]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a boolean representing if a given year is a leap year.</span><br />
*[[isValidMail]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether a provided e-mail string is valid.</span><br />
*[[removeHex]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function is used to remove hexadecimal numbers (colors, for example) from strings.<br />
*[[RGBToHex]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a string representing the color in hexadecimal.</span><br />
*[[toHex]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a decimal number to a hexadecimal number, as a fix to be used client-side.</span><br />
*[[secondsToTimeDesc]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a plain seconds-integer into a user-friendly time description.</span><br />
*[[string.count]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function counts the amount of occurences of a string in a string.</span><br />
*[[string.explode]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function splits a string at a given separator pattern and returns a table with the pieces.</span><br />
*[[switch]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows the value of a variable or expression to control the flow of program execution via a multiway branch.</span><br />
*[[var dump]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function outputs information about one or more variables using outputConsole.</span><br />
*[[wavelengthToRGBA]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a physical wavelength of light to a RGBA color.</span><br />
<br />
=== GUI functions === <br />
*[[centerWindow]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function centers a CEGUI window element responsively in any resolution.</span><br />
=====Comboboxes=====<br />
*[[guiComboBoxAdjustHeight]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function adjusts a CEGUI combobox element to have the correct height.</span><br />
=====Gridlists=====<br />
*[[getGridListRowIndexFromText]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the GridList row index from the specified text.</span><br />
*[[guiGridListGetSelectedText]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a string containing the inner text of a selected gridlist item.</span><br />
*[[guiGridListAddPlayers]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function add all online players to a grid list.</span><br />
*[[isTextInGridList]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if some text exist or not in the GridList.</span><br />
<br />
=== Math functions ===<br />
*[[mathNumber]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function is a workaround for the client-side floating-point precision of 24-bits.</span><br />
*[[math.hypot]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the Hypotenuse of the triangle given by sides x and y.</span><br />
*[[math.percent]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a percentage from two number values.</span><br />
*[[math.round]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Rounds a number whereas the number of decimals to keep and the method may be set.</span><br />
*[[reMap]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Re-maps a number from one range to another.</span><br />
<br />
=== Ped functions ===<br />
*[[getAlivePlayers (Client)|getAlivePlayers]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the alive players client-side.</span><br />
*[[getAlivePlayersInTeam]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the alive players in a team.</span><br />
*[[getOnlineAdmins]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of all logged-in administrators.</span><br />
*[[getPedMaxHealth]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a pedestrians's maximum health by converting it from their maximum health stat.</span><br />
*[[getPedMaxOxygenLevel]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a ped's maximum oxygen level by converting it from their maximum underwater stamina stat.</span><br />
*[[getPlayerFromNamePart]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a player from partial name.</span><br />
*[[getPlayerFromSerial]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a player from their serial.</span><br />
*[[getPlayersInGroup]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns all Players In Group .</span><br />
*[[getGuestPlayers]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets a players not login or players Guest .</span><br />
*[[getPlayersByData]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of players that have the specified data name.</span><br />
*[[getPlayersInPhotograph]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of all players in photograph.</span><br />
*[[isPedAiming]]<span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a pedestrian is aiming their weapon.</span><br />
*[[isPedDrivingVehicle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a specified pedestrian is driving a vehicle.</span><br />
*[[isPlayerInTeam]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a player is in a specified team.</span><br />
*[[isPedAimingNearPed]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This is similar to isPedAiming but uses a colshape to be more precise.</span><br />
*[[getPedEyesPosition]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to get peds eyes position.</span><br />
<br />
=== Resource functions ===<br />
*[[getResourceSettings]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the resource settings.</span><br />
*[[getResourceScripts]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the resource scripts.</span><br />
*[[refreshResource]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function refreshes your resource if you changed any of the files<br />
<br />
=== Sound functions ===<br />
*[[isSoundFinished]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a sound element has finished.</span><br />
*[[stopSoundSlowly]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function stop your sound element slowly.</span><br />
<br />
=== Table functions ===<br />
*[[rangeToTable]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a string range to a table containing number values.</span><br />
*[[setTableProtected]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function protects a table and makes it read-only.</span><br />
*[[table.copy]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function copies a whole table and all the tables in that table.</span><br />
*[[table.compare]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether two given tables are equal.</span><br />
*[[table.empty]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether a table is empty.</span><br />
*[[table.map]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function goes through a table and replaces every field with the return of the passed function, where the field's value is passed as first argument and optionally more arguments.</span><br />
*[[table.merge]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function merges two or more tables together.</span><br />
*[[table.random]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function retrieves a random value from a table.</span><br />
*[[table.size]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the absolute size of a table.</span><br />
*[[table.removeValue]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function removes a specified value from a table.</span><br />
*[[Sort_Functions]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» These functions are able to sort your tables by a key.</span><br />
<br />
=== Team functions ===<br />
*[[getTeamFromColor]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a team element by the specified color.</span><br />
*[[getTeamWithFewestPlayers]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a team element with least players of all the specified teams.</span><br />
<br />
=== Vehicle funcions === <br />
*[[getRandomVehicle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets a random vehicle.</span><br />
*[[getValidVehicleModels]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of all valid vehicle models.</span><br />
*[[getVehicleRespawnPosition]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to get the respawn position of a vehicle.</span><br />
*[[getVehiclesCountByType]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the amount of vehicles by the given type as an integer value.</span><br />
*[[isVehicleEmpty]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether a vehicle is empty.</span><br />
*[[getNearestVehicle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets the nearest vehicle to the specified player in a specified distance.</span><br />
*[[isVehicleOccupied]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a specified vehicle is occupied.</span><br />
*[[isVehicleMovingBackwards]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a specified vehicle is moving backwards.</span><br />
*[[isVehicleOnRoof]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether vehicle is on roof.</span><br />
*[[setVehicleGravityPoint]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function sets a vehicle's gravity in the direction of a 3 dimensional coordinate with the strength specified.</span><br />
<br />
=== Weapon functions === <br />
*[[getJetpackWeaponsEnabled]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of enabled weapons usable on a jetpack.</span><br />
<br />
=== XML functions ===<br />
*[[getXMLNodes]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns all children of a XML node.</span><br />
<br />
=== Utility ===<br />
*[[Check]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if its arguments are of the right type and calls the error-function if one is not.</span><br />
*[[coroutine.resume]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function applies a fix for hidden coroutine error messages.</span><br />
*[[callClientFunction]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to call any client-side function from the server's side.</span><br />
*[[callServerFunction]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to call any server-side function from the client's side.</span><br />
*[[animate]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to use interpolateBetween without render event and easily used.</span><br />
*[[getBanFromName]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This functions returns the ban of the given playername.</span><br />
*[[getCurrentFPS]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the frames per second at which GTA: SA is running.</span><br />
*[[IfElse]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns one of two values based on a boolean expression.</span><br />
*[[isCursorOnElement]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether the cursor is in a particular area.</span><br />
*[[isMouseInCircle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a cursor position is in circular area or not.</span><br />
*[[isMouseInPosition]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to check whether the mouse cursor/pointer is within a rectangular position.</span><br />
*[[iterElements]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns ''a time-saving'' iterator for your for-loops.</span><br />
*[[vector3:compare]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This method checks whether two vectors match, with optional precision.</span><br />
*[[thisCommandHandlersExist]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This method checks a string if this exist as command Handlers</span><br />
<br />
[[Category:Useful Functions]]</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=Template:Useful_Functions&diff=50537Template:Useful Functions2017-03-08T23:23:24Z<p>Renkon: /* Data functions */</p>
<hr />
<div>=== ACL functions ===<br />
*[[aclGroupClone]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function clone a group to another group with/without ACLs and/or objects.</span><br />
*[[getPlayerAcls]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of all ACL groups on a player.</span><br />
*[[isPlayerInACL]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a player element is in an ACL group.</span><br />
*[[renameAclGroup]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gives an existing ACL group a new name.</span><br />
<br />
=== Account functions ===<br />
*[[setAccountName]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function is used to change an existing account's name.</span><br />
*[[removeAccountData]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function is used to remove data from account .</span><br />
<br />
=== Camera functions ===<br />
*[[smoothMoveCamera]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to create a cinematic camera flight.<br />
<br />
=== Cursor functions ===<br />
*[[getCursorMoveOn]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks in which way the cursor is currently moving.</span><br />
<br />
=== Drawing functions ===<br />
*[[dxDrawAnimWindow]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws an animated 2D window on the screen.</span><br />
*[[dxDrawCircle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a number of 2D lines in order to achieve a circle shape on the screen.</span><br />
*[[dxDrawOctagon3D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function creates a 3D Octagon</span><br />
*[[dxDrawTriangle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This is a function that will create a triangle with dx lines.</span><br />
*[[dxDrawLinedRectangle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This is a function that will create a rectangle outline with dx lines.</span><br />
*[[dxDrawBorderedRectangle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This is a function that will create a bordered rectangle .</span><br />
*[[dxDrawGifImage]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function simulates the effect of a GIF image by using image sprites in 2D.</span><br />
*[[dxDrawImage3D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a 3D image in GTA world.</span><br />
*[[dxDrawImageOnElement]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws an image on any element.</span><br />
*[[dxDrawLoading]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a loading bar on the screen.</span><br />
*[[dxDrawProgressBar]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function simulates a progress bar drawed using DirectDraw.</span><br />
*[[dxDrawRectangle3D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a 3D rectangle in GTA world.</span><br />
*[[dxDrawTextOnElement]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a text on any element.</span><br />
*[[dxGetFontSizeFromHeight]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function calculates the font size from given height.</span><br />
*[[dxGetRealFontHeight]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function calculates the height of a font.</span><br />
<br />
=== Effects functions ===<br />
*[[attachEffect]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you attach an effect to an element.</span><br />
<br />
=== Elements functions === <br />
*[[getElementSpeed]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the specified element's speed in m/s, km/h or mph.</span><br />
*[[getElementsInDimension]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of elements that are in the specified dimension.</span><br />
*[[getElementsWithinMarker]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of elements that are within a marker's collision shape.</span><br />
*[[isElementInPhotograph]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if an element is in the player's camera picture area.</span><br />
*[[isElementInRange]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to check if an element's range to a main point is within the maximum range.</span><br />
*[[isElementMoving]]<span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if an element is moving.</span><br />
*[[isElementWithinAColShape]]<span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if an element is within a collision shape element.</span><br />
*[[multi_check]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks one element to many, handy and clean.</span><br />
*[[setElementSpeed]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to set the speed of an element in kph or mph units.</span><br />
<br />
=== Events ===<br />
*[[onVehicleWeaponFire]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This code implements an event that is triggered when a player in a vehicle fires a vehicle's weapon.</span><br />
<br />
=== Input functions ===<br />
*[[bindControlKeys]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to bind each key bound to a control individually. Doing this bypasses a little MTA restriction.</span><br />
*[[getBoundControls]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of control names that are bound to the specified key.</span><br />
*[[unbindControlKeys]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to unbind each key bound to a control individually. Use this function with [[bindControlKeys]].</span><br />
<br />
=== Data functions === <br />
*[[Byte2human]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts an integer (number of bytes) into a human-readable unit.</span><br />
*[[capitalize]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function capitalizes a given string.</span><br />
*[[convertNumber]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts and formats large numbers.</span><br />
*[[convertServerTickToTimeStamp]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts server ticks to a unix timestamp.</span><br />
*[[convertTextToSpeech]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts the provided text to a speech in the provided language which players can hear.</span><br />
*[[findRotation]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function takes two points and returns the direction from point A to point B.</span><br />
*[[FormatDate]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function formats a date on the basis of a format string and returns it.</span><br />
*[[getRealMonthM]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gives you the real months name</span><br />
*[[getRealMonthH]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function convert english months to arabic months</span><br />
*[[generateString]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function generates a random string with any characters.</span><br />
*[[generateRandomASCIIString]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a random string which uses ASCII characters. </span><br />
*[[getAge]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function calculates the age of a given birthday.</span><br />
*[[getDistanceBetweenPointAndSegment2D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function takes point coordinates and line (a segment) starting and ending coordinates. It returns the shortest distance between the point and the line.</span><br />
*[[getEasterDate]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns easter date monthday and month for a given year.</span><br />
*[[getKeyFromValueInTable]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the key of the specified value in a table.</span><br />
*[[getOffsetFromXYZ]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to take an entity and a position and calculate the relative offset between them accounting for rotations.</span><br />
*[[getPointFromDistanceRotation]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function finds a point based on a starting point, direction and distance.</span><br />
*[[getRGColorFromPercentage]] <span style="color:gray; font-family:'Georgia', sans-serif; font-size:smaller;">»This function returns two integers representing red and green colors according to the specified percentage.</span><br />
*[[getScreenRotationFromWorldPosition]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a screen relative rotation to a world position.</span><br />
*[[getTimestamp]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the UNIX timestamp of a specified date and time.</span><br />
*[[isLeapYear]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a boolean representing if a given year is a leap year.</span><br />
*[[isValidMail]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether a provided e-mail string is valid.</span><br />
*[[removeHex]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function is used to remove hex color codes from strings.<br />
*[[RGBToHex]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a string representing the color in hexadecimal.</span><br />
*[[toHex]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a decimal number to a hexadecimal number, as a fix to be used client-side.</span><br />
*[[secondsToTimeDesc]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a plain seconds-integer into a user-friendly time description.</span><br />
*[[string.count]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function counts the amount of occurences of a string in a string.</span><br />
*[[string.explode]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function splits a string at a given separator pattern and returns a table with the pieces.</span><br />
*[[switch]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows the value of a variable or expression to control the flow of program execution via a multiway branch.</span><br />
*[[var dump]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function outputs information about one or more variables using outputConsole.</span><br />
*[[wavelengthToRGBA]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a physical wavelength of light to a RGBA color.</span><br />
<br />
=== GUI functions === <br />
*[[centerWindow]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function centers a CEGUI window element responsively in any resolution.</span><br />
=====Comboboxes=====<br />
*[[guiComboBoxAdjustHeight]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function adjusts a CEGUI combobox element to have the correct height.</span><br />
=====Gridlists=====<br />
*[[getGridListRowIndexFromText]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the GridList row index from the specified text.</span><br />
*[[guiGridListGetSelectedText]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a string containing the inner text of a selected gridlist item.</span><br />
*[[guiGridListAddPlayers]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function add all online players to a grid list.</span><br />
*[[isTextInGridList]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if some text exist or not in the GridList.</span><br />
<br />
=== Math functions ===<br />
*[[mathNumber]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function is a workaround for the client-side floating-point precision of 24-bits.</span><br />
*[[math.hypot]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the Hypotenuse of the triangle given by sides x and y.</span><br />
*[[math.percent]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a percentage from two number values.</span><br />
*[[math.round]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Rounds a number whereas the number of decimals to keep and the method may be set.</span><br />
<br />
=== Ped functions ===<br />
*[[getAlivePlayers (Client)|getAlivePlayers]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the alive players client-side.</span><br />
*[[getAlivePlayersInTeam]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the alive players in a team.</span><br />
*[[getOnlineAdmins]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of all logged-in administrators.</span><br />
*[[getPedMaxHealth]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a pedestrians's maximum health by converting it from their maximum health stat.</span><br />
*[[getPedMaxOxygenLevel]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a ped's maximum oxygen level by converting it from their maximum underwater stamina stat.</span><br />
*[[getPlayerFromNamePart]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a player from partial name.</span><br />
*[[getPlayerFromSerial]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a player from their serial.</span><br />
*[[getPlayersInGroup]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns all Players In Group .</span><br />
*[[getGuestPlayers]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets a players not login or players Guest .</span><br />
*[[getDimensionEmpty]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns id Dimension Empty .</span><br />
*[[getPlayersByData]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of players that have the specified data name.</span><br />
*[[getPlayersInPhotograph]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of all players in photograph.</span><br />
*[[isPedAiming]]<span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a pedestrian is aiming their weapon.</span><br />
*[[isPedDrivingVehicle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a specified pedestrian is driving a vehicle.</span><br />
*[[isPlayerInTeam]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a player is in a specified team.</span><br />
*[[isPedAimingNearPed]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This is similar to isPedAiming but uses a colshape to be more precise.</span><br />
*[[getPedEyesPosition]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to get peds eyes position.</span><br />
<br />
=== Resource functions ===<br />
*[[getResourceSettings]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the resource settings.</span><br />
*[[getResourceScripts]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the resource scripts.</span><br />
*[[refreshResource]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function refreshes your resource if you changed any of the files<br />
<br />
=== Sound functions ===<br />
*[[isSoundFinished]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a sound element has finished.</span><br />
*[[stopSoundSlowly]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function stop your sound element slowly.</span><br />
<br />
=== Table functions ===<br />
*[[rangeToTable]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a string range to a table containing number values.</span><br />
*[[setTableProtected]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function protects a table and makes it read-only.</span><br />
*[[table.copy]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function copies a whole table and all the tables in that table.</span><br />
*[[table.compare]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether two given tables are equal.</span><br />
*[[table.empty]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether a table is empty.</span><br />
*[[table.map]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function goes through a table and replaces every field with the return of the passed function, where the field's value is passed as first argument and optionally more arguments.</span><br />
*[[table.merge]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function merges two or more tables together.</span><br />
*[[table.random]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function retrieves a random value from a table.</span><br />
*[[table.size]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the absolute size of a table.</span><br />
*[[table.removeValue]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function removes a specified value from a table.</span><br />
<br />
=== Team functions ===<br />
*[[getTeamFromColor]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a team element by the specified color.</span><br />
*[[getTeamWithFewestPlayers]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a team element with least players of all the specified teams.</span><br />
<br />
=== Vehicle funcions === <br />
*[[getRandomVehicle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets a random vehicle.</span><br />
*[[getValidVehicleModels]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of all valid vehicle models.</span><br />
*[[getVehicleRespawnPosition]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to get the respawn position of a vehicle.</span><br />
*[[getVehiclesCountByType]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the amount of vehicles by the given type as an integer value.</span><br />
*[[isVehicleEmpty]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether a vehicle is empty.</span><br />
*[[isVehicleOccupied]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a specified vehicle is occupied.</span><br />
*[[isVehicleOnRoof]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether vehicle is on roof.</span><br />
*[[setVehicleGravityPoint]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function sets a vehicle's gravity in the direction of a 3 dimensional coordinate with the strength specified.</span><br />
<br />
=== Weapon functions === <br />
*[[getJetpackWeaponsEnabled]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of enabled weapons usable on a jetpack.</span><br />
<br />
=== XML functions ===<br />
*[[getXMLNodes]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns all children of a XML node.</span><br />
<br />
=== Utility ===<br />
*[[Check]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if its arguments are of the right type and calls the error-function if one is not.</span><br />
*[[coroutine.resume]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function applies a fix for hidden coroutine error messages.</span><br />
*[[callClientFunction]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to call any client-side function from the server's side.</span><br />
*[[callServerFunction]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to call any server-side function from the client's side.</span><br />
*[[createAnimation]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to use interpolateBetween without render event and easily used.</span><br />
*[[getBanFromName]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This functions returns the ban of the given playername.</span><br />
*[[getCurrentFPS]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns the frames per second at which GTA: SA is running.</span><br />
*[[IfElse]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns one of two values based on a boolean expression.</span><br />
*[[isCursorOnElement]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether the cursor is in a particular area.</span><br />
*[[isMouseInCircle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a cursor position is in circular area or not.</span><br />
*[[isMouseInPosition]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to check whether the mouse cursor/pointer is within a rectangular position.</span><br />
*[[iterElements]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns ''a time-saving'' iterator for your for-loops.</span><br />
*[[vector3:compare]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This method checks whether two vectors match, with optional precision.</span><br />
<br />
[[Category:Useful Functions]]</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=Byte2human&diff=50536Byte2human2017-03-08T23:21:27Z<p>Renkon: Created page with "__NOTOC__ {{Useful Function}} This function lets you transform a number of bytes into a human readable unit. ==Syntax== <syntaxhighlight lang="lua"> string byte2human ( int..."</p>
<hr />
<div>__NOTOC__<br />
{{Useful Function}}<br />
This function lets you transform a number of bytes into a human readable unit.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
string byte2human ( int bytes )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''bytes:''' The value which you want to get the human readable version.<br />
<br />
===Returns===<br />
Returns a string which shows the number transformed into a human-friendly string.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function byte2human(bytes, si)<br />
local threshold = si and 1000 or 1024<br />
if (math.abs(bytes) < threshold) then<br />
return bytes .. " B"<br />
end<br />
local units = <br />
si and {"kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}<br />
or {"KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}<br />
local unitIndex = 0<br />
repeat<br />
bytes = bytes / threshold<br />
unitIndex = unitIndex + 1<br />
until not (math.abs(bytes) >= threshold and unitIndex < #units)<br />
return math.simpleround(bytes, 2) .. " " .. units[unitIndex]<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
(based on http://stackoverflow.com/a/14919494/2980812)<br />
<br />
==See Also==<br />
{{Useful_Functions}}<br />
[[:Category:Useful_Functions]]</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=User:Renkon&diff=50535User:Renkon2017-03-08T23:17:55Z<p>Renkon: </p>
<hr />
<div>==Who am I==<br />
<br />
I'm a 21 year-old boy from Argentina who fancies playing Multi Theft Auto. I started playing SA-MP back in 2007 and moved to MTA in late 2009. Since then I have never left the community (although I got registered in 2010). I'm currently active in FFS Gaming community and the forum itself.<br />
<br />
==Feedback==<br />
<br />
*Alexs_Steel approves this guy</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=Table.empty&diff=50347Table.empty2017-01-18T04:03:46Z<p>Renkon: fixed how to check if its empty.. since current state would show {[false] = 0} as empty</p>
<hr />
<div>{{Useful Function}}<br />
<lowercasetitle></lowercasetitle><br />
__NOTOC__<br />
This function check is empty table or not.<br />
==Syntax==<br />
<syntaxhighlight lang="lua">boolean table.empty( table a )</syntaxhighlight><br />
<br />
===Required Arguments===<br />
* '''a''': The table for check.<br />
<br />
===Returns===<br />
Returns the true if table is empty or false in otherwise. <br />
<br />
<section name="Code" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function table.empty( a )<br />
if type( a ) ~= "table" then<br />
return false<br />
end<br />
<br />
return next(a) == nil<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
<section name="Example" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
print( 'empty = ' .. tostring( table.empty( { [0] = 1 } ) ) ) -- false<br />
print( 'empty = ' .. tostring( table.empty( { [10] = 10, [2] = 2 } ) ) ) -- false<br />
print( 'empty = ' .. tostring( table.empty( { } ) ) ) -- true<br />
</syntaxhighlight><br />
</section><br />
<br />
Author: Kenix & Renkon<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=Installing_and_Running_MTASA_Server_on_GNU_Linux&diff=49755Installing and Running MTASA Server on GNU Linux2016-11-03T23:29:21Z<p>Renkon: </p>
<hr />
<div>== Installation 64 bit ==<br />
<br />
=== Main binary ===<br />
Download the latest stable 64 bit Linux binaries:<br />
rm -f multitheftauto_linux_x64-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/multitheftauto_linux_x64-{{Current Version|full}}.tar.gz<br />
<br />
Unpack into a directory:<br />
tar -xf multitheftauto_linux_x64-{{Current Version|full}}.tar.gz<br />
<br />
=== Default config ===<br />
Download the default config files:<br />
rm -f baseconfig-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/baseconfig-{{Current Version|full}}.tar.gz<br />
<br />
Unpack and move into the deathmatch directory:<br/><br />
('''''Note:''' Only do this for new installations as it will overwrite any existing config files.)''<br />
tar -xf baseconfig-{{Current Version|full}}.tar.gz<br />
mv baseconfig/* multitheftauto_linux_x64-{{Current Version|full}}/mods/deathmatch<br />
<br />
Change to the MTA server install directory:<br />
cd multitheftauto_linux_x64-{{Current Version|full}}<br />
<br />
=== Test ===<br />
You can now test if the server will start correctly:<br />
./mta-server64<br />
<br />
=== Default resources ===<br />
If you need the default resources:<br />
Download the latest default resources zip from http://mirror.mtasa.com/mtasa/resources/<br />
and unzip into '''mods/deathmatch/resources'''<br />
<br/><br />
'''Make sure you are in the MTA server install directory when following this example:'''<br />
apt-get install unzip<br />
mkdir mods/deathmatch/resources<br />
cd mods/deathmatch/resources<br />
rm -f mtasa-resources-latest.zip<br />
wget <nowiki>http</nowiki>://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip<br />
unzip mtasa-resources-latest.zip<br />
rm -f mtasa-resources-latest.zip<br />
cd ../../..<br />
<br />
<br />
== Installation 32 bit ==<br />
<br />
=== Main binary===<br />
Download the latest stable 32 bit Linux binaries:<br />
rm -f multitheftauto_linux-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/multitheftauto_linux-{{Current Version|full}}.tar.gz<br />
<br />
Unpack into a directory:<br />
tar -xf multitheftauto_linux-{{Current Version|full}}.tar.gz<br />
<br />
=== Default config ===<br />
Download the default config files:<br />
rm -f baseconfig-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/baseconfig-{{Current Version|full}}.tar.gz<br />
<br />
Unpack and move into the deathmatch directory:<br/><br />
('''''Note:''' Only do this for new installations as it will overwrite any existing config files.)''<br />
tar -xf baseconfig-{{Current Version|full}}.tar.gz<br />
mv baseconfig/* multitheftauto_linux-{{Current Version|full}}/mods/deathmatch<br />
<br />
Change to the MTA server install directory:<br />
cd multitheftauto_linux-{{Current Version|full}}<br />
<br />
=== Test ===<br />
You can now test if the server will start correctly:<br />
./mta-server<br />
<br />
=== Default resources ===<br />
If you need the default resources:<br />
Download the latest default resources zip from http://mirror.mtasa.com/mtasa/resources/<br />
and unzip into '''mods/deathmatch/resources'''<br />
<br/><br />
'''Make sure you are in the MTA server install directory when following this example:'''<br />
apt-get install unzip<br />
mkdir mods/deathmatch/resources<br />
cd mods/deathmatch/resources<br />
rm -f mtasa-resources-latest.zip<br />
wget <nowiki>http</nowiki>://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip<br />
unzip mtasa-resources-latest.zip<br />
rm -f mtasa-resources-latest.zip<br />
cd ../../..<br />
<br />
<br />
<br />
== Running with 32 or 64 bit Linux==<br />
=== Make sure your server libraries and stuff are up to date ===<br />
On Debian/Ubuntu this is done with:<br />
apt-get update<br />
apt-get upgrade<br />
<br />
===Troubleshooting===<br />
* If you get a problem with such as "libreadline.so.5: cannot open shared object file: No such file or directory.", it can be solved on 32 bit Debian/Ubuntu by doing this:<br />
<br />
apt-get install libreadline5<br />
<br />
* If you get a problem with such as "libncursesw.so.5 cannot open shared object file: No such file or directory", it can be solved on 32 bit Debian/Ubuntu by doing this:<br />
<br />
apt-get install libncursesw5<br />
<br />
'''Note:''' If you experience this issue on a 64-bit machine while trying to run the 32-bit MTA server, then you should install the following package on a 64-bit Debian/Ubuntu machine (as root):<br />
<br />
apt-get install lib32ncursesw5<br />
<br />
You can find more 32-bit library alternatives on this page: [http://www.debian.org/distrib/packages#search_contents www.debian.org/distrib/packages#search_contents].<br />
<br />
== MySQL Troubleshooting==<br />
* If you are using the inbuilt MySQL functions such as [[dbConnect]] and [[dbQuery]], you will need to have '''libmysqlclient.so.16''' installed.<br />
* If you get a problem with such as "libmysqlclient.so.16: cannot open shared object file: No such file or directory", it can be solved on Debian/Ubuntu by doing this:<br />
<br />
apt-get install libmysqlclient16<br />
<br />
If that fails:<br />
* For 32 bit Linux, download [http://nightly.mtasa.com/files/modules/32/libmysqlclient.so.16 32 bit libmysqlclient.so.16] and put it in '''/usr/lib/'''<br />
* For 64 bit Linux, download [http://nightly.mtasa.com/files/modules/64/libmysqlclient.so.16 64 bit libmysqlclient.so.16] and put it in '''/usr/lib/'''<br />
<br />
==[Optional] Installing and Configuring an External Web Server==<br />
Instructions on how to install and configure Nginx as an external web server for MTA is here: [[Installing and Configuring Nginx as an External Web Server]]<br />
<br />
== Server crashes ==<br />
<br />
If your Linux server crashes, please obtain a backtrace and post a report on our [http://bugs.mtasa.com/ Bug tracker]<br />
<br />
====To obtain a backtrace:====<br />
===Do you have a core dump file in the the MTA server directory?===<br />
It's usually called 'core', and usually over 100MB, and looks something like this:<br />
[[Image:Core.png]]<br />
====If you have a core dump file in the the MTA server directory:====<br />
*Install gdb. To install gdb on Debian, use this command:<br />
apt-get install gdb<br />
*And from the MTA install directory do this command<br />
gdb mta-server -c core<br />
*When gdb launches, do this command to get a module list:<br />
i sh<br />
*And then this command to get a backtrace:<br />
bt<br />
*Save the output<br />
*(To exit gdb, use the quit command)<br />
<br />
====If you do not have a core dump file in the the MTA server directory:====<br />
*Install gdb. To install gdb on Debian, use this command:<br />
apt-get install gdb<br />
*And from the MTA server directory start the mta-server like this:<br />
gdb mta-server -ex "set print thread-events off" --eval-command run<br />
*Now wait for a crash. (Ignore any weird screen output in the meantime)<br />
*When a crash occurs, do this command to get a module list:<br />
i sh<br />
*And then this command to get a backtrace:<br />
bt<br />
*Save the output<br />
*(To exit gdb, use the quit command)<br />
<br />
<br />
== '''Server freezes''' ==<br />
<br />
If your Linux server freezes, please obtain a backtrace with thread information and post a report on our [http://bugs.mtasa.com/ Bug tracker]<br />
<br />
====To obtain a backtrace with thread information:====<br />
*Install gdb. To install gdb on Debian, use this command:<br />
apt-get install gdb<br />
*And from the MTA server directory start the mta-server like this:<br />
gdb mta-server -ex "set print thread-events off" --eval-command run<br />
*Now wait for a freeze. (Ignore any weird screen output in the meantime)<br />
*When a freeze occurs, press ctrl-c to start gdb<br />
*Then do this command to get a module list:<br />
i sh<br />
*And then this command to get a backtrace:<br />
bt<br />
*And then this command to get thread information:<br />
info threads<br />
*Save the output<br />
*(To exit gdb, use the quit command)<br />
<br />
== Automatic installer ==<br />
<br />
=== Prerequisites ===<br />
Make sure you have bash, unzip, tar and wget available on your server.<br />
Also notice that for 64-bit servers the 64-bit binary will be installed, otherwise 32-bit binary will be.<br />
<br />
=== Source code ===<br />
#!/bin/bash -x<br />
#==============================================================================#<br />
# mtasa-install #<br />
#------------------------------------------------------------------------------#<br />
# This shellscript installs MTA:SA on your server. You can configure it and #<br />
# modify it as desired, you can even improve it if you want. #<br />
#==============================================================================#<br />
<br />
NUM_VERSION=undef<br />
FUL_VERSION=undef<br />
ARCH_TYPE=""<br />
<br />
getServerVersion()<br />
{<br />
wget https://raw.githubusercontent.com/multitheftauto/mtasa-blue/master/Server/version.h # we need to find latest stable version here<br />
local MAJOR_VERSION="$(cat version.h | grep "#define MTASA_VERSION_MAJOR" | awk '{ print $3 }' | sed 's/\r//g')"<br />
local MINOR_VERSION="$(cat version.h | grep "#define MTASA_VERSION_MINOR" | awk '{ print $3 }' | sed 's/\r//g')"<br />
local MAINTENANCE_VERSION="$(cat version.h | grep "#define MTASA_VERSION_MAINTENANCE" | awk '{ print $3 }' | sed 's/\r//g')"<br />
NUM_VERSION="${MAJOR_VERSION}${MINOR_VERSION}${MAINTENANCE_VERSION}"<br />
FUL_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${MAINTENANCE_VERSION}"<br />
rm -f version.h<br />
}<br />
<br />
getArchitecture()<br />
{<br />
if ((1<<32)); then<br />
ARCH_TYPE="_x64"<br />
fi<br />
}<br />
<br />
downloadFiles()<br />
{<br />
wget http://linux.mtasa.com/dl/${NUM_VERSION}/multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}.tar.gz<br />
wget http://linux.mtasa.com/dl/${NUM_VERSION}/baseconfig-${FUL_VERSION}.tar.gz<br />
}<br />
<br />
unpack()<br />
{<br />
tar -xf multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}.tar.gz<br />
tar -xf baseconfig-${FUL_VERSION}.tar.gz<br />
}<br />
<br />
moveConfig()<br />
{<br />
mv baseconfig/* multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}/mods/deathmatch<br />
rm -rf baseconfig<br />
cd multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}<br />
}<br />
<br />
installResources()<br />
{<br />
mkdir mods/deathmatch/resources<br />
cd mods/deathmatch/resources<br />
wget http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip<br />
unzip mtasa-resources-latest.zip<br />
cd ../../..<br />
}<br />
<br />
clean()<br />
{<br />
rm -f ../multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}.tar.gz<br />
rm -f ../baseconfig-${FUL_VERSION}.tar.gz<br />
rm -f mods/deathmatch/resources/mtasa-resources-latest.zip<br />
}<br />
<br />
main()<br />
{<br />
getServerVersion<br />
getArchitecture<br />
clean<br />
downloadFiles<br />
unpack<br />
moveConfig<br />
installResources<br />
clean<br />
<br />
if ((1<<32)); then # 64 bits<br />
echo "Installation ready! Use ./mta-server64 to initialize server"<br />
else<br />
echo "Installation ready! Use ./mta-server to initialize server"<br />
fi<br />
}<br />
<br />
main # calling program entry point<br />
<br />
=== Procedure ===<br />
To proceed with installation, save somewhere with read-write-execute access (777) the mtasa-install shell. Finally, proceed to execute it (./mtasa-install for example).</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=Installing_and_Running_MTASA_Server_on_GNU_Linux&diff=49754Installing and Running MTASA Server on GNU Linux2016-11-03T23:27:02Z<p>Renkon: </p>
<hr />
<div>== Installation 64 bit ==<br />
<br />
=== Main binary ===<br />
Download the latest stable 64 bit Linux binaries:<br />
rm -f multitheftauto_linux_x64-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/multitheftauto_linux_x64-{{Current Version|full}}.tar.gz<br />
<br />
Unpack into a directory:<br />
tar -xf multitheftauto_linux_x64-{{Current Version|full}}.tar.gz<br />
<br />
=== Default config ===<br />
Download the default config files:<br />
rm -f baseconfig-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/baseconfig-{{Current Version|full}}.tar.gz<br />
<br />
Unpack and move into the deathmatch directory:<br/><br />
('''''Note:''' Only do this for new installations as it will overwrite any existing config files.)''<br />
tar -xf baseconfig-{{Current Version|full}}.tar.gz<br />
mv baseconfig/* multitheftauto_linux_x64-{{Current Version|full}}/mods/deathmatch<br />
<br />
Change to the MTA server install directory:<br />
cd multitheftauto_linux_x64-{{Current Version|full}}<br />
<br />
=== Test ===<br />
You can now test if the server will start correctly:<br />
./mta-server64<br />
<br />
=== Default resources ===<br />
If you need the default resources:<br />
Download the latest default resources zip from http://mirror.mtasa.com/mtasa/resources/<br />
and unzip into '''mods/deathmatch/resources'''<br />
<br/><br />
'''Make sure you are in the MTA server install directory when following this example:'''<br />
apt-get install unzip<br />
mkdir mods/deathmatch/resources<br />
cd mods/deathmatch/resources<br />
rm -f mtasa-resources-latest.zip<br />
wget <nowiki>http</nowiki>://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip<br />
unzip mtasa-resources-latest.zip<br />
rm -f mtasa-resources-latest.zip<br />
cd ../../..<br />
<br />
<br />
== Installation 32 bit ==<br />
<br />
=== Main binary===<br />
Download the latest stable 32 bit Linux binaries:<br />
rm -f multitheftauto_linux-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/multitheftauto_linux-{{Current Version|full}}.tar.gz<br />
<br />
Unpack into a directory:<br />
tar -xf multitheftauto_linux-{{Current Version|full}}.tar.gz<br />
<br />
=== Default config ===<br />
Download the default config files:<br />
rm -f baseconfig-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/baseconfig-{{Current Version|full}}.tar.gz<br />
<br />
Unpack and move into the deathmatch directory:<br/><br />
('''''Note:''' Only do this for new installations as it will overwrite any existing config files.)''<br />
tar -xf baseconfig-{{Current Version|full}}.tar.gz<br />
mv baseconfig/* multitheftauto_linux-{{Current Version|full}}/mods/deathmatch<br />
<br />
Change to the MTA server install directory:<br />
cd multitheftauto_linux-{{Current Version|full}}<br />
<br />
=== Test ===<br />
You can now test if the server will start correctly:<br />
./mta-server<br />
<br />
=== Default resources ===<br />
If you need the default resources:<br />
Download the latest default resources zip from http://mirror.mtasa.com/mtasa/resources/<br />
and unzip into '''mods/deathmatch/resources'''<br />
<br/><br />
'''Make sure you are in the MTA server install directory when following this example:'''<br />
apt-get install unzip<br />
mkdir mods/deathmatch/resources<br />
cd mods/deathmatch/resources<br />
rm -f mtasa-resources-latest.zip<br />
wget <nowiki>http</nowiki>://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip<br />
unzip mtasa-resources-latest.zip<br />
rm -f mtasa-resources-latest.zip<br />
cd ../../..<br />
<br />
<br />
<br />
== Running with 32 or 64 bit Linux==<br />
=== Make sure your server libraries and stuff are up to date ===<br />
On Debian/Ubuntu this is done with:<br />
apt-get update<br />
apt-get upgrade<br />
<br />
===Troubleshooting===<br />
* If you get a problem with such as "libreadline.so.5: cannot open shared object file: No such file or directory.", it can be solved on 32 bit Debian/Ubuntu by doing this:<br />
<br />
apt-get install libreadline5<br />
<br />
* If you get a problem with such as "libncursesw.so.5 cannot open shared object file: No such file or directory", it can be solved on 32 bit Debian/Ubuntu by doing this:<br />
<br />
apt-get install libncursesw5<br />
<br />
'''Note:''' If you experience this issue on a 64-bit machine while trying to run the 32-bit MTA server, then you should install the following package on a 64-bit Debian/Ubuntu machine (as root):<br />
<br />
apt-get install lib32ncursesw5<br />
<br />
You can find more 32-bit library alternatives on this page: [http://www.debian.org/distrib/packages#search_contents www.debian.org/distrib/packages#search_contents].<br />
<br />
== MySQL Troubleshooting==<br />
* If you are using the inbuilt MySQL functions such as [[dbConnect]] and [[dbQuery]], you will need to have '''libmysqlclient.so.16''' installed.<br />
* If you get a problem with such as "libmysqlclient.so.16: cannot open shared object file: No such file or directory", it can be solved on Debian/Ubuntu by doing this:<br />
<br />
apt-get install libmysqlclient16<br />
<br />
If that fails:<br />
* For 32 bit Linux, download [http://nightly.mtasa.com/files/modules/32/libmysqlclient.so.16 32 bit libmysqlclient.so.16] and put it in '''/usr/lib/'''<br />
* For 64 bit Linux, download [http://nightly.mtasa.com/files/modules/64/libmysqlclient.so.16 64 bit libmysqlclient.so.16] and put it in '''/usr/lib/'''<br />
<br />
==[Optional] Installing and Configuring an External Web Server==<br />
Instructions on how to install and configure Nginx as an external web server for MTA is here: [[Installing and Configuring Nginx as an External Web Server]]<br />
<br />
== Server crashes ==<br />
<br />
If your Linux server crashes, please obtain a backtrace and post a report on our [http://bugs.mtasa.com/ Bug tracker]<br />
<br />
====To obtain a backtrace:====<br />
===Do you have a core dump file in the the MTA server directory?===<br />
It's usually called 'core', and usually over 100MB, and looks something like this:<br />
[[Image:Core.png]]<br />
====If you have a core dump file in the the MTA server directory:====<br />
*Install gdb. To install gdb on Debian, use this command:<br />
apt-get install gdb<br />
*And from the MTA install directory do this command<br />
gdb mta-server -c core<br />
*When gdb launches, do this command to get a module list:<br />
i sh<br />
*And then this command to get a backtrace:<br />
bt<br />
*Save the output<br />
*(To exit gdb, use the quit command)<br />
<br />
====If you do not have a core dump file in the the MTA server directory:====<br />
*Install gdb. To install gdb on Debian, use this command:<br />
apt-get install gdb<br />
*And from the MTA server directory start the mta-server like this:<br />
gdb mta-server -ex "set print thread-events off" --eval-command run<br />
*Now wait for a crash. (Ignore any weird screen output in the meantime)<br />
*When a crash occurs, do this command to get a module list:<br />
i sh<br />
*And then this command to get a backtrace:<br />
bt<br />
*Save the output<br />
*(To exit gdb, use the quit command)<br />
<br />
<br />
== '''Server freezes''' ==<br />
<br />
If your Linux server freezes, please obtain a backtrace with thread information and post a report on our [http://bugs.mtasa.com/ Bug tracker]<br />
<br />
====To obtain a backtrace with thread information:====<br />
*Install gdb. To install gdb on Debian, use this command:<br />
apt-get install gdb<br />
*And from the MTA server directory start the mta-server like this:<br />
gdb mta-server -ex "set print thread-events off" --eval-command run<br />
*Now wait for a freeze. (Ignore any weird screen output in the meantime)<br />
*When a freeze occurs, press ctrl-c to start gdb<br />
*Then do this command to get a module list:<br />
i sh<br />
*And then this command to get a backtrace:<br />
bt<br />
*And then this command to get thread information:<br />
info threads<br />
*Save the output<br />
*(To exit gdb, use the quit command)<br />
<br />
== Automatic installer ==<br />
<br />
=== Prerequisites ===<br />
Make sure you have bash, unzip, tar and wget available on your server.<br />
Also notice that for 64-bit servers the 64-bit binary will be installed, otherwise 32-bit binary will be.<br />
<br />
=== Source code ===<br />
#!/bin/bash -x<br />
#==============================================================================#<br />
# mtasa-install #<br />
#------------------------------------------------------------------------------#<br />
# This shellscript installs MTA:SA on your server (working for RHEL, CentOS #<br />
# and Oracle Linux. You can configure it and modify it as desired, you can #<br />
# even improve it if you want. #<br />
#==============================================================================#<br />
<br />
NUM_VERSION=undef<br />
FUL_VERSION=undef<br />
ARCH_TYPE=""<br />
<br />
getServerVersion()<br />
{<br />
wget https://raw.githubusercontent.com/multitheftauto/mtasa-blue/master/Server/version.h # we need to find latest stable version here<br />
local MAJOR_VERSION="$(cat version.h | grep "#define MTASA_VERSION_MAJOR" | awk '{ print $3 }' | sed 's/\r//g')"<br />
local MINOR_VERSION="$(cat version.h | grep "#define MTASA_VERSION_MINOR" | awk '{ print $3 }' | sed 's/\r//g')"<br />
local MAINTENANCE_VERSION="$(cat version.h | grep "#define MTASA_VERSION_MAINTENANCE" | awk '{ print $3 }' | sed 's/\r//g')"<br />
NUM_VERSION="${MAJOR_VERSION}${MINOR_VERSION}${MAINTENANCE_VERSION}"<br />
FUL_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${MAINTENANCE_VERSION}"<br />
rm -f version.h<br />
}<br />
<br />
getArchitecture()<br />
{<br />
if ((1<<32)); then<br />
ARCH_TYPE="_x64"<br />
fi<br />
}<br />
<br />
downloadFiles()<br />
{<br />
wget http://linux.mtasa.com/dl/${NUM_VERSION}/multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}.tar.gz<br />
wget http://linux.mtasa.com/dl/${NUM_VERSION}/baseconfig-${FUL_VERSION}.tar.gz<br />
}<br />
<br />
unpack()<br />
{<br />
tar -xf multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}.tar.gz<br />
tar -xf baseconfig-${FUL_VERSION}.tar.gz<br />
}<br />
<br />
moveConfig()<br />
{<br />
mv baseconfig/* multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}/mods/deathmatch<br />
rm -rf baseconfig<br />
cd multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}<br />
}<br />
<br />
installResources()<br />
{<br />
mkdir mods/deathmatch/resources<br />
cd mods/deathmatch/resources<br />
wget http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip<br />
unzip mtasa-resources-latest.zip<br />
cd ../../..<br />
}<br />
<br />
clean()<br />
{<br />
rm -f ../multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}.tar.gz<br />
rm -f ../baseconfig-${FUL_VERSION}.tar.gz<br />
rm -f mods/deathmatch/resources/mtasa-resources-latest.zip<br />
}<br />
<br />
main()<br />
{<br />
getServerVersion<br />
getArchitecture<br />
clean<br />
downloadFiles<br />
unpack<br />
moveConfig<br />
installResources<br />
clean<br />
<br />
if ((1<<32)); then # 64 bits<br />
echo "Installation ready! Use ./mta-server64 to initialize server"<br />
else<br />
echo "Installation ready! Use ./mta-server to initialize server"<br />
fi<br />
}<br />
<br />
main # calling program entry point<br />
<br />
=== Procedure ===<br />
To proceed with installation, save somewhere with read-write-execute access (777) the mtasa-install shell. Finally, proceed to execute it (./mtasa-install for example).</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=Installing_and_Running_MTASA_Server_on_GNU_Linux&diff=49753Installing and Running MTASA Server on GNU Linux2016-11-03T23:23:48Z<p>Renkon: </p>
<hr />
<div>== Installation 64 bit ==<br />
<br />
=== Main binary ===<br />
Download the latest stable 64 bit Linux binaries:<br />
rm -f multitheftauto_linux_x64-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/multitheftauto_linux_x64-{{Current Version|full}}.tar.gz<br />
<br />
Unpack into a directory:<br />
tar -xf multitheftauto_linux_x64-{{Current Version|full}}.tar.gz<br />
<br />
=== Default config ===<br />
Download the default config files:<br />
rm -f baseconfig-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/baseconfig-{{Current Version|full}}.tar.gz<br />
<br />
Unpack and move into the deathmatch directory:<br/><br />
('''''Note:''' Only do this for new installations as it will overwrite any existing config files.)''<br />
tar -xf baseconfig-{{Current Version|full}}.tar.gz<br />
mv baseconfig/* multitheftauto_linux_x64-{{Current Version|full}}/mods/deathmatch<br />
<br />
Change to the MTA server install directory:<br />
cd multitheftauto_linux_x64-{{Current Version|full}}<br />
<br />
=== Test ===<br />
You can now test if the server will start correctly:<br />
./mta-server64<br />
<br />
=== Default resources ===<br />
If you need the default resources:<br />
Download the latest default resources zip from http://mirror.mtasa.com/mtasa/resources/<br />
and unzip into '''mods/deathmatch/resources'''<br />
<br/><br />
'''Make sure you are in the MTA server install directory when following this example:'''<br />
apt-get install unzip<br />
mkdir mods/deathmatch/resources<br />
cd mods/deathmatch/resources<br />
rm -f mtasa-resources-latest.zip<br />
wget <nowiki>http</nowiki>://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip<br />
unzip mtasa-resources-latest.zip<br />
rm -f mtasa-resources-latest.zip<br />
cd ../../..<br />
<br />
<br />
== Installation 32 bit ==<br />
<br />
=== Main binary===<br />
Download the latest stable 32 bit Linux binaries:<br />
rm -f multitheftauto_linux-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/multitheftauto_linux-{{Current Version|full}}.tar.gz<br />
<br />
Unpack into a directory:<br />
tar -xf multitheftauto_linux-{{Current Version|full}}.tar.gz<br />
<br />
=== Default config ===<br />
Download the default config files:<br />
rm -f baseconfig-{{Current Version|full}}.tar.gz<br />
wget <nowiki>http</nowiki>://linux.mtasa.com/dl/{{Current Version|fullnodots}}/baseconfig-{{Current Version|full}}.tar.gz<br />
<br />
Unpack and move into the deathmatch directory:<br/><br />
('''''Note:''' Only do this for new installations as it will overwrite any existing config files.)''<br />
tar -xf baseconfig-{{Current Version|full}}.tar.gz<br />
mv baseconfig/* multitheftauto_linux-{{Current Version|full}}/mods/deathmatch<br />
<br />
Change to the MTA server install directory:<br />
cd multitheftauto_linux-{{Current Version|full}}<br />
<br />
=== Test ===<br />
You can now test if the server will start correctly:<br />
./mta-server<br />
<br />
=== Default resources ===<br />
If you need the default resources:<br />
Download the latest default resources zip from http://mirror.mtasa.com/mtasa/resources/<br />
and unzip into '''mods/deathmatch/resources'''<br />
<br/><br />
'''Make sure you are in the MTA server install directory when following this example:'''<br />
apt-get install unzip<br />
mkdir mods/deathmatch/resources<br />
cd mods/deathmatch/resources<br />
rm -f mtasa-resources-latest.zip<br />
wget <nowiki>http</nowiki>://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip<br />
unzip mtasa-resources-latest.zip<br />
rm -f mtasa-resources-latest.zip<br />
cd ../../..<br />
<br />
<br />
<br />
== Running with 32 or 64 bit Linux==<br />
=== Make sure your server libraries and stuff are up to date ===<br />
On Debian/Ubuntu this is done with:<br />
apt-get update<br />
apt-get upgrade<br />
<br />
===Troubleshooting===<br />
* If you get a problem with such as "libreadline.so.5: cannot open shared object file: No such file or directory.", it can be solved on 32 bit Debian/Ubuntu by doing this:<br />
<br />
apt-get install libreadline5<br />
<br />
* If you get a problem with such as "libncursesw.so.5 cannot open shared object file: No such file or directory", it can be solved on 32 bit Debian/Ubuntu by doing this:<br />
<br />
apt-get install libncursesw5<br />
<br />
'''Note:''' If you experience this issue on a 64-bit machine while trying to run the 32-bit MTA server, then you should install the following package on a 64-bit Debian/Ubuntu machine (as root):<br />
<br />
apt-get install lib32ncursesw5<br />
<br />
You can find more 32-bit library alternatives on this page: [http://www.debian.org/distrib/packages#search_contents www.debian.org/distrib/packages#search_contents].<br />
<br />
== MySQL Troubleshooting==<br />
* If you are using the inbuilt MySQL functions such as [[dbConnect]] and [[dbQuery]], you will need to have '''libmysqlclient.so.16''' installed.<br />
* If you get a problem with such as "libmysqlclient.so.16: cannot open shared object file: No such file or directory", it can be solved on Debian/Ubuntu by doing this:<br />
<br />
apt-get install libmysqlclient16<br />
<br />
If that fails:<br />
* For 32 bit Linux, download [http://nightly.mtasa.com/files/modules/32/libmysqlclient.so.16 32 bit libmysqlclient.so.16] and put it in '''/usr/lib/'''<br />
* For 64 bit Linux, download [http://nightly.mtasa.com/files/modules/64/libmysqlclient.so.16 64 bit libmysqlclient.so.16] and put it in '''/usr/lib/'''<br />
<br />
==[Optional] Installing and Configuring an External Web Server==<br />
Instructions on how to install and configure Nginx as an external web server for MTA is here: [[Installing and Configuring Nginx as an External Web Server]]<br />
<br />
== Server crashes ==<br />
<br />
If your Linux server crashes, please obtain a backtrace and post a report on our [http://bugs.mtasa.com/ Bug tracker]<br />
<br />
====To obtain a backtrace:====<br />
===Do you have a core dump file in the the MTA server directory?===<br />
It's usually called 'core', and usually over 100MB, and looks something like this:<br />
[[Image:Core.png]]<br />
====If you have a core dump file in the the MTA server directory:====<br />
*Install gdb. To install gdb on Debian, use this command:<br />
apt-get install gdb<br />
*And from the MTA install directory do this command<br />
gdb mta-server -c core<br />
*When gdb launches, do this command to get a module list:<br />
i sh<br />
*And then this command to get a backtrace:<br />
bt<br />
*Save the output<br />
*(To exit gdb, use the quit command)<br />
<br />
====If you do not have a core dump file in the the MTA server directory:====<br />
*Install gdb. To install gdb on Debian, use this command:<br />
apt-get install gdb<br />
*And from the MTA server directory start the mta-server like this:<br />
gdb mta-server -ex "set print thread-events off" --eval-command run<br />
*Now wait for a crash. (Ignore any weird screen output in the meantime)<br />
*When a crash occurs, do this command to get a module list:<br />
i sh<br />
*And then this command to get a backtrace:<br />
bt<br />
*Save the output<br />
*(To exit gdb, use the quit command)<br />
<br />
<br />
== '''Server freezes''' ==<br />
<br />
If your Linux server freezes, please obtain a backtrace with thread information and post a report on our [http://bugs.mtasa.com/ Bug tracker]<br />
<br />
====To obtain a backtrace with thread information:====<br />
*Install gdb. To install gdb on Debian, use this command:<br />
apt-get install gdb<br />
*And from the MTA server directory start the mta-server like this:<br />
gdb mta-server -ex "set print thread-events off" --eval-command run<br />
*Now wait for a freeze. (Ignore any weird screen output in the meantime)<br />
*When a freeze occurs, press ctrl-c to start gdb<br />
*Then do this command to get a module list:<br />
i sh<br />
*And then this command to get a backtrace:<br />
bt<br />
*And then this command to get thread information:<br />
info threads<br />
*Save the output<br />
*(To exit gdb, use the quit command)<br />
<br />
== Automatic installer ==<br />
<br />
=== Prerequisites ===<br />
Make sure you have bash, unzip, tar and wget available on your server.<br />
Also notice that for 64-bit servers the 64-bit binary will be installed, otherwise 32-bit binary will be.<br />
<br />
=== Source code ===<br />
#!/bin/bash -x<br />
#==============================================================================#<br />
# mtasa-install #<br />
#------------------------------------------------------------------------------#<br />
# This shellscript installs MTA:SA on your server (working for RHEL, CentOS #<br />
# and Oracle Linux. You can configure it and modify it as desired, you can #<br />
# even improve it if you want. #<br />
#==============================================================================#<br />
<br />
NUM_VERSION=undef<br />
FUL_VERSION=undef<br />
ARCH_TYPE=""<br />
<br />
getServerVersion()<br />
{<br />
wget https://raw.githubusercontent.com/multitheftauto/mtasa-blue/master/Server/version.h # we need to find latest stable version here<br />
local MAJOR_VERSION="$(cat version.h | grep "#define MTASA_VERSION_MAJOR" | awk '{ print $3 }' | sed 's/\r//g')"<br />
local MINOR_VERSION="$(cat version.h | grep "#define MTASA_VERSION_MINOR" | awk '{ print $3 }' | sed 's/\r//g')"<br />
local MAINTENANCE_VERSION="$(cat version.h | grep "#define MTASA_VERSION_MAINTENANCE" | awk '{ print $3 }' | sed 's/\r//g')"<br />
NUM_VERSION="${MAJOR_VERSION}${MINOR_VERSION}${MAINTENANCE_VERSION}"<br />
FUL_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${MAINTENANCE_VERSION}"<br />
rm -f version.h<br />
}<br />
<br />
getArchitecture()<br />
{<br />
if ((1<<32)); then<br />
ARCH_TYPE="_x64"<br />
fi<br />
}<br />
<br />
downloadFiles()<br />
{<br />
wget http://linux.mtasa.com/dl/${NUM_VERSION}/multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}.tar.gz<br />
wget http://linux.mtasa.com/dl/${NUM_VERSION}/baseconfig-${FUL_VERSION}.tar.gz<br />
}<br />
<br />
unpack()<br />
{<br />
tar -xf multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}.tar.gz<br />
tar -xf baseconfig-${FUL_VERSION}.tar.gz<br />
}<br />
<br />
moveConfig()<br />
{<br />
mv baseconfig/* multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}/mods/deathmatch<br />
rm -rf baseconfig<br />
cd multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}<br />
}<br />
<br />
installResources()<br />
{<br />
mkdir mods/deathmatch/resources<br />
cd mods/deathmatch/resources<br />
wget http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip<br />
unzip mtasa-resources-latest.zip<br />
cd ../../..<br />
}<br />
<br />
clean()<br />
{<br />
rm -f ../multitheftauto_linux${ARCH_TYPE}-${FUL_VERSION}.tar.gz<br />
rm -f ../baseconfig-${FUL_VERSION}.tar.gz<br />
rm -f mods/deathmatch/resources/mtasa-resources-latest.zip<br />
}<br />
<br />
main()<br />
{<br />
getServerVersion<br />
getArchitecture<br />
clean<br />
downloadFiles<br />
unpack<br />
moveConfig<br />
installResources<br />
clean<br />
<br />
if ((1<<32)); then # 64 bits<br />
echo "Installation ready! Use ./mta-server64 to initialize server"<br />
else<br />
echo "Installation ready! Use ./mta-server to initialize server"<br />
fi<br />
}<br />
<br />
main # calling program entry point</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=User:Renkon&diff=38199User:Renkon2014-01-07T03:37:10Z<p>Renkon: </p>
<hr />
<div>==Who am I==<br />
<br />
I'm a 18 year-old boy from Argentina who fancies playing Multi Theft Auto. I started playing SA-MP back in 2007 and moved to MTA in late 2009. Since then I have never left the community (although I got registered in 2010). I'm currently active in Drunk Drivers Club community and the forum itself.<br />
<br />
==Services==<br />
<br />
At the moment I offer my scripting services for MTA:SA. If you are interested please go to http://forum.mtasa.com/viewtopic.php?f=5&t=68603 (my service's forum thread)</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=SetVehicleNitroCount&diff=38012SetVehicleNitroCount2014-01-02T06:36:54Z<p>Renkon: typo</p>
<hr />
<div>__NOTOC__ <br />
{{Client function}}<br />
{{New feature/item|3.0131|1.3.1|4993|<br />
This function sets the nitro count to the [[vehicle]].<br />
}}<br />
{{Warning|Only works if the vehicle is streamed in}}<br />
==Syntax== <br />
<syntaxhighlight lang="lua">bool setVehicleNitroCount ( vehicle theVehicle, int count )</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''theVehicle''' The [[vehicle]] which you want to set.<br />
*'''count''' Nitro count you want to set (ranges from 0-100, 101 is infinite).<br />
<br />
===Returns===<br />
Returns ''true'' if the nitro count was set successfully to the vehicle, ''false'' otherwise.<br />
<br />
==Example==<br />
<section name="Client" class="client" show="true"><br />
This function installs nitro in the vehicle and then sets the count to infinite when the player enters the vehicle.<br />
<syntaxhighlight lang="lua"><br />
function infiniteNitro(pPlayer)<br />
if pPlayer == localPlayer then<br />
if not getVehicleUpgradeOnSlot(source, 8) then -- Does the vehicle have nitro installed or not<br />
addVehicleUpgrade(source, 1010) -- Install nitrous<br />
end<br />
setVehicleNitroCount(source, 101) -- Set the nitro count to infinite<br />
end<br />
end<br />
addEventHandler("onClientVehicleEnter", root, infiniteNitro)<br />
</syntaxhighlight><br />
</section><br />
<br />
==Requirements==<br />
{{Requirements|n/a|1.3.1-9.04993|}}<br />
<br />
==See Also==<br />
{{Client_vehicle_functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=DxDrawAnimWindow&diff=37995DxDrawAnimWindow2013-12-23T01:10:12Z<p>Renkon: Edited example, as it was wrong, so fixed it</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function is for creating and animating a dX Window.<br />
* '''NOTE:''' This is made to be used clientside!.<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua">bool dxDrawAnimWindow ( string text, int height, int width, int color, string element font, string anim)</syntaxhighlight><br />
<br />
===Required Arguments=== <br />
* '''text:''' The text of the window<br />
* '''height:''' The height of the window<br />
* '''width:''' The width of the window<br />
* '''color:''' The color of the window<br />
* '''font:''' A element or string representing the font.<br />
* '''anim:''' The easing or animation type. See https://wiki.multitheftauto.com/wiki/Easing] For more Types-<br />
<br />
==Code==<br />
<section name="Clientside script" class="client" show="true"><br />
<syntaxhighlight lang="lua"><br />
function dxDrawAnimWindow(text,height,width,color,font,anim)<br />
local x,y = guiGetScreenSize()<br />
<br />
btwidth = width<br />
btheight = height/20<br />
<br />
local now = getTickCount()<br />
local elapsedTime = now - start<br />
local endTime = start + 1500<br />
local duration = endTime - start<br />
local progress = elapsedTime / duration<br />
local x1, y1, z1 = interpolateBetween ( 0, 0, 0, width, height, 255, progress, anim)<br />
local x2, y2, z2 = interpolateBetween ( 0, 0, 0, btwidth, btheight, btheight/11, progress, anim)<br />
<br />
posx = (x/2)-(x1/2)<br />
posy = (y/2)-(y1/2)<br />
<br />
dxDrawRectangle ( posx, posy-y2, x2, y2, color )<br />
dxDrawRectangle ( posx, posy, x1, y1, tocolor ( 0, 0, 0, 200 ) )<br />
dxDrawText ( text, 0, -(y1)-y2, x, y, tocolor ( 255, 255, 255, 255 ), z2,font,"center","center") <br />
<br />
<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Use==<br />
Always remeber to define the "start" value with getTickCount() and use onClientRender or onClientPreRender<br />
<section name="Clientside example" class="client" show="true"><br />
<syntaxhighlight lang="lua">function content()<br />
local color = tocolor ( 0, 0, 0, 200 )<br />
dxDrawAnimWindow ( "My Animated Window", 520, 600, color, "default-bold", "OutBounce")<br />
end<br />
bindKey ( "F2", "down", main )<br />
function main()<br />
start = getTickCount()<br />
addEventHandler ( "onClientRender", getRootElement(), content )<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
<br />
Author: Bc#<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=Template:Useful_Functions&diff=37988Template:Useful Functions2013-12-22T22:04:53Z<p>Renkon: </p>
<hr />
<div>*[[dxDrawAnimWindow]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Create Animated Dx Window</span><br />
*[[callClientFunction]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to call any clientside function from the server's side.</span><br />
*[[callServerFunction]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to call any server-side function from the client's side.</span><br />
*[[centerWindow]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function center the window in any resolution.</span><br />
*[[Check]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if it's arguments are of the right types and calls the error-function if one isn't.</span><br />
*[[convertNumber]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts large numbers and adds commas to it. (Example: 100000 -> 100,000)</span><br />
*[[coroutine.resume]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Fix for hidden coroutine error messages</span><br />
*[[dxDrawCircle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a 2D line in a circle shape on the screen.</span><br />
*[[dxDrawColorText]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a dx text with #RRGGBB color codes support.</span><br />
*[[dxDrawGifImage]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function simulates the effect of a GIF image by using image sprites.</span><br />
*[[dxDrawImage3D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a 3D image.</span><br />
*[[dxDrawPartialCircle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a 2D line in a partial circle shape on the screen.</span><br />
*[[dxDrawRectangle3D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function draws a 3D rectangle.</span><br />
*[[dxGetFontSizeFromHeight]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function calculate a font size from given height for dxDraw.</span><br />
*[[dxGetRealFontHeight]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Accurately measures the pixel height of a font.</span><br />
*[[findRotation]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Takes two points and returns the direction from point A to point B.</span><br />
*[[FormatDate]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Formats a date on the basis of a format string and returns it.</span><br />
*[[GenerateString]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» With this function you can generate a random string with any characters.</span><br />
*[[getAge]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function calculates the age of a birthday.</span><br />
*[[getAlivePlayers (Client)|getAlivePlayers]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns all the alive players by a client side, so you can store them into a Gridlist or something like that, faster.</span><br />
*[[getAlivePlayersInTeam]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the alive players in a team.</span><br />
*[[getBoundControls]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a list of control names that are bound to the specified key.</span><br />
*[[getCursorMoveOn]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks in which way the cursor is currently moving.</span><br />
*[[getDistanceBetweenPointAndSegment2D]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Takes point coordinates and line (a segment) starting and ending coordinates. It returns the shortest distance between the point and the line.</span><br />
*[[getElementSpeed]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to get element speed in kph or mph units.</span><br />
*[[getElementsInDimension]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets the elements that are in the specified dimension.</span><br />
*[[getElementsWithinMarker]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets the elements that are in a markers colshape.</span><br />
*[[getJetpackWeaponsEnabled]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of enabled weapons usable on a jetpack.</span><br />
*[[getOffsetFromXYZ]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to take an entity and a position and calculate the relative offset between them accounting for rotations.</span><br />
*[[getOnlineAdmins]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function will give the online admins.</span><br />
*[[getOnlineStaff]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Returns all online staff, names separated by two spaces.</span><br />
*[[getPlayersByData]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets players who have data name you passed to it.</span><br />
*[[getPlayerFromNamePart]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to get player From his Name part.</span><br />
*[[getPlayersInPhotograph]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets all the players in a photograph.</span><br />
*[[getPlayerFromSerial]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets an online player from their serial.</span><br />
*[[getPointFromDistanceRotation]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Finds a point based on a starting point, direction and distance.</span><br />
*[[getResourceSettings]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table of the resource settings.</span><br />
*[[getRGColorFromPercentage]] <span style="color:gray; font-family:'Georgia', sans-serif; font-size:smaller;">»This function returns two integers representing Red and Green colors according to the percentage requested.</span><br />
*[[getTeamFromColor]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets a team from it's color. (Related to: [[getTeamFromName]])</span><br />
*[[getTimestamp]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» With this function you can get the UNIX timestamp.</span><br />
*[[getValidVehicleModels]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a table containing valid MTA Vehicle models.</span><br />
*[[getXMLNodes]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Returns all children of a node</span><br />
*[[getVehicleRespawnPosition]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to get the spawn position of a vehicle.</span><br />
*[[guiComboBoxAdjustHeight]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Adjusts the combobox to have a correct height.</span><br />
*[[IfElse]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Returns one of two values based on a boolean expression.</span><br />
*[[isElementInPhotograph]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if an element was in the player's camera picture.</span><br />
*[[isElementInRange]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to check is the element's range to the main point is smaller than (or as big as) the maximum range.</span><br />
*[[isElementMoving]]<span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if an element is moving.</span><br />
*[[isElementWithinAColShape]]<span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if the [[element]] is in a [[colshape]].</span><br />
*[[isPedAiming]]<span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if a ped is aiming.</span><br />
*[[isPlayerInACL]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function will check to see if a player element is in an ACL group.</span><br />
*[[isPlayerInTeam]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function check if the player in the team.</span><br />
*[[isLeapYear]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Checks if the given year is a leap year.</span><br />
*[[isVehicleOnRoof]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether vehicle is on roof.</span><br />
*[[isVehicleEmpty]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks whether a vehicle is empty.</span><br />
*[[iterElements]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Returns an iterator for your for loops saving time typing ipairs( getElementsByType( type ) ), instead you type: iterElements( type ).</span><br />
*[[mathNumber]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function is a workaround for the clientside floating-point precision of 24-bits</span><br />
*[[math.round]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Rounds a number whereas the number of decimals to keep and the method may be set.</span><br />
*[[multi_check]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks one element to many, handy and clean.</span><br />
*[[onVehicleWeaponFire]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This code implements an event that is triggered when a player in a vehicle fires a vehicles weapon.</span><br />
*[[RGBToHex]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function returns a string representing the color in hexadecimal.</span><br />
*[[setElementSpeed]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allows you to set moving element speed in kph or mph units.</span><br />
*[[setTableProtected]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Protects a table and makes it read-only.</span><br />
*[[setVehicleGravityPoint]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This clientside function sets a vehicle's gravity in the direction of a 3 dimensional coordinate with the strength specified.</span><br />
*[[smoothMoveCamera]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This clientside function allows you to create a cinematic camera flight.<br />
*[[string.count]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function counts a text from a text.</span><br />
*[[string.explode]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function splits a string at a given separator pattern and returns a table with the pieces.</span><br />
*[[switch]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function allow the value of a variable or expression to control the flow of program execution via a multiway branch.</span><br />
*[[table.copy]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function copies a whole table and all the tables in that table.</span><br />
*[[table.compare]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function check if both tables is equal. </span><br />
*[[table.empty]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function check is empty table or not.</span><br />
*[[table.map]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function goes through a table and replaces every field with the return of the passed function, where the field's value is passed as first argument and optionally more arguments.</span><br />
*[[table.merge]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Merges two or more tables in the first.</span><br />
*[[table.random]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function retrieves a random variable from a table.</span><br />
*[[table.size]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» Finds the absolute size of a table.</span><br />
*[[toHex]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a decimal number to a hexadecimal number, as a fix to be used clientside.</span><br />
*[[var dump]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function outputs information about one or more variables using outputConsole()</span><br />
*[[wavelengthToRGBA]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function converts a phisical wavelength of light to a RGBA color.</span><br />
[[Category:Useful Functions]]</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34207GetRGColorFromPercentage2012-12-10T18:22:14Z<p>Renkon: /* Example */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows the vehicle health with a different color depending on its health in the bottom part of the screen.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
function showHealth()<br />
local health = getElementHealth(getPedOccupiedVehicle(localPlayer)) - 250<br />
-- When the car has got a health of 250, it turns into fire, so we remove 250 of the original health in order not to take it into account.<br />
if health < 0 then health = 0 end -- In case it goes negative, we set it as if it were 0.<br />
-- Now we need to make the conversion to a number between 0 to 100 knowing that health goes from 0 to 750.<br />
local percentage = math.floor((health*0.133333333333)+0.5) -- Transformation into percentage.<br />
-- We now use the function<br />
local r, g = getRGColorFromPercentage(percentage)<br />
-- We show it<br />
dxDrawText("Health: "..percentage.."%", sW/2-100, sH-45, sW/2+100, sH-15, tocolor(r, g, 0, 255), 1, "default", "center", "center")<br />
end<br />
<br />
-- We add the handler of the function when player enters a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
addEventHandler("onClientPreRender", root, showHealth)<br />
end )<br />
<br />
-- We remove it when the player leaves a car.<br />
addEventHandler("onClientPlayerVehicleExit", localPlayer, <br />
function()<br />
removeEventHandler("onClientPreRender", root, showHealth)<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}<br />
[[:Category:Useful_Functions]]</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34206GetRGColorFromPercentage2012-12-10T02:15:55Z<p>Renkon: </p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows the vehicle health with a different color depending on its health in the bottom part of the screen.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
function showHealth()<br />
local health = getElementHealth(getPedOccupiedVehicle(localPlayer)) - 250<br />
-- When the car has got a health of 250, it turns into fire, so we remove 250 of the original health in order not to take it into account.<br />
if health < 0 then health = 0 end -- In case it goes negative, we set it as if it were 0.<br />
-- Now we need to make the conversion to a number between 0 to 100 knowing that health goes from 0 to 750.<br />
local percentage = math.floor((health*0.133333333333)+0.5) -- Transformation into percentage.<br />
-- We now use the function<br />
local r, g = getRGColorFromPercentage(percentage)<br />
-- We show it<br />
dxDrawText("Health: "..percentage.."%", sW/2-100, sH-45, sW/2+100, sH-15, tocolor(r, g, 0, 255), 1, "default", "center", "center")<br />
end<br />
<br />
-- We add the handler of the function when player enters a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
addEventHandler("onClientPreRender", root, showHealth)<br />
end )<br />
<br />
-- We remove it when the player leaves a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
removeEventHandler("onClientPreRender", root, showHealth)<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}<br />
[[:Category:Useful_Functions]]</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34205GetRGColorFromPercentage2012-12-10T02:07:34Z<p>Renkon: /* Example */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows the vehicle health with a different color depending on its health in the bottom part of the screen.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
function showHealth()<br />
local health = getElementHealth(getPedOccupiedVehicle(localPlayer)) - 250<br />
-- When the car has got a health of 250, it turns into fire, so we remove 250 of the original health in order not to take it into account.<br />
if health < 0 then health = 0 end -- In case it goes negative, we set it as if it were 0.<br />
-- Now we need to make the conversion to a number between 0 to 100 knowing that health goes from 0 to 750.<br />
local percentage = math.floor((health*0.133333333333)+0.5) -- Transformation into percentage.<br />
-- We now use the function<br />
local r, g = getRGColorFromPercentage(percentage)<br />
-- We show it<br />
dxDrawText("Health: "..percentage.."%", sW/2-100, sH-45, sW/2+100, sH-15, tocolor(r, g, 0, 255), 1, "default", "center", "center")<br />
end<br />
<br />
-- We add the handler of the function when player enters a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
addEventHandler("onClientPreRender", root, showHealth)<br />
end )<br />
<br />
-- We remove it when the player leaves a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
removeEventHandler("onClientPreRender", root, showHealth)<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34204GetRGColorFromPercentage2012-12-10T02:05:55Z<p>Renkon: /* Example */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows a vehicle health with a different color depending on its health.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
function showHealth()<br />
local health = getElementHealth(getPedOccupiedVehicle(localPlayer)) - 250<br />
-- When the car has got a health of 250, it turns into fire, so we remove 250 of the original health in order not to take it into account.<br />
if health < 0 then health = 0 end -- In case it goes negative, we set it as if it were 0.<br />
-- Now we need to make the conversion to a number between 0 to 100 knowing that health goes from 0 to 750.<br />
local percentage = math.floor((health*0.133333333333)+0.5) -- Transformation into percentage.<br />
-- We now use the function<br />
local r, g = getRGColorFromPercentage(percentage)<br />
-- We show it<br />
dxDrawText("Health: "..percentage.."%", sW/2-100, sH-45, sW/2+100, sH-15, tocolor(r, g, 0, 255), 1, "default", "center", "center")<br />
end<br />
<br />
-- We add the handler of the function when player enters a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
addEventHandler("onClientPreRender", root, showHealth)<br />
end )<br />
<br />
-- We remove it when the player leaves a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
removeEventHandler("onClientPreRender", root, showHealth)<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34203GetRGColorFromPercentage2012-12-10T02:01:13Z<p>Renkon: /* Example */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows a vehicle health with a different color depending on its health.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
function showHealth()<br />
local health = getElementHealth(getPedOccupiedVehicle(localPlayer)) - 250<br />
-- When the car has got a health of 250, it turns into fire, so we remove 250 of the original health in order not to take it into account.<br />
if health < 0 then health = 0 end -- In case it goes negative, we set it as if it were 0.<br />
-- Now we need to make the conversion to a number between 0 to 100 knowing that health goes from 0 to 750.<br />
local percentage = math.floor((health*0.133333333333)+0.5) -- Transformation into percentage.<br />
-- We now use the function<br />
local r, g = getRGColorFromPercentage(percentage)<br />
-- We show it<br />
dxDrawText("Health: "..percentage.."%", sW/2-100, sH-45, sW/2+100, sH-15, tocolor(r, g, 0, 255), 1, "default", "center", "center")<br />
end<br />
<br />
-- We add the handler of the function when player enters a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
addEventHandler("onClientRender", root, showHealth)<br />
end )<br />
<br />
-- We remove it when the player leaves a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
removeEventHandler("onClientRender", root, showHealth)<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34202GetRGColorFromPercentage2012-12-10T01:49:42Z<p>Renkon: /* Example */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows a vehicle health with a different color depending on its health.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
function showHealth()<br />
local health = getElementHealth(getPedOccupiedVehicle(localPlayer)) - 250<br />
-- When the car has got a health of 250, it turns into fire, so we remove 250 of the original health in order not to take it into account.<br />
if health < 0 then health = 0 end -- In case it goes negative, we set it as if it were 0.<br />
-- Now we need to make the conversion to a number between 0 to 100 knowing that health goes from 0 to 750.<br />
local percentage = math.floor((health*0.133333333333)+0.5) -- Transformation into percentage.<br />
-- We now use the function<br />
local r, g = getRGColorFromPercentage(percentage)<br />
-- We show it<br />
dxDrawText(percentage.."%", sW/2-100, sH-45, sW/2+100, sH-15, tocolor(r, g, 0, 255), 1, "default", "center", "center")<br />
end<br />
<br />
-- We add the handler of the function when player enters a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
addEventHandler("onClientRender", root, showHealth)<br />
end )<br />
<br />
-- We remove it when the player leaves a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
removeEventHandler("onClientRender", root, showHealth)<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34201GetRGColorFromPercentage2012-12-10T01:48:53Z<p>Renkon: /* Example */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Client-Side Example" class="client" show="true"><br />
This example shows a vehicle health with a different color depending on its health.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
function showHealth()<br />
local health = getElementHealth(getPedOccupiedVehicle(localPlayer)) - 250<br />
-- When the car has got a health of 250, it turns into fire, so we remove 250 of the original health in order not to take it into account.<br />
if health < 0 then health = 0 end -- In case it goes negative, we set it as if it were 0.<br />
-- Now we need to make the conversion to a number between 0 to 100 knowing that health goes from 0 to 750.<br />
local percentage = math.floor((health*0.133333333333/10)+0.5) -- Transformation into percentage.<br />
-- We now use the function<br />
local r, g = getRGColorFromPercentage(percentage)<br />
-- We show it<br />
dxDrawText(percentage.."%", sW/2-100, sH-45, sW/2+100, sH-15, tocolor(r, g, 0, 255), 1, "default", "center", "center")<br />
end<br />
<br />
-- We add the handler of the function when player enters a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
addEventHandler("onClientRender", root, showHealth)<br />
end )<br />
<br />
-- We remove it when the player leaves a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
removeEventHandler("onClientRender", root, showHealth)<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34200GetRGColorFromPercentage2012-12-10T01:48:02Z<p>Renkon: </p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Server" class="server" show="true"><br />
This example shows a vehicle health with a different color depending on its health.<br />
<syntaxhighlight lang="lua"><br />
local sW, sH = guiGetScreenSize()<br />
<br />
function showHealth()<br />
local health = getElementHealth(getPedOccupiedVehicle(localPlayer)) - 250<br />
-- When the car has got a health of 250, it turns into fire, so we remove 250 of the original health in order not to take it into account.<br />
if health < 0 then health = 0 end -- In case it goes negative, we set it as if it were 0.<br />
-- Now we need to make the conversion to a number between 0 to 100 knowing that health goes from 0 to 750.<br />
local percentage = math.floor((health*0.133333333333/10)+0.5) -- Transformation into percentage.<br />
-- We now use the function<br />
local r, g = getRGColorFromPercentage(percentage)<br />
-- We show it<br />
dxDrawText(percentage.."%", sW/2-100, sH-45, sW/2+100, sH-15, tocolor(r, g, 0, 255), 1, "default", "center", "center")<br />
end<br />
<br />
-- We add the handler of the function when player enters a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
addEventHandler("onClientRender", root, showHealth)<br />
end )<br />
<br />
-- We remove it when the player leaves a car.<br />
addEventHandler("onClientPlayerVehicleEnter", localPlayer, <br />
function()<br />
removeEventHandler("onClientRender", root, showHealth)<br />
end )<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34199GetRGColorFromPercentage2012-12-10T01:32:43Z<p>Renkon: /* Code */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
</section><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34198GetRGColorFromPercentage2012-12-10T01:32:21Z<p>Renkon: /* Code */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<section name="Server/Client-Side Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34197GetRGColorFromPercentage2012-12-10T01:27:41Z<p>Renkon: /* Code */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" or percentage > 100 or percentage < 0 then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34196GetRGColorFromPercentage2012-12-10T01:26:49Z<p>Renkon: /* Syntax */</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkonhttps://wiki.multitheftauto.com/index.php?title=GetRGColorFromPercentage&diff=34195GetRGColorFromPercentage2012-12-10T01:23:31Z<p>Renkon: Created page with "{{Useful Function}} __NOTOC__ This function lets you get an RG Color depending on the percentage. ==Syntax== <syntaxhighlight lang="lua"> int, int, int getRGColorFromPercentage ( int percentage..."</p>
<hr />
<div>{{Useful Function}}<br />
__NOTOC__<br />
This function lets you get an RG Color depending on the percentage.<br />
<br />
==Syntax== <br />
<syntaxhighlight lang="lua"><br />
int, int, int getRGColorFromPercentage ( int percentage )<br />
</syntaxhighlight> <br />
<br />
===Required Arguments=== <br />
*'''percentage:''' The value which you want to get the RGB from. It must be between 0 and 100.<br />
<br />
===Returns===<br />
Returns two integers, with red, and green values if percentage goes between 0 and 100. Returns false otherwise.<br />
<br />
==Code==<br />
<syntaxhighlight lang="lua"><br />
function getRGColorFromPercentage(percentage)<br />
if not percentage or percentage and type(percentage) ~= "number" then outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2 ) return false end<br />
if percentage > 50 then<br />
local temp = 100 - percentage<br />
return temp*5.1, 255<br />
elseif percentage == 50 then<br />
return 255, 255<br />
else<br />
return 255, percentage*5.1<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
'''Author: Renkon'''<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>Renkon