-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.lua
121 lines (99 loc) · 3.74 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
local webHookLink = "INSERT DISCORD WEBHOOK LINK HERE"
CreateThread(function()
while true do
local sleep = 10000
local OnlineMedics = 0
local xPlayers = ESX.GetExtendedPlayers()
for k, xPlayer in pairs(xPlayers) do
if isMedic(xPlayer.job.name) then
OnlineMedics = OnlineMedics + 1
end
end
TriggerClientEvent('msk_aimedic:refreshMedics', -1, OnlineMedics)
Wait(sleep)
end
end)
RegisterServerEvent('msk_aimedic:removeMoney', function()
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local cash = xPlayer.getAccount('money').money
local account = 'money'
if cash < Config.RevivePrice then account = 'bank' end
xPlayer.removeAccountMoney(account, Config.RevivePrice)
if Config.Society.enable then
TriggerEvent('esx_addonaccount:getSharedAccount', Config.Society.account, function(account)
if not account then return print(('^1Society %s not found on Event ^2 msk_aimedic:removeMoney ^0'):format(Config.Society.account)) end
account.addMoney(Config.RevivePrice)
end)
end
sendDiscordLog(xPlayer)
end)
ESX.RegisterServerCallback('msk_aimedic:getOnlineMedics', function(source, cb)
local src = source
local OnlineMedics = 0
local xPlayers = ESX.GetExtendedPlayers()
for k, xPlayer in pairs(xPlayers) do
if isMedic(xPlayer.job.name) then
OnlineMedics = OnlineMedics + 1
end
end
cb(OnlineMedics)
end)
isMedic = function(playerJob)
for k, job in pairs(Config.Jobs.jobs) do
if job == playerJob then
return true
end
end
return false
end
comma = function(int, tag)
if not tag then tag = '.' end
local newInt = int
while true do
newInt, k = string.gsub(newInt, "^(-?%d+)(%d%d%d)", '%1'..tag..'%2')
if (k == 0) then
break
end
end
return newInt
end
sendDiscordLog = function(xPlayer)
if not Config.DiscordLog then return end
local content = {{
["title"] = "MSK AI Medic",
["description"] = Translation[Config.Locale]['discord_webhook']:format(xPlayer.name, xPlayer.source),
["color"] = Config.botColor,
["footer"] = {
["text"] = "© MSK Scripts • " .. os.date("%d/%m/%Y %H:%M:%S"),
["icon_url"] = Config.botAvatar
}
}}
PerformHttpRequest(webHookLink, function(err, text, headers) end, 'POST', json.encode({
username = Config.botName,
embeds = content,
avatar_url = Config.botAvatar
}), {
['Content-Type'] = 'application/json'
})
end
GithubUpdater = function()
local GetCurrentVersion = function()
return GetResourceMetadata( GetCurrentResourceName(), "version" )
end
local CurrentVersion = GetCurrentVersion()
local resourceName = "[^2"..GetCurrentResourceName().."^0]"
if Config.VersionChecker then
PerformHttpRequest('https://raw.githubusercontent.com/MSK-Scripts/msk_aimedic/main/VERSION', function(Error, NewestVersion, Header)
if CurrentVersion == NewestVersion then
print(resourceName .. '^2 ✓ Resource is Up to Date^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
elseif CurrentVersion ~= NewestVersion then
print(resourceName .. '^1 ✗ Resource Outdated. Please Update!^0 - ^5Current Version: ^1' .. CurrentVersion .. '^0')
print('^5Newest Version: ^2' .. NewestVersion .. '^0 - ^6Download here:^9 https://github.com/MSK-Scripts/msk_aimedic/releases/tag/v'.. NewestVersion .. '^0')
end
end)
else
print(resourceName .. '^2 ✓ Resource loaded^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
end
end
GithubUpdater()