-
Notifications
You must be signed in to change notification settings - Fork 2
/
shavit-perf random edit.sp
185 lines (150 loc) · 4.01 KB
/
shavit-perf random edit.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <sourcemod>
#include <sdktools>
#undef REQUIRE_PLUGIN
#include <shavit>
#define PLUGIN_VERSION "1.3"
#pragma newdecls required
#pragma semicolon 1
bool gB_Jumped[MAXPLAYERS+1];
bool gB_OnGround[MAXPLAYERS+1];
int gI_LandedAt[MAXPLAYERS+1];
bool g_bLate = false;
bool g_bShavit = false;
chatstrings_t gS_ChatStrings;
public Plugin myinfo =
{
name = "[shavit] !perf",
author = "shavit, Saenger.ItsWar, Uronic",
description = "Plays a sound whenever you land a perfect jump.",
version = PLUGIN_VERSION,
url = "https://github.com/shavitush/bhoptimer"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_bLate = late;
return APLRes_Success;
}
public void OnPluginStart()
{
HookEvent("player_jump", Player_Jump);
if(g_bLate)
{
Shavit_OnChatConfigLoaded();
}
g_bShavit = LibraryExists("shavit");
}
public void OnLibraryAdded(const char[] name)
{
if(StrEqual(name, "shavit"))
{
g_bShavit = true;
}
}
public void OnLibraryRemoved(const char[] name)
{
if(StrEqual(name, "shavit"))
{
g_bShavit = false;
}
}
public void Shavit_OnChatConfigLoaded()
{
Shavit_GetChatStrings(sMessagePrefix, gS_ChatStrings.sPrefix, sizeof(chatstrings_t::sPrefix));
Shavit_GetChatStrings(sMessageText, gS_ChatStrings.sText, sizeof(chatstrings_t::sText));
Shavit_GetChatStrings(sMessageWarning, gS_ChatStrings.sWarning, sizeof(chatstrings_t::sWarning));
Shavit_GetChatStrings(sMessageVariable, gS_ChatStrings.sVariable, sizeof(chatstrings_t::sVariable));
Shavit_GetChatStrings(sMessageVariable2, gS_ChatStrings.sVariable2, sizeof(chatstrings_t::sVariable2));
Shavit_GetChatStrings(sMessageStyle, gS_ChatStrings.sStyle, sizeof(chatstrings_t::sStyle));
}
public void OnMapStart()
{
PrecacheSound("buttons/lightswitch2.wav", true);
}
public void Player_Jump(Event event, const char[] name, bool dontBroadcast)
{
gB_Jumped[GetClientOfUserId(GetEventInt(event, "userid"))] = true;
}
public Action OnPlayerRunCmd(int client, int &buttons)
{
if(g_bShavit)
{
if(!IsPlayerAlive(client) || IsFakeClient(client) || !IsScroll(client))
{
return Plugin_Continue;
}
}
else
{
if(!IsPlayerAlive(client) || IsFakeClient(client))
{
return Plugin_Continue;
}
}
MoveType mtMoveType = GetEntityMoveType(client);
bool bInWater = (GetEntProp(client, Prop_Send, "m_nWaterLevel") >= 2);
int iTicks = GetGameTickCount();
bool bOnGround = ((GetEntPropEnt(client, Prop_Send, "m_hGroundEntity") != -1) && mtMoveType == MOVETYPE_WALK && !bInWater);
if(bOnGround && !gB_OnGround[client])
{
gI_LandedAt[client] = iTicks;
}
else if(!bOnGround && gB_OnGround[client] && gB_Jumped[client] && iTicks - gI_LandedAt[client] <= 1)
{
int[] iClients = new int[MaxClients];
int iCount = 0;
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i) && GetObservingPlayer(i) == client)
{
iClients[iCount++] = i;
}
}
if(iCount > 0)
{
EmitSound(iClients, iCount, "buttons/lightswitch2.wav");
for (int i = 0; i < iCount; i++)
{
if(g_bShavit)
{
Shavit_StopChatSound();
Shavit_PrintToChat(iClients[i], "%s Perfect Jump.", gS_ChatStrings.sPrefix);
}
else
{
PrintToChat(iClients[i], "\x01[\x06Perf\x01] Perfect Jump.");
}
}
}
}
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)
{
if(Shavit_GetStyleSettingInt(Shavit_GetBhopStyle(client), "autobhop") == 0)
{
return true;
}
else
{
return false;
}
}