Skip to content

Commit

Permalink
Update server.lua
Browse files Browse the repository at this point in the history
Adding hour fixes
  • Loading branch information
isgrandson authored Oct 4, 2022
1 parent 943ecc1 commit 3d75014
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions ESX/id_playtimereward/server/server.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
ESX = nil
local ActivePlayerTimers = {}
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

local randomkey = math.random(1000000000000, 9999999999999)

AddEventHandler('onResourceStart', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then return end
TriggerClientEvent('id_playtimereward:client:randomkey', source, randomkey)
ActivePlayerTimers[source] = os.time()
end)

RegisterNetEvent("id_playtimereward:addHour")
AddEventHandler("id_playtimereward:addHour", function()
ESX.RegisterServerCallback('id_playtimereward:addHour', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)

if (math.ceil((os.time() - ActivePlayerTimers[xPlayer.source])/60) < (GlobalState.Minutes - 1)) then
DropPlayer(xPlayer.source, GlobalState.KickMessage)
return
end

if xPlayer then
MySQL.scalar('SELECT hour FROM users WHERE identifier = ?', {xPlayer.identifier}, function(hour)
if hour < GlobalState.Hours then
MySQL.update('UPDATE users SET hour = hour + 1 WHERE identifier = ?', {xPlayer.identifier})
ActivePlayerTimers[xPlayer.source] = os.time()
end
end)
end
Expand All @@ -45,7 +29,7 @@ end)


RegisterNetEvent("id_playtimereward:giveReward")
AddEventHandler("id_playtimereward:giveReward", function(plates, password)
AddEventHandler("id_playtimereward:giveReward", function(plates)
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer then
Expand Down

0 comments on commit 3d75014

Please sign in to comment.