startResource | Multi Theft Auto: Wiki Skip to content

startResource

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function starts a resource either persistently or as a dependency of the current resource. If you start the resource persistently, the resource will run until stopped either using stopResource or by the server admin. A resource started as a dependency will stop when your resource stops, if no other resources have it as a depdendency. This is the same effect as using an include in your meta.xml file.

OOP Syntax Help! I don't understand this!

Syntax

bool startResource ( resource resourceToStart, [ bool persistent = false, bool startIncludedResources = true, bool loadServerConfigs = true, bool loadMaps = true, bool loadServerScripts = true, bool loadHTML = true, bool loadClientConfigs = true, bool loadClientScripts = true, bool loadFiles = true ] )
Required Arguments
  • resourceToStart: The resource that should be started.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • persistent (default: false): A boolean specifying if the resource should continue to run even after the current resource has been stopped or not. If this is true then the resource will run until another resource or user terminates it or the server shuts down. If this is false then resourceToStart will stop when thisResource stops.
  • startIncludedResources (default: true): A boolean specifying if the resource's included/dependant resources will be started.
  • loadServerConfigs (default: true): A boolean specifying if server side config (XML) files should be loaded with the resource.
  • loadMaps (default: true): A boolean specifying if any .map files will be started with the resource.
  • loadServerScripts (default: true): A boolean specifying if server side script files should be started alongside the resource.
  • loadHTML (default: true): A boolean specifying if HTML files should be started alongside the resource.
  • loadClientConfigs (default: true): A boolean specifying if client configs should be loaded alongside the resource.
  • loadClientScripts (default: true): A boolean specifying if client scripts should be loaded and started alongside the resource.
  • loadFiles (default: true): A boolean specifying if client-side files should be loaded alongside the resource.

Returns

  • bool: value

Returns true if the resource has been started successfully, false otherwise.

Code Examples

shared

This example starts a specified resource with the command; "/resource-start".

function startTheResource ( thePlayer, command, resourceName )
if ( resourceName ) then -- Check if they specified a resource name
local resource = getResourceFromName ( resourceName ) -- Get the resource
local start = startResource ( resource ) -- Start the resource
if ( start ) then -- If it was successfully started...
outputChatBox ( resourceName .. " was started successfully.", thePlayer, 255, 0, 0 )
else -- If it wasn't successfully started...
outputChatBox ( "This resource doesn't exist.", thePlayer, 255, 0, 0 )
end
else -- If they didn't put a resource name...
outputChatBox ( "Please specify a resource to start.", thePlayer, 255, 0, 0 )
end
end
addCommandHandler ( "resource-start", startTheResource ) -- Make it trigger when somebody types "/resource-start"