-
Notifications
You must be signed in to change notification settings - Fork 5
/
enhanced_flashbang_reapi.sma
138 lines (110 loc) · 3.55 KB
/
enhanced_flashbang_reapi.sma
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// ReEnhancedFlashBang
// -- Made by lonewolf <igorkelvin@gmail.com>
// -- http://github.com/igorkelvin/amxx-plugins
//
// -- Inspired by Subb98 @ https://github.com/Subb98/No-team-flash
// -- Thanks to "Numb / ConnorMcLeod | Wilian M." for "No Flash Team"
#include <amxmodx>
#include <reapi>
#include <vector>
#include <xs>
#pragma semicolon 1
#define PLUGIN "Enhanced FlashBang Reapi"
#define AUTHOR "lonewolf"
#define VERSION "0.1"
#define URL "https://github.com/igorkelvin/amxx-plugins"
enum Cvars
{
FIX,
TEAM,
SELF,
FF
};
new cvars[Cvars];
enum FlashTeammates
{
DONT,
ALWAYS,
DEPEND,
PARTIALLY
};
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
cvars[FIX] = create_cvar("amx_flash_fix", "1", _, "Fixes flashbangs blinding when turned around");
cvars[TEAM] = create_cvar("amx_flash_team", "0", _, "<0-2> Allow team flashing. 0 - Don't flash teammates; 1 - Always flash teammates; 2 - Only flash teammates if mp_friendlyfire is '1'; 3 - Partially blind teammates");
cvars[SELF] = create_cvar("amx_flash_self", "1", _, "<0|1> Allow self flashing");
cvars[FF] = get_cvar_pointer("mp_friendlyfire");
// todo: check regame/reapi version?
RegisterHookChain(RG_PlayerBlind, "event_RG_PlayerBlind");
}
//todo: check if this event triggers on every ScreenFade event or just when blinded by flashbang
public event_RG_PlayerBlind(const id, const inflictor, const attacker, Float:fadetime, Float:fadehold, alpha, Float:color[3])
{
if (!is_user_connected(id))
{
return HC_CONTINUE;
}
new we_should_fix_flashbangs = get_pcvar_num(cvars[FIX]);
new FlashTeammates:flash_teammates = FlashTeammates:get_pcvar_num(cvars[TEAM]);
new bool:is_same_team = (get_member(id, m_iTeam) == get_member(attacker, m_iTeam));
if (id == attacker)
{
if (!get_pcvar_num(cvars[SELF]))
{
return HC_SUPERCEDE;
}
}
else if (is_same_team && flash_teammates == DONT || (flash_teammates == DEPEND && !get_pcvar_num(cvars[FF])))
{
return HC_SUPERCEDE;
}
if (alpha == 255)
{
new Float:dot = 1337.0;
if (we_should_fix_flashbangs)
{
if (!is_entity(inflictor))
{
return HC_CONTINUE;
}
static Float:nade_origin[3];
static Float:lineofsight[3];
static Float:tmp[3];
static Float:v_forward[3];
get_entvar(inflictor, var_origin, nade_origin);
get_entvar(id, var_origin, lineofsight);
get_entvar(id, var_view_ofs, tmp);
xs_vec_add(lineofsight, tmp, lineofsight);
xs_vec_sub(nade_origin, lineofsight, lineofsight);
get_entvar(id, var_v_angle, tmp);
angle_vector(tmp, ANGLEVECTOR_FORWARD, v_forward);
dot = xs_vec_dot(lineofsight, v_forward);
}
if (dot < 0 || (is_same_team && flash_teammates == PARTIALLY && (id != attacker)))
{
new last_alpha = get_current_alpha(id);
alpha = (last_alpha < 200) ? 200 : last_alpha;
SetHookChainArg(6, ATYPE_INTEGER, alpha);
}
}
return HC_CONTINUE;
}
public get_current_alpha(id)
{
new Float:start_time = get_member(id, m_blindStartTime);
new Float:fade_time = get_member(id, m_blindFadeTime);
new Float:hold_time = get_member(id, m_blindHoldTime);
new Float:end_time = fade_time + hold_time + start_time;
new Float:now = get_gametime();
new last_alpha = get_member(id, m_blindAlpha);
hold_time = hold_time + start_time - now;
if (hold_time <= 0.0)
{
hold_time = 0.0;
new Float:ratio = (end_time - now) / fade_time;
last_alpha = floatround(float(last_alpha) * ratio);
fade_time *= ratio;
}
return last_alpha;
}