Daemon666 / CSB Warn System Publiczny

amx_warn stores warnings per SteamID in nVault; reaching a count kicks, a higher count bans for a set time. Warnings expire after N days.

v1.0.0 136 pobrań GPL-3.0 Ostatnia aktualizacja Aug 23, 2026
csb_warn_system.sma v1.0.0 200 wierszy · 5.5 KB Surowy
1 /*
2 * CSB Warn System
3 * Copyright (C) 2026 counter-strike-boost.com
4 *
5 * amx_warn records a warning against a player's SteamID in nVault. Reaching a
6 * cvar-defined count kicks the player; a higher count bans them for a set time
7 * with the engine banid command. Warnings expire after N days, and say /warns
8 * (or amx_warns) shows a player's current count.
9 *
10 * This program is free software: you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License as published by the Free Software
12 * Foundation, either version 3 of the License, or (at your option) any later
13 * version. It is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See <https://www.gnu.org/licenses/> for details.
16 */
17
18 #include <amxmodx>
19 #include <amxmisc>
20 #include <nvault>
21
22 new const PLUGIN[] = "CSB Warn System"
23 new const VERSION[] = "1.0.0"
24 new const AUTHOR[] = "counter-strike-boost.com"
25
26 #define NO_VAULT (-1)
27
28 new g_iVault = NO_VAULT
29 new g_pEnabled, g_pKickAt, g_pBanAt, g_pBanTime, g_pExpireDays
30
31 public plugin_init()
32 {
33 register_plugin(PLUGIN, VERSION, AUTHOR)
34
35 g_pEnabled = register_cvar("csb_warn_enabled", "1")
36 g_pKickAt = register_cvar("csb_warn_kick", "3")
37 g_pBanAt = register_cvar("csb_warn_ban", "5")
38 g_pBanTime = register_cvar("csb_warn_bantime", "60")
39 g_pExpireDays = register_cvar("csb_warn_expire", "7")
40
41 register_concmd("amx_warn", "cmdWarn", ADMIN_KICK, "<target> [reason] - give a player a warning")
42 register_concmd("amx_warns", "cmdWarns", ADMIN_KICK, "<target> - show a player's warning count")
43
44 register_clcmd("say /warns", "cmdMyWarns")
45 register_clcmd("say_team /warns", "cmdMyWarns")
46 }
47
48 public plugin_cfg()
49 {
50 g_iVault = nvault_open("csb_warns")
51
52 if (g_iVault == NO_VAULT)
53 log_amx("[CSB Warn] could not open nVault 'csb_warns' - warnings disabled.")
54 }
55
56 public plugin_end()
57 {
58 if (g_iVault != NO_VAULT)
59 nvault_close(g_iVault)
60 }
61
62 /* returns the current, non-expired warning count for a SteamID */
63 loadWarns(const authid[])
64 {
65 if (g_iVault == NO_VAULT)
66 return 0
67
68 new value[32]
69
70 if (!nvault_get(g_iVault, authid, value, charsmax(value)))
71 return 0
72
73 new countStr[16], timeStr[16]
74 strtok(value, countStr, charsmax(countStr), timeStr, charsmax(timeStr), ' ')
75
76 new count = str_to_num(countStr)
77 new last = str_to_num(timeStr)
78
79 new expireDays = get_pcvar_num(g_pExpireDays)
80
81 if (expireDays > 0 && last > 0)
82 {
83 new age = get_systime() - last
84
85 if (age > expireDays * 86400)
86 return 0
87 }
88
89 return count
90 }
91
92 saveWarns(const authid[], count)
93 {
94 if (g_iVault == NO_VAULT)
95 return
96
97 new value[32]
98 formatex(value, charsmax(value), "%d %d", count, get_systime())
99 nvault_pset(g_iVault, authid, value)
100 }
101
102 public cmdWarn(id, level, cid)
103 {
104 if (!cmd_access(id, level, cid, 1))
105 return PLUGIN_HANDLED
106
107 if (!get_pcvar_num(g_pEnabled))
108 {
109 console_print(id, "[CSB] Warnings are disabled.")
110 return PLUGIN_HANDLED
111 }
112
113 new arg[32]
114 read_argv(1, arg, charsmax(arg))
115
116 new target = cmd_target(id, arg, CMDTARGET_OBEY_IMMUNITY)
117
118 if (!target)
119 return PLUGIN_HANDLED
120
121 new reason[64]
122 read_argv(2, reason, charsmax(reason))
123 trim(reason)
124
125 if (!reason[0])
126 copy(reason, charsmax(reason), "No reason given")
127
128 new authid[35], tname[32]
129 get_user_authid(target, authid, charsmax(authid))
130 get_user_name(target, tname, charsmax(tname))
131
132 new count = loadWarns(authid) + 1
133 saveWarns(authid, count)
134
135 new aname[32]
136 if (id)
137 get_user_name(id, aname, charsmax(aname))
138 else
139 copy(aname, charsmax(aname), "CONSOLE")
140
141 new kickAt = get_pcvar_num(g_pKickAt)
142 new banAt = get_pcvar_num(g_pBanAt)
143
144 client_print(0, print_chat, "^x04[CSB]^x03 %s^x01 warned^x03 %s^x01 (%d/%d): %s",
145 aname, tname, count, banAt, reason)
146 log_amx("[CSB Warn] %s warned %s <%s> (%d) - %s", aname, tname, authid, count, reason)
147
148 if (banAt > 0 && count >= banAt)
149 {
150 new banMin = get_pcvar_num(g_pBanTime)
151 client_print(0, print_chat, "[CSB] %s reached %d warnings and was banned for %d minutes.", tname, count, banMin)
152 server_cmd("banid %d #%d kick", banMin, get_user_userid(target))
153 server_cmd("writeid")
154 return PLUGIN_HANDLED
155 }
156
157 if (kickAt > 0 && count >= kickAt)
158 {
159 client_print(0, print_chat, "[CSB] %s reached %d warnings and was kicked.", tname, count)
160 server_cmd("kick #%d ^"Too many warnings^"", get_user_userid(target))
161 }
162
163 return PLUGIN_HANDLED
164 }
165
166 public cmdWarns(id, level, cid)
167 {
168 if (!cmd_access(id, level, cid, 1))
169 return PLUGIN_HANDLED
170
171 new arg[32]
172 read_argv(1, arg, charsmax(arg))
173
174 new target = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
175
176 if (!target)
177 return PLUGIN_HANDLED
178
179 new authid[35], tname[32]
180 get_user_authid(target, authid, charsmax(authid))
181 get_user_name(target, tname, charsmax(tname))
182
183 new count = loadWarns(authid)
184
185 console_print(id, "[CSB] %s has %d active warning(s) (ban at %d).", tname, count, get_pcvar_num(g_pBanAt))
186 return PLUGIN_HANDLED
187 }
188
189 public cmdMyWarns(id)
190 {
191 new authid[35]
192 get_user_authid(id, authid, charsmax(authid))
193
194 new count = loadWarns(authid)
195
196 client_print(id, print_chat, "[CSB] You have %d active warning(s). Ban at %d, kick at %d.",
197 count, get_pcvar_num(g_pBanAt), get_pcvar_num(g_pKickAt))
198 return PLUGIN_HANDLED
199 }
200