Jump to content

[HELP] PlayTime Save


1LoL1

Recommended Posts

Please could someone do this to add scripts save system? when is disconnected, log in, restart the script so I will delete playtime.. and I would like it so that when I disconnect, log in, restart the script so I'm saved. Please.

Here is script:

exports.scoreboard:addScoreboardColumn('PlayTime') 
  
local t = { } 
  
function checkValues( source,arg1,arg2) 
    if (arg2 >= 60) then 
        t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 
        t[ source ][ 'sec' ] = 0 
    end 
    if (arg1 >= 60) then 
        t[ source ][ 'min' ] = 0 
        t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 
    end 
    return arg1, arg2 
end 
      
setTimer( 
    function( ) 
        for _, v in pairs( getElementsByType( "player" ) ) do 
            if (not t[ v ]) then 
                t[ v ] = { 
                            ["hour"] = 0, 
                             ["min"] = 0, 
                             ["sec"] = 0 
                            } 
            end 
  
            t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 
            local min,sec = checkValues ( 
                    v, 
                    t[ v ][ 'min' ] or 0, 
                    t[ v ][ 'sec' ] or 0 
                        )   
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
  
            setElementData( 
                v, 
                "PlayTime", 
                tostring( hour )..':'..tostring( min )..':'..tostring( sec ) 
            ) 
        end 
    end, 
    1000, 0 
) 
    
function onPlayerQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
        local sValue = getElementData( source,'PlayTime' ) 
        setAccountData ( playeraccount, "PlayTime", tostring(sValue) ) 
    end 
    t[ source ] = nil 
end 
  
function onPlayerLogin (_, playeraccount ) 
    if ( playeraccount ) then 
        local time = getAccountData ( playeraccount, "PlayTime" ) 
        if ( time ) then 
            setElementData ( source, "PlayTime", time ) 
                else 
            setElementData ( source, "PlayTime",0 ) 
        setAccountData ( playeraccount, "PlayTime",0 ) 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) 

Edited by Guest
Link to comment

I used this:

addEventHandler ( "onResourceStart" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local minutes = getAccountData ( pAccount , "Online.minutes" ) 
                if minutes then 
                    local hours = getAccountData ( pAccount , "Online.hours" ) 
                    if # tostring ( minutes ) == 1 then 
                        minutes = "0" .. minutes 
                    end 
                    if # tostring ( hours ) == 1 then 
                        hours = "0" .. hours 
                    end 
                    setElementData ( player , "Online" , hours .. ":" .. minutes .. ":00" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                else 
                    setAccountData ( pAccount , "Online.minutes" , 0 ) 
      
              setAccountData ( pAccount , "Online.hours" , 0 ) 
                    setElementData ( player , "Online" , "00:00:00" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                end 
            else 
                setElementData ( player , "Online" , "N/A" ) 
            end 
        end 
    end 
) 
  
addEventHandler ( "onResourceStop" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local timer = getElementData ( player , "Online.timer" ) 
                if isTimer ( timer ) then 
                    killTimer ( timer ) 
                end 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerLogin" , root , 
    function ( _ , pAccount ) 
        local minutes = getAccountData ( pAccount , "Online.minutes" ) 
        if minutes then 
            local hours = getAccountData ( pAccount , "Online.hours" ) 
            if # tostring ( minutes ) == 1 then 
                minutes = "0" .. minutes 
            end 
            if # tostring ( hours ) == 1 then 
                hours = "0" .. hours 
            end 
            setElementData ( source , "Online" , hours .. ":" .. minutes .. ":00" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        else 
            setAccountData ( pAccount , "Online.minutes" , 0 ) 
            setAccountData ( pAccount , "Online.hours" , 0 ) 
            setElementData ( source , "Online" , "00:00:00" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerLogout" , root , 
    function ( pAccount ) 
        local timer = getElementData ( source , "Online.timer" ) 
        if isTimer ( timer ) then 
            killTimer ( timer ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerJoin" , root , 
    function ( ) 
        setElementData ( source , "Online" , "N/A" ) 
    end 
) 
  
addEventHandler ( "onPlayerQuit" , root , 
    function ( ) 
        local pAccount = getPlayerAccount ( source ) 
        if not isGuestAccount ( pAccount ) then 
            local timer = getElementData ( source , "Online.timer" ) 
            if isTimer ( timer ) then 
                killTimer ( timer ) 
            end 
        end 
    end 
) 
  
function updatePlayerOnline ( player ) 
    local pAccount = getPlayerAccount ( player ) 
    local minutes = getAccountData ( pAccount , "Online.minutes" ) 
    local hours = getAccountData ( pAccount , "Online.hours" ) 
    minutes = tostring ( tonumber ( minutes ) + 1 ) 
    if minutes == "60" then 
        hours = tostring ( tonumber ( hours ) + 1 ) 
        minutes = "00" 
    end 
    setAccountData ( pAccount , "Online.minutes" , tonumber ( minutes ) ) 
    setAccountData ( pAccount , "Online.hours" , tonumber ( hours ) ) 
    if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end 
    if # tostring ( hours ) == 1 then hours = "0" .. hours end 
    setElementData ( player , "Online" , hours .. ":" .. minutes .. ":00" ) 
    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
    setElementData ( player , "Online.timer" , timer ) 
end 

but how to edit to 4:40:40 time? or 0:00:00.

Link to comment
Don't show seconds, you'll have to update element data each second for every player in the server, so useless yet so costly.

You already have hours and minutes, just construct a string out of them.

Edited but again not work :(

addEventHandler ( "onResourceStart" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local seconds = getAccountData ( pAccount , "Online.seconds" ) 
                if seconds then 
                local minutes = getAccountData ( pAccount , "Online.minutes" ) 
                if minutes then 
                    local hours = getAccountData ( pAccount , "Online.hours" ) 
                    if # tostring ( seconds ) == 1 then 
                        seconds = "0" .. seconds 
                    end 
                    if # tostring ( minutes ) == 1 then 
                        minutes = "0" .. minutes 
                    end 
                    if # tostring ( hours ) == 1 then 
                        hours = "0" .. hours 
                    end 
                    setElementData ( player , "Online" , hours .. ":" .. minutes .. ":" .. seconds .. "" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                else 
                    setAccountData ( pAccount , "Online.seconds" , 0 ) 
                    setAccountData ( pAccount , "Online.minutes" , 0 ) 
      
              setAccountData ( pAccount , "Online.hours" , 0 ) 
                    setElementData ( player , "Online" , "00:00:00" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                end 
            else 
                setElementData ( player , "Online" , "N/A" ) 
            end 
        end 
    end 
) 
  
addEventHandler ( "onResourceStop" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local timer = getElementData ( player , "Online.timer" ) 
                if isTimer ( timer ) then 
                    killTimer ( timer ) 
                end 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerLogin" , root , 
    function ( _ , pAccount ) 
        local seconds = getAccountData ( pAccount , "Online.seconds" ) 
        if seconds then 
        local minutes = getAccountData ( pAccount , "Online.minutes" ) 
        if minutes then 
            local hours = getAccountData ( pAccount , "Online.hours" ) 
            if # tostring ( seconds ) == 1 then 
                minutes = "0" .. minutes 
            end 
            if # tostring ( minutes ) == 1 then 
                minutes = "0" .. minutes 
            end 
            if # tostring ( hours ) == 1 then 
                hours = "0" .. hours 
            end 
            setElementData ( source , "Online" , hours .. ":" .. minutes .. ":" .. seconds .."" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        else 
            setAccountData ( pAccount , "Online.seconds" , 0 ) 
            setAccountData ( pAccount , "Online.minutes" , 0 ) 
            setAccountData ( pAccount , "Online.hours" , 0 ) 
            setElementData ( source , "Online" , "00:00:00" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerLogout" , root , 
    function ( pAccount ) 
        local timer = getElementData ( source , "Online.timer" ) 
        if isTimer ( timer ) then 
            killTimer ( timer ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerJoin" , root , 
    function ( ) 
        setElementData ( source , "Online" , "N/A" ) 
    end 
) 
  
addEventHandler ( "onPlayerQuit" , root , 
    function ( ) 
        local pAccount = getPlayerAccount ( source ) 
        if not isGuestAccount ( pAccount ) then 
            local timer = getElementData ( source , "Online.timer" ) 
            if isTimer ( timer ) then 
                killTimer ( timer ) 
            end 
        end 
    end 
) 
  
function updatePlayerOnline ( player ) 
    local pAccount = getPlayerAccount ( player ) 
    local seconds = getAccountData ( pAccount , "Online.seconds" ) 
    local minutes = getAccountData ( pAccount , "Online.minutes" ) 
    local hours = getAccountData ( pAccount , "Online.hours" ) 
    seconds = tostring ( tonumber ( seconds ) + 1 ) 
    if seconds == "60" then 
    minutes = tostring ( tonumber ( minutes ) + 1 ) 
    if minutes == "60" then 
        hours = tostring ( tonumber ( hours ) + 1 ) 
        minutes = "00" 
    end 
    setAccountData ( pAccount , "Online.seconds" , tonumber ( seconds ) ) 
    setAccountData ( pAccount , "Online.minutes" , tonumber ( minutes ) ) 
    setAccountData ( pAccount , "Online.hours" , tonumber ( hours ) ) 
    if # tostring ( seconds ) == 1 then seconds = "0" .. seconds end 
    if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end 
    if # tostring ( hours ) == 1 then hours = "0" .. hours end 
    setElementData ( player , "Online" , hours .. ":" .. minutes .. ":" .. seconds .. "" ) 
    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
    setElementData ( player , "Online.timer" , timer ) 
end 

Link to comment
What doesn't work exactly? You need to tell us if there is any errors in /debugscript 3, and what happens and what doesn't.

Here is error:

ERROR: Loading script failed: [gameplay]/PlayTime/playtime.lua:130: "end" expected (to close "function" at line 53) near ""

Link to comment
addEventHandler ( "onResourceStart" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local seconds = getAccountData ( pAccount , "Online.seconds" ) 
                if seconds then 
                local minutes = getAccountData ( pAccount , "Online.minutes" ) 
                if minutes then 
                    local hours = getAccountData ( pAccount , "Online.hours" ) 
                    if # tostring ( seconds ) == 1 then 
                        seconds = "0" .. seconds 
                    end 
                    if # tostring ( minutes ) == 1 then 
                        minutes = "0" .. minutes 
                    end 
                    if # tostring ( hours ) == 1 then 
                        hours = "0" .. hours 
                    end 
                    setElementData ( player , "Online" , hours .. ":" .. minutes .. ":" .. seconds .. "" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                else 
                    setAccountData ( pAccount , "Online.seconds" , 0 ) 
                    setAccountData ( pAccount , "Online.minutes" , 0 ) 
      
              setAccountData ( pAccount , "Online.hours" , 0 ) 
                    setElementData ( player , "Online" , "00:00:00" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                end 
            else 
                setElementData ( player , "Online" , "N/A" ) 
            end 
        end 
    end 
end) 
  
addEventHandler ( "onResourceStop" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local timer = getElementData ( player , "Online.timer" ) 
                if isTimer ( timer ) then 
                    killTimer ( timer ) 
                end 
            end 
        end 
    end) 
  
addEventHandler ( "onPlayerLogin" , root , 
    function ( _ , pAccount ) 
        local seconds = getAccountData ( pAccount , "Online.seconds" ) 
        if seconds then 
        local minutes = getAccountData ( pAccount , "Online.minutes" ) 
        if minutes then 
            local hours = getAccountData ( pAccount , "Online.hours" ) 
            if # tostring ( seconds ) == 1 then 
                minutes = "0" .. minutes 
            end 
            if # tostring ( minutes ) == 1 then 
                minutes = "0" .. minutes 
            end 
            if # tostring ( hours ) == 1 then 
                hours = "0" .. hours 
            end 
            setElementData ( source , "Online" , hours .. ":" .. minutes .. ":" .. seconds .."" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        else 
            setAccountData ( pAccount , "Online.seconds" , 0 ) 
            setAccountData ( pAccount , "Online.minutes" , 0 ) 
            setAccountData ( pAccount , "Online.hours" , 0 ) 
            setElementData ( source , "Online" , "00:00:00" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        end 
    end 
end) 
  
addEventHandler ( "onPlayerLogout" , root , 
    function ( pAccount ) 
        local timer = getElementData ( source , "Online.timer" ) 
        if isTimer ( timer ) then 
            killTimer ( timer ) 
        end 
    end) 
  
addEventHandler ( "onPlayerJoin" , root , 
    function ( ) 
        setElementData ( source , "Online" , "N/A" ) 
    end) 
  
addEventHandler ( "onPlayerQuit" , root , 
    function ( ) 
        local pAccount = getPlayerAccount ( source ) 
        if not isGuestAccount ( pAccount ) then 
            local timer = getElementData ( source , "Online.timer" ) 
            if isTimer ( timer ) then 
                killTimer ( timer ) 
            end 
        end 
    end) 
  
function updatePlayerOnline ( player ) 
    local pAccount = getPlayerAccount ( player ) 
    local seconds = getAccountData ( pAccount , "Online.seconds" ) 
    local minutes = getAccountData ( pAccount , "Online.minutes" ) 
    local hours = getAccountData ( pAccount , "Online.hours" ) 
    seconds = tostring ( tonumber ( seconds ) + 1 ) 
    if seconds == "60" then 
    minutes = tostring ( tonumber ( minutes ) + 1 ) 
    end 
    if minutes == "60" then 
        hours = tostring ( tonumber ( hours ) + 1 ) 
        minutes = "00" 
    end 
    setAccountData ( pAccount , "Online.seconds" , tonumber ( seconds ) ) 
    setAccountData ( pAccount , "Online.minutes" , tonumber ( minutes ) ) 
    setAccountData ( pAccount , "Online.hours" , tonumber ( hours ) ) 
    if # tostring ( seconds ) == 1 then seconds = "0" .. seconds end 
    if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end 
    if # tostring ( hours ) == 1 then hours = "0" .. hours end 
    setElementData ( player , "Online" , hours .. ":" .. minutes .. ":" .. seconds .. "" ) 
    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
    setElementData ( player , "Online.timer" , timer ) 
end 

Link to comment
Having a timer for each player is a terrible idea, worst if it's server-side, timers are terrible when it comes to performance.

If I were you, I would use a single timer to update everyone's online time.

And here you know add Save System?

exports.scoreboard:addScoreboardColumn('Online Time') 
  
local t = { } 
  
function checkValues( source,arg1,arg2) 
    if (arg2 >= 60) then 
        t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 
        t[ source ][ 'sec' ] = 0 
    end 
    if (arg1 >= 60) then 
        t[ source ][ 'min' ] = 0 
        t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 
    end 
    return arg1, arg2 
end 
      
setTimer( 
    function( ) 
        for _, v in pairs( getElementsByType( "player" ) ) do 
            if (not t[ v ]) then 
                t[ v ] = { 
                            ["hour"] = 0, 
                             ["min"] = 0, 
                             ["sec"] = 0 
                            } 
            end 
  
            t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 
            local min,sec = checkValues ( 
                    v, 
                    t[ v ][ 'min' ] or 0, 
                    t[ v ][ 'sec' ] or 0 
                        )   
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
  
            setElementData( 
                v, 
                "Online Time", 
                tostring( hour )..':'..tostring( min )..':'..tostring( sec ) 
            ) 
        end 
    end, 
    1000, 0 
) 
    
function onPlayerQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
        local sValue = getElementData( source,'Online Time' ) 
        setAccountData ( playeraccount, "Online Time", tostring(sValue) ) 
    end 
    t[ source ] = nil 
end 
  
function onPlayerLogin (_, playeraccount ) 
    if ( playeraccount ) then 
        local time = getAccountData ( playeraccount, "Online Time" ) 
        if ( time ) then 
            setElementData ( source, "Online Time", time ) 
                else 
            setElementData ( source, "Online Time",0 ) 
        setAccountData ( playeraccount, "Online Time",0 ) 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) 

Link to comment

try this

and yeah it is work

:)

-- # Server Side : 
--[[ 
------------------------------------------------- 
original script 
credits to Yakuza.Real and solidsnake and kenix 
viewtopic.php?f=91&t=40132 
  
------------------------------------------------- 
  
booo just fix it  
Mr.Pres[T]ege : 
  
Remake the script using ( SQL ) To Save it . 
  
]] 
exports.scoreboard:addScoreboardColumn('PlayTime') 
  
addEventHandler("onResourceStart",resourceRoot, 
    function (      ) 
            executeSQLQuery ( "CREATE TABLE IF NOT EXISTS Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime )" ) 
            outputDebugString ("Execute SQL Loadded !") 
    end 
) 
local t = { } 
  
function checkValues( source,arg1,arg2) 
    if (arg2 >= 60) then 
        t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 
        t[ source ][ 'sec' ] = 0 
    end 
    if (arg1 >= 60) then 
        t[ source ][ 'min' ] = 0 
        t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 
    end 
    return arg1, arg2 
end 
      
setTimer( 
    function( ) 
        for _, v in pairs( getElementsByType( "player" ) ) do 
            if (not t[ v ]) then 
                t[ v ] = { 
                            ["hour"] = 0, 
                             ["min"] = 0, 
                             ["sec"] = 0 
                            } 
            end 
            t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 
            local min,sec = checkValues ( 
                    v, 
                    t[ v ][ 'min' ] or 0, 
                    t[ v ][ 'sec' ] or 0 
                        )   
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
  
            setElementData( 
                v, 
                "PlayTime", 
                tostring( hour )..':'..tostring( min )..':'..tostring( sec ) 
            ) 
        end 
    end, 
    1000, 0 
) 
    
function SaveDataOnQuit (  ) 
    local sValue = getElementData( source,'PlayTime' ) 
    local hour = tonumber( t[ source ][ 'hour' ] or 0 ) 
    local min = tonumber( t[ source ][ 'min' ] or 0 ) 
    local sec = tonumber( t[ source ][ 'sec' ] or 0 ) 
    local serial = getPlayerSerial ( source ) 
    local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",serial) 
     if ( type ( Results ) == "table" and #Results == 0 or not Results ) then 
        executeSQLQuery ( "INSERT INTO Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)",serial,hour,min,sec,sValue ) 
    else 
        executeSQLQuery('UPDATE Prestege_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerSerial =?', hour, min, sec, sValue, serial) 
    end 
    t[ source ] = nil 
end 
addEventHandler("onPlayerQuit",root,SaveDataOnQuit) 
  
function SaveDataOnStop (  )  
 for k,v in ipairs ( getElementsByType("player") ) do 
    local playeraccount = getPlayerAccount ( v ) 
    local sValue = getElementData( v,'PlayTime' ) 
    if not ( t [ v ] ) then 
        t [ v ]  = {    } 
    end 
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
    local min = tonumber( t[ v ][ 'min' ] or 0 ) 
    local sec = tonumber( t[ v ][ 'sec' ] or 0 ) 
    local serial = getPlayerSerial ( v ) 
     local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( v ) ) 
     if ( type ( Results ) == "table" and #Results == 0 or not Results ) then 
        executeSQLQuery ( "INSERT INTO Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)",serial,hour,min,sec,sValue ) 
    else 
        executeSQLQuery('UPDATE Prestege_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerSerial =?', hour, min, sec, sValue, serial) 
        end  
    end 
end 
addEventHandler("onResourceStop",resourceRoot,SaveDataOnStop) 
  
function GetDataOnStart ( ) 
 for _,v in ipairs ( getElementsByType ( "player" ) ) do 
 local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( v ) ) 
    if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end 
   if not t[ v ] then 
    t[ v ] = {} 
   end 
        t[ v ]["hour"] = tonumber(Results[1]["Hours"]) 
        t[ v ]["min"] = tonumber(Results[1]["Minuts"]) 
        t[ v ]["sec"] = tonumber(Results[1]["Seconds"]) 
    end 
end 
addEventHandler("onResourceStart",resourceRoot,GetDataOnStart) 
  
function GetDataOnJoin (    ) 
    local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( source ) ) 
    if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end 
            setElementData ( source, "PlayTime", Results[1]["PlayAllTime"] ) 
               if not t[ source ] then 
                    t[ source ] = {} 
                end 
            t[ source ]["hour"] = tonumber(Results[1]["Hours"]) 
            t[ source ]["min"] = tonumber(Results[1]["Minuts"]) 
            t[ source ]["sec"] = tonumber(Results[1]["Seconds"]) 
    end 
addEventHandler("onPlayerJoin",root,GetDataOnJoin) 

تنبية بسيط #

اتصال بالقاعدهـ فـ من الممكن بـ نسبة 85 % انة يسبب لاق يعني مو لازم حساب يحفظ بـ السريال عدلت المود بـ نسبة 60 %

Link to comment
try this

and yeah it is work

:)

-- # Server Side : 
--[[ 
------------------------------------------------- 
original script 
credits to Yakuza.Real and solidsnake and kenix 
viewtopic.php?f=91&t=40132 
  
------------------------------------------------- 
  
booo just fix it  
Mr.Pres[T]ege : 
  
Remake the script using ( SQL ) To Save it . 
  
]] 
exports.scoreboard:addScoreboardColumn('PlayTime') 
  
addEventHandler("onResourceStart",resourceRoot, 
    function (      ) 
            executeSQLQuery ( "CREATE TABLE IF NOT EXISTS Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime )" ) 
            outputDebugString ("Execute SQL Loadded !") 
    end 
) 
local t = { } 
  
function checkValues( source,arg1,arg2) 
    if (arg2 >= 60) then 
        t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 
        t[ source ][ 'sec' ] = 0 
    end 
    if (arg1 >= 60) then 
        t[ source ][ 'min' ] = 0 
        t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 
    end 
    return arg1, arg2 
end 
      
setTimer( 
    function( ) 
        for _, v in pairs( getElementsByType( "player" ) ) do 
            if (not t[ v ]) then 
                t[ v ] = { 
                            ["hour"] = 0, 
                             ["min"] = 0, 
                             ["sec"] = 0 
                            } 
            end 
            t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 
            local min,sec = checkValues ( 
                    v, 
                    t[ v ][ 'min' ] or 0, 
                    t[ v ][ 'sec' ] or 0 
                        )   
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
  
            setElementData( 
                v, 
                "PlayTime", 
                tostring( hour )..':'..tostring( min )..':'..tostring( sec ) 
            ) 
        end 
    end, 
    1000, 0 
) 
    
function SaveDataOnQuit (  ) 
    local sValue = getElementData( source,'PlayTime' ) 
    local hour = tonumber( t[ source ][ 'hour' ] or 0 ) 
    local min = tonumber( t[ source ][ 'min' ] or 0 ) 
    local sec = tonumber( t[ source ][ 'sec' ] or 0 ) 
    local serial = getPlayerSerial ( source ) 
    local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",serial) 
     if ( type ( Results ) == "table" and #Results == 0 or not Results ) then 
        executeSQLQuery ( "INSERT INTO Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)",serial,hour,min,sec,sValue ) 
    else 
        executeSQLQuery('UPDATE Prestege_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerSerial =?', hour, min, sec, sValue, serial) 
    end 
    t[ source ] = nil 
end 
addEventHandler("onPlayerQuit",root,SaveDataOnQuit) 
  
function SaveDataOnStop (  )  
 for k,v in ipairs ( getElementsByType("player") ) do 
    local playeraccount = getPlayerAccount ( v ) 
    local sValue = getElementData( v,'PlayTime' ) 
    if not ( t [ v ] ) then 
        t [ v ]  = {    } 
    end 
    local hour = tonumber( t[ v ][ 'hour' ] or 0 ) 
    local min = tonumber( t[ v ][ 'min' ] or 0 ) 
    local sec = tonumber( t[ v ][ 'sec' ] or 0 ) 
    local serial = getPlayerSerial ( v ) 
     local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( v ) ) 
     if ( type ( Results ) == "table" and #Results == 0 or not Results ) then 
        executeSQLQuery ( "INSERT INTO Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)",serial,hour,min,sec,sValue ) 
    else 
        executeSQLQuery('UPDATE Prestege_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerSerial =?', hour, min, sec, sValue, serial) 
        end  
    end 
end 
addEventHandler("onResourceStop",resourceRoot,SaveDataOnStop) 
  
function GetDataOnStart ( ) 
 for _,v in ipairs ( getElementsByType ( "player" ) ) do 
 local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( v ) ) 
    if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end 
   if not t[ v ] then 
    t[ v ] = {} 
   end 
        t[ v ]["hour"] = tonumber(Results[1]["Hours"]) 
        t[ v ]["min"] = tonumber(Results[1]["Minuts"]) 
        t[ v ]["sec"] = tonumber(Results[1]["Seconds"]) 
    end 
end 
addEventHandler("onResourceStart",resourceRoot,GetDataOnStart) 
  
function GetDataOnJoin (    ) 
    local Results = executeSQLQuery("SELECT * FROM Prestege_Save_Time WHERE PlayerSerial=?",getPlayerSerial ( source ) ) 
    if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end 
            setElementData ( source, "PlayTime", Results[1]["PlayAllTime"] ) 
               if not t[ source ] then 
                    t[ source ] = {} 
                end 
            t[ source ]["hour"] = tonumber(Results[1]["Hours"]) 
            t[ source ]["min"] = tonumber(Results[1]["Minuts"]) 
            t[ source ]["sec"] = tonumber(Results[1]["Seconds"]) 
    end 
addEventHandler("onPlayerJoin",root,GetDataOnJoin) 

تنبية بسيط #

اتصال بالقاعدهـ فـ من الممكن بـ نسبة 85 % انة يسبب لاق يعني مو لازم حساب يحفظ بـ السريال عدلت المود بـ نسبة 60 %

Thanks work. :D

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