Jump to content

ask about auto restart resource


hamed

Recommended Posts

You can do it by yourself, you only need this:

setTimer(
    function()  
        if getResourceState(yourResource) == "running" then
            restartResource(yourResource)
        end
    end,
600000, 0)

But I don't think this is very optimized if you ask me.

Edited by Peti
Link to comment
On 20/02/2019 at 19:15, Peti said:

Which errors are you getting? Show me your code to see what is happening.

WARNING: autor/server.lua:3: Bad argument @ 'getResourceState' [Expected resource-data at argument 1, got nil]

On 20/02/2019 at 21:02, stPatrick said:

Insert this line somewhere your code:


-- SERVER SIDE
setTimer(restartResource, 600000, 1, getThisResource())


 

just this? or add this on peti rescourse?

On 20/02/2019 at 21:15, Knuck said:

 
setTimer(
    function()  
        createVehicle(ID,X,Y,Z,ROT,etc)
        end
    end,
600000, 0)

Hope this helps!

no men i want a script for automatic restart resource for respawn car maps . you get my mean?

Link to comment
  • Moderators
local selectedResourceName = "" -- < fill in

-- This function will be restarting a selected resource.
local function restartSelectedResource (selectedResource)
	
	local resourceState = getResourceState(selectedResource)
	if resourceState == "running" then
		restartResource(selectedResource)
	elseif resourceState == "loaded" then
		startResource(selectedResource)
	end
	
end

addEventHandler("onResourceStart", resourceRoot, 
function ()
	local selectedResource = getResourceFromName(selectedResourceName)
	if selectedResource then
		setTimer(restartSelectedResource, 600000, 0, selectedResource)
	else
		outputChatBox("Can't find the selected resource.")
		cancelEvent(true, "Can't find the selected resource.")
	end
end)

 

 

 

Make sure the resource has access to these functions

<right name="function.startResource" access="true" />
<right name="function.restartResource" access="true" />
  • startResource
  • restartResource

Those functions are blocked by default because they are used for administration purposes.

 

 

Step 1

The rights can be requested by the resource if you add these lines in to your meta.xml:

<aclrequest>
	<right name="function.startResource" access="true" />
	<right name="function.restartResource" access="true" />
</aclrequest>

 

Step 2

Commands left to do: (fill in the <resourceName> of the resource that contains this script)

/refreshall

/aclrequest allow <resourceName> all

 

 

 

 

 

 

  • Like 1
Link to comment

Or maybe you just want to respawn vehicles with these functions:

setVehicleRespawnPosition -- optional
setTimer
getElementsByType
-- getElementsByType("vehicle", resourceRoot) : to retrieve all vehicles created on the same resource whose function is)
respawnVehicle

 

Edited by DNL291
Link to comment
34 minutes ago, IIYAMA said:

local selectedResourceName = "" -- < fill in

-- This function will be restarting a selected resource.
local function restartSelectedResource (selectedResource)
	
	local resourceState = getResourceState(selectedResource)
	if resourceState == "running" then
		restartResource(selectedResource)
	elseif resourceState == "loaded" then
		startResource(selectedResource)
	end
	
end

addEventHandler("onResourceStart", resourceRoot, 
function ()
	local selectedResource = getResourceFromName(selectedResourceName)
	if selectedResource then
		setTimer(restartSelectedResource, 600000, 0, selectedResource)
	else
		outputChatBox("Can't find the selected resource.")
		cancelEvent(true, "Can't find the selected resource.")
	end
end)


 

 

 

Make sure the resource has access to these functions


<right name="function.startResource" access="true" />
<right name="function.restartResource" access="true" />
  • startResource
  • restartResource

Those functions are blocked by default because they are used for administration purposes.

 

 

Step 1

The rights can be requested by the resource if you add these lines in to your meta.xml:


<aclrequest>
	<right name="function.startResource" access="true" />
	<right name="function.restartResource" access="true" />
</aclrequest>

 

Step 2

Commands left to do: (fill in the <resourceName> of the resource that contains this script)

/refreshall

/aclrequest allow <resourceName> all

 

very ty for help me man . good luck

 

 

 

 

 

Link to comment
On 22/02/2019 at 01:03, IIYAMA said:

local selectedResourceName = "" -- < fill in

-- This function will be restarting a selected resource.
local function restartSelectedResource (selectedResource)
	
	local resourceState = getResourceState(selectedResource)
	if resourceState == "running" then
		restartResource(selectedResource)
	elseif resourceState == "loaded" then
		startResource(selectedResource)
	end
	
end

addEventHandler("onResourceStart", resourceRoot, 
function ()
	local selectedResource = getResourceFromName(selectedResourceName)
	if selectedResource then
		setTimer(restartSelectedResource, 600000, 0, selectedResource)
	else
		outputChatBox("Can't find the selected resource.")
		cancelEvent(true, "Can't find the selected resource.")
	end
end)

 

 

 

Make sure the resource has access to these functions


<right name="function.startResource" access="true" />
<right name="function.restartResource" access="true" />
  • startResource
  • restartResource

Those functions are blocked by default because they are used for administration purposes.

 

 

Step 1

The rights can be requested by the resource if you add these lines in to your meta.xml:


<aclrequest>
	<right name="function.startResource" access="true" />
	<right name="function.restartResource" access="true" />
</aclrequest>

 

Step 2

Commands left to do: (fill in the <resourceName> of the resource that contains this script)

/refreshall

/aclrequest allow <resourceName> all

 

 

 

 

 

this is beter than all i thing

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...