-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhl_goto.sp
350 lines (297 loc) · 9.05 KB
/
hl_goto.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
#include <sourcemod>
#include <sdktools>
#pragma semicolon 1
#pragma newdecls required
#define PLUGIN_VERSION "1.7"
ConVar gcv_bPluginEnabled;
ConVar gcv_bBotsEnabled;
ConVar gcv_bIgnoreImmunity;
public Plugin myinfo =
{
name = "Teleport Player",
author = "Headline, Snippents From : HyperKiLLeR",
description = "Teleport player(s)",
version = PLUGIN_VERSION,
url = "http://www.michaelwflaherty.com"
};
public void OnPluginStart()
{
LoadTranslations("common.phrases");
gcv_bPluginEnabled = CreateConVar("hl_goto_enabled", "1", "Enables and disables the goto plugin", FCVAR_NOTIFY, true, 0.0, true, 1.0);
gcv_bBotsEnabled = CreateConVar("hl_goto_allow_bots", "1", "Enables and disables the ability to move bots", FCVAR_NOTIFY, true, 0.0, true, 1.0);
gcv_bIgnoreImmunity = CreateConVar("hl_goto_ignore_immunity", "0", "Enable to ignore immunity permissions", FCVAR_NOTIFY, true, 0.0, true, 1.0);
RegAdminCmd("sm_goto", Command_Goto, ADMFLAG_SLAY, "Go to a player");
RegAdminCmd("sm_bring", Command_Bring, ADMFLAG_SLAY, "Teleport a player to you");
RegAdminCmd("sm_telemenu", Command_TeleMenu, ADMFLAG_SLAY, "Opens the Teleport Menu");
}
public Action Command_Bring(int client, int args)
{
if (!gcv_bPluginEnabled.BoolValue)
{
ReplyToCommand(client, "The goto plugin is disabled!");
return Plugin_Handled;
}
if (args != 1)
{
ReplyToCommand(client, "[SM] Usage bring <target>");
return Plugin_Handled;
}
float fTeleportOrigin[3];
float fPlayerOrigin[3];
char sTarget[65];
GetCmdArg(1, sTarget, sizeof(sTarget));
char sTargetName[MAX_TARGET_LENGTH];
int a_iTargets[MAXPLAYERS];
int iTargetCount;
bool bTN_ML;
if((iTargetCount = ProcessTargetString(sTarget, client, a_iTargets, MAXPLAYERS, (gcv_bIgnoreImmunity.BoolValue)?(COMMAND_FILTER_NO_IMMUNITY|COMMAND_FILTER_ALIVE):(COMMAND_FILTER_ALIVE), sTargetName, sizeof(sTargetName), bTN_ML)) <= 0)
{
PrintToConsole(client, "Not found or invalid parameter.");
return Plugin_Handled;
}
for (int i = 0; i < iTargetCount; i++)
{
int target = a_iTargets[i];
if(IsValidClient(target, gcv_bBotsEnabled.BoolValue?true:false))
{
GetCollisionPoint(client, fPlayerOrigin);
fTeleportOrigin[0] = fPlayerOrigin[0];
fTeleportOrigin[1] = fPlayerOrigin[1];
fTeleportOrigin[2] = (fPlayerOrigin[2] + 4);
TeleportEntity(target, fTeleportOrigin, NULL_VECTOR, NULL_VECTOR);
ReplyToCommand(client, "[SM] Player(s) have been teleported!");
PrintToChat(target, "[SM] You have been brought to %N!", client);
}
}
return Plugin_Handled;
}
public Action Command_Goto(int client, int args)
{
if (!gcv_bPluginEnabled.BoolValue)
{
ReplyToCommand(client, "The hl_goto plugin is disabled!");
return Plugin_Handled;
}
if (args != 1)
{
ReplyToCommand(client, "[SM] Usage sm_goto <target>");
return Plugin_Handled;
}
float fTeleportOrigin[3];
float fPlayerOrigin[3];
char sArg1[MAX_NAME_LENGTH];
GetCmdArg(1, sArg1, sizeof(sArg1));
int iTarget = FindTarget(client, sArg1, gcv_bBotsEnabled.BoolValue?false:true, true);
if (iTarget == -1)
{
return Plugin_Handled;
}
GetClientAbsOrigin(iTarget, fPlayerOrigin);
fTeleportOrigin[0] = fPlayerOrigin[0];
fTeleportOrigin[1] = fPlayerOrigin[1];
fTeleportOrigin[2] = (fPlayerOrigin[2] + 73);
TeleportEntity(client, fTeleportOrigin, NULL_VECTOR, NULL_VECTOR);
PrintToChat(iTarget, "[SM] %N has been brought to you!", client);
PrintToChat(client, "[SM] You have been brought to %N!", iTarget);
return Plugin_Handled;
}
public Action Command_TeleMenu(int client, int args)
{
OpenMainMenu(client);
return Plugin_Handled;
}
public void OpenMainMenu(int client)
{
Menu menu = new Menu(MainMenu_CallBack, MenuAction_Select | MenuAction_End);
menu.SetTitle("Main Menu :");
menu.AddItem("bring", "Bring Player(s)");
menu.AddItem("goto", "Go To Player");
menu.Display(client, MENU_TIME_FOREVER);
}
public int MainMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
{
switch (action)
{
case MenuAction_Select:
{
char item[64];
GetMenuItem(menu, param2, item, sizeof(item));
if (StrEqual(item, "bring"))
{
OpenBringMenu(param1);
}
else if (StrEqual(item, "goto"))
{
OpenGoToMenu(param1);
}
}
case MenuAction_End:
{
delete menu;
}
}
}
void OpenBringMenu(int client)
{
Menu menu = new Menu(BringMenu_CallBack, MenuAction_Select | MenuAction_End);
menu.SetTitle("Bring Menu");
char sCommand[32] = "sm_bring";
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i, gcv_bBotsEnabled.BoolValue?true:false, false))
{
char sInfoBuffer[256];
char sName[MAX_NAME_LENGTH];
char sUserID[MAX_NAME_LENGTH];
char sDisplay[128];
IntToString(GetClientUserId(i), sUserID, sizeof(sUserID));
GetClientName(i, sName, sizeof(sName));
Format(sDisplay, sizeof(sDisplay), "%s (%s)", sName, sUserID);
Format(sInfoBuffer, sizeof(sInfoBuffer), "%s %s", sCommand, sUserID);
menu.AddItem(sInfoBuffer, sDisplay);
}
}
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
public int BringMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
{
switch (action)
{
case MenuAction_Select:
{
char sInfo[64];
GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
char sTempArray[2][32];
ExplodeString(sInfo, " ", sTempArray, sizeof(sTempArray), sizeof(sTempArray[]));
if(!IsValidClient(GetClientOfUserId(StringToInt(sTempArray[1]))))
{
ReplyToCommand(param1, "Invalid target.");
}
else if(!IsPlayerAlive(GetClientOfUserId(StringToInt(sTempArray[1]))))
{
ReplyToCommand(param1, "Player no longer alive.");
}
else
{
char sCommand[300];
Format(sCommand, sizeof(sCommand), "%s #%i", sTempArray[0], StringToInt(sTempArray[1]));
FakeClientCommand(param1, sCommand);
}
}
case MenuAction_Cancel:
{
//param1 is client, param2 is cancel reason (see MenuCancel types)
if (param2 == MenuCancel_ExitBack)
{
OpenMainMenu(param1);
}
}
case MenuAction_End:
{
//param1 is MenuEnd reason, if canceled param2 is MenuCancel reason
delete menu;
}
}
}
void OpenGoToMenu(int client)
{
Menu menu = new Menu(GoToMenu_Callback, MenuAction_Select | MenuAction_End);
menu.SetTitle("Bring Menu ");
char sCommand[32] = "sm_goto";
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i, gcv_bBotsEnabled.BoolValue?true:false, false))
{
char sInfoBuffer[256];
char sName[MAX_NAME_LENGTH];
char sUserID[MAX_NAME_LENGTH];
char sDisplay[128];
IntToString(GetClientUserId(i), sUserID, sizeof(sUserID));
GetClientName(i, sName, sizeof(sName));
Format(sDisplay, sizeof(sDisplay), "%s (%s)", sName, sUserID);
Format(sInfoBuffer, sizeof(sInfoBuffer), "%s %s", sCommand, sUserID);
menu.AddItem(sInfoBuffer, sDisplay);
}
}
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
public int GoToMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
{
switch (action)
{
case MenuAction_Select:
{
//param1 is client, param2 is sInfo
char sInfo[64];
GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
char sTempArray[2][32];
ExplodeString(sInfo, " ", sTempArray, sizeof(sTempArray), sizeof(sTempArray[]));
if(!IsValidClient(GetClientOfUserId(StringToInt(sTempArray[1]))))
{
ReplyToCommand(param1, "Invalid target.");
}
else if(!IsPlayerAlive(GetClientOfUserId(StringToInt(sTempArray[1]))))
{
ReplyToCommand(param1, "Player no longer alive.");
}
else
{
char sCommand[300];
Format(sCommand, sizeof(sCommand), "%s #%i", sTempArray[0], StringToInt(sTempArray[1]));
FakeClientCommand(param1, sCommand);
}
}
case MenuAction_Cancel:
{
//param1 is client, param2 is cancel reason (see MenuCancel types)
if (param2 == MenuCancel_ExitBack)
{
OpenMainMenu(param1);
}
}
case MenuAction_End:
{
//param1 is MenuEnd reason, if canceled param2 is MenuCancel reason
delete menu;
}
}
}
void GetCollisionPoint(int client, float pos[3])
{
float vOrigin[3];
float vAngles[3];
GetClientEyePosition(client, vOrigin);
GetClientEyeAngles(client, vAngles);
Handle trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SOLID, RayType_Infinite, TraceEntityFilterPlayer);
if(TR_DidHit(trace))
{
TR_GetEndPosition(pos, trace);
delete trace;
return;
}
delete trace;
}
bool TraceEntityFilterPlayer(int entity, int contentsMask)
{
return entity > MaxClients;
}
bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
{
if(!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
{
return false;
}
return true;
}
/* Changelog
1.0 - Initial Release
1.1 - Added LoadTranslations because I forgot
1.2 - Removed cstrike.inc (allowed access for TF2/etc games)
1.3 - Added CVAR to enable/disable the teleportation of bots & fixed issue where the config file wouldn't get executed
1.4 - Fixed OnConVarChange issue
1.5 - Added menus!
1.6 - Fixed targeting issue & Ported over to new syntax
1.7 - Cleaned code, added new cvar, and removed autoexecconfig
*/