StopObject: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Updated command handler)
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__
{{Server client function}}
<!-- 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 will allow you to stop an object that is currently moving.
This will allow you to stop an object that is currently moving.
Line 23: Line 24:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function objectMoveControl ( player, commandName, state )
function objectMoveControl ( player, commandName, state )
--On "toggleobjectmove" in console, activate this command, which also asks the player to define the value for the varible 'state'.  
    --On "toggleobjectmove" in console, activate this command, which also asks the player to define the value for the varible 'state'.  
if state == "on" then
    if state == "on" then
outputChatBox ( "Moving object randomly" )
        outputChatBox ( "Moving object randomly" )
mytimer = setTimer ( "randomObjectMovement", 2250, 0 )
        mytimer = setTimer ( randomObjectMovement, 2250, 0 )
--if player types "on" for the state varible, turn on the timer, which triggers a funciton called randomObjectMovement that asks the object to move whenever it is called (not included for this example). The timer runs every 2 1/4 seconds for 0 times, which means it runs infintely.
        -- if the player types "on" for the state variable, turn on the timer, which triggers a function
elseif state == "off" then
        -- called randomObjectMovement that moves the object whenever it is called (not included for
outputChatBox ( "Stopping object movement" )
        -- this example). The timer runs every 2 1/4 seconds for 0 times, which means it runs infinitely.
killTimer ( mytimer )
    elseif state == "off" then
stopObject ( myobject )
        outputChatBox ( "Stopping object movement" )
--If player typed "off" for state, stop the object movement immediately and kill the randomObjectMovement timer, which triggers the randomObjectMovement function.
        killTimer ( mytimer )
else
        stopObject ( myobject )
        outputChatBox ( "must define object state as 'on' or 'off'" )
        -- if the player typed "off" for state, stop the object movement immediately and kill the
        --If player said something besides "on" or "off" for state, do nothing
        -- randomObjectMovement timer
end
    else
        outputChatBox ( "must define object state as 'on' or 'off'" )
        -- if the player typed something besides "on" or "off" for state, do nothing
    end
end
end
addCommandHandler ( "toggleobjectmove", objectMoveControl )
addCommandHandler ( "toggleobjectmove", objectMoveControl )

Revision as of 18:40, 15 August 2007

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.

function objectMoveControl ( player, commandName, state )
    --On "toggleobjectmove" in console, activate this command, which also asks the player to define the value for the varible 'state'. 
    if state == "on" then
        outputChatBox ( "Moving object randomly" )
        mytimer = setTimer ( randomObjectMovement, 2250, 0 )
        -- if the player types "on" for the state variable, turn on the timer, which triggers a function
        -- called randomObjectMovement that moves the object whenever it is called (not included for
        -- this example). The timer runs every 2 1/4 seconds for 0 times, which means it runs infinitely.
    elseif state == "off" then
        outputChatBox ( "Stopping object movement" )
        killTimer ( mytimer )
        stopObject ( myobject )
        -- if the player typed "off" for state, stop the object movement immediately and kill the
        -- randomObjectMovement timer
    else
        outputChatBox ( "must define object state as 'on' or 'off'" )
        -- if the player typed something besides "on" or "off" for state, do nothing
     end
end
addCommandHandler ( "toggleobjectmove", objectMoveControl )

See Also