Skip to content

Commit f2d23ba

Browse files
Rank restrictions: Different CVars for restrict text & voice chats (#302)
* Rank restrictions: Separate restrictions for voice and text chats * Rank restrictions: fix compile errors * Rank restrictions: update cfg * fix compilation
1 parent 40c434b commit f2d23ba

2 files changed

Lines changed: 97 additions & 35 deletions

File tree

cstrike/addons/amxmodx/configs/plugins/ChatAdditions/CA_Addon_RankRestrictions.cfg

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Restrictions Types
1+
// Restrictions Type
22
// 0 - Disable restrictions
33
// 1 - Level restrictions
44
// 2 - Kills count restrictions
@@ -17,11 +17,17 @@ ca_rankrestrictions_type "1"
1717
// Maximum: "1.000000"
1818
ca_rankrestrictions_type_kills "1"
1919

20-
// Min kills count to access voice & text chat
20+
// Min kills count to access VOICE chat
2121
// -
2222
// Default: "10"
2323
// Minimum: "0.000000"
24-
ca_rankrestrictions_min_kills "10"
24+
ca_rankrestrictions_min_kills_voice_chat "10"
25+
26+
// Min kills count to access TEXT chat
27+
// -
28+
// Default: "10"
29+
// Minimum: "0.000000"
30+
ca_rankrestrictions_min_kills_text_chat "10"
2531

2632
// Level System Types
2733
// 0 - Advanced Experience System
@@ -37,11 +43,17 @@ ca_rankrestrictions_min_kills "10"
3743
// Maximum: "6.000000"
3844
ca_rankrestrictions_type_level "1"
3945

40-
// Min Level to access voice & text chat
46+
// Min Level to access VOICE chat
47+
// -
48+
// Default: "2"
49+
// Minimum: "0.000000"
50+
ca_rankrestrictions_min_level_voice_chat "2"
51+
52+
// Min Level to access TEXT chat
4153
// -
4254
// Default: "2"
4355
// Minimum: "0.000000"
44-
ca_rankrestrictions_min_level "2"
56+
ca_rankrestrictions_min_level_text_chat "2"
4557

4658
// User immunity flag
4759
// -
@@ -53,4 +65,4 @@ ca_rankrestrictions_immunity_flag "a"
5365
// Default: "0"
5466
// Minimum: "0.000000"
5567
// Maximum: "1.000000"
56-
ca_rankrestrictions_steam_immunity "0"
68+
ca_rankrestrictions_steam_immunity "0"

cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma

Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,25 @@ native get_user_skill(player, &Float: skill);
1717
native get_user_stats(player, stats[STATSX_MAX_STATS], bodyhits[MAX_BODYHITS]);
1818
//
1919

20-
enum any: rankRestrictionsType {
20+
21+
enum any: eChatType {
22+
voice_chat,
23+
text_chat
24+
}
25+
26+
enum any: eRankRestrictionsType {
2127
rr_type_none,
2228
rr_type_level,
2329
rr_type_frags
2430
}
2531

2632
new ca_rankrestrictions_type,
2733
ca_rankrestrictions_type_kills,
28-
ca_rankrestrictions_min_kills,
34+
ca_rankrestrictions_min_kills_voice_chat,
35+
ca_rankrestrictions_min_kills_text_chat,
2936
ca_rankrestrictions_type_level,
30-
ca_rankrestrictions_min_level,
37+
ca_rankrestrictions_min_level_voice_chat,
38+
ca_rankrestrictions_min_level_text_chat,
3139
ca_rankrestrictions_immunity_flag[16],
3240
ca_rankrestrictions_steam_immunity
3341

@@ -84,7 +92,7 @@ public native_filter(const name[], index, trap) {
8492

8593
Create_CVars() {
8694
bind_pcvar_num(create_cvar("ca_rankrestrictions_type", "1",
87-
.description = "Restrictions Types\n\
95+
.description = "Restrictions Type\n\
8896
0 - Disable restrictions\n\
8997
1 - Level restrictions\n\
9098
2 - Kills count restrictions",
@@ -102,10 +110,16 @@ Create_CVars() {
102110
), ca_rankrestrictions_type_kills
103111
)
104112

105-
bind_pcvar_num(create_cvar("ca_rankrestrictions_min_kills", "10",
106-
.description = "Min kills count to access voice & text chat",
113+
bind_pcvar_num(create_cvar("ca_rankrestrictions_min_kills_voice_chat", "10",
114+
.description = "Min kills count to access VOICE chat",
115+
.has_min = true, .min_val = 0.0
116+
), ca_rankrestrictions_min_kills_voice_chat
117+
)
118+
119+
bind_pcvar_num(create_cvar("ca_rankrestrictions_min_kills_text_chat", "10",
120+
.description = "Min kills count to access TEXT chat",
107121
.has_min = true, .min_val = 0.0
108-
), ca_rankrestrictions_min_kills
122+
), ca_rankrestrictions_min_kills_text_chat
109123
)
110124

111125
bind_pcvar_num(create_cvar("ca_rankrestrictions_type_level", "1",
@@ -122,10 +136,16 @@ Create_CVars() {
122136
), ca_rankrestrictions_type_level
123137
)
124138

125-
bind_pcvar_num(create_cvar("ca_rankrestrictions_min_level", "2",
126-
.description = "Min Level to access voice & text chat",
139+
bind_pcvar_num(create_cvar("ca_rankrestrictions_min_level_voice_chat", "2",
140+
.description = "Min Level to access VOICE chat",
127141
.has_min = true, .min_val = 0.0
128-
), ca_rankrestrictions_min_level
142+
), ca_rankrestrictions_min_level_voice_chat
143+
)
144+
145+
bind_pcvar_num(create_cvar("ca_rankrestrictions_min_level_text_chat", "2",
146+
.description = "Min Level to access TEXT chat",
147+
.has_min = true, .min_val = 0.0
148+
), ca_rankrestrictions_min_level_text_chat
129149
)
130150

131151
bind_pcvar_string(create_cvar("ca_rankrestrictions_immunity_flag", "a",
@@ -143,19 +163,23 @@ Create_CVars() {
143163
}
144164

145165
public CA_Client_Say(player, const bool: isTeamMessage, const message[]) {
146-
if(!CanCommunicate(player)) {
166+
if(!CanCommunicate(player, true, text_chat)) {
147167
return CA_SUPERCEDE
148168
}
149169

150170
return CA_CONTINUE
151171
}
152172

153173
public CA_Client_Voice(const listener, const sender) {
154-
// need chat notification?
155-
return CanCommunicate(sender, false) ? CA_CONTINUE : CA_SUPERCEDE
174+
if(!CanCommunicate(sender, false, voice_chat)) {
175+
// need chat notification?
176+
return CA_SUPERCEDE
177+
}
178+
179+
return CA_CONTINUE
156180
}
157181

158-
bool: CanCommunicate(const player, const bool: print = true) {
182+
bool: CanCommunicate(const player, const bool: print, chatType) {
159183
if(ca_rankrestrictions_type <= rr_type_none) {
160184
return true
161185
}
@@ -169,24 +193,50 @@ bool: CanCommunicate(const player, const bool: print = true) {
169193
return true
170194
}
171195

172-
if(ca_rankrestrictions_type == rr_type_level && GetUserLevel(player) < ca_rankrestrictions_min_level) {
173-
if(print) {
174-
client_print_color(player, print_team_red, "%L",
175-
player, "RankRestrictions_Warning_MinLevel", ca_rankrestrictions_min_level
176-
)
196+
switch(chatType) {
197+
case voice_chat: {
198+
if(ca_rankrestrictions_type == rr_type_level && GetUserLevel(player) < ca_rankrestrictions_min_level_voice_chat) {
199+
if(print) {
200+
client_print_color(player, print_team_red, "%L",
201+
player, "RankRestrictions_Warning_MinLevel", ca_rankrestrictions_min_level_voice_chat
202+
)
203+
}
204+
205+
return false
206+
}
207+
208+
if(ca_rankrestrictions_type == rr_type_frags && GetUserFragsFromStats(player) < ca_rankrestrictions_min_kills_voice_chat) {
209+
if(print) {
210+
client_print_color(player, print_team_red, "%L",
211+
player, "RankRestrictions_Warning_MinKills", ca_rankrestrictions_min_kills_voice_chat
212+
)
213+
}
214+
215+
return false
216+
}
177217
}
178218

179-
return false
180-
}
181-
182-
if(ca_rankrestrictions_type == rr_type_frags && GetUserFragsFromStats(player) < ca_rankrestrictions_min_kills) {
183-
if(print) {
184-
client_print_color(player, print_team_red, "%L",
185-
player, "RankRestrictions_Warning_MinKills", ca_rankrestrictions_min_kills
186-
)
219+
case text_chat: {
220+
if(ca_rankrestrictions_type == rr_type_level && GetUserLevel(player) < ca_rankrestrictions_min_level_text_chat) {
221+
if(print) {
222+
client_print_color(player, print_team_red, "%L",
223+
player, "RankRestrictions_Warning_MinLevel", ca_rankrestrictions_min_level_text_chat
224+
)
225+
}
226+
227+
return false
228+
}
229+
230+
if(ca_rankrestrictions_type == rr_type_frags && GetUserFragsFromStats(player) < ca_rankrestrictions_min_kills_text_chat) {
231+
if(print) {
232+
client_print_color(player, print_team_red, "%L",
233+
player, "RankRestrictions_Warning_MinKills", ca_rankrestrictions_min_kills_text_chat
234+
)
235+
}
236+
237+
return false
238+
}
187239
}
188-
189-
return false
190240
}
191241

192242
return true

0 commit comments

Comments
 (0)