OnPlayerResourceStart: Difference between revisions
Jump to navigation
Jump to search
m (typo) |
Fernando187 (talk | contribs) (Remove obsolete Requirements section) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Server event}} | {{Server event}} | ||
{{Added feature/item | {{Added feature/item|1.5.9|1.5.8|20957|This event is triggered when a [[resource]] has loaded client-side for a [[player]].}} | ||
__NOTOC__ | __NOTOC__ | ||
==Parameters== | ==Parameters== | ||
Line 7: | Line 7: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
*'''loadedResource''': The [[resource]] that was loaded on the client | *'''loadedResource''': The [[resource]] that was loaded on the client. | ||
==Source== | ==Source== | ||
Line 13: | Line 13: | ||
==Example== | ==Example== | ||
This example shows how you can trigger a custom event | This example shows how you can trigger a custom event client-side defined in the same resource as soon as the player is ready (resource loaded on client): | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function onPlayerResourceStart(startedResource) | |||
local resourceName = getResourceName(startedResource) | |||
local playerName = getPlayerName(source) | |||
local matchingResource = (startedResource == resource) -- 'resource' is predefined variable, see: https://wiki.multitheftauto.com/wiki/Predefined_variables_list#MTA_Predefined_variables | |||
local chatMessage = (resourceName.." has started for "..playerName) | |||
-- | outputChatBox(chatMessage) -- display message when any resource starts for player | ||
if ( | |||
if (not matchingResource) then -- check if startedResource matches current, if it doesn't do not trigger custom event | |||
return false | |||
end | end | ||
end) | |||
triggerClientEvent(source, "onClientCustomEvent", resourceRoot) -- send a custom clientside event defined in this resource, for specific player (source) only | |||
end | |||
addEventHandler("onPlayerResourceStart", root, onPlayerResourceStart) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{See also/Server event|Resource events}} | {{See also/Server event|Resource events}} |
Latest revision as of 17:29, 7 November 2024
This event is triggered when a resource has loaded client-side for a player.
Parameters
resource loadedResource
- loadedResource: The resource that was loaded on the client.
Source
The source of this event is the player who loaded the resource.
Example
This example shows how you can trigger a custom event client-side defined in the same resource as soon as the player is ready (resource loaded on client):
function onPlayerResourceStart(startedResource) local resourceName = getResourceName(startedResource) local playerName = getPlayerName(source) local matchingResource = (startedResource == resource) -- 'resource' is predefined variable, see: https://wiki.multitheftauto.com/wiki/Predefined_variables_list#MTA_Predefined_variables local chatMessage = (resourceName.." has started for "..playerName) outputChatBox(chatMessage) -- display message when any resource starts for player if (not matchingResource) then -- check if startedResource matches current, if it doesn't do not trigger custom event return false end triggerClientEvent(source, "onClientCustomEvent", resourceRoot) -- send a custom clientside event defined in this resource, for specific player (source) only end addEventHandler("onPlayerResourceStart", root, onPlayerResourceStart)
See Also
Resource events
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled