-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreerun.sp
119 lines (103 loc) · 2.9 KB
/
freerun.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
#include <tf2>
#include <tf2_stocks>
bool
g_bRoundStarted = false,
g_bFreerun = false;
public Plugin myinfo =
{
name = "Deathrun: Freerun",
author = "myst",
description = "Adds the ability for Death to activate a freerun.",
version = "1.0"
};
public void OnPluginStart()
{
HookEvent("arena_round_start", Event_RoundStart);
HookEvent("arena_win_panel", Event_RoundEnd);
RegConsoleCmd("sm_fr", Command_Freerun);
RegConsoleCmd("sm_free", Command_Freerun);
RegConsoleCmd("sm_freer", Command_Freerun);
RegConsoleCmd("sm_freerun", Command_Freerun);
}
public void OnMapStart()
{
g_bRoundStarted = false;
CreateTimer(1.0, Timer_HUD, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public void OnMapEnd() {
g_bRoundStarted = false;
}
public Action Event_RoundStart(Handle hEvent, char[] sEventName, bool bDontBroadcast)
{
g_bRoundStarted = true;
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i))
{
if (GetClientTeam(i) == view_as<int>(TFTeam_Blue) && IsPlayerAlive(i))
{
SetHudTextParamsEx(-1.0, -1.0, 1.0, {255,255,255,255}, {0,0,0,0}, 2, 0.1, 0.1, 0.1);
ShowHudText(i, -1, "Freerun? Type !fr to grant runners a free round.");
break;
}
}
}
}
public Action Event_RoundEnd(Handle hEvent, char[] sEventName, bool bDontBroadcast)
{
g_bRoundStarted = false;
g_bFreerun = false;
}
public Action Command_Freerun(int iClient, int iArgs)
{
if (g_bRoundStarted && GetClientTeam(iClient) == view_as<int>(TFTeam_Blue) && IsPlayerAlive(iClient))
{
g_bFreerun = true;
TF2_RemoveAllWeapons(iClient);
PrintHintTextToAll("FREERUN! Traps can no longer be activated.");
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i))
{
if (GetClientTeam(i) == view_as<int>(TFTeam_Blue) && IsPlayerAlive(i))
{
SetHudTextParamsEx(-1.0, -1.0, 2.0, {255,255,255,255}, {0,0,0,0}, 2, 0.1, 0.1, 0.1);
ShowHudText(i, -1, "FREERUN! Traps can no longer be activated.");
break;
}
}
}
}
else
{
if (GetClientTeam(iClient) != view_as<int>(TFTeam_Blue))
PrintToChat(iClient, "[SM] You have to be death to do a free run.");
else if (GetClientTeam(iClient) == view_as<int>(TFTeam_Blue) && !IsPlayerAlive(iClient))
PrintToChat(iClient, "[SM] You have to be alive to do this.");
else if (!g_bRoundStarted)
PrintToChat(iClient, "[SM] Please wait for the round to start first.");
}
return Plugin_Handled;
}
public Action Timer_HUD(Handle hTimer)
{
if (g_bFreerun && g_bRoundStarted)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i))
{
SetHudTextParamsEx(-1.0, 0.88, 1.0, {255,255,255,255}, {255,255,255,200}, 2, 0.1, 0.1, 0.1);
ShowHudText(i, -1, "Free Run");
}
}
}
}
stock bool IsValidClient(int iClient, bool bReplay = true)
{
if (iClient <= 0 || iClient > MaxClients || !IsClientInGame(iClient))
return false;
if (bReplay && (IsClientSourceTV(iClient) || IsClientReplay(iClient)))
return false;
return true;
}