-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.lua
72 lines (59 loc) · 2.55 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
-- Made by Tazio
-- add_ace Adminrole taz.staff allow
-- add_principal identifier.steam:[hexid] Adminrole
-- if discord is true then it will send clock in and out times through webhook
local DISCORD_NAME = "Staff Duty"
local DISCORD_URL = ""
local DISCORD_IMAGE = "https://pbs.twimg.com/profile_images/847824193899167744/J1Teh4Di_400x400.jpg" -- must end with .jpg or .png
local staff = "taz.staff"
-- Editing stuff below this line will be at your own risk
local people = { }
RegisterCommand("staffduty",function(source, args)
local name = GetPlayerName(source) -- Gets player name
if IsPlayerAceAllowed(source, staff) and has_value(people, name) then
TriggerClientEvent('chat:addMessage', -1, { args = { "^7[ ^3Staff Duty ^7] (^3 " .. name.." ^7)", " is now ^8OFF ^7duty" }, color = 255, 0, 0 }) -- Sends message in chat
removeFirst(people, name) -- Set table to remove the name
sendToDiscord(name, "is now **OFF** duty") -- Sends message to discord
elseif IsPlayerAceAllowed(source, staff) and not has_value(people, name) then
TriggerClientEvent('chat:addMessage', -1, { args = { "^7[ ^3Staff Duty ^7] (^3 " .. name.." ^7)", " is now ^2ON ^7duty"}, color = 255, 0, 0 })
table.insert(people, name)
sendToDiscord(name, "is now **ON** duty")
end
end, true)
AddEventHandler('playerDropped', function(reason)
name = GetPlayerName(source)
if has_value(people, name) then
TriggerClientEvent('chat:addMessage', -1, { args = { "^7[ ^3Staff Duty ^7] (^3 " .. name.." ^7)", " is now ^8OFF ^7duty" }, color = 255, 0, 0 }) -- Sends message in chat
removeFirst(people, name) -- Set table to remove the name
sendToDiscord(name, "is now **OFF** duty") -- Sends message to discord
end
end)
function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
function removeFirst(tbl, val)
for i, v in ipairs(tbl) do
if v == val then
return table.remove(tbl, i)
end
end
end
function sendToDiscord(name, message)
local date = os.date('*t')
local connect = {
{
["color"] = "8663711",
["title"] = "**" .. name .. "**",
["description"] = message,
["footer"] = {
["text"] = "Made by Tazio " .. date.hour .. ':' .. date.min .. ':' .. date.sec,
},
}
}
PerformHttpRequest(DISCORD_URL, function(err, text, headers) end, 'POST', json.encode({username = DISCORD_NAME, embeds = connect, avatar_url = DISCORD_IMAGE}), { ['Content-Type'] = 'application/json' })
end