So, I’m trying to make this script, that will allow to add money (callback from database) on top of otherwise standard paycheck.
But I’m unsure, how to correctly execute it. Maybe you could take a look at it? I basically took IRL jail time jailer script and edited it a bit, to demonstrate what I’m trying to make here. This idea is actually based on a suggestion of my players, as they are not happy about just adding money to account. This money boost should encourage players to still actually play and work for their reward (but to also make their life easier for exchange). If @Jager_Bom could help out as well on this, since he made that perfect Jail script, working on similar principle, that would be awesome!
Here’s roughly what I’m after. Excuse the mess, this is simply too complex task for me. Hopefully, you will get the idea from looking at it
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
--[[
CREATE TABLE IF NOT EXISTS `tebex_rewards` (
`identifier` varchar(100) NOT NULL,
`No1` varchar(100) DEFAULT '50',
`No1_time` int(11) unsigned DEFAULT NULL,
`No2` int(11) DEFAULT '20',
`No2_time` int(11) unsigned DEFAULT NULL,
`No3` int(11) DEFAULT '10',
`No3_time` int(11) unsigned DEFAULT NULL,
`No4` int(11) DEFAULT '5',
`No4_time` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
]]
RegisterCommand("ActivatingBoostNo1", ActivatingBoostNo1, true) -- comming from tebex
function ActivatingBoostNo1(_, arg)
local identifier = arg[1] --identifier = "fivem:111111" -- example of identifier passed by from Tebex
local ThisBoostTimeValue = 864000 -- equivalent to 10 days for perk boost
currenttime = os.time(os.date("!*t"))
print(currenttime)
-- let's check, if there is already printed record in DB
MySQL.Async.fetchAll("SELECT * FROM tebex_rewards WHERE identifier=@identifier VALUES (@identifier,@No1_time)" {
['@identifier'] = identifier
}, function(result)
if result[1] ~= nil and result[1] > currenttime then -- checking if record is already there? And also, if the already written value is still higher than current time - we want to add timelimit, not to cut it down by new order
MySQL.Async.execute("INSERT INTO tebex_rewards (No1_time) VALUES (@No1_time) ON DUPLICATE KEY UPDATE No1_time=@No1_time", {
['@No1_time'] = result[1] + ThisBoostTimeValue
}
)
else -- normal record, alternatively, rewrite of the previous, old one
MySQL.Async.execute("INSERT INTO tebex_rewards (identifier,No1_time) VALUES (@identifier,@No1_time) ON DUPLICATE KEY UPDATE identifier=@identifier,No1_time=@No1_time", {
['@identifier'] = identifier,
['@No1_time'] = currenttime + ThisBoostTimeValue
}
)
end
end)
end
-- callback being called from any job related script that operates payouts, to be able to add to value due to perks being active
ESX.RegisterServerCallback('tebex-rewards:ReadAvailableRewards', function(source, cb)
MySQL.Async.fetchAll("SELECT * FROM tebex_rewards WHERE identifier=@identifier", {['@identifier'] = identifier}, function(result)
--[[
-- how to check available individual rewards via timestamp limit from SQL?
-- No1_time, No2_time, No3_time, No4_time -> if those are still active (ahead of actual time) or not?
-- and how to get correctly result of time difference/availability of those perks?
--
]]
cb(result) -- if no result (no perks have been found), then cb(false) - somehow
end)
end)
I will really appreciate any help on this. And I guess there will be more people that could benefit from this as well