OnPlayerResourceStart: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Update styling of code example, remove ugly spacing)
Line 15: Line 15:
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):
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 10:58, 23 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

This template will be deleted.

See Also

Resource events


Event functions