From Multi Theft Auto: Wiki
Jump to navigation Jump to search

This event is triggered when a resource has loaded client-side for a player.


resource loadedResource
  • loadedResource: The resource that was loaded on the client.


The source of this event is the player who loaded the resource.


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

	triggerClientEvent(source, "onClientCustomEvent", resourceRoot) -- send a custom clientside event defined in this resource, for specific player (source) only
addEventHandler("onPlayerResourceStart", root, onPlayerResourceStart)


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