OnResourcePreStart: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Started with onResourcePreStart, format? (not in the source found))
 
No edit summary
Line 2: Line 2:
__NOTOC__
__NOTOC__
This event is triggered before a resource is loaded.
This event is triggered before a resource is loaded.
'''Important:''' If you attach this event to the root element it will called when ''any'' resource starts, not just the resource your script is running inside. As such, most of the time you will want to check that the resource passed to this event matches your resource (compare with the value returned by [[getThisResource]]) before doing anything. Alternatively you can attach the event to [[getResourceRootElement]]([[getThisResource]]()).


==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--TODO
resource startingResource
</syntaxhighlight>
</syntaxhighlight>  
 
*'''startingResource''': The resource that is starting


==Source==
==Source==
The [[event system#Event source|source]] of this event is the root [[element]] in the resource that is starting.


==Cancel effect==
==Cancel effect==


==Example==
==Example==
This code will output the name of any resource that is starting.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--TODO
function displayStartingRes ( res )
outputChatBox ( "Resource " .. getResourceName(res) .. " is starting", getRootElement(), 255, 255, 255 )
end
addEventHandler ( "onPreResourceStart", getRootElement(), displayStartingRes )
</syntaxhighlight>
</syntaxhighlight>


Line 20: Line 29:


[[Category: Incomplete]]
[[Category: Incomplete]]
[[Category: Needs Example]]

Revision as of 20:26, 20 May 2009

This event is triggered before a resource is loaded.

Important: If you attach this event to the root element it will called when any resource starts, not just the resource your script is running inside. As such, most of the time you will want to check that the resource passed to this event matches your resource (compare with the value returned by getThisResource) before doing anything. Alternatively you can attach the event to getResourceRootElement(getThisResource()).

Parameters

resource startingResource
  • startingResource: The resource that is starting

Source

The source of this event is the root element in the resource that is starting.

Cancel effect

Example

This code will output the name of any resource that is starting.

function displayStartingRes ( res )
	outputChatBox ( "Resource " .. getResourceName(res) .. " is starting", getRootElement(), 255, 255, 255 )
end
addEventHandler ( "onPreResourceStart", getRootElement(), displayStartingRes )

See Also

Resource events


Event functions