Jump to content

x[ مشكلة ]x مشكلة في مود حفظ الوقت


Recommended Posts

السلام عليكم

كل سنة وانتم بخير

معايا سعات معدل عليه

لما جيت اشغل مود السعات في السيرفر عملت توزيع واخدت التوزيع علشان اجربه

ولما طلعت من السيرفر ودخلت تاني سعاتي راحت حاولت اطلع المشكلة في السكربت بس مفهمتش حاجا

ياريت مساعدة الأسكربت

سيرفر

exports.scoreboard:addScoreboardColumn('Online')
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
)
 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,
                "Online",
                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' )
		local hour = tonumber( t[ source ][ 'hour' ] or 0 )
		local min = tonumber( t[ source ][ 'min' ] or 0 )
		local sec = tonumber( t[ source ][ 'sec' ] or 0 )
        setAccountData ( playeraccount, "Online-hour", tostring(hour) )
        setAccountData ( playeraccount, "Online-min", tostring(min) )
        setAccountData ( playeraccount, "Online-sec", tostring(sec) )
        setAccountData ( playeraccount, "Online", tostring(sValue) )
    end
    t[ source ] = nil
end
addEventHandler ( "onPlayerQuit", root, onPlayerQuit )

function onPlayerLogin (_, playeraccount )
    if ( playeraccount ) then
	exports.scoreboard:addScoreboardColumn('Online' , source)
    local time = getAccountData ( playeraccount, "Online" )
	local hou = getAccountData ( playeraccount, "Online-hour")
	local min = getAccountData ( playeraccount, "Online-min")
	local sec = getAccountData ( playeraccount, "Online-sec")
        if ( time ) then
            setElementData ( source, "Online", time )
			t[ source ]["hour"] = tonumber(hou)
			t[ source ]["min"] = tonumber(min)
			t[ source ]["sec"] = tonumber(sec)
        else
            setElementData ( source, "Online",0 )
            setAccountData ( playeraccount, "Online",0 )
        end
    end
end
addEventHandler ( "onPlayerLogin", root, onPlayerLogin )

function SaveDataOnLogout (previousAccount)
    local acc = previousAccount
    local sValue = getElementData( source,'Online')
    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 accountName = getAccountName (acc)
    local Results = executeSQLQuery("SELECT * FROM Prestege2_Save_Time WHERE PlayerAccount=?", accountName)
    if ( type ( Results ) == "table" and #Results == 0 or not Results ) then
        executeSQLQuery ( "INSERT INTO Prestege2_Save_Time ( PlayerAccount,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)", accountName,hour,min,sec,sValue )
	else
        executeSQLQuery('UPDATE Prestege2_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerAccount =?', hour, min, sec, sValue, getAccountName (acc))
    end
	t[ source ] = nil
    exports.scoreboard:removeScoreboardColumn('Online' , source)
end
addEventHandler ("onPlayerLogout",root, SaveDataOnLogout)

function SaveDataOnStop ()
  for _,v in ipairs (getElementsByType ("player")) do
    if not isGuestAccount (getPlayerAccount (v)) then
      local acc = getPlayerAccount (v)
      local sValue = getElementData( v,'Online' )
      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 Results = executeSQLQuery("SELECT * FROM Prestege2_Save_Time WHERE PlayerAccount=?", getAccountName (acc))
      if ( type ( Results ) == "table" and #Results == 0 or not Results ) then
        executeSQLQuery ( "INSERT INTO Prestege2_Save_Time ( PlayerAccount,Hours,Minuts,Seconds,PlayAllTime ) VALUES(?,?,?,?,?)", getAccountName (acc), hour,min,sec,sValue)
      else
        executeSQLQuery('UPDATE Prestege2_Save_Time SET Hours =?, Minuts =?, Seconds =?, PlayAllTime =? WHERE PlayerAccount =?', hour, min, sec, sValue, getAccountName (acc))
      end
    end
  end
end
addEventHandler ("onResourceStop",getResourceRootElement(), SaveDataOnStop)
 
function GetDataOnStart ()
  for _,v in ipairs (getElementsByType ("player")) do
    if not isGuestAccount (getPlayerAccount (v)) then
      local acc = getPlayerAccount (v)
      local Results = executeSQLQuery("SELECT * FROM Prestege2_Save_Time WHERE PlayerAccount=?", getAccountName (acc))
      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"])
	  exports.scoreboard:addScoreboardColumn ( 'Online' , v )
    end
  end
end
addEventHandler("onResourceStart",getResourceRootElement(), GetDataOnStart)

addCommandHandler('لوحة',
function(thePlayer)
    if isObjectInACLGroup ( "user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup ( "Console" ) ) then
        triggerClientEvent(thePlayer,'openn',thePlayer)
    end
end
)

 

Link to comment
3 hours ago, MR.StoRm said:

تقدر تستفيد من هذا المود ,: 

 

طب اخي انا عرفت مشكلتي

بس عايزك تحللي المشكلة دي بس

function onPlayerQuit ( )
    local playeraccount = getPlayerAccount ( source )
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
        local sValue = getElementData( source,'Online' )
		local hour = tonumber( t[ source ][ 'hour' ] or 0 )
		local min = tonumber( t[ source ][ 'min' ] or 0 )
		local sec = tonumber( t[ source ][ 'sec' ] or 0 )
        setAccountData ( playeraccount, "Online-hour", tostring(hour) )
        setAccountData ( playeraccount, "Online-min", tostring(min) )
        setAccountData ( playeraccount, "Online-sec", tostring(sec) )
        setAccountData ( playeraccount, "Online", tostring(sValue) )
    end
    t[ source ] = nil
end
addEventHandler ( "onPlayerQuit", root, onPlayerQuit )
addEventHandler ( "onPlayerLogout", root, onPlayerQuit )

لما اجي اخرج يحفظ الوقت لاكن لما اجي اعمل تسجيل الخروج مبيحفظش الوقت ليه

ياريت لو شفت ترد

Link to comment
57 minutes ago, Ahmed_Negm said:

طب اخي انا عرفت مشكلتي

بس عايزك تحللي المشكلة دي بس


function onPlayerQuit ( )    local playeraccount = getPlayerAccount ( source )    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then        local sValue = getElementData( source,'Online' )		local hour = tonumber( t[ source ][ 'hour' ] or 0 )		local min = tonumber( t[ source ][ 'min' ] or 0 )		local sec = tonumber( t[ source ][ 'sec' ] or 0 )        setAccountData ( playeraccount, "Online-hour", tostring(hour) )        setAccountData ( playeraccount, "Online-min", tostring(min) )        setAccountData ( playeraccount, "Online-sec", tostring(sec) )        setAccountData ( playeraccount, "Online", tostring(sValue) )    end    t[ source ] = nilendaddEventHandler ( "onPlayerQuit", root, onPlayerQuit )addEventHandler ( "onPlayerLogout", root, onPlayerQuit )

لما اجي اخرج يحفظ الوقت لاكن لما اجي اعمل تسجيل الخروج مبيحفظش الوقت ليه

ياريت لو شفت ترد

ليه حاطط tostring 

و القيمه الهتطلع هتبقي عدد 

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