This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.lua
55 lines (39 loc) · 2.07 KB
/
server.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local cooldown = {}
RegisterCommand(Config.CommandName, function(source)
local xPlayer = ESX.GetPlayerFromId(source)
if cooldown[xPlayer.source] == nil or (GetGameTimer() - cooldown[xPlayer.source]) * 0.001 >= Config.Cooldown then
MySQL.query('SELECT secondjob, secondjob_grade FROM users WHERE identifier = ?', {
xPlayer.identifier
}, function(result)
if result[1] ~= nil and result[1].secondjob ~= nil and result[1].secondjob_grade ~= nil then
MySQL.update('UPDATE users SET secondjob = @secondjob, secondjob_grade = @secondjob_grade WHERE identifier = @identifier', {
secondjob = xPlayer.job.name,
secondjob_grade = xPlayer.job.grade,
identifier = xPlayer.identifier,
}, function(rows)
if rows ~= 0 then
if Config.Discord.Enable then
SendToDiscord(string.format(Config.Discord.Message, xPlayer.name, xPlayer.job.name..' `'..xPlayer.job.grade..'`', result[1].secondjob.. ' `'..result[1].secondjob_grade..'`'))
end
xPlayer.setJob(result[1].secondjob, result[1].secondjob_grade)
xPlayer = ESX.GetPlayerFromId(xPlayer.source)
if Config.SwitchMessage ~= '' then
SendNotification(xPlayer.source, string.format(Config.SwitchMessage, xPlayer.job.label..': '..xPlayer.job.grade_label))
end
cooldown[xPlayer.source] = GetGameTimer()
end
end)
end
end)
else
SendNotification(xPlayer.source, string.format(Config.CooldownMessage, math.ceil(Config.Cooldown - (GetGameTimer() - cooldown[xPlayer.source]) * 0.001)))
end
end)
if Config.Discord.Enable then
SendToDiscord = function(msg)
local embed = {{ color = Config.Discord.Color, description = msg }}
PerformHttpRequest(Config.Discord.Webhook, function(err, text, headers) end, 'POST', json.encode({username = Config.Discord.Name, embeds = embed, avatar_url = Config.Discord.Image}), { ['Content-Type'] = 'application/json' })
end
end
MySQL.update('ALTER TABLE users ADD COLUMN IF NOT EXISTS secondjob VARCHAR(50) NOT NULL DEFAULT "unemployed"')
MySQL.update('ALTER TABLE users ADD COLUMN IF NOT EXISTS secondjob_grade INT(11) NOT NULL DEFAULT 0')