RestartResource: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(23 intermediate revisions by 14 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server function}}
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
__NOTOC__
This fake function is for use with blah & blah and does blahblahblabhalbhl
This function restarts a running resource. Restarting will destroy all the elements that the resource has created (as stopping the resource does).
{{Note|
*Don't forget to give admin rights to the resource, in which you are using restartResource function or it won't work.
*This function does not restart the resource immediately. Restarts are queued up until the end of the server's frame to ensure that they occur in the correct order (and that dependent resources can start and stop correctly). The resource being restarted will have an [[onResourceStop]] event triggered and the restarted instance will receive an [[onResourceStart]] event. Remember that the element and resource variables will be invalidated during the restart, though of course, the resource's name will not.}}


==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">
resource getThisResource ( )
bool restartResource ( resource theResource [, bool persistent = false, bool configs = true, bool maps = true, bool scripts = true, bool html = true, bool clientConfigs = true, bool clientScripts = true, bool clientFiles = true ] )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[resource]]:restart}}
===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 -->
*'''theResource:''' the [[resource]] you want to restart.
*'''argumentName:''' description


<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===
===Optional Arguments===  
*'''persistent:''' Unused
{{OptionalArg}}
*'''configs:''' Reload configs?
*'''argumentName2:''' description
*'''maps:''' Reload maps?
*'''argumentName3:''' description
*'''scripts:''' Reload (server) scripts?
*'''html:''' Reload html files (for resource web access)?
*'''clientConfigs:''' Reload client configs?
*'''clientScripts:''' Reload client scripts?
*'''clientFiles:''' Reload files?


===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 was restarted, ''false'' if the resource wasn't running, or an invalid resource was passed.
Returns ''true'' if blah, ''false'' otherwise. <br \>
false on fail


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
Example 1: This function restarts all running resources.
This example does...
<syntaxhighlight lang="lua">
<!-- 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 -->
function restartAllResources()
-- we store a table of resources
local allResources = getResources()
-- for each one of them,
for index, res in ipairs(allResources) do
-- if it's running,
if getResourceState(res) == "running" then
-- then restart it
restartResource(res)
end
end
end
</syntaxhighlight>
 
Example 2: This example will restart the specify resource every 3600000 milliseconds (hour).
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
setTimer(
blabhalbalhb --abababa
    function() 
--This line does this...
--restarting this resource every hour
mooo
        restartResource(getThisResource())
    end,
3600000, 0)
</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|server}}
{{FunctionArea_functions}}
[[Category:Incomplete]] -- leave this unless you complete the function

Latest revision as of 22:48, 6 September 2024

This function restarts a running resource. Restarting will destroy all the elements that the resource has created (as stopping the resource does).

[[{{{image}}}|link=|]] Note:
  • Don't forget to give admin rights to the resource, in which you are using restartResource function or it won't work.
  • This function does not restart the resource immediately. Restarts are queued up until the end of the server's frame to ensure that they occur in the correct order (and that dependent resources can start and stop correctly). The resource being restarted will have an onResourceStop event triggered and the restarted instance will receive an onResourceStart event. Remember that the element and resource variables will be invalidated during the restart, though of course, the resource's name will not.

Syntax

bool restartResource ( resource theResource [, bool persistent = false, bool configs = true, bool maps = true, bool scripts = true, bool html = true, bool clientConfigs = true, bool clientScripts = true, bool clientFiles = true ] )

OOP Syntax Help! I don't understand this!

Method: resource:restart(...)


Required Arguments

  • theResource: the resource you want to restart.

Optional Arguments

  • persistent: Unused
  • configs: Reload configs?
  • maps: Reload maps?
  • scripts: Reload (server) scripts?
  • html: Reload html files (for resource web access)?
  • clientConfigs: Reload client configs?
  • clientScripts: Reload client scripts?
  • clientFiles: Reload files?

Returns

Returns true if the resource was restarted, false if the resource wasn't running, or an invalid resource was passed.

Example

Example 1: This function restarts all running resources.

function restartAllResources()
	-- we store a table of resources
	local allResources = getResources()
	-- for each one of them,
	for index, res in ipairs(allResources) do
		-- if it's running,
		if getResourceState(res) == "running" then
			-- then restart it
			restartResource(res)
		end
	end
end

Example 2: This example will restart the specify resource every 3600000 milliseconds (hour).

setTimer(
    function()  
	--restarting this resource every hour
        restartResource(getThisResource())
    end,
3600000, 0)

See Also