-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrpg_interact.sp
162 lines (130 loc) · 4.5 KB
/
rpg_interact.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
/*
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_job_police>
#pragma newdecls required
int g_iPlayerPrevButtons[MAXPLAYERS + 1];
Handle g_hOnPlayerInteractionStarted;
Handle g_hOnPlayerInteraction;
ArrayList g_aInteractions;
public Plugin myinfo =
{
name = "[T-RP] Interact Core",
author = PLUGIN_AUTHOR,
description = "Adds Player to Player interaction interface to T-RP",
version = PLUGIN_VERSION,
url = "https://totenfluch.de"
};
public void OnPluginStart() {
g_aInteractions = CreateArray(128, 16);
ClearArray(g_aInteractions);
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
/*
Registers a new Interaction
@Param1 -> char interaction[64]
@return none
*/
CreateNative("interact_registerInteract", Native_RegisterInteract);
/*
Forward when a Client uses another Client
@Param1 -> int client
@Param2 -> int target
@return -
*/
g_hOnPlayerInteractionStarted = CreateGlobalForward("OnPlayerInteractionStarted", ET_Ignore, Param_Cell, Param_Cell);
/*
Forward when a Client interacts with another Client
@Param1 -> int client
@Param2 -> int target
@Param2 -> char interaction[64]
@return -
*/
g_hOnPlayerInteraction = CreateGlobalForward("OnPlayerInteract", ET_Ignore, Param_Cell, Param_Cell, Param_String);
}
public int Native_RegisterInteract(Handle plugin, int numParams) {
char tempinteraction[64];
GetNativeString(1, tempinteraction, 64);
if (FindStringInArray(g_aInteractions, tempinteraction) == -1)
PushArrayString(g_aInteractions, tempinteraction);
}
public void OnClientPostAdminCheck(int client) {
g_iPlayerPrevButtons[client] = 0;
}
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_USE) && iButtons & IN_USE) {
int target;
if ((target = GetClientAimTarget(client, false)) > -1) {
if (isValidClient(target)) {
if (!police_isPlayerCuffed(target)) {
float clientPos[3];
float targetPos[3];
GetClientAbsOrigin(client, clientPos);
GetClientAbsOrigin(target, targetPos);
if (GetVectorDistance(clientPos, targetPos) <= 75.0)
onInteract(client, target);
}
}
}
}
g_iPlayerPrevButtons[client] = iButtons;
}
}
public void onInteract(int client, int target) {
Call_StartForward(g_hOnPlayerInteractionStarted);
Call_PushCell(client);
Call_PushCell(target);
Call_Finish();
char name[MAX_NAME_LENGTH + 8];
GetClientName(target, name, sizeof(name));
Menu interactMenu = CreateMenu(interactMenuHandler);
SetMenuTitle(interactMenu, name);
char id[64];
IntToString(EntIndexToEntRef(target), id, sizeof(id));
AddMenuItem(interactMenu, id, "Poke Player");
for (int i = 0; i < GetArraySize(g_aInteractions); i++) {
char tempI[64];
GetArrayString(g_aInteractions, i, tempI, sizeof(tempI));
AddMenuItem(interactMenu, id, tempI);
}
DisplayMenu(interactMenu, client, 30);
}
public int interactMenuHandler(Handle menu, MenuAction action, int client, int item) {
if (action == MenuAction_Select) {
char cValue[64];
int style;
char display[64];
GetMenuItem(menu, item, cValue, sizeof(cValue), style, display, sizeof(display));
int target = EntRefToEntIndex(StringToInt(cValue));
if (StrEqual(display, "Poke Player"))
PrintToChat(target, "You've been poked by %N", client);
Call_StartForward(g_hOnPlayerInteraction);
Call_PushCell(client);
Call_PushCell(target);
Call_PushString(display);
Call_Finish();
}
if (action == MenuAction_End) {
delete menu;
}
}
stock bool isValidClient(int client) {
return (1 <= client <= MaxClients && IsClientInGame(client));
}