-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
36 lines (33 loc) · 1.47 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
local lastAdvertisement = nil
RegisterNetEvent('lifeinvader:sendMessage', function(message)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.getMoney() >= Config.cost then
if lastAdvertisement ~= nil then
local minutes = os.difftime(tonumber(os.time()), lastAdvertisement) / 60
if minutes >= Config.cooldown then
lastAdvertisement = tonumber(os.time())
sendAdvertisement(xPlayer, message)
else
xPlayer.showNotification(string.format(Config.locale.CurrentlyOnCooldown, ESX.Math.Round(Config.cooldown - minutes, 2)))
end
else
lastAdvertisement = tonumber(os.time())
sendAdvertisement(xPlayer, message)
end
end
end)
function sendAdvertisement(xPlayer, message)
xPlayer.removeMoney(Config.cost)
TriggerClientEvent('lifeinvader:sendNotification', -1, message)
local embed = {
{
["color"] = 15158332,
["title"] = string.format(Config.locale.PostedAdvertisementLog, xPlayer.getName()),
["description"] = message,
["footer"] = {
["text"] = os.date("%c")
}
}
}
PerformHttpRequest(Config.webhook, function(err, text, headers) end, 'POST', json.encode({username = Config.name, avatar_url= "https://wiki.rage.mp/images/5/5e/Char_lifeinvader.jpg" ,embeds = embed}), { ['Content-Type']= 'application/json' })
end