StopObject: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
<!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | <!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | ||
This | This will allow you to stop an element that is currently moving. | ||
==Syntax== | ==Syntax== | ||
| Line 11: | Line 11: | ||
===Required Arguments=== | ===Required Arguments=== | ||
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type --> | <!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type --> | ||
*''' | *'''theelement:''' This is the element whose movement you wish to stop | ||
===Returns=== | ===Returns=== | ||
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | <!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | ||
Returns ''true'' if | Returns ''true'' if successful, ''false'' otherwise. | ||
==Example== | ==Example== | ||
| Line 83: | Line 77: | ||
==See Also== | ==See Also== | ||
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc --> | <!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc --> | ||
{{ | {{Element_functions}} | ||
[[Category:Incomplete]] -- leave this unless you complete the function | [[Category:Incomplete]] -- leave this unless you complete the function | ||
Revision as of 01:52, 12 April 2007
This will allow you to stop an element that is currently moving.
Syntax
bool stopObject ( element theelement )
Required Arguments
- theelement: This is the element whose movement you wish to stop
Returns
Returns true if successful, false otherwise.
Example
This will allow you to toggle the random movement of a staircase object model and stop it immediately with the stopObject command.
addCommandHandler ( "toggleobjectmove", "objectMoveControl" )
function objectMoveControl ( player, commandName, state )
--This command handler activate on text "toggleobjectmove" in
--the console. It also asks that the player define the varible
--'state' after the commandname
if state == "on" then
outputChatBox ( "Moving object randomly" )
mytimer = setTimer ( "randomObjectMovement", 2250, 0 )
--if player type "on" for state, then we turn on the timer that
--triggers the function randomObjectMovement. It triggers the
--function every 2 1/4 seconds for an infinite amount of times,
--since times is defined as 0.
elseif state == "off" then
outputChatBox ( "Stopping object movement" )
killTimer ( mytimer )
stopObject ( myobject )
--If player typed "off" for state, then stop the object movement
--immediately and kill the random object movement timer, which
--triggers the randomObjectMovement function
else
outputChatBox ( "must define object state as 'on' or 'off'" )
--If player said something besides "on" or "off" for state, do nothing
end
end
function randomObjectMovement ()
curx, cury, curz = getElementPosition ( myobject )
--Get the xyz position of myobject
xmath = randInt(1,2)
if xmath == 1 then
newx = curx + randInt(1,3)
else
newx = curx - randInt(1,3)
end
ymath = randInt(1,2)
if ymath == 1 then
newy = cury + randInt(1,3)
else
newy = cury - randInt(1,3)
end
zmath = randInt(1,2)
if zmath == 1 then
newz = curz + randInt(1,3)
else
newz = curz - randInt(1,3)
end
--Decide randomly whether to add or subtract from the coordinates,
--and randomly add or subtract 1, 2, or 3
moveObject ( myobject, 2000, newx, newy, newz )
--Tell the object to move to our new coordinates in 2 seconds time
end
See Also
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement
-- leave this unless you complete the function