MoveObject: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
==Description==
This function will smoothly move an object from its current position/rotation to the given target position/rotation in the given time. If the function fails for some reason, it will return false.
This function will smoothly move an object from its current position/rotation to the given target position/rotation in the given time. If the function fails for some reason, it will return false.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua"> bool moveObject ( object, time, targetx, targety, targetz, targetrx, targetry, targetrz )</syntaxhighlight>
<syntaxhighlight lang="lua"> bool moveObject ( object theObject, int time, float targetx, float targety, float targetz, [ float targetrx, float targetry, float targetrz ] )</syntaxhighlight>


===Required Arguments===
===Required Arguments===
* '''object''': The object that will be moved.
* '''theObject''': The object that will be moved.
* '''time''': The time in milliseconds the object will arrive at the destination.
* '''time''': The time in milliseconds the object will arrive at the destination.
* '''targetx''': The X value of the target position
* '''targetx''': The X value of the target position
Line 19: Line 18:


===Returns===
===Returns===
Returns true if the function moved the object succesfully, and returns false otherwise.
Returns ''true'' if the function moved the object succesfully, and returns ''false'' otherwise.


==Example==
==Example==
<syntaxhighlight lang="lua">someGuy = getPlayerFromNick ( "someGuy" )
<syntaxhighlight lang="lua">
if ( someGuy ) then
-- Find a player called 'someguy'
  x, y, z = getPlayerPosition ( someGuy )
someGuy = getPlayerFromNick ( "someguy" )
  bed = createObject ( 1700, x + 5, y, z )
-- If a player called someguy was found then
  moveObject ( bed, 3000, x, y, z )
if ( someGuy ) then
  outputChatBox ( "Moving a bed towards someguy", player )
-- Get the player's position
else
x, y, z = getPlayerPosition ( someGuy )
  outputChatBox ( "Player someguy doesn't exist", player )
-- Create a bed (1700) object near to the player
end</syntaxhighlight>
bed = createObject ( 1700, x + 5, y, z )
-- Move the bed towards the player over 3 seconds (3000 milliseconds)
moveObject ( bed, 3000, x, y, z )
-- Tell the player in the chat box
outputChatBox ( "Moving a bed towards you!", someGuy )
else
-- Tell everyone that a player called 'someguy' could not be found
outputChatBox ( "Player someguy doesn't exist" )
end
</syntaxhighlight>

Revision as of 17:10, 18 May 2006

This function will smoothly move an object from its current position/rotation to the given target position/rotation in the given time. If the function fails for some reason, it will return false.

Syntax

 bool moveObject ( object theObject, int time, float targetx, float targety, float targetz, [ float targetrx, float targetry, float targetrz ] )

Required Arguments

  • theObject: The object that will be moved.
  • time: The time in milliseconds the object will arrive at the destination.
  • targetx: The X value of the target position
  • targety: The Y value of the target position
  • targetz: The Z value of the target position

Optional Arguments

  • targetrx: The X value of the target rotation
  • targetry: The Y value of the target rotation
  • targetrz: The Z value of the target rotation

Returns

Returns true if the function moved the object succesfully, and returns false otherwise.

Example

-- Find a player called 'someguy'
someGuy = getPlayerFromNick ( "someguy" )
-- If a player called someguy was found then
if ( someGuy ) then
	-- Get the player's position
	x, y, z = getPlayerPosition ( someGuy )
	-- Create a bed (1700) object near to the player
	bed = createObject ( 1700, x + 5, y, z )
	-- Move the bed towards the player over 3 seconds (3000 milliseconds)
	moveObject ( bed, 3000, x, y, z )
	-- Tell the player in the chat box
	outputChatBox ( "Moving a bed towards you!", someGuy )
else
	-- Tell everyone that a player called 'someguy' could not be found
	outputChatBox ( "Player someguy doesn't exist" )
end