This repository has been archived by the owner on Nov 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerrespawn.sp
138 lines (117 loc) · 2.96 KB
/
playerrespawn.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
#pragma semicolon 1
#include <sourcemod>
#include <autoexecconfig>
#undef REQUIRE_PLUGIN
#include <updater>
#undef REQUIRE_EXTENSIONS
#include <cstrike>
#include <tf2>
#include <dodhooks>
#define REQUIRE_EXTENSIONS
#define RESPAWN_VERSION "1.1.0"
#define UPDATE_URL "http://update.bara.in/playerrespawn.txt"
new Handle:g_HEnablePlugin = INVALID_HANDLE;
new Handle:g_hEnableCount = INVALID_HANDLE;
new Handle:g_hRespawnCount = INVALID_HANDLE;
new g_iRespawnCount[MAXPLAYERS+1] = 0;
public Plugin:myinfo =
{
name = "Player Respawn",
author = "Bara",
description = "Players are able to respawn themselves",
version = RESPAWN_VERSION,
url = "www.bara.in"
}
public OnPluginStart()
{
LoadTranslations("playerrespawn.phrases");
CreateConVar("playerrespawn_version", RESPAWN_VERSION, "Player Respawn", FCVAR_NOTIFY|FCVAR_DONTRECORD);
AutoExecConfig_SetFile("plugin.playerrespawn", "sourcemod");
AutoExecConfig_SetCreateFile(true);
g_HEnablePlugin = AutoExecConfig_CreateConVar("respawn_enable", "1", "Enable / Disable this Player Respawn Plugin", _, true, 0.0, true, 1.0);
g_hEnableCount = AutoExecConfig_CreateConVar("respawn_enable_count", "1", "Enable / Disable certain number of Respawn per Round", _, true, 0.0, true, 1.0);
g_hRespawnCount = AutoExecConfig_CreateConVar("respawn_count", "2", "How many respawn Count per Round?");
AutoExecConfig_ExecuteFile();
AutoExecConfig_CleanFile();
RegConsoleCmd("sm_respawn", Command_Respawn);
HookEvent("round_end", Event_RoundEnd);
if (LibraryExists("updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
}
public OnLibraryAdded(const String:name[])
{
if (StrEqual(name, "updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
}
public Event_RoundEnd(Handle:event,const String:name[],bool:dontBroadcast)
{
if(GetConVarInt(g_HEnablePlugin))
{
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientValid(i))
{
g_iRespawnCount[i] = 0;
}
}
}
}
public Action:Command_Respawn(client, args)
{
if(GetConVarInt(g_HEnablePlugin))
{
if(!IsPlayerAlive(client))
{
if(GetConVarInt(g_hEnableCount))
{
if(GetConVarInt(g_hRespawnCount) != g_iRespawnCount[client])
{
g_iRespawnCount[client]++;
Respawn_Player(client);
}
else
{
ReplyToCommand(client, "%T", "RespawnReached", client);
}
}
else
{
Respawn_Player(client);
}
}
else
{
ReplyToCommand(client, "%T", "PlayerAlive", client);
}
}
}
stock Respawn_Player(client)
{
if(GetEngineVersion() == Engine_CSS || GetEngineVersion() == Engine_CSGO)
{
CS_RespawnPlayer(client);
PrintToChatAll("%t", "PlayerSpawned", client);
}
else if(GetEngineVersion() == Engine_TF2)
{
TF2_RespawnPlayer(client);
PrintToChatAll("%t", "PlayerSpawned", client);
}
else if(GetEngineVersion() == Engine_DODS)
{
RespawnPlayer(client, true);
PrintToChatAll("%t", "PlayerSpawned", client);
}
}
public bool:IsClientValid(client)
{
if(client > 0 && client <= MaxClients && IsClientInGame(client))
{
return true;
}
return false;
}