This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathins_items.sp
375 lines (316 loc) · 10.3 KB
/
ins_items.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define DMG_HEADSHOT (1 << 31) /**< Damage from a headshot. */
enum Teams
{
TEAM_NONE = 0,
TEAM_SPECTATORS,
TEAM_SECURITY,
TEAM_INSURGENTS,
};
new g_nFireResistance_ID = 8;
new g_nSunglasses_ID = 31;
new g_nDoubleJump_ID = 26;
new g_nSpeedBoost_ID = 27;
new g_nGasMask_ID = 25;
new g_iPlayerEquipGear;
new g_iSpeedOffset;
new g_nClientRunnerID = 0;
new
Handle:g_cvJumpBoost = INVALID_HANDLE,
Handle:g_cvJumpEnable = INVALID_HANDLE,
Handle:g_cvJumpMax = INVALID_HANDLE,
Float:g_flBoost = 380.0,
bool:g_bDoubleJump = true,
g_fLastButtons[MAXPLAYERS+1],
g_fLastFlags[MAXPLAYERS+1],
bool:g_bPlayerJump[MAXPLAYERS+1],
g_iJumps[MAXPLAYERS+1],
g_iJumpMax
public Plugin:myinfo =
{
name = "[INS] Items",
author = "Neko-",
description = "Custom item ability for INS",
version = "1.0.5"
};
public OnPluginStart()
{
//Find player gear offset
g_iPlayerEquipGear = FindSendPropInfo("CINSPlayer", "m_EquippedGear");
//Find player speed offset
g_iSpeedOffset = FindSendPropInfo("CBasePlayer","m_flLaggedMovementValue");
if(g_iSpeedOffset == -1)
SetFailState("Offset \"m_flLaggedMovementValue\" not found!");
g_cvJumpEnable = CreateConVar(
"sm_doublejump_enabled", "1",
"Enables double-jumping.",
FCVAR_PLUGIN|FCVAR_NOTIFY
);
g_cvJumpBoost = CreateConVar(
"sm_doublejump_boost", "380.0",
"The amount of vertical boost to apply to double jumps.",
FCVAR_PLUGIN|FCVAR_NOTIFY
);
g_cvJumpMax = CreateConVar(
"sm_doublejump_max", "1",
"The maximum number of re-jumps allowed while already jumping.",
FCVAR_PLUGIN|FCVAR_NOTIFY
);
HookConVarChange(g_cvJumpBoost, convar_ChangeBoost);
HookConVarChange(g_cvJumpEnable, convar_ChangeEnable);
HookConVarChange(g_cvJumpMax, convar_ChangeMax);
g_bDoubleJump = GetConVarBool(g_cvJumpEnable);
g_flBoost = GetConVarFloat(g_cvJumpBoost);
g_iJumpMax = GetConVarInt(g_cvJumpMax);
HookEvent("player_pick_squad", Event_PlayerPickSquad_Post, EventHookMode_Post);
HookEvent("player_blind", Event_OnFlashPlayerPre, EventHookMode_Pre);
HookEvent("player_spawn", Event_PlayerRespawnPre, EventHookMode_Pre);
//AddCommandListener(ResupplyListener, "inventory_resupply");
//AddCommandListener(ResupplyListener, "inventory_confirm");
}
public OnMapEnd()
{
g_nClientRunnerID = 0;
}
public OnClientPutInServer(client)
{
//If not fake client
if(!IsFakeClient(client))
{
//Hook damage
SDKHook(client, SDKHook_OnTakeDamage, Hook_OnTakeDamage);
g_bPlayerJump[client] = false;
}
}
public Event_PlayerPickSquad_Post(Handle:event, const String:name[], bool:dontBroadcast )
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
decl String:class_template[64];
GetEventString(event, "class_template",class_template,sizeof(class_template));
if(client && (StrContains(class_template, "runner") > -1))
{
g_nClientRunnerID = client;
}
}
public Action:Event_OnFlashPlayerPre(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new nCurrentPlayerTeam = GetClientTeam(client);
//Check if player is connected and is alive and player team is security
if((IsClientConnected(client)) && (IsPlayerAlive(client)) && (nCurrentPlayerTeam == view_as<int>(TEAM_SECURITY)))
{
//Get player the 4th gear item which is accessory (3rd offset with a DWORD(4 bytes))
new nAccessoryItemID = GetEntData(client, g_iPlayerEquipGear + (4 * 3));
//If accessory is sunglasses item ID)
if(nAccessoryItemID == g_nSunglasses_ID)
{
//Set player flash alpha (Which is the opacity)
SetEntPropFloat(client, Prop_Send, "m_flFlashMaxAlpha", 0.5);
}
}
return Plugin_Continue;
}
public Action:Hook_OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3])
{
if(!IsValidClient(victim))
{
return Plugin_Continue;
}
//Get player armor ID
new nArmorItemID = GetEntData(victim, g_iPlayerEquipGear);
//Get player helmet ID
new nHelmetItemID = GetEntData(victim, g_iPlayerEquipGear + (4 * 1));
//Get weapon of the attacker
decl String:sGrenade[32];
GetEdictClassname(inflictor, sGrenade, sizeof(sGrenade));
//If player armor is FR (Which is fire resistance armor) and attacker weapon is fire
if((StrEqual(sGrenade, "grenade_anm14") || StrEqual(sGrenade, "grenade_molotov") || StrEqual(sGrenade, "grenade_m203_incid") || StrEqual(sGrenade, "grenade_gp25_incid")) && (nArmorItemID == g_nFireResistance_ID))
{
damage = 1.5;
return Plugin_Changed;
}
//If player armor is Toxic smoke
if((StrEqual(sGrenade, "grenade_gas")) && (nHelmetItemID == g_nGasMask_ID))
{
damage = 0.0;
return Plugin_Changed;
}
if((!IsValidClient(attacker)) || (GetClientTeam(victim) == GetClientTeam(attacker)))
{
return Plugin_Continue;
}
if(weapon > 0)
{
decl String:sWeapon[32];
GetEdictClassname(weapon, sWeapon, sizeof(sWeapon));
//Sniper
if(StrEqual(sWeapon, "weapon_sks") && ((nHelmetItemID != 23) && (nHelmetItemID != 24)))
{
damage *= 100.0;
return Plugin_Changed;
}
//Helmet
if(damagetype & DMG_HEADSHOT)
{
if(nHelmetItemID == 23)
{
damage = 65.0;
return Plugin_Changed;
}
else if(nHelmetItemID == 24)
{
damage = 33.0;
return Plugin_Changed;
}
}
}
return Plugin_Continue;
}
public Action:Event_PlayerRespawnPre(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
//Check if player is connected and is alive and player team is security
if(IsClientConnected(client))
{
//Speed boost
//Get player misc item (5th offset with a DWORD(4 bytes))
new nPerkItemID = GetEntData(client, g_iPlayerEquipGear + (4 * 4));
//If item is speed boost ID
if((nPerkItemID == g_nSpeedBoost_ID) || (client == g_nClientRunnerID))
{
//Increase player speedboost by 20%
SetEntDataFloat(client, g_iSpeedOffset, 1.20);
}
else
{
//Reset player speed to 1
SetEntDataFloat(client, g_iSpeedOffset, 1.0);
}
//If item is doublejump ID
if(nPerkItemID == g_nDoubleJump_ID)
{
g_bPlayerJump[client] = true;
}
else
{
g_bPlayerJump[client] = false;
}
}
}
public Action:ResupplyListener(client, const String:cmd[], argc)
{
//Get current client team
new nCurrentPlayerTeam = GetClientTeam(client);
//Check if player is connected and is alive and player team is security
if((IsClientConnected(client)) && (IsPlayerAlive(client)) && (nCurrentPlayerTeam == view_as<int>(TEAM_SECURITY)))
{
//Speed boost
//Get player misc item (5th offset with a DWORD(4 bytes))
new nPerkItemID = GetEntData(client, g_iPlayerEquipGear + (4 * 4));
//If item is speed boost ID
if(nPerkItemID == g_nSpeedBoost_ID)
{
//Increase player speedboost by 20%
SetEntDataFloat(client, g_iSpeedOffset, 1.20);
}
else
{
//Reset player speed to 1
SetEntDataFloat(client, g_iSpeedOffset, 1.0);
}
//If item is doublejump ID
if(nPerkItemID == g_nDoubleJump_ID)
{
g_bPlayerJump[client] = true;
}
else
{
g_bPlayerJump[client] = false;
}
}
return Plugin_Continue;
}
//----------------------------------------
// Start double jump check
// Originally coded by someone else
//----------------------------------------
public convar_ChangeBoost(Handle:convar, const String:oldVal[], const String:newVal[]) {
g_flBoost = StringToFloat(newVal)
}
public convar_ChangeEnable(Handle:convar, const String:oldVal[], const String:newVal[]) {
if (StringToInt(newVal) >= 1) {
g_bDoubleJump = true
} else {
g_bDoubleJump = false
}
}
public convar_ChangeMax(Handle:convar, const String:oldVal[], const String:newVal[]) {
g_iJumpMax = StringToInt(newVal)
}
public OnGameFrame() {
if (g_bDoubleJump) { // double jump active
for (new i = 1; i <= MaxClients; i++) { // cycle through players
if (
IsClientInGame(i) && // is in the game
IsPlayerAlive(i) // is alive
) {
DoubleJump(i) // Check for double jumping
}
}
}
}
stock DoubleJump(const any:client) {
new
fCurFlags = GetEntityFlags(client), // current flags
fCurButtons = GetClientButtons(client) // current buttons
if (g_fLastFlags[client] & FL_ONGROUND) { // was grounded last frame
if (
!(fCurFlags & FL_ONGROUND) && // becomes airbirne this frame
!(g_fLastButtons[client] & IN_JUMP) && // was not jumping last frame
fCurButtons & IN_JUMP // started jumping this frame
) {
OriginalJump(client) // process jump from the ground
}
} else if ( // was airborne last frame
fCurFlags & FL_ONGROUND // becomes grounded this frame
) {
Landed(client) // process landing on the ground
} else if ( // remains airborne this frame
!(g_fLastButtons[client] & IN_JUMP) && // was not jumping last frame
fCurButtons & IN_JUMP // started jumping this frame
) {
ReJump(client) // process attempt to double-jump
}
g_fLastFlags[client] = fCurFlags // update flag state for next frame
g_fLastButtons[client] = fCurButtons // update button state for next frame
}
stock OriginalJump(const any:client) {
g_iJumps[client]++ // increment jump count
}
stock Landed(const any:client) {
g_iJumps[client] = 0 // reset jumps count
}
stock ReJump(const any:client) {
//Double jump check with item
//Get player misc item (5th offset with a DWORD(4 bytes))
new nPerkItemID = GetEntData(client, g_iPlayerEquipGear + (4 * 4))
//If item is 26 then its double jump perk. Allow player to perform a double jump
if((nPerkItemID == g_nDoubleJump_ID) && g_bPlayerJump[client])
{
if ( 1 <= g_iJumps[client] <= g_iJumpMax) { // has jumped at least once but hasn't exceeded max re-jumps
g_iJumps[client]++ // increment jump count
decl Float:vVel[3]
GetEntPropVector(client, Prop_Data, "m_vecVelocity", vVel) // get current speeds
vVel[2] = g_flBoost
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vVel) // boost player
}
}
}
bool:IsValidClient(client)
{
if ( !( 1 <= client <= MaxClients ) || !IsClientInGame(client) )
return false;
return true;
}