Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.90 KB | None | 0 0
  1. isZero = false
  2.  
  3. function checkTime () -- проверяет каждую минуту реальное время
  4. local time = getRealTime()
  5. local minutes = time.minute
  6.  
  7.     if minutes == 0 then
  8.         isZero = true
  9.     else
  10.         isZero = false
  11.     end
  12. end
  13. setTimer(checkTime, 1000,0)
  14. addEventHandler ( "onResourceStart", getResourceRootElement(), checkTime )
  15.  
  16. function onlinePlayers(T)
  17.   local count = 0
  18.   for _ in pairs(T) do count = count + 1 end
  19.   return count
  20. end
  21.  
  22. function SetDogtagsTimer() -- таймер на выдачу жетонов
  23. if onlinePlayers(getElementsByType ("player")) > 15 then ammount =  2 else ammount = 1 end
  24.    
  25.     if isZero then -- если 00 минут
  26.         for _,thePlayer in ipairs (getElementsByType ( "player" )) do
  27.             if not isGuestAccount( getPlayerAccount( thePlayer ) ) then
  28.                 if getElementData(thePlayer, "onlineSpent") > 50 then
  29.                     setElementData(thePlayer , "Жетон", (getElementData(thePlayer, "Жетон") or 0) + ammount )
  30.                     setElementData(thePlayer , "onlineSpent", 0)
  31.                     setAccountData(getPlayerAccount(thePlayer), "onlineSpent", 0)
  32.                 end
  33.             end
  34.         end
  35.     else
  36.             for _,thePlayer in ipairs(getElementsByType ( "player" )) do
  37.                 if not isGuestAccount( getPlayerAccount( thePlayer )) then
  38.                     setElementData(thePlayer , "onlineSpent", getElementData( thePlayer, "onlineSpent") + 1)
  39.                 end
  40.             end
  41.     end
  42. end
  43. setTimer(SetDogtagsTimer, 60 * 1000,0)
  44. addEventHandler ( "onResourceStart", getResourceRootElement(), SetDogtagsTimer)
  45.  
  46. function setOnlineTimeOnLogin() -- присвоить количетсво минут онлайн при логине
  47. local playerAccount = getPlayerAccount(source)
  48.  
  49.     if getAccountData(playerAccount, "onlineSpent") == false then
  50.         setAccountData(playerAccount, "onlineSpent", 0)
  51.     end
  52.       setElementData(source, "onlineSpent", getAccountData(playerAccount, "onlineSpent"))
  53.  
  54.       outputChatBox( "Account:" .. tostring(getAccountData(playerAccount, "onlineSpent")))
  55.       outputChatBox( "ElementData:" .. tostring(getElementData(source, "onlineSpent")))
  56. end
  57. addEventHandler ( "onPlayerLogin", getRootElement(), setOnlineTimeOnLogin )
  58.  
  59. function setOnlineTimeOnLogout() -- присвоить количетсво минут онлайн при выходе игрока
  60. local playerAccount = getPlayerAccount(source)
  61.  
  62.     if getAccountData(playerAccount, "onlineSpent") == false then
  63.         setAccountData(playerAccount, "onlineSpent", 0)
  64.     end
  65.         setAccountData(playerAccount, "onlineSpent", getElementData(source, "onlineSpent"))
  66.  
  67.       outputChatBox( "Account:" .. tostring(getAccountData(playerAccount, "onlineSpent")))
  68.       outputChatBox( "ElementData:" .. tostring(getElementData(source, "onlineSpent")))
  69. end
  70. addEventHandler ( "onPlayerQuit", getRootElement(), setOnlineTimeOnLogout )
  71. addEventHandler ( "onPlayerLogout", getRootElement(), setOnlineTimeOnLogout )
  72.  
  73. function setOnlineTimeOnResourceStart() -- задать elementdata всем игрокам при старте ресурса
  74.     for _,thePlayer in ipairs(getElementsByType ( "player" )) do
  75.         if not isGuestAccount( getPlayerAccount( thePlayer ) ) then
  76.             if getAccountData(getPlayerAccount(thePlayer), "onlineSpent") == false then
  77.                setAccountData(getPlayerAccount(thePlayer), "onlineSpent", 0)
  78.             end
  79.                setElementData(thePlayer, "onlineSpent", getAccountData(getPlayerAccount(thePlayer), "onlineSpent"))
  80.         end
  81.     end
  82. end
  83. addEventHandler ( "onResourceStart", getResourceRootElement(), setOnlineTimeOnResourceStart)
  84.  
  85. function setOnlineTimeOnResourceStop() -- задать elementdata всем игрокам при остановке ресурса
  86.     for _,thePlayer in ipairs(getElementsByType ( "player" )) do
  87.         if not isGuestAccount( getPlayerAccount( thePlayer ) ) then
  88.             setAccountData(getPlayerAccount(thePlayer), "onlineSpent", getElementData(thePlayer, "onlineSpent"))
  89.         end
  90.     end
  91. end
  92. addEventHandler ( "onResourceStop", getResourceRootElement(), setOnlineTimeOnResourceStop )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement