Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit c1a5d0a

Browse files
authored
Rework csdm_protection (#25)
* Remove sprite protection * Remove block_damage option
1 parent 4425289 commit c1a5d0a

File tree

4 files changed

+20
-118
lines changed

4 files changed

+20
-118
lines changed

cstrike/addons/amxmodx/configs/csdm/config.ini

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ hide_hud_flags = "ft"
4545
; 0 = disable
4646
protection_time = 2.0
4747

48-
; Protection time icon (notify).
49-
; Note: It works if "protection_time" above 1.9 sec.
50-
; Sprite name defined in hud.txt ("" = disabled).
51-
sprite_name = "suithelmet_full"
52-
5348
; Colors of glow shell, leave this in quotes
5449
; The digits are "R G B"
5550
; random value "random"
@@ -59,8 +54,6 @@ render_color_ct = "0 0 220"
5954
; Alpha transparency (as A gets higher, the glow shell is thicker)
6055
render_alpha = 15
6156

62-
; Protected player can't take damage
63-
block_damage = 1
6457

6558

6659
[mapcleaner]

cstrike/addons/amxmodx/configs/csdm/extraconfigs/_de_dust2.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ hide_hud_flags = "ft"
4545
; 0 = disable
4646
protection_time = 2.0
4747

48-
; Protection time icon (notify).
49-
; Note: It works if "protection_time" above 1.9 sec.
50-
; Sprite name defined in hud.txt ("" = disabled).
51-
sprite_name = "suithelmet_full"
5248

5349
; Colors of glow shell, leave this in quotes
5450
; The digits are "R G B"
@@ -59,8 +55,6 @@ render_color_ct = "0 0 220"
5955
; Alpha transparency (as A gets higher, the glow shell is thicker)
6056
render_alpha = 15
6157

62-
; Protected player can't take damage
63-
block_damage = 1
6458

6559

6660
[mapcleaner]

cstrike/addons/amxmodx/configs/csdm/extraconfigs/_prefix_de.ini

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ hide_hud_flags = "ft"
4545
; 0 = disable
4646
protection_time = 2.0
4747

48-
; Protection time icon (notify).
49-
; Note: It works if "protection_time" above 1.9 sec.
50-
; Sprite name defined in hud.txt ("" = disabled).
51-
sprite_name = "suithelmet_full"
52-
5348
; Colors of glow shell, leave this in quotes
5449
; The digits are "R G B"
5550
; random value "random"
@@ -59,8 +54,6 @@ render_color_ct = "0 0 220"
5954
; Alpha transparency (as A gets higher, the glow shell is thicker)
6055
render_alpha = 15
6156

62-
; Protected player can't take damage
63-
block_damage = 1
6457

6558

6659
[mapcleaner]

cstrike/addons/amxmodx/scripting/CSDM_ReAPI/csdm_protection.sma

Lines changed: 20 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,9 @@
22
#include <csdm>
33

44

5-
#define IsPlayer(%1) (1 <= (%1) <= g_iMaxPlayers)
6-
#define PlayerTask(%1) (%1 + PROTECTION_TASK_ID)
7-
#define GetPlayerByTaskID(%1) (%1 - PROTECTION_TASK_ID)
8-
9-
const PROTECTION_TASK_ID = 216897
10-
11-
enum color_e { Float:R, Float:G, Float:B }
12-
13-
enum
14-
{
15-
STATUSICON_HIDE,
16-
STATUSICON_SHOW,
17-
STATUSICON_FLASH
18-
}
19-
20-
new bool:g_bIsProtected[MAX_CLIENTS + 1]
21-
new g_iMaxPlayers
22-
23-
new g_szSpriteName[18] = "suithelmet_full" // max lenght = 16
24-
new Float:g_flRenderAlpha = 10.0, bool:g_bBlockDamage = true, Float: g_fImmunityTime;
25-
new Float:g_flTeamColors[TeamName][color_e] =
26-
{
5+
new Float:g_fImmunityTime
6+
new Float:g_flRenderAlpha = 10.0
7+
new Float:g_flTeamColors[TeamName][3] = {
278
{0.0, 0.0, 0.0},
289
{235.0, 0.0, 0.0}, // TEAM_TERRORIST
2910
{0.0, 0.0, 235.0}, // TEAM_CT
@@ -39,16 +20,8 @@ public plugin_init()
3920
{
4021
register_plugin("CSDM Protection", CSDM_VERSION, "wopox1337")
4122

42-
if(g_fImmunityTime > 0.0) {
43-
if(g_bBlockDamage)
44-
RegisterHookChain(RG_CSGameRules_FPlayerCanTakeDamage, "CSGameRules_FPlayerCanTakeDmg", .post = false)
45-
46-
RegisterHookChain(RG_CBasePlayer_SetSpawnProtection, "CBasePlayer_SetSpawnProtection", .post = true)
47-
RegisterHookChain(RG_CBasePlayer_RemoveSpawnProtection, "CBasePlayer_RemoveSpawnProtection", .post = true)
48-
49-
}
50-
51-
g_iMaxPlayers = get_maxplayers()
23+
RegisterHookChain(RG_CBasePlayer_SetSpawnProtection, "CBasePlayer_SetSpawnProtection", .post = true)
24+
RegisterHookChain(RG_CBasePlayer_RemoveSpawnProtection, "CBasePlayer_RemoveSpawnProtection", .post = true)
5225
}
5326

5427
public CSDM_Initialized(const szVersion[])
@@ -64,28 +37,14 @@ public CSDM_ConfigurationLoad(const ReadTypes:iReadAction)
6437

6538
public CBasePlayer_SetSpawnProtection(const pPlayer, Float: time)
6639
{
67-
SetEffects(pPlayer, time)
40+
SetEffects(pPlayer)
6841
}
6942

7043
public CBasePlayer_RemoveSpawnProtection(const pPlayer)
7144
{
7245
RemoveEffects(pPlayer)
7346
}
7447

75-
public CSGameRules_FPlayerCanTakeDmg(const pPlayer, const pAttacker)
76-
{
77-
if(pPlayer == pAttacker || !IsPlayer(pAttacker))
78-
return HC_CONTINUE
79-
80-
if(g_bIsProtected[pAttacker]) // protected attacker can't take damage
81-
{
82-
SetHookChainReturn(ATYPE_INTEGER, false)
83-
return HC_SUPERCEDE
84-
}
85-
86-
return HC_CONTINUE
87-
}
88-
8948
public ReadCfg(const szLineData[], const iSectionID)
9049
{
9150
new szKey[MAX_KEY_LEN], szValue[MAX_VALUE_LEN], szSign[2]
@@ -96,15 +55,6 @@ public ReadCfg(const szLineData[], const iSectionID)
9655
{
9756
g_fImmunityTime = str_to_float(szValue)
9857
}
99-
else if(equali(szKey, "block_damage"))
100-
{
101-
g_bBlockDamage = bool:(str_to_num(szValue))
102-
}
103-
else if(equali(szKey, "sprite_name"))
104-
{
105-
copy(g_szSpriteName, charsmax(g_szSpriteName), szValue)
106-
strtolower(g_szSpriteName)
107-
}
10858
else if(equali(szKey, "render_color_", 13))
10959
{
11060
new szRed[4], szGreen[4], szBlue[4]
@@ -113,13 +63,13 @@ public ReadCfg(const szLineData[], const iSectionID)
11363

11464
if(parse(szValue, szRed, charsmax(szRed), szGreen, charsmax(szGreen), szBlue, charsmax(szBlue)) == 3)
11565
{
116-
g_flTeamColors[iTeam][R] = floatclamp(str_to_float(szRed), 1.0, 255.0)
117-
g_flTeamColors[iTeam][G] = floatclamp(str_to_float(szGreen), 1.0, 255.0)
118-
g_flTeamColors[iTeam][B] = floatclamp(str_to_float(szBlue), 1.0, 255.0)
66+
g_flTeamColors[iTeam][0] = floatclamp(str_to_float(szRed), 1.0, 255.0)
67+
g_flTeamColors[iTeam][1] = floatclamp(str_to_float(szGreen), 1.0, 255.0)
68+
g_flTeamColors[iTeam][2] = floatclamp(str_to_float(szBlue), 1.0, 255.0)
11969
}
12070
else if(equali(szValue, "random"))
12171
{
122-
g_flTeamColors[iTeam][R] = g_flTeamColors[iTeam][G] = g_flTeamColors[iTeam][B] = 0.0
72+
g_flTeamColors[iTeam][0] = g_flTeamColors[iTeam][1] = g_flTeamColors[iTeam][2] = 0.0
12373
}
12474
}
12575
else if(equali(szKey, "render_alpha"))
@@ -128,51 +78,23 @@ public ReadCfg(const szLineData[], const iSectionID)
12878
}
12979
}
13080

131-
SetEffects(const pPlayer, Float: time)
81+
SetEffects(const pPlayer)
13282
{
13383
// https://github.com/s1lentq/ReGameDLL_CS/blob/bc2c3176e46e2c32ebc0110e7df879ea7ddbfafa/regamedll/dlls/player.cpp#L9532
13484
set_entvar(pPlayer, var_rendermode, kRenderFxNone)
13585

13686
new TeamName:iTeam = get_member(pPlayer, m_iTeam)
137-
if(!g_flTeamColors[iTeam][R] && !g_flTeamColors[iTeam][G] && !g_flTeamColors[iTeam][B])
138-
{
139-
new Float:flColor[color_e]
140-
flColor[R] = random_float(1.0, 255.0)
141-
flColor[G] = random_float(1.0, 255.0)
142-
flColor[B] = random_float(1.0, 255.0)
87+
new bool: isRandomColor = (!g_flTeamColors[iTeam][0] && !g_flTeamColors[iTeam][1] && !g_flTeamColors[iTeam][2])
88+
if(!isRandomColor) {
89+
rg_set_rendering(pPlayer, kRenderFxGlowShell, g_flTeamColors[iTeam], g_flRenderAlpha)
14390

144-
rg_set_rendering(pPlayer, kRenderFxGlowShell, flColor, g_flRenderAlpha)
145-
}
146-
else rg_set_rendering(pPlayer, kRenderFxGlowShell, g_flTeamColors[iTeam], g_flRenderAlpha)
147-
148-
if(g_szSpriteName[0] && time >= 1.5) {
149-
SendStatusIcon(pPlayer, STATUSICON_FLASH)
91+
return
15092
}
151-
}
15293

153-
RemoveEffects(const pPlayer)
154-
{
155-
if(is_user_connected(pPlayer))
156-
{
157-
rg_set_rendering(pPlayer)
94+
new Float:flColor[3]
95+
flColor[0] = random_float(1.0, 255.0)
96+
flColor[1] = random_float(1.0, 255.0)
97+
flColor[2] = random_float(1.0, 255.0)
15898

159-
if(g_szSpriteName[0]) {
160-
SendStatusIcon(pPlayer)
161-
}
162-
}
163-
}
164-
165-
stock SendStatusIcon(const pPlayer, iStatus = STATUSICON_HIDE, red = 0, green = 160, blue = 0)
166-
{
167-
static iMsgIdStatusIcon
168-
if(iMsgIdStatusIcon || (iMsgIdStatusIcon = get_user_msgid("StatusIcon")))
169-
{
170-
message_begin(MSG_ONE_UNRELIABLE, iMsgIdStatusIcon, .player = pPlayer)
171-
write_byte(iStatus) // status: 0 - off, 1 - on, 2 - flash
172-
write_string(g_szSpriteName)
173-
write_byte(red)
174-
write_byte(green)
175-
write_byte(blue)
176-
message_end()
177-
}
99+
rg_set_rendering(pPlayer, kRenderFxGlowShell, flColor, g_flRenderAlpha)
178100
}

0 commit comments

Comments
 (0)