Jump to content

Little problem


z24d

Recommended Posts

Hi guys i have a problem at that code

i need it work for the serial not account but

Sir debug saying

Client triggred serverside event onPlayerTimeSaverStart, but event is not added serverside

Codes |

-- #ServerSide 
exports.scoreboard:addScoreboardColumn('PlayTime') 
 addEvent("addTime",true) 
addEvent("removeTime",true) 
addEvent("ToServer",true) 
local t = { } 
local w = {} 
addEventHandler("ToServer",root, 
function (word,get,time) 
 if word and tonumber(get) and tonumber(time) then 
table.insert(w,{word,get}) 
setTimer(function () 
 for _,v in ipairs(w) do 
  if v[1] == word and v[2] == get then 
   table.remove(w,i) 
   end 
 end 
end,time*60*60*1000,1) 
end 
end 
) 
  
addEventHandler("onConsole",root, 
function (msg) 
 for _,v in ipairs(w) do 
  if msg == v[1] then 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
     if not getAccountData ( playeraccount, "time-"..msg) then 
      addPlayerTime(source,v[2]) 
      setAccountData( playeraccount, "time-"..msg,true) 
    end 
   end 
  end 
 end 
end 
) 
  
  
addEventHandler("addTime",root, 
function (to,time) 
 if to == "all" then 
  for _,v in ipairs(getElementsByType("player")) do 
   addPlayerTime(v,time) 
  end 
  else 
   plr = getPlayerFromName(to) 
    if plr then 
    addPlayerTime(plr,time) 
    end 
 end 
end 
) 
  
  
addEventHandler("removeTime",root, 
function (to,time) 
 if to == "all" then 
  for _,v in ipairs(getElementsByType("player")) do 
   removePlayerTime(v,time) 
  end 
  else 
   plr = getPlayerFromName(to) 
    if plr then 
    removePlayerTime(plr,time) 
    end 
 end 
end 
) 
  
  
addEventHandler("onResourceStart",resourceRoot, 
    function (      ) 
            executeSQLQuery ( "CREATE TABLE IF NOT EXISTS Prestege_Save_Time ( PlayerSerial,Hours,Minuts,Seconds,PlayAllTime )" ) 
            outputDebugString ("Execute SQL Loadded !") 
    end 
) 
 function addPlayerTime(plr,time) 
 time = math.floor(time) 
 t[plr]['hour'] = tonumber(t[plr]['hour'] or 0) + time 
 end 
  
  function removePlayerTime(plr,time) 
  time = math.floor(time) 
 t[plr]['hour'] = tonumber(t[plr]['hour'] or 0) - time 
 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) 
  
  
addCommandHandler('Open', 
function(thePlayer) 
local account = getPlayerAccount ( thePlayer ) 
    if isObjectInACLGroup ( "user.".. getAccountName ( account ), aclGetGroup ( "Console" ) )   then 
        outputChatBox('* Welcome !',thePlayer,0,155,255,true) 
        triggerClientEvent(thePlayer,'openn',thePlayer) 
        else 
        outputChatBox('* You not have permission to Access',thePlayer,255,0,0,true) 
    end 
end 
) 
  

Client

  
GUIEditor = { 
    checkbox = {}, 
    staticimage = {}, 
    edit = {}, 
    button = {}, 
    window = {}, 
    label = {}, 
    gridlist = {} 
} 
  
    function cr() 
         GUIEditor.window[1] = guiCreateWindow(384, 91, 524, 553, "Mr.M[O]Dy", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetVisible(GUIEditor.window[1],false) 
        GUIEditor.gridlist[1] = guiCreateGridList(10, 56, 206, 327, false, GUIEditor.window[1]) 
        local PlayerName =  guiGridListAddColumn(GUIEditor.gridlist[1], "[6.A] | Player Name", 0.4) 
        local PlayerTime =  guiGridListAddColumn(GUIEditor.gridlist[1], "[6.A] | Hours", 0.4) 
        GUIEditor.edit[1] = guiCreateEdit(247, 86, 246, 32, "", false, GUIEditor.window[1]) 
        GUIEditor.label[1] = guiCreateLabel(443, 57, 209, 19, "[6.A] | Number of Hours :", false, GUIEditor.window[1]) 
        GUIEditor.checkbox[1] = guiCreateCheckBox(243, 149, 151, 18, "[6.A] | Select all !", false, false, GUIEditor.window[1]) 
        GUIEditor.button[1] = guiCreateButton(240, 322, 107, 45, "[6.A] | Give Time!", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FF00FF00") 
        GUIEditor.button[2] = guiCreateButton(394, 322, 107, 45, "[6.A] | Take Time", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFFF0000") 
        GUIEditor.edit[2] = guiCreateEdit(12, 29, 204, 21, "[6.A] | Search ", false, GUIEditor.window[1]) 
        GUIEditor.label[2] = guiCreateLabel(1, 390, 566, 15, "_______________________________________________________________________________________________________________________", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[2], "default-bold-small") 
        guiLabelSetColor(GUIEditor.label[2], 255, 0, 0) 
        GUIEditor.label[3] = guiCreateLabel(421, 427, 90, 15, "[6.A] | Give name", false, GUIEditor.window[1]) 
        GUIEditor.edit[3] = guiCreateEdit(385, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.label[4] = guiCreateLabel(62, 427, 90, 15, "[6.A] | Hourses :", false, GUIEditor.window[1]) 
        GUIEditor.edit[4] = guiCreateEdit(47, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.button[3] = guiCreateButton(216, 500, 133, 37, "[6.A] | Close", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[3], "NormalTextColour", "FF00FF00") 
        GUIEditor.edit[5] = guiCreateEdit(216, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.label[5] = guiCreateLabel(245, 427, 90, 15, "[6.A] | Give Name !", false, GUIEditor.window[1]) 
        GUIEditor.staticimage[1] = guiCreateStaticImage(321, 187, 117, 96, "logo.png", false, GUIEditor.window[1]) 
    end 
addEventHandler("onClientResourceStart", resourceRoot,cr) 
addEventHandler("onClientGUIClick",root, 
function () 
 if source == GUIEditor.checkbox[1] then 
  if guiCheckBoxGetSelected(source) then 
  guiGridListSetSelectedItem(GUIEditor.gridlist[1],-1,-1) 
  end 
 elseif source == GUIEditor.gridlist[1] then 
  if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
  guiCheckBoxSetSelected(GUIEditor.checkbox[1],false) 
  end 
  elseif source == GUIEditor.edit[2] then 
   if guiGetText(source) == "Search ...." then 
    guiSetText(source,"") 
   end 
  elseif source == GUIEditor.button[1] and guiGetText(GUIEditor.edit[1]) ~= "" and tonumber(guiGetText(GUIEditor.edit[1])) then 
    if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
    triggerServerEvent("addTime",root,"all",tonumber(guiGetText(GUIEditor.edit[1]))) 
    else 
     triggerServerEvent("addTime",root,guiGridListGetItemText(GUIEditor.gridlist[1],guiGridListGetSelectedItem(GUIEditor.gridlist[1]),1),tonumber(guiGetText(GUIEditor.edit[1]))) 
  end 
    elseif source == GUIEditor.button[2] and guiGetText(GUIEditor.edit[1]) ~= "" and tonumber(guiGetText(GUIEditor.edit[1])) then 
    showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
    if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
    triggerServerEvent("removeTime",root,"all",tonumber(guiGetText(GUIEditor.edit[1]))) 
    else 
     triggerServerEvent("removeTime",root,guiGridListGetItemText(GUIEditor.gridlist[1],guiGridListGetSelectedItem(GUIEditor.gridlist[1]),1),tonumber(guiGetText(GUIEditor.edit[1]))) 
  end 
  elseif source == GUIEditor.button[3] and guiGetText(GUIEditor.label[3]) ~= "" and guiGetText(GUIEditor.label[4]) ~= "" and guiGetText(GUIEditor.label[5]) ~= "" then 
  triggerServerEvent("ToServer",root,guiGetText(GUIEditor.edit[3]),guiGetText(GUIEditor.edit[4]),guiGetText(GUIEditor.edit[5])) 
  showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
 end 
end 
) 
addEventHandler("onClientGUIChanged",root, 
function () 
 if source == GUIEditor.edit[2] then 
searchgd(GUIEditor.gridlist[1],guiGetText(source)) 
 end 
end 
) 
function getPlayerTime(plr) 
return getElementData(plr,"PlayTime") 
end 
function SetPlayersInGD( GridList ) 
 if GridList then 
  if getElementType ( GridList ) == "gui-gridlist" then 
   if guiGridListClear ( GridList ) then 
    for i, v in next, getElementsByType ( "player" ) do 
     local Row = guiGridListAddRow ( GridList ) 
      guiGridListSetItemText ( GridList, Row, 1, getPlayerName ( v ), false, false ) 
      guiGridListSetItemText ( GridList, Row, 2, getPlayerTime( v ), false, false ) 
    end 
   end 
  end 
 end 
end 
function searchgd(GridList,name) 
 if guiGridListClear ( GridList ) then 
    for i, v in next, getElementsByType ( "player" ) do 
     if not string.find(getPlayerName(v),name) then return end 
     local Row = guiGridListAddRow ( GridList ) 
      guiGridListSetItemText ( GridList, Row, 1, getPlayerName ( v ), false, false ) 
      guiGridListSetItemText ( GridList, Row, 2, getPlayerTime( v ), false, false ) 
    end 
   end 
end 
addEvent('openn',true) 
addEventHandler('openn',root, 
function () 
  showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
  SetPlayersInGD(GUIEditor.gridlist[1]) 
  guiSetText(GUIEditor.edit[1],"") 
  guiSetText(GUIEditor.edit[2],"Search ....") 
  guiSetText(GUIEditor.edit[3],"") 
  guiSetText(GUIEditor.edit[4],"") 
  guiSetText(GUIEditor.edit[5],"") 
end 
) 
  

Link to comment

theres a one help me at this code but

the Panel is not working

  
GUIEditor = { 
    checkbox = {}, 
    staticimage = {}, 
    edit = {}, 
    button = {}, 
    window = {}, 
    label = {}, 
    gridlist = {} 
} 
  
    function cr() 
         GUIEditor.window[1] = guiCreateWindow(384, 91, 524, 553, "Mr.M[O]Dy", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetVisible(GUIEditor.window[1],false) 
        GUIEditor.gridlist[1] = guiCreateGridList(10, 56, 206, 327, false, GUIEditor.window[1]) 
        local PlayerName =  guiGridListAddColumn(GUIEditor.gridlist[1], " | Name", 0.4) 
        local PlayerTime =  guiGridListAddColumn(GUIEditor.gridlist[1], "  | Hourss", 0.4) 
        GUIEditor.edit[1] = guiCreateEdit(247, 86, 246, 32, "", false, GUIEditor.window[1]) 
        GUIEditor.label[1] = guiCreateLabel(443, 57, 209, 19, "  | Hours number :", false, GUIEditor.window[1]) 
        GUIEditor.checkbox[1] = guiCreateCheckBox(243, 149, 151, 18, "  | Select all", false, false, GUIEditor.window[1]) 
        GUIEditor.button[1] = guiCreateButton(240, 322, 107, 45, "  | Give time", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FF00FF00") 
        GUIEditor.button[2] = guiCreateButton(394, 322, 107, 45, "  | take time", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFFF0000") 
        GUIEditor.edit[2] = guiCreateEdit(12, 29, 204, 21, "  | Search ", false, GUIEditor.window[1]) 
        GUIEditor.label[2] = guiCreateLabel(1, 390, 566, 15, "_______________________________________________________________________________________________________________________", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[2], "default-bold-small") 
        guiLabelSetColor(GUIEditor.label[2], 255, 0, 0) 
        GUIEditor.label[3] = guiCreateLabel(421, 427, 90, 15, "  | Take h Command", false, GUIEditor.window[1]) 
        GUIEditor.edit[3] = guiCreateEdit(385, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.label[4] = guiCreateLabel(62, 427, 90, 15, "  | Hourss:", false, GUIEditor.window[1]) 
        GUIEditor.edit[4] = guiCreateEdit(47, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.button[3] = guiCreateButton(216, 500, 133, 37, "  | Close", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[3], "NormalTextColour", "FF00FF00") 
        GUIEditor.edit[5] = guiCreateEdit(216, 452, 129, 18, "", false, GUIEditor.window[1]) 
        GUIEditor.label[5] = guiCreateLabel(245, 427, 90, 15, "  |Take h Command !", false, GUIEditor.window[1]) 
        GUIEditor.staticimage[1] = guiCreateStaticImage(321, 187, 117, 96, "logo.png", false, GUIEditor.window[1]) 
    end 
addEventHandler("onClientResourceStart", resourceRoot,cr) 
addEventHandler("onClientGUIClick",root, 
function () 
 if source == GUIEditor.checkbox[1] then 
  if guiCheckBoxGetSelected(source) then 
  guiGridListSetSelectedItem(GUIEditor.gridlist[1],-1,-1) 
  end 
 elseif source == GUIEditor.gridlist[1] then 
  if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
  guiCheckBoxSetSelected(GUIEditor.checkbox[1],false) 
  end 
  elseif source == GUIEditor.edit[2] then 
   if guiGetText(source) == "Search ...." then 
    guiSetText(source,"") 
   end 
  elseif source == GUIEditor.button[1] and guiGetText(GUIEditor.edit[1]) ~= "" and tonumber(guiGetText(GUIEditor.edit[1])) then 
    if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
    triggerServerEvent("addTime",root,"all",tonumber(guiGetText(GUIEditor.edit[1]))) 
    else 
     triggerServerEvent("addTime",root,guiGridListGetItemText(GUIEditor.gridlist[1],guiGridListGetSelectedItem(GUIEditor.gridlist[1]),1),tonumber(guiGetText(GUIEditor.edit[1]))) 
  end 
    elseif source == GUIEditor.button[2] and guiGetText(GUIEditor.edit[1]) ~= "" and tonumber(guiGetText(GUIEditor.edit[1])) then 
    showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
    if guiCheckBoxGetSelected(GUIEditor.checkbox[1]) then 
    triggerServerEvent("removeTime",root,"all",tonumber(guiGetText(GUIEditor.edit[1]))) 
    else 
     triggerServerEvent("removeTime",root,guiGridListGetItemText(GUIEditor.gridlist[1],guiGridListGetSelectedItem(GUIEditor.gridlist[1]),1),tonumber(guiGetText(GUIEditor.edit[1]))) 
  end 
  elseif source == GUIEditor.button[3] and guiGetText(GUIEditor.label[3]) ~= "" and guiGetText(GUIEditor.label[4]) ~= "" and guiGetText(GUIEditor.label[5]) ~= "" then 
  triggerServerEvent("ToServer",root,guiGetText(GUIEditor.edit[3]),guiGetText(GUIEditor.edit[4]),guiGetText(GUIEditor.edit[5])) 
  showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
 end 
end 
) 
addEventHandler("onClientGUIChanged",root, 
function () 
 if source == GUIEditor.edit[2] then 
searchgd(GUIEditor.gridlist[1],guiGetText(source)) 
 end 
end 
) 
function getPlayerTime(plr) 
return getElementData(plr,"PlayTime") 
end 
function SetPlayersInGD( GridList ) 
 if GridList then 
  if getElementType ( GridList ) == "gui-gridlist" then 
   if guiGridListClear ( GridList ) then 
    for i, v in next, getElementsByType ( "player" ) do 
     local Row = guiGridListAddRow ( GridList ) 
      guiGridListSetItemText ( GridList, Row, 1, getPlayerName ( v ), false, false ) 
      guiGridListSetItemText ( GridList, Row, 2, getPlayerTime( v ), false, false ) 
    end 
   end 
  end 
 end 
end 
function searchgd(GridList,name) 
 if guiGridListClear ( GridList ) then 
    for i, v in next, getElementsByType ( "player" ) do 
     if not string.find(getPlayerName(v),name) then return end 
     local Row = guiGridListAddRow ( GridList ) 
      guiGridListSetItemText ( GridList, Row, 1, getPlayerName ( v ), false, false ) 
      guiGridListSetItemText ( GridList, Row, 2, getPlayerTime( v ), false, false ) 
    end 
   end 
end 
  
SetPlayersInGD(GUIEditor.gridlist[1]) 
  
addEvent('openn',true) 
addEventHandler('openn',root, 
function () 
  showCursor(not guiGetVisible(GUIEditor.window[1])) 
  guiSetVisible(GUIEditor.window[1],not guiGetVisible(GUIEditor.window[1])) 
  SetPlayersInGD(GUIEditor.gridlist[1]) 
  guiSetText(GUIEditor.edit[1],"") 
  guiSetText(GUIEditor.edit[2],"Search....") 
  guiSetText(GUIEditor.edit[3],"") 
  guiSetText(GUIEditor.edit[4],"") 
  guiSetText(GUIEditor.edit[5],"") 
end 
) 

ServerSide

exports.scoreboard:addScoreboardColumn('PlayTime') 
  
addEvent("addTime",true) 
addEvent("removeTime",true) 
addEvent("ToServer",true) 
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 = { } 
local w = {} 
 addEventHandler("ToServer",root, 
function (word,get,time) 
 if word and tonumber(get) and tonumber(time) then 
table.insert(w,{word,get}) 
setTimer(function () 
 for _,v in ipairs(w) do 
  if v[1] == word and v[2] == get then 
   table.remove(w,i) 
   end 
 end 
end,time*60*60*1000,1) 
end 
end 
) 
addEventHandler("onConsole",root, 
function (msg) 
 for _,v in ipairs(w) do 
  if msg == v[1] then 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
     if not getAccountData ( playeraccount, "time-"..msg) then 
      addPlayerTime(source,v[2]) 
      setAccountData( playeraccount, "time-"..msg,true) 
    end 
   end 
  end 
 end 
end 
) 
  
addEventHandler("addTime",root, 
function (to,time) 
 if to == "all" then 
  for _,v in ipairs(getElementsByType("player")) do 
   addPlayerTime(v,time) 
  end 
  else 
   plr = getPlayerFromName(to) 
    if plr then 
    addPlayerTime(plr,time) 
    end 
 end 
end 
) 
  
addEventHandler("removeTime",root, 
function (to,time) 
 if to == "all" then 
  for _,v in ipairs(getElementsByType("player")) do 
   removePlayerTime(v,time) 
  end 
  else 
   plr = getPlayerFromName(to) 
    if plr then 
    removePlayerTime(plr,time) 
    end 
 end 
end 
) 
 function addPlayerTime(plr,time) 
 time = math.floor(time) 
 t[plr]['hour'] = tonumber(t[plr]['hour'] or 0) + time 
 end 
  function removePlayerTime(plr,time) 
  time = math.floor(time) 
 t[plr]['hour'] = tonumber(t[plr]['hour'] or 0) - time 
 end 
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 
) 
    
addEventHandler("onPlayerQuit",root, 
function (  ) 
    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("onResourceStop",resourceRoot, 
function (  ) 
 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("onResourceStart",resourceRoot, 
function ( ) 
 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("onPlayerJoin",root, 
function (    ) 
    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 
 ) 
  
  
addCommandHandler('Panel', 
function(thePlayer) 
local account = getPlayerAccount ( thePlayer ) 
    if isObjectInACLGroup ( "user.".. getAccountName ( account ), aclGetGroup ( "Console" ) )   then 
        outputChatBox('* Welcome !',thePlayer,0,155,255,true) 
        triggerClientEvent(thePlayer,'openn',thePlayer) 
        else 
        outputChatBox('* You not have permission to Access',thePlayer,255,0,0,true) 
    end 
end 
) 

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