-
Notifications
You must be signed in to change notification settings - Fork 11
/
kz_fog.sma
119 lines (86 loc) · 2.55 KB
/
kz_fog.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
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <kreedz_api>
#include <kreedz_util>
#include <settings_api>
#define PLUGIN "[KZ] Frames on the ground"
#define VERSION __DATE__
#define AUTHOR "ggv"
enum OptionsEnum {
optBoolFog,
};
new g_Options[OptionsEnum];
enum _:UserDataStruct {
bool:ud_isFogEnabled,
ud_fogCounter,
ud_flags,
Float:ud_prevTime,
};
new g_UserData[MAX_PLAYERS + 1][UserDataStruct];
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
kz_register_cmd("fog", "cmdFog");
RegisterHam(Ham_Player_PreThink, "player", "OnPlayerPreThink");
bindOptions();
}
public bindOptions() {
g_Options[optBoolFog] = find_option_by_name("fog");
}
public OnCellValueChanged(id, optionId, newValue) {
if (optionId == g_Options[optBoolFog]) {
g_UserData[id][ud_isFogEnabled] = !!newValue;
}
}
public cmdFog(id) {
g_UserData[id][ud_isFogEnabled] = !g_UserData[id][ud_isFogEnabled];
if (g_UserData[id][ud_isFogEnabled]) {
client_print_color(id, print_team_default, "^4[KZ] ^1Fog enabled.");
} else {
client_print_color(id, print_team_default, "^4[KZ] ^1Fog disabled.");
}
set_option_cell(id, g_Options[optBoolFog], g_UserData[id][ud_isFogEnabled]);
return PLUGIN_HANDLED;
}
public OnPlayerPreThink(id) {
if (!g_UserData[id][ud_isFogEnabled] || !is_user_alive(id)) {
return;
}
g_UserData[id][ud_flags] = pev(id, pev_flags);
if (g_UserData[id][ud_flags] & FL_ONGROUND) {
if (g_UserData[id][ud_fogCounter] <= 10)
g_UserData[id][ud_fogCounter]++;
}
else {
if (isUserSurfing(id)) {
g_UserData[id][ud_fogCounter] = 0;
return;
}
if (g_UserData[id][ud_fogCounter] > 0 && g_UserData[id][ud_fogCounter] < 10) {
if (get_gametime() - g_UserData[id][ud_prevTime] <= 0.3) {
// prevent fog spam on mcj
g_UserData[id][ud_prevTime] = get_gametime();
g_UserData[id][ud_fogCounter] = 0;
return;
}
set_dhudmessage(255, 255, 255, -1.0, 0.75, 0, 0.0, 0.5, 0.05, 0.05);
show_dhudmessage(id, "fog: %d", g_UserData[id][ud_fogCounter]);
g_UserData[id][ud_prevTime] = get_gametime();
}
g_UserData[id][ud_fogCounter] = 0;
}
}
stock bool:isUserSurfing(id) {
static Float:origin[3], Float:dest[3];
pev(id, pev_origin, origin);
dest[0] = origin[0];
dest[1] = origin[1];
dest[2] = origin[2] - 1.0;
static Float:flFraction;
engfunc(EngFunc_TraceHull, origin, dest, 0,
g_UserData[id][ud_flags] & FL_DUCKING ? HULL_HEAD : HULL_HUMAN, id, 0);
get_tr2(0, TR_flFraction, flFraction);
if (flFraction >= 1.0) return false;
get_tr2(0, TR_vecPlaneNormal, dest);
return dest[2] <= 0.7;
}