Skip to content

Commit d43f0eb

Browse files
committed
Add enable/disable custom respawn location cvar
Add sm_player_spawns cvar to allow enabling/disabling custom respawn locations. Players will not be able to set/clear respawn locations and will instead be respawned at the map defined spawn locations when sm_player_spawns is set to 0.
1 parent 73a84cd commit d43f0eb

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ https://forums.alliedmods.net/showthread.php?p=877834
2020
- Counter Strike: Global Offensive
2121

2222
<h2>Cvars:</h2>
23-
`sm_player_spawns_version = 1.0.0` (cannot be changed)
24-
25-
`sm_players_spawn_admin_only = 1` - Toggles Admin Only spawn saving
23+
- `sm_player_spawns_version = 1.1.0` (cannot be changed)
24+
- `sm_player_spawns = 1` - Respawn players to their custom locations on death; 0 - disabled, 1 - enabled
25+
- `sm_players_spawn_admin_only = 1` - Toggles Admin Only spawn saving; 0 - disabled, 1 - enabled
2626

2727
<h2>Cmds:</h2>
2828
- `sm_setspawn`
@@ -33,5 +33,7 @@ https://forums.alliedmods.net/showthread.php?p=877834
3333
- playerspawns.smx into /addons/sourcemod/plugins
3434

3535
<h2>Changelog:</h2>
36+
- 1.1.0 (2015-01-21)
37+
- Add `sm_player_spawns` cvar to allow enabling/disabling custom spawn locations
3638
- 1.0.0 (2015-01-21)
3739
- Initial release

playerspawns.smx

264 Bytes
Binary file not shown.

playerspawns.sp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Custom Spawn V1.0
2+
* Custom Spawn V1.1.0
33
* By David Y.
44
* 2015-01-21
55
*
@@ -21,6 +21,7 @@
2121
#include <sdktools>
2222

2323
new Handle:sm_players_spawn_admin_only = INVALID_HANDLE;
24+
new Handle:sm_player_spawns = INVALID_HANDLE;
2425

2526
static Float:SpawnPoint[MAXPLAYERS][3];
2627
static bool:SpawnSet[MAXPLAYERS];
@@ -30,13 +31,14 @@ public Plugin:myinfo = {
3031
name = "Player Spawns",
3132
author = "David Y.",
3233
description = "Players set a custom spawnpoint for themselves.",
33-
version = "1.0.0",
34+
version = "1.1.0",
3435
url = "http://www.davidvyee.com/"
3536
}
3637

3738
public OnPluginStart() {
38-
CreateConVar("sm_player_spawns_version", "1.0.0", "Player Spawns Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
39-
sm_players_spawn_admin_only = CreateConVar("sm_players_spawn_admin_only", "0", "Toggles Admin Only spawn saving.", FCVAR_PLUGIN);
39+
CreateConVar("sm_player_spawns_version", "1.1.0", "Player Spawns Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
40+
sm_player_spawns = CreateConVar("sm_player_spawns", "1", "Respawn players to their custom locations on death; 0 - disabled, 1 - enabled");
41+
sm_players_spawn_admin_only = CreateConVar("sm_players_spawn_admin_only", "0", "Toggles Admin Only spawn saving; 0 - disabled, 1 - enabled", FCVAR_PLUGIN);
4042
RegConsoleCmd("sm_setspawn", SetSpawn);
4143
RegConsoleCmd("sm_clearspawn", ClearSpawn);
4244

@@ -52,6 +54,12 @@ public OnClientPutInServer(Client) {
5254
}
5355

5456
public Action:SetSpawn(Client, Args) {
57+
new playerSpawnsState = GetConVarInt(sm_player_spawns);
58+
if(playerSpawnsState == 0) {
59+
PrintToChat(Client, "[SM] You cannot set your spawn location because player spawns has been disabled.");
60+
return Plugin_Handled;
61+
}
62+
5563
if(SpawnSetDisabled == true) {
5664
PrintToChat(Client, "[SM] You cannot set your spawn right now.");
5765
return Plugin_Handled;
@@ -89,6 +97,12 @@ public Action:SetSpawn(Client, Args) {
8997
}
9098

9199
public Action:ClearSpawn(Client, Args) {
100+
new playerSpawnsState = GetConVarInt(sm_player_spawns);
101+
if(playerSpawnsState == 0) {
102+
PrintToChat(Client, "[SM] You cannot clear your spawn location because player spawns has been disabled.");
103+
return Plugin_Handled;
104+
}
105+
92106
if(Args == 0) {
93107
if(Client == 0) {
94108
return Plugin_Handled;
@@ -202,17 +216,20 @@ public Action:ClearSpawn(Client, Args) {
202216

203217
public PlayerSpawn(Handle:Event, const String:Name[], bool:Broadcast)
204218
{
205-
decl Client;
206-
Client = GetClientOfUserId(GetEventInt(Event, "userid"));
219+
new playerSpawnsState = GetConVarInt(sm_player_spawns);
220+
if(playerSpawnsState > 0) {
221+
decl Client;
222+
Client = GetClientOfUserId(GetEventInt(Event, "userid"));
207223

208-
new AdminId:id = GetUserAdmin(Client);
224+
new AdminId:id = GetUserAdmin(Client);
209225

210-
if(GetConVarBool(sm_players_spawn_admin_only) && id == INVALID_ADMIN_ID) {
211-
return;
212-
}
226+
if(GetConVarBool(sm_players_spawn_admin_only) && id == INVALID_ADMIN_ID) {
227+
return;
228+
}
213229

214-
if(SpawnSet[Client]) {
215-
TeleportEntity(Client, SpawnPoint[Client], NULL_VECTOR, NULL_VECTOR);
230+
if(SpawnSet[Client]) {
231+
TeleportEntity(Client, SpawnPoint[Client], NULL_VECTOR, NULL_VECTOR);
232+
}
216233
}
217234
}
218235

0 commit comments

Comments
 (0)