StopObject: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 8: Line 8:
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool stopObject ( element object )
bool stopObject ( object theobject )
</syntaxhighlight>  
</syntaxhighlight>  



Revision as of 01:57, 12 April 2007

Dialog-information.png This article needs checking.

Reason(s): This had stuff put by someone else that said it stops elements but its called stopobject so I wrote it for objects and see also is defined as object category. Not sure? --Ransom 20:54, 11 April 2007 (CDT)


This will allow you to stop an object that is currently moving.

Syntax

bool stopObject ( object theobject )

Required Arguments

  • theobject: This is the object 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