<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hiroko</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hiroko"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Hiroko"/>
	<updated>2026-05-02T12:18:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetElementSpeed&amp;diff=52338</id>
		<title>GetElementSpeed</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetElementSpeed&amp;diff=52338"/>
		<updated>2017-09-21T19:47:53Z</updated>

		<summary type="html">&lt;p&gt;Hiroko: Example now works if copy &amp;amp; pasted&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Useful Function}}&lt;br /&gt;
This function returns the speed of an element in m/s, km/h or mph.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
float/nil getElementSpeed ( element theElement [, int/string unit=&amp;quot;m/s&amp;quot; ] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required arguments===&lt;br /&gt;
* '''theElement''': the [[element]] you want to get the speed of. Compatible [[element]] types are:&lt;br /&gt;
** [[Player|Players]]&lt;br /&gt;
** [[Ped|Peds]]&lt;br /&gt;
** [[Object|Objects]]&lt;br /&gt;
** [[Vehicle|Vehicles]]&lt;br /&gt;
** [[Projectile|Projectiles]]&lt;br /&gt;
&lt;br /&gt;
===Optional arguments===&lt;br /&gt;
{{OptionalArg}}&lt;br /&gt;
* '''Unit''': The unit of the speed returned. If not specified, the unit will be ''m/s''. It can be specified as a ''[[string]]'' or ''number'' as follows:&lt;br /&gt;
** '''0''' or '''m/s''': meters per second (speed unit of the [http://en.wikipedia.org/wiki/International_System_of_Units International System of Units], used in formal contexts).&lt;br /&gt;
** '''1''' or '''km/h''': kilometres per hour (the most common speed unit, used in most countries).&lt;br /&gt;
** '''2''' or '''mph''': miles per hour (used in some English-speaking countries).&lt;br /&gt;
&lt;br /&gt;
==Returns==&lt;br /&gt;
This function returns a ''number'' containing the [[element]]'s speed if the arguments provided are valid. It returns ''[[nil]]'' plus an ''error'' otherwise.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Function source&amp;quot; class=&amp;quot;both&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
'''It is recommended to use MTA:SA 1.4''' or higher with this function to use [[OOP]].&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function getElementSpeed(theElement, unit)&lt;br /&gt;
    -- Check arguments for errors&lt;br /&gt;
    assert(isElement(theElement), &amp;quot;Bad argument 1 @ getElementSpeed (element expected, got &amp;quot; .. type(theElement) .. &amp;quot;)&amp;quot;)&lt;br /&gt;
    local elementType = getElementType(theElement)&lt;br /&gt;
    assert(elementType == &amp;quot;player&amp;quot; or elementType == &amp;quot;ped&amp;quot; or elementType == &amp;quot;object&amp;quot; or elementType == &amp;quot;vehicle&amp;quot; or elementType == &amp;quot;projectile&amp;quot;, &amp;quot;Invalid element type @ getElementSpeed (player/ped/object/vehicle/projectile expected, got &amp;quot; .. elementType .. &amp;quot;)&amp;quot;)&lt;br /&gt;
    assert((unit == nil or type(unit) == &amp;quot;string&amp;quot; or type(unit) == &amp;quot;number&amp;quot;) and (unit == nil or (tonumber(unit) and (tonumber(unit) == 0 or tonumber(unit) == 1 or tonumber(unit) == 2)) or unit == &amp;quot;m/s&amp;quot; or unit == &amp;quot;km/h&amp;quot; or unit == &amp;quot;mph&amp;quot;), &amp;quot;Bad argument 2 @ getElementSpeed (invalid speed unit)&amp;quot;)&lt;br /&gt;
    -- Default to m/s if no unit specified and 'ignore' argument type if the string contains a number&lt;br /&gt;
    unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit))&lt;br /&gt;
    -- Setup our multiplier to convert the velocity to the specified unit&lt;br /&gt;
    local mult = (unit == 0 or unit == &amp;quot;m/s&amp;quot;) and 50 or ((unit == 1 or unit == &amp;quot;km/h&amp;quot;) and 180 or 111.84681456)&lt;br /&gt;
    -- Return the speed by calculating the length of the velocity vector, after converting the velocity to the specified unit&lt;br /&gt;
    return (Vector3(getElementVelocity(theElement)) * mult).length&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Clientside example&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example draws the local player's speed rounded to a single decimal in the top-right corner of the screen in different units.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local sx = guiGetScreenSize()&lt;br /&gt;
local function drawSpeed()&lt;br /&gt;
    local vehicle = getPedOccupiedVehicle(getLocalPlayer())&lt;br /&gt;
    local speedms, speedkmh, speedmph = getElementSpeed(vehicle), getElementSpeed(vehicle, 1), getElementSpeed(vehicle, 2)&lt;br /&gt;
    local roundedSpeedms, roundedSpeedkmh, roundedSpeedmph = math.floor(speedms) == speedms and speedms or string.format(speedms, &amp;quot;%.1f&amp;quot;), math.floor(speedkmh) == speedkmh and speedkmh or string.format(speedkmh, &amp;quot;%.1f&amp;quot;), math.floor(speedmph) == speedmph and speedmph or string.format(speedmph, &amp;quot;%.1f&amp;quot;)&lt;br /&gt;
    local speedoText = &amp;quot;Current speed: &amp;quot; .. roundedSpeedms .. &amp;quot; m/s | &amp;quot; .. roundedSpeedkmh .. &amp;quot; km/h | &amp;quot; .. roundedSpeedmph .. &amp;quot; mph&amp;quot;&lt;br /&gt;
    dxDrawText(speedoText, sx - dxGetTextWidth(speedoText), 0)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onClientPreRender&amp;quot;, getRootElement(), drawSpeed)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Hiroko</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=BitXor&amp;diff=46347</id>
		<title>BitXor</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=BitXor&amp;diff=46347"/>
		<updated>2016-01-08T21:54:28Z</updated>

		<summary type="html">&lt;p&gt;Hiroko: Example added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
{{New feature/item|3.0132|1.3.2|5340|&lt;br /&gt;
This function performs a bitwise XOR-conjunction (exclusive OR) on two or more (unsigned) 32-bit [[Int|integers]]. See [http://en.wikipedia.org/wiki/Bitwise_operation#XOR Bitwise operation] for more details.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
uint bitXor ( uint var1, uint var2, ... )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required arguments===&lt;br /&gt;
*'''varN:''' The value you want to perform a XOR-conjunction on&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the conjuncted value.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
This example will do a bitwise XOR of x1, x2, ...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local x1 = 0x14 -- binary: 0001 0100&lt;br /&gt;
local x2 = 0x1C -- binary: 0001 1100&lt;br /&gt;
&lt;br /&gt;
bitXor(x1, x2)  -- return  0000 1000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Bit_functions}}&lt;/div&gt;</summary>
		<author><name>Hiroko</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=BitOr&amp;diff=46346</id>
		<title>BitOr</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=BitOr&amp;diff=46346"/>
		<updated>2016-01-08T21:50:08Z</updated>

		<summary type="html">&lt;p&gt;Hiroko: Example added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
{{New feature/item|3.0132|1.3.2|5340|&lt;br /&gt;
This function performs a bitwise OR-conjunction on two or more (unsigned) 32-bit [[Int|integers]]. See [http://en.wikipedia.org/wiki/Bitwise_operation#OR Bitwise operation] for more details.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
uint bitOr ( uint var1, uint var2, ... )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required arguments===&lt;br /&gt;
*'''varN:''' The value you want to perform an OR-conjunction on&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the conjuncted value.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
This example will do a bitwise OR of x1, x2, ...&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local x1 = 0x31 -- binary: 0011 0001&lt;br /&gt;
local x2 = 0x19 -- binary: 0001 1001&lt;br /&gt;
&lt;br /&gt;
bitOr(x1, x2)   -- return  0011 1001&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Bit_functions}}&lt;/div&gt;</summary>
		<author><name>Hiroko</name></author>
	</entry>
</feed>