StopObject: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
 
(17 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Needs_Checking|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? --[[User:Ransom|Ransom]] 20:54, 11 April 2007 (CDT)}}
__NOTOC__
 
{{Server client function}}
__NOTOC__
<!-- 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.


==Syntax==  
==Syntax==  
<!-- 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 ( object theobject )
bool stopObject ( object theObject )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[object]]:stop||}}
===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 -->
*'''theObject:''' the [[object]] whose movement you wish to stop
*'''theobject:''' This is the object 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 -->
* ''true'' if successful.
Returns ''true'' if successful, ''false'' otherwise.
* ''false'' otherwise.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This will allow you to toggle the random movement of a staircase object model using a ''randomObjectMovement'' function and stop it immediately with the stopObject command. This is achieved by using a "toggleobjectmove" command with a "on" or "off" parameter.
This will allow you to toggle the random movement of a staircase object model and stop it immediately with the stopObject command.
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler ( "toggleobjectmove", "objectMoveControl" )
function objectMoveControl ( thePlayer, 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
    if state == "on" then
--also asks for a value for the varible 'state' e
        outputChatBox ( "Moving object randomly" )
if state == "on" then
        mytimer = setTimer ( randomObjectMovement, 2250, 0 )
outputChatBox ( "Moving object randomly" )
        -- if the player types "on" for the state variable, turn on the timer, which triggers a function
mytimer = setTimer ( "randomObjectMovement", 2250, 0 )
        -- called randomObjectMovement that moves the object whenever it is called (not included for
--if player types "on" for the state varible, turn on the timer,
         -- this example). The timer runs every 2 1/4 seconds for 0 times, which means it runs infinitely.
--which triggers the function randomObjectMovement that makes
    elseif state == "off" then
         the object move in random directions. The tiemer runs every 2 1/4
        outputChatBox ( "Stopping object movement" )
        seconds for 0 times, which means it runs infintely.
        killTimer ( mytimer )
elseif state == "off" then
        stopObject ( myobject )
outputChatBox ( "Stopping object movement" )
        -- if the player typed "off" for state, stop the object movement immediately and kill the
killTimer ( mytimer )
        -- randomObjectMovement timer
stopObject ( myobject )
    else
--If player typed "off" for state, 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'" )
         outputChatBox ( "must define object state as 'on' or 'off'" )
         --If player said something besides "on" or "off" for state, do nothing
         -- if the player typed something besides "on" or "off" for state, do nothing
end
    end
end
end
 
addCommandHandler ( "toggleobjectmove", objectMoveControl )
</syntaxhighlight>
</syntaxhighlight>


==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 -->
{{Object_functions}}
{{Object_functions}}

Latest revision as of 12:08, 31 October 2023

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

Syntax

bool stopObject ( object theObject )

OOP Syntax Help! I don't understand this!

Method: object:stop(...)


Required Arguments

  • theObject: the object whose movement you wish to stop

Returns

  • true if successful.
  • false otherwise.

Example

This will allow you to toggle the random movement of a staircase object model using a randomObjectMovement function and stop it immediately with the stopObject command. This is achieved by using a "toggleobjectmove" command with a "on" or "off" parameter.

function objectMoveControl ( thePlayer, 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