-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrpg_interact_giveitem.sp
120 lines (101 loc) · 3.52 KB
/
rpg_interact_giveitem.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
/*
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 <rpg_interact>
#include <tStocks>
#include <rpg_jobs_core>
#pragma newdecls required
int g_iPlayerTarget[MAXPLAYERS + 1];
char g_cInteraction[64] = "Give Item";
public Plugin myinfo =
{
name = "[T-RP] Interact: Give Item",
author = PLUGIN_AUTHOR,
description = "Adds the Option 'Give Item' to T-RP interact",
version = PLUGIN_VERSION,
url = "https://totenfluch.de"
};
public void OnPluginStart() { }
public void OnMapStart() {
interact_registerInteract(g_cInteraction);
}
public void OnPlayerInteract(int client, int target, char interaction[64]) {
if (!StrEqual(g_cInteraction, interaction))
return;
Menu menu = CreateMenu(giveItemMenuHandler);
char menuTitle[256];
Format(menuTitle, sizeof(menuTitle), "Give %N an Item", g_iPlayerTarget[client]);
SetMenuTitle(menu, menuTitle);
int maxItems = inventory_getClientItemsAmount(client);
for (int i = 0; i <= maxItems; i++) {
if (inventory_isValidItem(client, i)) {
char itemName[128];
if (inventory_getItemNameBySlotAndClient(client, i, itemName, "")) {
char cId[8];
IntToString(i, cId, sizeof(cId));
AddMenuItem(menu, cId, itemName);
}
}
}
DisplayMenu(menu, client, 60);
}
public int giveItemMenuHandler(Handle menu, MenuAction action, int client, int item) {
if (action == MenuAction_Select) {
float playerPos[3];
float entPos[3];
if (!isValidClient(client))
return;
if (!isValidClient(g_iPlayerTarget[client]))
return;
GetClientAbsOrigin(client, playerPos);
GetClientAbsOrigin(g_iPlayerTarget[client], entPos);
if (GetVectorDistance(playerPos, entPos) > 100.0)
return;
char cId[8];
GetMenuItem(menu, item, cId, sizeof(cId));
int theId = StringToInt(cId);
char reason[256];
Format(reason, sizeof(reason), "Transfered from %N to %N", client, g_iPlayerTarget[client]);
char categoryBuffer[128];
inventory_getItemCategoryBySlotAndClient(client, theId, categoryBuffer, "");
if (StrEqual(categoryBuffer, "Police Weapon") && !jobs_isActiveJob(client, "Police")) {
PrintToChat(client, "[-T-] Cannot transfer this Item");
return;
}
char flags[8];
inventory_getItemFlagsBySlot(client, theId, flags);
if (StrContains(flags, "v") != -1 && !isVipRank2(g_iPlayerTarget[client])) {
PrintToChat(client, "[-T-] Cannot transfer this Item (VIP Only)");
return;
}
if (inventory_isValidItem(client, theId)) {
inventory_transferItemToPlayerBySlot(client, g_iPlayerTarget[client], theId, reason);
}
}
if (action == MenuAction_End) {
delete menu;
}
}
public void OnClientPostAdminCheck(int client) {
g_iPlayerTarget[client] = -1;
}
public void OnPlayerInteractionStarted(int client, int target) {
g_iPlayerTarget[client] = target;
}