OnResourceStateChange: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{Server event}} <!-- Change version when https://buildinfo.multitheftauto.com will be updated --> {{Added feature/item|1.6.1|1.6.0|22430| This event is triggered when a resource's state is changed. This event is an extended version of onResourceLoadStateChange }} __NOTOC__ ==Parameters== <syntaxhighlight lang="lua"> resource changedResource, string oldState, string newState </syntaxhighlight> *'''changedResource''': The resource that was either loaded, re...") |
Fernando187 (talk | contribs) m (formatting) |
||
(One intermediate revision by one other user not shown) | |||
Line 6: | Line 6: | ||
}} | }} | ||
__NOTOC__ | __NOTOC__ | ||
{{Note|Possible states: | |||
* '''loaded''' - when resource is loaded but not running | |||
* '''running''' - when resource is loaded and running | |||
* '''starting''' - when resource is starting | |||
* '''stopping''' - when resource is stopping | |||
* '''unloaded''' - when resource is not loaded}} | |||
==Parameters== | ==Parameters== | ||
Line 18: | Line 24: | ||
==Source== | ==Source== | ||
The [[event system#Event source|source]] of this event is the root [[element]]. | The [[event system#Event source|source]] of this event is the root [[element]]. | ||
==Example== | ==Example== |
Latest revision as of 17:48, 1 June 2025
Parameters
resource changedResource, string oldState, string newState
- changedResource: The resource that was either loaded, reloaded or is unloading.
- oldState: The state the resource was in before it changed.
- newState: The state the resource has changed to.
Source
The source of this event is the root element.
Example
This code will output the state of resource when it's state will be changed:
addEventHandler('onResourceStateChange', root, function(res, oldState, newState) iprint('Resource '..getResourceName(res)..' has changed its state from '..oldState..' to '..newState) end)
See Also
Resource events
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled