-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrpg_inventory_weaponhandler.sp
340 lines (295 loc) · 11.6 KB
/
rpg_inventory_weaponhandler.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
/*
T-RP
Copyright (C) 2017 Christian Ziegler
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma semicolon 1
#define PLUGIN_AUTHOR "Totenfluch"
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <sdktools>
#include <rpg_inventory_core>
#include <smlib>
#include <rpg_jobs_core>
#pragma newdecls required
int g_iLatestSlotUsed[MAXPLAYERS + 1];
char g_cLastItemUsed[MAXPLAYERS + 1][128];
int g_iPlayerPrevButtons[MAXPLAYERS + 1];
/*
CS:GO Grenades Indexes
*/
#define CSGO_HEGRENADE_AMMO 13
#define CSGO_FLASH_AMMO 14
#define CSGO_SMOKE_AMMO 15
#define INCENDERY_AND_MOLOTOV_AMMO 16
#define DECOY_AMMO 17
public Plugin myinfo =
{
name = "[T-RP] Inventory: Weapon Handler",
author = PLUGIN_AUTHOR,
description = "Handles weapon equip and stash for T-RP",
version = PLUGIN_VERSION,
url = "https://totenfluch.de"
};
public void OnPluginStart()
{
RegConsoleCmd("sm_stash", cmdStashWeapon, "Stashes Weapon to inventory");
//AddCommandListener(dropCSGO, "drop");
}
public void OnMapStart() {
inventory_addItemHandle("Weapon", 4);
inventory_addItemHandle("item_kevlar", 1);
inventory_addItemHandle("item_assaultsuit", 1);
}
public void OnClientAuthorized(int client) {
g_iLatestSlotUsed[client] = -1;
strcopy(g_cLastItemUsed[client], 128, "");
}
public Action cmdStashWeapon(int client, int args) {
stashWeapon(client, false, "");
return Plugin_Handled;
}
public void inventory_onItemUsed(int client, char itemname[128], int weight, char category[64], char category2[64], int rarity, char timestamp[64], int slot) {
if (!(StrContains(category, "Weapon") != -1 || StrEqual(itemname, "item_kevlar") || StrEqual(itemname, "item_assaultsuit")))
return;
if (StrEqual(category, "Police Weapon") && !jobs_isActiveJob(client, "Police")) {
PrintToChat(client, "[-T-] Can not use Police Weapon");
return;
}
Menu wMenu = CreateMenu(weaponMenuHandler);
strcopy(g_cLastItemUsed[client], 128, itemname);
g_iLatestSlotUsed[client] = slot;
char out[512];
Format(out, sizeof(out), "Used: %s (Weight: %i|Category: %s|Category2: %s|rarity: %i | Slot: %i)", itemname, weight, category, category2, rarity, slot);
PrintToConsole(client, out);
SetMenuTitle(wMenu, "What do you want to do?");
if (StrContains(itemname, "weapon_") != -1) {
AddMenuItem(wMenu, "EquipAndStash", "Equip Weapon (Stashes weapon slot)");
//AddMenuItem(wMenu, "GiveWeapon", "Give me the Weapon");
AddMenuItem(wMenu, "Delete", "Delete Weapon");
} else if (StrEqual(itemname, "item_assaultsuit")) {
SetMenuTitle(wMenu, "What do you want to do?");
AddMenuItem(wMenu, "eqSuit", "Equip Assaultsuit");
AddMenuItem(wMenu, "Delete", "Delete Assaultsuit");
} else if (StrEqual(itemname, "item_kevlar")) {
SetMenuTitle(wMenu, "What do you want to do?");
AddMenuItem(wMenu, "eqKevlar", "Equip Kevlar");
AddMenuItem(wMenu, "Delete", "Delete Kevlar");
} else {
delete wMenu;
return;
}
DisplayMenu(wMenu, client, 30);
}
public int weaponMenuHandler(Handle menu, MenuAction action, int client, int item) {
if (action == MenuAction_Select) {
char cValue[32];
GetMenuItem(menu, item, cValue, sizeof(cValue));
if (StrEqual(cValue, "EquipAndStash")) {
int slot = getSlot(g_cLastItemUsed[client]);
if (slot != 3) {
if (stashWeaponSlot(client, slot)) {
takeItem(client, g_cLastItemUsed[client], g_iLatestSlotUsed[client]);
}
} else {
takeItem(client, g_cLastItemUsed[client], g_iLatestSlotUsed[client]);
}
} else if (StrEqual(cValue, "GiveWeapon")) {
takeItem(client, g_cLastItemUsed[client], g_iLatestSlotUsed[client]);
} else if (StrEqual(cValue, "Delete")) {
inventory_removePlayerItems(client, g_cLastItemUsed[client], 1, "Deleted from Inventory");
} else if (StrEqual(cValue, "eqSuit")) {
takeItemSuit(client, g_cLastItemUsed[client]);
} else if (StrEqual(cValue, "eqKevlar")) {
takeItemSuit(client, g_cLastItemUsed[client]);
}
strcopy(g_cLastItemUsed[client], 128, "");
}
if (action == MenuAction_End) {
delete menu;
}
}
public void stashWeapon(int client, bool useOverride, char[] weapon) {
char item[128];
GetClientWeapon(client, item, sizeof(item));
if (useOverride)
strcopy(item, sizeof(item), weapon);
if (StrContains(item, "knife") != -1) {
PrintToChat(client, "Can't stash this one");
return;
}
if (StrEqual(item, "")) {
int wpindex = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
GetEntityClassname(wpindex, item, sizeof(item));
}
if (StrEqual(item, ""))
return;
int slot = getSlot(item);
if (slot != -1 && slot != 3) {
int weaponIndex = GetPlayerWeaponSlot(client, slot);
if (weaponIndex != -1) {
int primaryWeaponClip = Weapon_GetPrimaryClip(weaponIndex);
int primaryWeaponAmmo = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryReserveAmmoCount");
char weaponType[64];
if (jobs_isActiveJob(client, "Police"))
strcopy(weaponType, sizeof(weaponType), "Police Weapon");
else
strcopy(weaponType, sizeof(weaponType), "Weapon");
if (inventory_givePlayerItem(client, item, primaryWeaponClip * 1000 + primaryWeaponAmmo, "", weaponType, "Weapon", 2, "Stashed Weapon")) {
RemovePlayerItem(client, weaponIndex);
RemoveEdict(weaponIndex);
}
}
} else if (slot == 3) {
char weaponType[64];
if (jobs_isActiveJob(client, "Police"))
strcopy(weaponType, sizeof(weaponType), "Police Weapon");
else
strcopy(weaponType, sizeof(weaponType), "Weapon");
if (inventory_givePlayerItem(client, item, 1, "", weaponType, "Weapon", 2, "Stashed Grenade"))
Client_RemoveWeapon(client, item, true, true);
}
if (GetPlayerWeaponSlot(client, 2) != -1)
EquipPlayerWeapon(client, GetPlayerWeaponSlot(client, 2));
}
public bool stashWeaponSlot(int client, int slot) {
if (slot != -1 && slot != 3) {
int weaponIndex = GetPlayerWeaponSlot(client, slot);
if (weaponIndex != -1) {
int primaryWeaponClip = Weapon_GetPrimaryClip(weaponIndex);
int primaryWeaponAmmo = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryReserveAmmoCount");
char item[128];
Entity_GetClassName(weaponIndex, item, sizeof(item));
char weaponType[64];
if (jobs_isActiveJob(client, "Police"))
strcopy(weaponType, sizeof(weaponType), "Police Weapon");
else
strcopy(weaponType, sizeof(weaponType), "Weapon");
if (inventory_givePlayerItem(client, item, primaryWeaponClip * 1000 + primaryWeaponAmmo, "", weaponType, "Weapon", 2, "Stashed Weapon")) {
RemovePlayerItem(client, weaponIndex);
RemoveEdict(weaponIndex);
if (GetPlayerWeaponSlot(client, 2) != -1)
EquipPlayerWeapon(client, GetPlayerWeaponSlot(client, 2));
return true;
} else {
return false;
}
}
}
return true;
}
public void takeItemSuit(int client, char[] item) {
char item2[128];
strcopy(item2, sizeof(item2), item);
if (inventory_removePlayerItems(client, item2, 1, "Taken from Inventory")) {
SetEntProp(client, Prop_Data, "m_ArmorValue", 100, 1);
if (StrContains(item2, "assaultsuit") != -1) {
SetEntProp(client, Prop_Send, "m_bHasHelmet", 1);
}
}
}
public void takeItem(int client, char[] item, int islot) {
char cItem[128];
inventory_getItemNameBySlotAndClient(client, islot, cItem, "");
if (!StrEqual(cItem, item)) {
LogError("%N had an error with equiping >%s< | >%s<", client, item, cItem);
PrintToChat(client, "[-T-] There was an error equiping your Weapon");
return;
}
char item2[128];
strcopy(item2, sizeof(item2), item);
int weight = inventory_getItemWeightBySlot(client, islot);
inventory_deleteItemBySlot(client, islot, "Equiped Weapon");
GivePlayerItem(client, item);
int slot = getSlot(item2);
if (GetPlayerWeaponSlot(client, slot) != -1 && slot != 3) {
EquipPlayerWeapon(client, GetPlayerWeaponSlot(client, slot));
int weaponIndex;
if ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1) {
Weapon_SetClips(weaponIndex, weight / 1000, weight % 1000);
SetEntProp(weaponIndex, Prop_Send, "m_iPrimaryReserveAmmoCount", weight % 1000);
}
}
}
public int getSlot(char item[128]) {
if (isPistol(item))
return 1;
else if (isSMG(item) || isRifle(item) || isShotgun(item) || isSniper(item) || isMg(item))
return 0;
else if (isGrenade(item))
return 3;
return -1;
}
public bool isPistol(char[] weaponName) {
if (StrContains(weaponName, "hkp2000", false) != -1 || StrContains(weaponName, "p250", false) != -1 || StrContains(weaponName, "glock", false) != -1 || StrContains(weaponName, "deagle", false) != -1 || StrContains(weaponName, "revolver", false) != -1 || StrContains(weaponName, "usp", false) != -1 || StrContains(weaponName, "tec9", false) != -1 || StrContains(weaponName, "fiveseven", false) != -1 || StrContains(weaponName, "cz75a", false) != -1 || StrContains(weaponName, "elite", false) != -1) {
return true;
} else {
return false;
}
}
public bool isSMG(char[] weaponName) {
if (StrContains(weaponName, "p90", false) != -1 || StrContains(weaponName, "mp7", false) != -1 || StrContains(weaponName, "ump45", false) != -1 || StrContains(weaponName, "mp9", false) != -1 || StrContains(weaponName, "mac10", false) != -1 || StrContains(weaponName, "bizon", false) != -1) {
return true;
} else {
return false;
}
}
public bool isRifle(char[] weaponName) {
if (StrContains(weaponName, "ak47", false) != -1 || StrContains(weaponName, "aug", false) != -1 || StrContains(weaponName, "famas", false) != -1 || StrContains(weaponName, "galilar", false) != -1 || StrContains(weaponName, "sg556", false) != -1 || StrContains(weaponName, "m4a1", false) != -1) {
return true;
} else {
return false;
}
}
public bool isShotgun(char[] weaponName) {
if (StrContains(weaponName, "xm1014", false) != -1 || StrContains(weaponName, "mag7", false) != -1 || StrContains(weaponName, "nova", false) != -1 || StrContains(weaponName, "sawedoff", false) != -1) {
return true;
} else {
return false;
}
}
public bool isSniper(char[] weaponName) {
if (StrContains(weaponName, "awp", false) != -1 || StrContains(weaponName, "g3sg1", false) != -1 || StrContains(weaponName, "ssg08", false) != -1 || StrContains(weaponName, "scar20", false) != -1) {
return true;
} else {
return false;
}
}
public bool isMg(char[] weaponName) {
if (StrContains(weaponName, "negev", false) != -1 || StrContains(weaponName, "m249", false) != -1) {
return true;
} else {
return false;
}
}
public bool isGrenade(char[] weaponName) {
if (StrContains(weaponName, "grenade") != -1 || StrContains(weaponName, "decoy") != -1 || StrContains(weaponName, "molotov") != -1 || StrContains(weaponName, "flashbang") != -1)
return true;
return false;
}
int g_iDuckPushedTimes[MAXPLAYERS + 1];
public Action OnPlayerRunCmd(int client, int &iButtons, int &iImpulse, float fVelocity[3], float fAngles[3], int &iWeapon, int &tickcount) {
if (IsClientInGame(client) && IsPlayerAlive(client)) {
if (!(g_iPlayerPrevButtons[client] & IN_DUCK) && iButtons & IN_DUCK) {
if (g_iDuckPushedTimes[client] == 1)
cmdStashWeapon(client, 0);
else
g_iDuckPushedTimes[client] = 1;
CreateTimer(0.3, resetDucks, GetClientUserId(client));
}
g_iPlayerPrevButtons[client] = iButtons;
}
}
public Action resetDucks(Handle Timer, int client) {
int theClient = GetClientOfUserId(client);
g_iDuckPushedTimes[theClient] = 0;
}