This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSpawnProtection.sp
163 lines (132 loc) · 5.14 KB
/
SpawnProtection.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
#include <sourcemod>
#include <sdktools>
#pragma semicolon 1
#define TEAM_NONE 0
#define TEAM_SPECTATORS 1
new Handle:SpawnProtectionEnabled;
new Handle:SpawnProtectionTime;
new Handle:SpawnProtectionNotify;
new bool:g_bRoundStarted = false;
new bool:g_bGameStarted = false;
public Plugin:myinfo =
{
name = "[INS] SpawnProtection",
author = "Neko-",
description = "Adds spawn protection",
version = "1.0.2"
}
public OnPluginStart()
{
SpawnProtectionEnabled = CreateConVar("sp_enable", "1.0", "Enable or disable spawn protection", FCVAR_NONE, true, 0.0, true, 1.0);
SpawnProtectionTime = CreateConVar("sp_time", "10.0", "Enable or disable spawn protection", FCVAR_NONE, true, 1.0, true, 30.0);
SpawnProtectionNotify = CreateConVar("sp_notify", "1.0", "Enable or disable spawn protection", FCVAR_NONE, true, 0.0, true, 1.0);
AutoExecConfig(true, "ins.spawn_protection");
HookEvent("player_spawn", Event_PlayerSpawnPost);
HookEvent("round_start", Event_RoundStartPost);
HookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Post);
}
public OnMapStart()
{
g_bGameStarted = false;
}
public Action:Event_RoundStartPost(Handle:event, const String:name[], bool:dontBroadcast)
{
//When round just start, we set it to false cuz it havn't start yet
g_bRoundStarted = false;
new nTimerPreround;
//If g_bGameStarted is false, that's mean game havn't start yet. Which will use the first preround timer
if(!g_bGameStarted)
{
nTimerPreround = GetConVarInt(FindConVar("mp_timer_preround_first"));
CreateTimer(float(nTimerPreround), NoMoreRoundProtection);
}
//Else game already started, we will use the normal preround timer
else
{
nTimerPreround = GetConVarInt(FindConVar("mp_timer_preround"));
CreateTimer(float(nTimerPreround), NoMoreRoundProtection);
}
}
public Action:Event_PlayerSpawnPost(Handle:event, const String:name[], bool:dontBroadcast)
{
if(GetConVarInt(SpawnProtectionEnabled) == 1)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new clientTeam = GetClientTeam(client);
//If player is spectator or not in a team (continue)
if((clientTeam == TEAM_NONE) || (clientTeam == TEAM_SPECTATORS))
return Plugin_Continue;
//If player alive (continue)
if(!IsPlayerAlive(client))
return Plugin_Continue;
//If its a bot (continue)
//To prevent bot from having protection
if(IsFakeClient(client))
return Plugin_Continue;
new Float:Time = GetConVarFloat(SpawnProtectionTime);
//If game havn't started, we will use the first preround time and add it to the timer
if(!g_bGameStarted)
{
new Float:nTimerPreround = float(GetConVarInt(FindConVar("mp_timer_preround_first")));
Time += nTimerPreround;
}
//Else if round havn't start yet, we will use the normal preround time and add it to the timer
else if(!g_bRoundStarted)
{
new Float:nTimerPreround = float(GetConVarInt(FindConVar("mp_timer_preround")));
Time += nTimerPreround;
}
//Set damage taken to 0 (So player won't take damage)
SetEntProp(client, Prop_Data, "m_takedamage", 1, 1);
//Create a timer to restore the original damage taken
CreateTimer(Time, RemoveProtection, client);
//If notify set to 1 then we will notify the player that they have spawn protection
if(GetConVarInt(SpawnProtectionNotify) > 0)
//PrintToChat(client, "\x01\x0759b0f9[INS] \x01\x07ee1fd0[SpawnProtection] \x01You have spawn protection for %i seconds", RoundToNearest(Time));
PrintCenterText(client, "You have spawn protection for %i seconds", RoundToNearest(Time));
}
return Plugin_Continue;
}
public Action:Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
new victim = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
if((!IsFakeClient(victim)) && (victim == attacker))
{
//Create a timer to restore the original damage taken
CreateTimer(0.0, RemoveProtection, victim);
}
}
public Action:RemoveProtection(Handle:timer, any:client)
{
if(!IsValidClient(client))
return;
//Get player protection
new nTakeDamage = GetEntProp(client, Prop_Data, "m_takedamage");
//If player still in game
if(IsClientInGame(client) && (nTakeDamage == 1))
{
//Restore the original damage taken to player
SetEntProp(client, Prop_Data, "m_takedamage", 2, 1);
//If notify set to 1 then we will notify the player that their protection have been removed
if(GetConVarInt(SpawnProtectionNotify) > 0)
//PrintToChat(client, "\x01\x0759b0f9[INS] \x01\x07ee1fd0[SpawnProtection] \x01You no longer have spawn protection");
PrintCenterText(client, "You no longer have spawn protection");
}
}
public Action:NoMoreRoundProtection(Handle:timer)
{
//After round started, we set this to true to let it know that our round already started
g_bRoundStarted = true;
//Set g_bGameStarted to true if its false
if(!g_bGameStarted)
{
g_bGameStarted = true;
}
}
bool:IsValidClient(client)
{
if ( !( 1 <= client <= MaxClients ) || !IsClientInGame(client) )
return false;
return true;
}