Talk:IsElementMoving: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "Does this even work? It doesn't look like it does because it will always return false as that timer will execute 3000ms after that function, not inside it. Also did you check if ...")
 
No edit summary
Line 2: Line 2:


--[[User:Arran Fortuna|Arran Fortuna]] 14:11, 7 October 2012 (UTC)
--[[User:Arran Fortuna|Arran Fortuna]] 14:11, 7 October 2012 (UTC)
<br/><br/>
Arran you are partly right about "Does this even work?" it can return true but this only happens when there is movement on the X axis (it still returns false if there is only movement on the Y and or Z axis.
Also fyi getElementVelocity() does work on objects because an object is also an element.
'''Things that should get changed (imo) are:'''<br/>
- isObjectMoving() should be changed to isElementMoving() (because you can use this function all elements not only objects)<br/>
- The function should not only check for the movement on the X axis but also on the Y and Z
==It would look like this==
<syntaxhighlight lang="lua">
function isElementMoving(theElement)
if isElement(theElement)then --First check if the given argument is an element
local x, y, z = getElementVelocity(theElement) --Get the velocity of the element given in our argument
if x == 0 and y == 0 and z == 0 then --When there is no movement on X, Y or Z return false because our element is not moving
return false
else
return true
end
end
end
</syntaxhighlight>
I will change the page later today and also add some sample code!<br/>
[[User:CR=|CR=]] 11:35, 12 October 2012 (UTC)

Revision as of 11:35, 12 October 2012

Does this even work? It doesn't look like it does because it will always return false as that timer will execute 3000ms after that function, not inside it. Also did you check if getElementVelocity on the object works? Maybe it does.

--Arran Fortuna 14:11, 7 October 2012 (UTC)

Arran you are partly right about "Does this even work?" it can return true but this only happens when there is movement on the X axis (it still returns false if there is only movement on the Y and or Z axis. Also fyi getElementVelocity() does work on objects because an object is also an element.

Things that should get changed (imo) are:
- isObjectMoving() should be changed to isElementMoving() (because you can use this function all elements not only objects)
- The function should not only check for the movement on the X axis but also on the Y and Z

It would look like this

function isElementMoving(theElement)
	if isElement(theElement)then --First check if the given argument is an element
		local x, y, z = getElementVelocity(theElement) --Get the velocity of the element given in our argument
		if x == 0 and y == 0 and z == 0 then --When there is no movement on X, Y or Z return false because our element is not moving
			return false
		else
			return true
		end
	end
end

I will change the page later today and also add some sample code!
CR= 11:35, 12 October 2012 (UTC)