MoveObject: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 27: Line 27:
==Example==
==Example==
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
'''Example 1:''' This example moves every object in the game up 100 places in ten seconds.
'''Example 1:''' This example moves every object in the game up 100 units in ten seconds.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
allObjects = getElementsByType ( "object" )
allObjects = getElementsByType ( "object" )
for key,object in pairs(allObjects) do
for key, theObject in ipairs ( allObjects ) do
local origX,origY,origZ = getElementPosition ( object ) --get the origanal position
local origX, origY, origZ = getElementPosition ( theObject ) --get the origanal position
local newZ = origZ + 100 --make a new z position
local newZ = origZ + 100 -- make a new z position
moveObject ( object, 10000, origX, origY, newZ ) --move the object to this position in 10 seconds.
moveObject ( theObject, 10000, origX, origY, newZ ) --move the object to this position in 10 seconds.
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 17:15, 31 March 2009

This function will smoothly move an object from its current position to a specified rotation and position.

Syntax

bool moveObject ( object theObject, int time, float targetx, float targety, float targetz, [ float moverx, float movery, float moverz ] )

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

  • moverx: The rotation along the X axis relative to its current rotation, which is its starting angle.
  • movery: The rotation along the Y axis relative to its current rotation, which is its starting angle.
  • moverz: The rotation along the Z axis relative to its current rotation, which is its starting angle.

Relative rotation arguments allow for an object to spin multiple times within a single move.

Returns

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

Example

Click to collapse [-]
Server

Example 1: This example moves every object in the game up 100 units in ten seconds.

allObjects = getElementsByType ( "object" )
for key, theObject in ipairs ( allObjects ) do
	local origX, origY, origZ = getElementPosition ( theObject ) --get the origanal position
	local newZ = origZ + 100 -- make a new z position
	moveObject ( theObject, 10000, origX, origY, newZ ) --move the object to this position in 10 seconds.
end
Click to collapse [-]
Server

Example 2: This example created a model (of a bed) near a player called someguy, if they exist in the game. It will then move the model towards the player over 3 seconds.

-- 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 = getElementPosition ( 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

See Also