OnResourceStop: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 22: Line 22:
==Example==
==Example==
This example displays a message in the chatbox when a resource is stopped.
This example displays a message in the chatbox when a resource is stopped.
 
<section name="Example 1: Server" class="server" show="true">
<syntaxhighlight lang="lua" class="server" show="true">
<syntaxhighlight lang="lua" >
addEventHandler ( "onResourceStop", root,  
addEventHandler ( "onResourceStop", root,  
     function ( resource )
     function ( resource )
Line 30: Line 30:
)
)
</syntaxhighlight>
</syntaxhighlight>
</section>
<section name="Example 2: Server" class="server" show="true">
This example only outputs message if the stopped resource is the same resource where the eventHandler is.
<syntaxhighlight lang="lua" >
addEventHandler ( "onResourceStop", resourceRoot,
    function ( resource )
        outputChatBox ( "This resource has stoped", root, 255, 255, 255 )
  end
)
</syntaxhighlight>
</section>


{{See also/Server event|Resource events}}
{{See also/Server event|Resource events}}

Revision as of 22:37, 14 July 2017

This event is triggered when the resource is stopped. This can occur for a number of reasons:

  • The stop console command was used
  • The restart console command was used
  • The resource was modified (the resource will automatically restart)
  • Another resource stopped it using stopResource.

Note: If you wish to just detect a single resource being stopped, you should attach handlers for this event to the resource's root element. You can access this using getResourceRootElement.

Parameters

resource stoppedResource
  • stoppedResource: The resource that is being stopped.

Source

The source of this event is the root element of the resource that is being stopped.

Example

This example displays a message in the chatbox when a resource is stopped.

Click to collapse [-]
Example 1: Server
addEventHandler ( "onResourceStop", root, 
    function ( resource )
        outputChatBox ( "The Resource " .. getResourceName(resource) .. " was stopped!", root, 255, 255, 255 )
   end 
)
Click to collapse [-]
Example 2: Server

This example only outputs message if the stopped resource is the same resource where the eventHandler is.

addEventHandler ( "onResourceStop", resourceRoot, 
    function ( resource )
        outputChatBox ( "This resource has stoped", root, 255, 255, 255 )
   end 
)


See Also

Resource events


Event functions