forked from Trippxzz/velocitystatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
152 lines (130 loc) · 3.62 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
local webhooklink = 'https://discord.com/api/webhooks/' -- PUT YOUR WEBHOOK LINK
Citizen.CreateThread(function()
while true do
if Config.MessageId ~= nil and Config.MessageId ~= '' then
Players()
else
DeployStatusMessage()
break
end
Citizen.Wait(Config.UpdateTime)
end
end)
function DeployStatusMessage()
local footer = nil
if Config.Use24hClock then
footer = os.date('Date: %d/%m/%Y | Hour: %H:%M')
else
footer = os.date('Date: %d/%m/%Y | Hour: %I:%M %p')
end
if Config.Debug then
print('Deplying Status Message ['..footer..']')
end
local embed = {
{
["color"] = 3158326,
["title"] = "** Development message!**",
["description"] = 'Copy this message id and put it into Config and restart script!',
["footer"] = {
["text"] = footer,
},
}
}
PerformHttpRequest(webhooklink, function(err, text, headers) end, 'POST', json.encode({
embeds = embed,
}), { ['Content-Type'] = 'application/json' })
end
function Players()
local footer = nil
local xPlayers = ESX.GetPlayers()
local players = GetNumPlayerIndices()
local maxplayers = GetConvarInt('sv_maxclients', 0)
police = 0
medic = 0
staffs = 0
mechanic = 0
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.name == Config.Job1 then
police = police + 1
end
if xPlayer.job.name == Config.Job2 then
medic = medic + 1
end
if xPlayer.job.name == Config.Job3 then
mechanic = mechanic + 1
end
if xPlayer.getGroup() ~= "user" then
staffs = staffs + 1
end
end
if Config.Use24hClock then
footer = os.date('Date: %d/%m | Updated: %H:%M:%S')
else
footer = os.date('Date: %d/%m/%Y | Hour: %I:%M %p')
end
if Config.Debug then
print('Updating Status Message ['..footer..']')
end
local message = json.encode({
embeds = {
{
["username"] = "FiveM Status", -- CHANGE FOR YOUR NAME
["avatar_url"]= "https://cdn.discordapp.com/attachments/927442566071320586/1016500758377672795/Velocity_Develoment_Logo_4.png", -- CHANGE FOR YOUR LOGO
["color"] = 1287415, -- CHANGE FOR YOUR FAVORITE COLOR https://www.spycolor.com AND COPY THE DECIMAL VALUE
["title"] = '**FiveM Status**',
["fields"] = {
{
["name"]= "Officers ",
["value"]= "```"..police.."```",
["inline"]= true,
},
{
["name"]= "Mechanics ",
["value"]= "```" ..mechanic.."```",
["inline"]= true,
},
{
["name"]= "Medics",
["value"]= "```" ..medic.."```",
["inline"]= true,
},
{
["name"]= "Staffs ",
["value"]= "```" ..staffs.."```",
["inline"]= true,
},
{
["name"]= "Players ",
["value"]= "```[" ..players.. "/"..maxplayers.."]```",
["inline"]= true,
}
},
["image"]= {
["url"]= "https://cdn.discordapp.com/attachments/927442566071320586/1016505073452462221/standard_1.gif"
},
["footer"] = {
["text"] = footer,
},
}
},
})
PerformHttpRequest(webhooklink..'/messages/'..Config.MessageId, function(err, text, headers)
if Config.Debug then
print('[DEBUG] err=', err)
print('[DEBUG] text=', text)
end
end, 'PATCH',message, { ['Content-Type'] = 'application/json' })
end
ESX.RegisterServerCallback('callbackplayers', function(source, cb)
Players()
local data = {
cpolice = police,
cmedic = medic,
cstaffs = staffs,
cmechanic = mechanic,
}
cb(data)
end)