Promoveaza serverul

Initial release 1.0.0

Browse Source
1.0.0 - Initial release.
Daemon666 committed commit 1e80869213fe588847e0ed8647f7bbdd7a5d29f5
4 changed files with 295 additions and 0 deletions
+3 -0 CHANGELOG.md A
@@ -0,0 +1,3 @@
1 +## 1.0.0 (2025-09-03)
2 +
3 +1.0.0 - Initial release.
+1 -0 README.md A
@@ -0,0 +1 @@
1 +<p><strong>CSB Adverts</strong> shows rotating server messages read from a plain-text file. Each line carries its own display type (chat, HUD or DHUD) and may contain placeholders that are expanded when shown: <code>{HOSTNAME}</code>, <code>{TIMELEFT}</code>, <code>{NEXTMAP}</code>, <code>{PLAYERS}</code>, <code>{MAXPLAYERS}</code>, <code>{MAP}</code> and <code>{NAME}</code>. A per-map file is loaded automatically when it exists.</p><h2>Features</h2><ul><li>Coloured chat, HUD or DHUD per line</li><li>Live placeholders including the player's own name and the player count</li><li>Per-map advert files (<code>csb_adverts_&lt;map&gt;.ini</code>)</li><li>Every player can mute the adverts with <code>say /noads</code></li><li>A default config file is written on first run</li></ul><h2>Installation</h2><ol><li>Put <code>csb_adverts.amxx</code> in <code>addons/amxmodx/plugins/</code></li><li>Add it to <code>plugins.ini</code></li><li>Edit <code>addons/amxmodx/configs/csb_adverts.ini</code></li></ol>
+239 -0 addons/amxmodx/scripting/csb_adverts.sma A
@@ -0,0 +1,239 @@
1 +/*
2 + * CSB Adverts
3 + * Copyright (C) 2026 counter-strike-boost.com
4 + *
5 + * Rotating server messages read from a plain-text file and shown every N
6 + * seconds as coloured chat, a HUD message or a DHUD message. Each line carries
7 + * its own display type and may contain placeholders that are expanded at show
8 + * time: {HOSTNAME} {TIMELEFT} {NEXTMAP} {PLAYERS} {MAXPLAYERS} {MAP} {NAME}.
9 + * A per-map file is loaded automatically when it exists, and every player can
10 + * mute the adverts for himself with "say /noads".
11 + *
12 + * Inspired by the classic "Advertisements" plugins for AMX Mod X. This is an
13 + * independent GPL re-implementation; no original code is reused.
14 + *
15 + * This program is free software: you can redistribute it and/or modify it under
16 + * the terms of the GNU General Public License as published by the Free Software
17 + * Foundation, either version 3 of the License, or (at your option) any later
18 + * version. It is distributed in the hope that it will be useful, but WITHOUT
19 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 + * FOR A PARTICULAR PURPOSE. See <https://www.gnu.org/licenses/> for details.
21 + */
22 +
23 +#include <amxmodx>
24 +
25 +new const PLUGIN[] = "CSB Adverts"
26 +new const VERSION[] = "1.0.0"
27 +new const AUTHOR[] = "counter-strike-boost.com"
28 +
29 +#define MAX_ADS 48
30 +#define MAX_AD_LEN 192
31 +
32 +new g_szAds[MAX_ADS][MAX_AD_LEN]
33 +new g_iAdType[MAX_ADS] /* 0 = chat, 1 = hud, 2 = dhud */
34 +new g_iNumAds
35 +new g_iCurrent
36 +
37 +new bool:g_bMuted[33]
38 +
39 +new g_pEnabled, g_pInterval, g_pRandom, g_pPrefix
40 +
41 +public plugin_init()
42 +{
43 + register_plugin(PLUGIN, VERSION, AUTHOR)
44 +
45 + g_pEnabled = register_cvar("csb_adverts", "1")
46 + g_pInterval = register_cvar("csb_adverts_interval", "45")
47 + g_pRandom = register_cvar("csb_adverts_random", "0")
48 + g_pPrefix = register_cvar("csb_adverts_prefix", "[Server]")
49 +
50 + register_clcmd("say /noads", "cmdToggle")
51 + register_clcmd("say_team /noads", "cmdToggle")
52 +}
53 +
54 +public plugin_cfg()
55 +{
56 + loadAds()
57 +
58 + new Float:interval = get_pcvar_float(g_pInterval)
59 + if (interval < 5.0)
60 + interval = 5.0
61 +
62 + set_task(interval, "showNextAd", 0, _, _, "b")
63 +}
64 +
65 +public client_putinserver(id)
66 +{
67 + g_bMuted[id] = false
68 +}
69 +
70 +public cmdToggle(id)
71 +{
72 + g_bMuted[id] = !g_bMuted[id]
73 + client_print(id, print_chat, "[CSB] Adverts are now %s for you.", g_bMuted[id] ? "OFF" : "ON")
74 + return PLUGIN_HANDLED
75 +}
76 +
77 +loadAds()
78 +{
79 + g_iNumAds = 0
80 + g_iCurrent = 0
81 +
82 + new dir[128]
83 + get_localinfo("amxx_configsdir", dir, charsmax(dir))
84 +
85 + new map[32]
86 + get_mapname(map, charsmax(map))
87 +
88 + /* prefer a per-map file, fall back to the global one */
89 + new path[160]
90 + formatex(path, charsmax(path), "%s/csb_adverts_%s.ini", dir, map)
91 +
92 + if (!file_exists(path))
93 + formatex(path, charsmax(path), "%s/csb_adverts.ini", dir)
94 +
95 + if (!file_exists(path))
96 + {
97 + writeDefaults(path)
98 + }
99 +
100 + new fp = fopen(path, "rt")
101 + if (!fp)
102 + {
103 + log_amx("[CSB Adverts] could not open %s", path)
104 + return
105 + }
106 +
107 + new line[MAX_AD_LEN + 16]
108 +
109 + while (!feof(fp) && g_iNumAds < MAX_ADS)
110 + {
111 + fgets(fp, line, charsmax(line))
112 + trim(line)
113 +
114 + if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
115 + continue
116 +
117 + new type = 0
118 + new start = 0
119 +
120 + if (equali(line, "hud:", 4)) { type = 1; start = 4; }
121 + else if (equali(line, "dhud:", 5)) { type = 2; start = 5; }
122 + else if (equali(line, "chat:", 5)) { type = 0; start = 5; }
123 +
124 + new msg[MAX_AD_LEN]
125 + copy(msg, charsmax(msg), line[start])
126 + trim(msg)
127 +
128 + if (!msg[0])
129 + continue
130 +
131 + copy(g_szAds[g_iNumAds], charsmax(g_szAds[]), msg)
132 + g_iAdType[g_iNumAds] = type
133 + g_iNumAds++
134 + }
135 +
136 + fclose(fp)
137 +
138 + log_amx("[CSB Adverts] loaded %d advert(s) from %s", g_iNumAds, path)
139 +}
140 +
141 +writeDefaults(const path[])
142 +{
143 + new fp = fopen(path, "wt")
144 + if (!fp)
145 + return
146 +
147 + fputs(fp, "; CSB Adverts - one message per line.^n")
148 + fputs(fp, "; Prefix a line with chat:, hud: or dhud: to pick how it is shown.^n")
149 + fputs(fp, "; Placeholders: {HOSTNAME} {TIMELEFT} {NEXTMAP} {PLAYERS} {MAXPLAYERS} {MAP} {NAME}^n")
150 + fputs(fp, "chat: Welcome to {HOSTNAME}, {NAME}! There are {PLAYERS}/{MAXPLAYERS} players online.^n")
151 + fputs(fp, "chat: Current map is {MAP} - {TIMELEFT} left. Next map: {NEXTMAP}.^n")
152 + fputs(fp, "dhud: Type /noads to hide these messages.^n")
153 + fclose(fp)
154 +}
155 +
156 +public showNextAd()
157 +{
158 + if (!get_pcvar_num(g_pEnabled) || g_iNumAds < 1)
159 + return
160 +
161 + if (!get_playersnum())
162 + return
163 +
164 + new idx
165 + if (get_pcvar_num(g_pRandom))
166 + idx = random_num(0, g_iNumAds - 1)
167 + else
168 + {
169 + idx = g_iCurrent
170 + g_iCurrent = (g_iCurrent + 1) % g_iNumAds
171 + }
172 +
173 + new players[32], num
174 + get_players(players, num, "ch")
175 +
176 + for (new i = 0; i < num; i++)
177 + {
178 + new id = players[i]
179 +
180 + if (g_bMuted[id])
181 + continue
182 +
183 + new msg[MAX_AD_LEN]
184 + buildMessage(id, g_szAds[idx], msg, charsmax(msg))
185 +
186 + switch (g_iAdType[idx])
187 + {
188 + case 1:
189 + {
190 + set_hudmessage(0, 160, 255, -1.0, 0.18, 0, 0.0, 6.0, 0.2, 0.2, -1)
191 + show_hudmessage(id, "%s", msg)
192 + }
193 + case 2:
194 + {
195 + show_dhudmessage(id, "%s", msg)
196 + }
197 + default:
198 + {
199 + new prefix[32], out[MAX_AD_LEN + 40]
200 + get_pcvar_string(g_pPrefix, prefix, charsmax(prefix))
201 + formatex(out, charsmax(out), "^x04%s^x01 %s", prefix, msg)
202 + client_print_color(id, print_team_default, "%s", out)
203 + }
204 + }
205 + }
206 +}
207 +
208 +buildMessage(id, const src[], out[], len)
209 +{
210 + copy(out, len, src)
211 +
212 + new host[64], nextmap[32], map[32], name[32]
213 + new tl[16], pc[8], mx[8]
214 +
215 + get_cvar_string("hostname", host, charsmax(host))
216 + get_cvar_string("amx_nextmap", nextmap, charsmax(nextmap))
217 + if (!nextmap[0])
218 + copy(nextmap, charsmax(nextmap), "unknown")
219 +
220 + get_mapname(map, charsmax(map))
221 + get_user_name(id, name, charsmax(name))
222 +
223 + new left = get_timeleft()
224 + if (left > 0)
225 + formatex(tl, charsmax(tl), "%d:%02d", left / 60, left % 60)
226 + else
227 + copy(tl, charsmax(tl), "no limit")
228 +
229 + num_to_str(get_playersnum(), pc, charsmax(pc))
230 + num_to_str(get_maxplayers(), mx, charsmax(mx))
231 +
232 + replace_string(out, len, "{HOSTNAME}", host)
233 + replace_string(out, len, "{NEXTMAP}", nextmap)
234 + replace_string(out, len, "{TIMELEFT}", tl)
235 + replace_string(out, len, "{PLAYERS}", pc)
236 + replace_string(out, len, "{MAXPLAYERS}", mx)
237 + replace_string(out, len, "{MAP}", map)
238 + replace_string(out, len, "{NAME}", name)
239 +}
+52 -0 csb.json A
@@ -0,0 +1,52 @@
1 +{
2 + "name": "CSB Adverts",
3 + "category": "hud-info",
4 + "tags": "adverts, messages, rotation",
5 + "image": "",
6 + "original_author": "",
7 + "original_url": "",
8 + "license": "GPL-3.0",
9 + "title": "CSB Adverts",
10 + "short_desc": "Rotating server messages from a file, shown as coloured chat, HUD or DHUD, with placeholders and a per-player mute.",
11 + "version": "1.0.0",
12 + "amxx_min": "1.9",
13 + "amxx_compile_default": "1.9",
14 + "rehlds_ok": true,
15 + "hlds_ok": true,
16 + "regamedll_required": false,
17 + "metamod_flavor": "any",
18 + "reapi_required": false,
19 + "modules": "",
20 + "install_notes": "1. Put csb_adverts.amxx in addons/amxmodx/plugins/\n2. Add it to plugins.ini\n3. Edit configs/csb_adverts.ini (a default is written on first run)\n4. Uses client_print_color, so AMX Mod X 1.9+ is required",
21 + "known_conflicts": "",
22 + "cvars": [
23 + {
24 + "name": "csb_adverts",
25 + "default": "1",
26 + "description": "Enable the plugin."
27 + },
28 + {
29 + "name": "csb_adverts_interval",
30 + "default": "45",
31 + "description": "Seconds between messages (minimum 5)."
32 + },
33 + {
34 + "name": "csb_adverts_random",
35 + "default": "0",
36 + "description": "1 = pick a random line each time; 0 = go in order."
37 + },
38 + {
39 + "name": "csb_adverts_prefix",
40 + "default": "[Server]",
41 + "description": "Prefix shown in front of chat adverts."
42 + }
43 + ],
44 + "commands": [
45 + {
46 + "name": "say /noads",
47 + "access": "",
48 + "description": "Toggle the adverts on or off for yourself."
49 + }
50 + ],
51 + "main": "addons/amxmodx/scripting/csb_adverts.sma"
52 +}
0 53