-
Notifications
You must be signed in to change notification settings - Fork 2
/
shavit-perf.sp
171 lines (132 loc) · 4.02 KB
/
shavit-perf.sp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <sourcemod>
#include <sdktools>
#include <clientprefs>
#include <shavit>
#pragma newdecls required
#pragma semicolon 1
#define SOUND_PATH "shavit/perf.wav"
Handle gH_Cookie = null;
bool gB_Jumped[MAXPLAYERS+1];
bool gB_OnGround[MAXPLAYERS+1];
int gI_LandedAt[MAXPLAYERS+1];
public Plugin myinfo =
{
name = "[shavit] !perf",
author = "shavit",
description = "Plays a sound whenever you land a perfect jump.",
version = SHAVIT_VERSION,
url = "https://github.com/shavitush/bhoptimer"
}
public void OnPluginStart()
{
gH_Cookie = RegClientCookie("shavit_perf", "Perfect jump sound.", CookieAccess_Protected);
HookEvent("player_jump", Player_Jump);
RegConsoleCmd("sm_perf", Command_Perf);
RegConsoleCmd("sm_perfect", Command_Perf);
RegConsoleCmd("sm_perfectjump", Command_Perf);
RegConsoleCmd("sm_perfjump", Command_Perf);
}
public void OnMapStart()
{
AddFileToDownloadsTable("sound/" ... SOUND_PATH);
PrecacheSound(SOUND_PATH, true);
}
public void Player_Jump(Event event, const char[] name, bool dontBroadcast)
{
gB_Jumped[GetClientOfUserId(GetEventInt(event, "userid"))] = true;
}
public Action Command_Perf(int client, int args)
{
bool bEnabled = IsEnabled(client);
SetClientCookie(client, gH_Cookie, (bEnabled)? "0":"1");
char sText[chatstrings_t::sText];
Shavit_GetChatStrings(sMessageText, sText, chatstrings_t::sText);
char sVariable[chatstrings_t::sVariable];
Shavit_GetChatStrings(sMessageVariable, sVariable, chatstrings_t::sVariable);
char sWarning[chatstrings_t::sWarning];
Shavit_GetChatStrings(sMessageWarning, sWarning, chatstrings_t::sWarning);
if(bEnabled)
{
Shavit_PrintToChat(client, "Perfect jump sound %sdisabled%s.", sWarning, sText);
}
else
{
Shavit_PrintToChat(client, "Perfect jump sound %senabled%s.", sVariable, sText);
}
return Plugin_Handled;
}
public Action OnPlayerRunCmd(int client, int &buttons)
{
if(!IsPlayerAlive(client) || IsFakeClient(client) || !IsScroll(client))
{
return Plugin_Continue;
}
MoveType mtMoveType = GetEntityMoveType(client);
bool bInWater = (GetEntProp(client, Prop_Send, "m_nWaterLevel") >= 2);
int iTicks = GetGameTickCount();
int iMaxTicks = (IsFairScroll(client))? 2:1;
bool bOnGround = ((GetEntPropEnt(client, Prop_Send, "m_hGroundEntity") != -1) && mtMoveType == MOVETYPE_WALK && !bInWater);
if(bOnGround && !gB_OnGround[client])
{
gI_LandedAt[client] = iTicks;
}
// perfect jump
else if(!bOnGround && gB_OnGround[client] && gB_Jumped[client] && iTicks - gI_LandedAt[client] <= iMaxTicks)
{
int[] iClients = new int[MaxClients];
int iCount = 0;
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i) && GetObservingPlayer(i) == client && IsEnabled(i))
{
iClients[iCount++] = i;
}
}
if(iCount > 0)
{
EmitSound(iClients, iCount, SOUND_PATH);
}
}
gB_OnGround[client] = bOnGround;
gB_Jumped[client] = false;
return Plugin_Continue;
}
int GetObservingPlayer(int client)
{
int target = client;
if(IsClientObserver(client))
{
int iObserverMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
if(iObserverMode >= 3 && iObserverMode <= 5)
{
int iTarget = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if(IsValidClient(iTarget, true))
{
target = iTarget;
}
}
}
return target;
}
bool IsScroll(int client)
{
bool bAutoBhop = Shavit_GetStyleSettingBool(Shavit_GetBhopStyle(client), "autobhop");
return !bAutoBhop;
}
bool IsFairScroll(int client)
{
char sSpecial[sizeof(stylestrings_t::sSpecialString)];
Shavit_GetStyleStrings(Shavit_GetBhopStyle(client), sSpecialString, sSpecial, sizeof(sSpecial));
return (StrContains(sSpecial, "fairscroll", false) != -1);
}
bool IsEnabled(int client)
{
char sSetting[4];
GetClientCookie(client, gH_Cookie, sSetting, 4);
if(strlen(sSetting) == 0)
{
SetClientCookie(client, gH_Cookie, "0");
return false;
}
return view_as<bool>(StringToInt(sSetting));
}