Jump to content

Jail save =\


Dice

Recommended Posts

Posted
addEventHandler ( "onPlayerQuit", root,  
    function() 
        if getElementData ( source, "jailed" ) == true then 
            cur_jails = xmlFindChild ( jaildata, "CurrentJails", 0 ) 
            local crooks = xmlCreateChild ( cur_jails, "Crook" ) 
            local left, x, e = getTimerDetails ( runningTimers[source][newTabPos] ) 
            xmlNodeSetAttribute ( crooks, "name", getPlayerName ( source ) ) 
            xmlNodeSetAttribute ( crooks, "serial", getPlayerSerial ( source ) ) 
            xmlNodeSetAttribute ( crooks, "TimeLeft", left ) 
            setElementData ( source, "jailed", false ) 
            killTimer ( runningTimers[source][newTabPos] ) 
            xmlSaveFile ( jaildata ) 
        end 
    end ) 
     
loadedCrooks = {} 
  
function joinData() 
    local currentJails = xmlFindChild ( jaildata, "CurrentJails", 0 ) 
    local currentCrooks = xmlNodeGetChildren ( currentJails ) 
    if currentCrooks then 
        for i, crook in ipairs ( currentCrooks ) do 
            for name, value in ipairs ( xmlNodeGetAttributes ( crook ) ) do 
                outputChatBox ( name .. " = " .. value ) 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerJoin", root, joinData ) 

I have this script with the jail when a player quits and they are jailed,

it creates something like this...

<Crook name="sss" serial="xxxxxxxxxxxxxxxxxxxxxxxxxxxx" TimeLeft="149935"></Crook> 
        <Crook name="avc" serial="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" TimeLeft="152974"></Crook> 
        <Crook name="sccss" serial="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" TimeLeft="111436"></Crook> 

Posted

it doesnt work,,, idk how to read all the crooks children and on top of that get all the attributes for them, yes i know which ones to use but idk how to set it up.

Posted
it doesnt work,,, idk how to read all the crooks children and on top of that get all the attributes for them, yes i know which ones to use but idk how to set it up.

try this

function saveData(player) 
        if getElementData ( player, "jailed" ) == true then 
            cur_jails = xmlFindChild ( jaildata, "CurrentJails", 0 ) 
            local crooks = xmlCreateChild ( cur_jails, "Crook" ) 
            local left, x, e = getTimerDetails ( runningTimers[source][newTabPos] ) 
            xmlNodeSetAttribute ( crooks, "name", getPlayerName ( source ) ) 
            xmlNodeSetAttribute ( crooks, "serial", getPlayerSerial ( source ) ) 
            xmlNodeSetAttribute ( crooks, "TimeLeft", left ) 
            setElementData ( player, "jailed", false ) 
            killTimer ( runningTimers[source][newTabPos] ) 
            xmlSaveFile ( jaildata ) 
        end 
    end 
addEventHandler ( "onPlayerQuit", root, saveData) 
    
loadedCrooks = {} 
  
function joinData() 
    local currentJails = xmlFindChild ( jaildata, "CurrentJails", 0 ) 
    local currentCrooks = xmlNodeGetChildren ( currentJails ) 
    if currentCrooks then 
        for i, crook in ipairs ( currentCrooks ) do 
            for name, value in ipairs ( xmlNodeGetAttributes ( crook ) ) do 
                outputChatBox ( name .. " = " .. value ) 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerJoin", root, joinData ) 

I sleep xD..

Posted
oh, i'm not getting any errors if thats what u mean, but it is defined, on the top of my script.

You should define it each time an player quit/join to the server, because in the end of the event, you closing it with xmlSaveFile.

@ZL|LuCaS, onPlayerQuit don't have player parameter.

Posted
oh, i'm not getting any errors if thats what u mean, but it is defined, on the top of my script.

You should define it each time an player quit/join to the server, because in the end of the event, you closing it with xmlSaveFile.

@ZL|LuCaS, onPlayerQuit don't have player parameter.

lol. and truth and I'm sleepy bye..

Posted

yes, but I never unload it, unless the resource stops, and if it starts it loads it. all its doing is saving it

Posted

Make sure the XML is on server side, otherwise the client can just edit his/her jail time. I recommend using MySQL or SQL, because XML can cause server lag, if the file contains to much data.

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