Apo Posted June 1, 2016 Share Posted June 1, 2016 hi please help me how to make shot down safe command for stop all resource my server and shot down server Link to comment
tosfera Posted June 1, 2016 Share Posted June 1, 2016 you can use stopResource to stop all your resources, you should do it 1 by 1 so they get shut down normally and the event onResourceStop will be called. Save all your data in there, if needed. After that use shutdown to turn the server off. Link to comment
Apo Posted June 1, 2016 Author Share Posted June 1, 2016 my code not work local resourcesToWaitFor = { "admin","account" } local waitingForResources = {} local doShutdown = false addCommandHandler("safeshutdown", function(thePlayer) outputChatBox("Safely shutting down the server...") for k, resourceName in ipairs(resourcesToWaitFor) do local resource = getResourceFromName(resourceName) if(resource)then waitingForResources[resource] = true end end doShutdown = true for resource, resourceWaitState in pairs(waitingForResources) do stopResource(resource) end end, true, false) addEventHandler("onResourceStop", root, function(stoppedResource) if(doShutdown and waitingForResources[stoppedResource])then waitingForResources[stoppedResource] = false for resource, resourceState in pairs(waitingForResources) do if(resourceWaitState)then return false end end shutdown("The server has safely been shutdown.") end end) Link to comment
Gravestone Posted June 6, 2016 Share Posted June 6, 2016 First, add a code to every resource to save the data onResourceStop. When you're done, then add this code to a resource which has the right to command.shutdown: addCommandHandler ( "safeshutdown", function ( player, command, ... ) if ( hasObjectPermissionTo ( player, "function.shutdown" ) ) then local reason = table.concat({...}," ") local resources = getResources() for i,v in ipairs(resources) do stopResource(v) shutdown ( reason or "" ) end end end ) Link to comment
ViRuZGamiing Posted June 6, 2016 Share Posted June 6, 2016 First, add a code to every resource to save the data onResourceStop. When you're done, then add this code to a resource which has the right to command.shutdown: addCommandHandler ( "safeshutdown", function ( player, command, ... ) if ( hasObjectPermissionTo ( player, "function.shutdown" ) ) then local reason = table.concat({...}," ") local resources = getResources() for i,v in ipairs(resources) do stopResource(v) shutdown ( reason or "" ) end end end ) You're shutting down the server every iteration (so 1 resource would stop and then the server would stop) Link to comment
Gravestone Posted June 6, 2016 Share Posted June 6, 2016 I've tried the code, it works fine. Link to comment
Apo Posted June 7, 2016 Author Share Posted June 7, 2016 how to First, add a code to every resource to save the data onResourceStop? Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now