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
|
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#include <gokz/core>
#undef REQUIRE_EXTENSIONS
#undef REQUIRE_PLUGIN
#include <updater>
#pragma newdecls required
#pragma semicolon 1
public Plugin myinfo =
{
name = "GOKZ Goto",
author = "DanZay",
description = "Allows players to teleport to another player",
version = GOKZ_VERSION,
url = GOKZ_SOURCE_URL
};
#define UPDATER_URL GOKZ_UPDATER_BASE_URL..."gokz-goto.txt"
// =====[ PLUGIN EVENTS ]=====
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
RegPluginLibrary("gokz-goto");
return APLRes_Success;
}
public void OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("gokz-common.phrases");
LoadTranslations("gokz-goto.phrases");
RegisterCommands();
}
public void OnAllPluginsLoaded()
{
if (LibraryExists("updater"))
{
Updater_AddPlugin(UPDATER_URL);
}
}
public void OnLibraryAdded(const char[] name)
{
if (StrEqual(name, "updater"))
{
Updater_AddPlugin(UPDATER_URL);
}
}
// =====[ GOTO ]=====
// Returns whether teleport to target was successful
bool GotoPlayer(int client, int target, bool printMessage = true)
{
if (GOKZ_GetCoreOption(client, Option_Safeguard) > Safeguard_Disabled && GOKZ_GetTimerRunning(client) && GOKZ_GetValidTimer(client))
{
if (printMessage)
{
GOKZ_PrintToChat(client, true, "%t", "Safeguard - Blocked");
GOKZ_PlayErrorSound(client);
}
return false;
}
if (target == client)
{
if (printMessage)
{
GOKZ_PrintToChat(client, true, "%t", "Goto Failure (Not Yourself)");
GOKZ_PlayErrorSound(client);
}
return false;
}
if (!IsPlayerAlive(target))
{
if (printMessage)
{
GOKZ_PrintToChat(client, true, "%t", "Goto Failure (Dead)");
GOKZ_PlayErrorSound(client);
}
return false;
}
float targetOrigin[3];
float targetAngles[3];
Movement_GetOrigin(target, targetOrigin);
Movement_GetEyeAngles(target, targetAngles);
if (!IsPlayerAlive(client))
{
GOKZ_RespawnPlayer(client);
}
TeleportPlayer(client, targetOrigin, targetAngles);
GOKZ_PrintToChat(client, true, "%t", "Goto Success", target);
if (GOKZ_GetTimerRunning(client))
{
GOKZ_PrintToChat(client, true, "%t", "Timer Stopped (Goto)");
GOKZ_StopTimer(client);
}
return true;
}
// =====[ GOTO MENU ]=====
int DisplayGotoMenu(int client)
{
Menu menu = new Menu(MenuHandler_Goto);
menu.SetTitle("%T", "Goto Menu - Title", client);
int menuItems = GotoMenuAddItems(client, menu);
if (menuItems == 0)
{
delete menu;
}
else
{
menu.Display(client, MENU_TIME_FOREVER);
}
return menuItems;
}
public int MenuHandler_Goto(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
char info[16];
menu.GetItem(param2, info, sizeof(info));
int target = GetClientOfUserId(StringToInt(info));
if (!IsValidClient(target))
{
GOKZ_PrintToChat(param1, true, "%t", "Player No Longer Valid");
GOKZ_PlayErrorSound(param1);
DisplayGotoMenu(param1);
}
else if (!GotoPlayer(param1, target))
{
DisplayGotoMenu(param1);
}
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
// Returns number of items added to the menu
int GotoMenuAddItems(int client, Menu menu)
{
char display[MAX_NAME_LENGTH + 4];
int targetCount = 0;
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || !IsPlayerAlive(i) || i == client)
{
continue;
}
if (IsFakeClient(i))
{
FormatEx(display, sizeof(display), "BOT %N", i);
}
else
{
FormatEx(display, sizeof(display), "%N", i);
}
menu.AddItem(IntToStringEx(GetClientUserId(i)), display, ITEMDRAW_DEFAULT);
targetCount++;
}
return targetCount;
}
// =====[ COMMANDS ]=====
void RegisterCommands()
{
RegConsoleCmd("sm_goto", CommandGoto, "[KZ] Teleport to another player. Usage: !goto <player>");
}
public Action CommandGoto(int client, int args)
{
// If no arguments, display the goto menu
if (args < 1)
{
if (DisplayGotoMenu(client) == 0)
{
// No targets, so show error
GOKZ_PrintToChat(client, true, "%t", "No Players Found");
GOKZ_PlayErrorSound(client);
}
}
// Otherwise try to teleport to the specified player
else
{
char specifiedPlayer[MAX_NAME_LENGTH];
GetCmdArg(1, specifiedPlayer, sizeof(specifiedPlayer));
int target = FindTarget(client, specifiedPlayer, false, false);
if (target != -1)
{
GotoPlayer(client, target);
}
}
return Plugin_Handled;
}
|