-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathkid-setspawn.sp
132 lines (111 loc) · 3.02 KB
/
kid-setspawn.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
#include <sourcemod>
#include <sdktools>
#undef REQUIRE_PLUGIN
#include <shavit>
#pragma newdecls required
#pragma semicolon 1
bool gB_UseSpawnPosition[MAXPLAYERS + 1];
float gF_PlayerOrigin[MAXPLAYERS + 1][3];
float gF_PlayerAngles[MAXPLAYERS + 1][3];
int gI_SavedTrack[MAXPLAYERS + 1];
public Plugin myinfo =
{
name = "[shavit] SetSpawn",
author = "Nickelony",
description = "Allows players to set their own spawn position.",
version = "1.0",
url = "steamcommunity.com/id/nickelony"
}
public void OnPluginStart()
{
RegConsoleCmd("sm_setspawn", Command_SetSpawn);
RegConsoleCmd("sm_ssp", Command_SetSpawn);
RegConsoleCmd("sm_setstart", Command_SetSpawn);
RegConsoleCmd("sm_removestart", Command_ClearSpawn);
RegConsoleCmd("sm_removespawn", Command_ClearSpawn);
RegConsoleCmd("sm_clearspawn", Command_ClearSpawn);
RegConsoleCmd("sm_clearstart", Command_ClearSpawn);
}
public void OnClientPutInServer(int client)
{
gB_UseSpawnPosition[client] = false;
}
public Action Command_SetSpawn(int client, int args)
{
if(client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}
if(!IsValidClient(client))
{
return Plugin_Handled;
}
SetSpawn(client);
return Plugin_Handled;
}
public Action Command_ClearSpawn(int client, int args)
{
if(client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}
if(!IsValidClient(client))
{
return Plugin_Handled;
}
ClearSpawn(client);
return Plugin_Handled;
}
public void Shavit_OnRestart(int client, int track)
{
if(gB_UseSpawnPosition[client])
{
if(track == gI_SavedTrack[client])
{
Shavit_StopTimer(client);
RequestFrame(OnPostRestart, GetClientSerial(client));
// since the callbacks have been broken and calling out of place we're going to teleport them for 2 ticks.
// one for when it works, one for when it doesn't. both so that the angles don't flicker.
TeleportEntity(client, gF_PlayerOrigin[client], gF_PlayerAngles[client], NULL_VECTOR);
}
}
}
public void OnPostRestart(int serial)
{
int client = GetClientFromSerial(serial);
if(client > 0)
{
TeleportEntity(client, gF_PlayerOrigin[client], gF_PlayerAngles[client], NULL_VECTOR);
}
}
public void ClearSpawn(int client)
{
gB_UseSpawnPosition[client] = false;
Shavit_PrintToChat(client, "Spawn deleted.");
}
public void SetSpawn(int client)
{
if(Shavit_InsideZone(client, Zone_Start, -1))
{
if((GetClientButtons(client) & IN_DUCK) == IN_DUCK)
{
Shavit_PrintToChat(client, "You cannot duck while using this command");
return;
}
float origin[3];
GetEntPropVector(client, Prop_Send, "m_vecOrigin", origin);
float angles[3];
GetClientEyeAngles(client, angles);
gI_SavedTrack[client] = Shavit_GetClientTrack(client);
gF_PlayerOrigin[client] = origin;
gF_PlayerAngles[client] = angles;
gB_UseSpawnPosition[client] = true;
Shavit_PrintToChat(client, "Spawn saved.");
}
else
{
Shavit_PrintToChat(client, "You have to be in the start zone to use this command!");
}
}