Jump to content

ask about auto restart resource


hamed

Recommended Posts

Posted (edited)

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

Scripts

1. Mission: Pizza delivery [OPEN SOURCE]

Posted (edited)

Thx

On 15/02/2019 at 05:18, Peti said:

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.

He Dont Work Man :(

Edited by hamed
ss
Posted
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?

  • Moderators
Posted
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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted (edited)

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

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
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

 

 

 

 

 

Posted
18 hours ago, DNL291 said:

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

 

Isn't using these better?

toggleVehicleRespawn
setVehicleRespawnDelay
setVehicleIdleRespawnDelay

Lua Scripter

?ucet=miki_cz

Owner of mshost.cz MTA portal.

Posted
6 hours ago, MIKI785 said:

He said "respawn cars every 10 minutes", so I understood that he wants to respawn even if the vehicle is not idle or blown.

But for some reason, it looks like he just wants the resource to be restarted so ..

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
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

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