Jump to content

Resource Stop Priority


Rouzbeh

Recommended Posts

hi

i have this problem when shutting down server:

  
ERROR: work\server.lua:27: exports: Call to non-running server resource (sql) [string "?"] 
ERROR: afk\Server.lua:49: exports: Call to non-running server resource (sql) [string "?"] 
  

i am using mysql saving system and in sql resource connect to mysql...

so how i can prevent this error?

Edited by Guest
Link to comment
Are you sure it's named 'sql' and it is running for sure? The error message clearly states it isn't running.

come on!!!...

i Said when i shutting Down Server so all resources stop ...

i add "onResourceStop" event to save data to database, im not noob at all, but i just looking for a way can set a resource stop at last as others when i shut down mta server!

  
Server stopped! 
[2016-01-03 03:06:15] Stopping resources................................................. 
[2016-01-03 03:06:19] ERROR: work\server.lua:27: exports: Call to non-running server resource (sql) [string "?"] 
[2016-01-03 03:06:19] ERROR: afk\Server.lua:49: exports: Call to non-running server resource (sql) [string "?"] 
[2016-01-03 03:06:27] Closing SQLite3 database 
  

here sql resource stoped before 'work' and 'afk' resources so "onResourceStop" could'nt do export.sql:something()...

i want set 'sql' Resource close after all resources

Link to comment

The best way to do it is probably to create a command that saves data (maybe stopping work and afk resource first?) and then closes the server.

Something like this:

local resourcesToWaitFor = { "work", "afk" } 
local waitingForResources = {} 
local doShutdown = false 
  
addCommandHandler("safeshutdown", 
function(player) 
    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) 

Make sure the resource has the rights to use the shutdown function, etc.

Link to comment
The best way to do it is probably to create a command that saves data (maybe stopping work and afk resource first?) and then closes the server.

Something like this:

local resourcesToWaitFor = { "work", "afk" } 
local waitingForResources = {} 
local doShutdown = false 
  
addCommandHandler("safeshutdown", 
function(player) 
    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) 

Make sure the resource has the rights to use the shutdown function, etc.

ow very thanks, finally... u got my means :x

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