OnPlayerResourceStart: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (typo)
No edit summary
Line 1: Line 1:
{{Server event}}
{{Server event}}
{{Added feature/item|3.0159|1.5.8|1.5.8|20957|This event is triggered when a [[resource]] has loaded clientside for a [[player]]}}
{{Added feature/item|3.0159|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 clientside defined in the same resource as soon as the player is ready (resource loaded on client).
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">
addEventHandler("onPlayerResourceStart", root, function(loadedResource)
addEventHandler ("onPlayerResourceStart", root, function (loadedResource)
outputChatBox(getResourceName(loadedResource) .. " started for " .. getPlayerName(source))
outputChatBox (getResourceName (loadedResource) .. " started for " .. getPlayerName (source))


-- Trigger a custom clientside event defined in this resource
-- Trigger a custom clientside event defined in this resource
if (getResourceRootElement(loadedResource) == resourceRoot) then
if getResourceRootElement (loadedResource) == resourceRoot then
triggerClientEvent(source, "onClientCustomEvent", resourceRoot)  
triggerClientEvent (source, "onClientCustomEvent", resourceRoot)  
end
end
end)
end)

Revision as of 17:07, 20 September 2021

20957

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):

addEventHandler ("onPlayerResourceStart", root, function (loadedResource)
	outputChatBox (getResourceName (loadedResource) .. " started for " .. getPlayerName (source))

	-- Trigger a custom clientside event defined in this resource
	if getResourceRootElement (loadedResource) == resourceRoot then
		triggerClientEvent (source, "onClientCustomEvent", resourceRoot) 
	end
end)

Requirements

Minimum server version 1.5.8-9.20957
Minimum client version n/a

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.5.8-9.20957" />

See Also

Resource events


Event functions