Jump to content

help


Apo

Recommended Posts

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

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

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