-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsv_autopromote.lua
55 lines (40 loc) · 1.98 KB
/
sv_autopromote.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
-- This module is inspired by GPromote (https://github.com/RoniJames/GPromote)
------------------------------------------------------------------------------
------------------------------CONFIG START------------------------------------
------------------------------------------------------------------------------
local check_autopromote_timer = 10
local autopromote_ranks = { -- The first one will automatically be the starting group, it wont work with ranks outside of this table!
{rank = "user"},
{rank = "regular", playtime = "24h"},
{rank = "trusted", playtime = "3d"},
{rank = "veteran", playtime = "1w"},
}
local promote_sound = "/garrysmod/save_load1.wav" -- Make it an empty string to not play any sound (Inspired by APromote)
------------------------------------------------------------------------------
--------------------------------CONFIG END------------------------------------
------------------------------------------------------------------------------
local rank_to_key = {}
for k,v in ipairs(autopromote_ranks) do
rank_to_key[v.rank] = k
end
timer.Create("sA:AutoPromote", check_autopromote_timer, 0, function()
for k,v in ipairs(player.GetHumans()) do
local cur_rank_key = rank_to_key[v:GetUserGroup()]
if !cur_rank_key then continue end
local next_rank
local playtime = sAdmin.getTotalPlaytime(v)
for i = #autopromote_ranks, 1, -1 do
local rank_data = autopromote_ranks[i]
if !rank_data or !rank_data.rank or !rank_data.playtime or cur_rank_key >= i then continue end
local playtime_required = sAdmin.getTime(rank_data.playtime) or 0
if playtime >= playtime_required then
next_rank = rank_data
break end
end
if !next_rank then continue end
RunConsoleCommand("sa", "setrank", v:SteamID64(), next_rank.rank)
if promote_sound != "" then
v:SendLua("surface.PlaySound('"..promote_sound.."')")
end
end
end)