restartResource | Multi Theft Auto: Wiki Skip to content

restartResource

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 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.

OOP Syntax Help! I don't understand this!

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 ] )
Required Arguments
  • theResource: the resource you want to restart.
Optional Arguments

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

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

Returns

  • bool: value

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

Code Examples

shared

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