-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathl4d2_tank_announce_rl4d2l.sp
More file actions
112 lines (97 loc) · 2.49 KB
/
l4d2_tank_announce_rl4d2l.sp
File metadata and controls
112 lines (97 loc) · 2.49 KB
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
#pragma semicolon 1
#pragma newdecls required
#define L4D2Team_Infected 3
#define L4D2Infected_Tank 8
#include <sourcemod>
#include <sdktools_sound>
#include <colors>
#undef REQUIRE_PLUGIN
#include <l4d_tank_control_eq>
#define REQUIRE_PLUGIN
#define PLUGIN_VERSION "1.4.1"
#define DANG "ui/pickup_secret01.wav"
int tankCount = 0;
public Plugin myinfo =
{
name = "L4D2 Tank Announcer - RL4D2L",
author = "Visor, Forgetest, xoxo, devilesk",
description = "Announce in chat and via a sound when a Tank has spawned",
version = PLUGIN_VERSION,
url = "https://github.com/devilesk/rl4d2l-plugins"
};
public void OnPluginStart()
{
HookEvent("round_start", Event_RoundEnd, EventHookMode_PostNoCopy);
}
public void OnMapStart()
{
PrecacheSound(DANG);
}
public void Event_RoundEnd(Event hEvent, const char[] name, bool dontBroadcast)
{
tankCount = 0;
}
public void L4D_OnSpawnTank_Post(int client, const float vecPos[3], const float vecAng[3])
{
int tankClient = client;
char nameBuf[MAX_NAME_LENGTH];
tankCount++;
if (tankCount > 2) return;
if (IsTankSelection())
{
if (IsTank(tankClient) && !IsFakeClient(tankClient))
{
FormatEx(nameBuf, sizeof(nameBuf), "%N", tankClient);
}
else
{
tankClient = GetTankSelection();
if (tankClient > 0
&& IsClientInGame(tankClient))
{
FormatEx(nameBuf, sizeof(nameBuf), "%N", tankClient);
}
else
{
FormatEx(nameBuf, sizeof(nameBuf), "AI");
}
}
}
else
{
HookEvent("player_spawn", Event_PlayerSpawn);
return;
}
CPrintToChatAll("{red}[{default}!{red}] {olive}Tank {default}({red}Control: %s{default}) has spawned!", nameBuf);
EmitSoundToAll(DANG);
}
public void Event_PlayerSpawn(Event event, char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
// Tanky Client?
if (IsTank(client) && !IsFakeClient(client))
{
CPrintToChatAll("{red}[{default}!{red}] {olive}Tank {default}({red}Control: %N{default}) has spawned!", client);
EmitSoundToAll(DANG);
UnhookEvent("player_spawn", Event_PlayerSpawn);
}
}
/**
* Is the player the tank?
*
* @param client client ID
* @return bool
*/
bool IsTank(int client)
{
return (client > 0 && client <= MaxClients && IsClientInGame(client)
&& GetClientTeam(client) == L4D2Team_Infected
&& GetEntProp(client, Prop_Send, "m_zombieClass") == L4D2Infected_Tank);
}
/*
* @return true if GetTankSelection exist false otherwise.
*/
bool IsTankSelection()
{
return (GetFeatureStatus(FeatureType_Native, "GetTankSelection") != FeatureStatus_Unknown);
}