StartResource: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
m (elaborate on persistent)
 
(17 intermediate revisions by 10 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
{{Server function}}
This fake function is for use with blah & blah and does blahblahblabhalbhl
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.
 
The function also allows you to specify a number of boolean options. These allow you to disable the loading of various aspects of the resource. This is generally useful for editors rather than for actual gamemodes. It could also be used as a way to preview a resource before enabling the scripting aspects, though this could produce unreliable results. There is no way for a resource to tell if it is being run with any of these booleans set.


==Syntax==  
==Syntax==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
returnType functionName ( arguments )
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] )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[resource]]:start}}
===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''resourceToStart:''' The resource that should be started.
*'''argumentName:''' description


<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===  
===Optional Arguments===  
{{OptionalArg}}  
{{OptionalArg}}  
*'''argumentName2:''' description
*'''persistent:''' 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.
*'''argumentName3:''' description
*'''startIncludedResources:''' A boolean specifying if the resource's included/dependant resources will be started.
*'''loadServerConfigs:''' A boolean specifying if server side config (XML) files should be loaded with the resource. 
*'''loadMaps:''' A boolean specifying if any .map files will be started with the resource.
*'''loadServerScripts:''' A boolean specifying if server side script files should be started alongside the resource.
*'''loadHTML:''' A boolean specifying if HTML files should be started alongside the resource.
*'''loadClientConfigs:''' A boolean specifying if client configs should be loaded alongside the resource.
*'''loadClientScripts:''' A boolean specifying if client scripts should be loaded and started alongside the resource.
*'''loadFiles:''' A boolean specifying if client-side files should be loaded alongside the resource.


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''true'' if the resource has been started successfully, ''false'' otherwise.
Returns ''true'' if blah, ''false'' otherwise.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example starts a specified resource with the command; "/resource-start".
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function startTheResource ( thePlayer, command, resourceName )
blabhalbalhb --abababa
if ( resourceName ) then -- Check if they specified a resource name
--This line does this...
local resource = getResourceFromName ( resourceName ) -- Get the resource
mooo
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"
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Resource_functions}}
{{FunctionArea_functions}}
[[Category:Incomplete]] -- leave this unless you complete the function

Latest revision as of 21:26, 14 January 2020

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.

The function also allows you to specify a number of boolean options. These allow you to disable the loading of various aspects of the resource. This is generally useful for editors rather than for actual gamemodes. It could also be used as a way to preview a resource before enabling the scripting aspects, though this could produce unreliable results. There is no way for a resource to tell if it is being run with any of these booleans set.

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

OOP Syntax Help! I don't understand this!

Method: resource:start(...)


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. For more information on optional arguments, see optional arguments.

  • persistent: 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: A boolean specifying if the resource's included/dependant resources will be started.
  • loadServerConfigs: A boolean specifying if server side config (XML) files should be loaded with the resource.
  • loadMaps: A boolean specifying if any .map files will be started with the resource.
  • loadServerScripts: A boolean specifying if server side script files should be started alongside the resource.
  • loadHTML: A boolean specifying if HTML files should be started alongside the resource.
  • loadClientConfigs: A boolean specifying if client configs should be loaded alongside the resource.
  • loadClientScripts: A boolean specifying if client scripts should be loaded and started alongside the resource.
  • loadFiles: A boolean specifying if client-side files should be loaded alongside the resource.

Returns

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

Example

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"

See Also