Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gellipapa committed Sep 23, 2023
2 parents 467590d + 3006101 commit 1e23bba
Show file tree
Hide file tree
Showing 62 changed files with 1,933 additions and 1,062 deletions.
4 changes: 3 additions & 1 deletion [SQL]/legacy.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- ESX Tables

CREATE TABLE `addon_account` (
`name` varchar(60) NOT NULL,
`label` varchar(100) NOT NULL,
Expand Down Expand Up @@ -1012,4 +1014,4 @@ CREATE TABLE IF NOT EXISTS `banking` (
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

ALTER TABLE `users` ADD COLUMN `pincode` INT NULL;
ALTER TABLE `users` ADD COLUMN `pincode` INT NULL;
2 changes: 1 addition & 1 deletion [core]/cron/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 align='center'>[ESX] Cron</a></h1><p align='center'><b><a href='https://discord.esx-framework.org/'>Discord</a> - <a href='https://esx-framework.org/'>Website</a> - <a href='https://docs.esx-framework.org/legacy/installation'>Documentation</a></b></h5>
<h1 align='center'>[ESX] Cron</a></h1><p align='center'><b><a href='https://discord.esx-framework.org/'>Discord</a> - <a href='https://esx-framework.org/'>Website</a> - <a href='https://documentation.esx-framework.org/legacy/installation'>Documentation</a></b></h5>

A simple, but vital, resource that allows resources to Run tasks at specific intervals.

Expand Down
2 changes: 1 addition & 1 deletion [core]/cron/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ game 'gta5'
author 'ESX-Framework'
description 'cron'
lua54 'yes'
version '1.10.1'
version '1.10.2'

server_script 'server/main.lua'
36 changes: 18 additions & 18 deletions [core]/cron/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ function RunAt(h, m, cb)
}
end

function GetTime()
local timestamp = os.time()
local d = os.date('*t', timestamp).wday
local h = tonumber(os.date('%H', timestamp))
local m = tonumber(os.date('%M', timestamp))

return {
d = d,
h = h,
m = m
}
function GetUnixTimestamp()
return os.time()
end

function OnTime(d, h, m)
function OnTime(time)
for i = 1, #Jobs, 1 do
if Jobs[i].h == h and Jobs[i].m == m then
Jobs[i].cb(d, h, m)
local scheduledTimestamp = os.time({
hour = Jobs[i].h,
minute = Jobs[i].m,
second = 0, -- Assuming tasks run at the start of the minute
day = os.date('%d', time),
month = os.date('%m', time),
year = os.date('%Y', time)
})

if time >= scheduledTimestamp and (not LastTime or LastTime < scheduledTimestamp) then
Jobs[i].cb(Jobs[i].h, Jobs[i].m)
end
end
end

function Tick()
local time = GetTime()
local time = GetUnixTimestamp()

if time.h ~= LastTime.h or time.m ~= LastTime.m then
OnTime(time.d, time.h, time.m)
if not LastTime or os.date('%M', time) ~= os.date('%M', LastTime) then
OnTime(time)
LastTime = time
end

SetTimeout(60000, Tick)
end

LastTime = GetTime()
LastTime = GetUnixTimestamp()

Tick()

Expand Down
Loading

0 comments on commit 1e23bba

Please sign in to comment.