/
showdamage.sp
173 lines (138 loc) · 5.23 KB
/
showdamage.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
164
165
166
167
168
169
170
171
172
173
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sourcemod>
#include <clientprefs>
#define COND_THERMAL (1<<3)
//Version is auto-filled by the travis builder
public Plugin myinfo =
{
name = "Show Damage",
author = "exvel, stickz, malt",
description = "Shows damage in the center of the screen.",
version = "dummy",
url = "www.sourcemod.net"
}
int player_damage[MAXPLAYERS + 1];
bool block_timer[MAXPLAYERS + 1] = {false,...};
char DamageEventName[16];
int MaxDamage = 10000000;
#include "nd_show_damage/clientprefs.sp"
//CVars' handles
ConVar gcvar_enabled;
ConVar gcvar_ff;
ConVar gcvar_own_dmg;
ConVar gcvar_text_area;
#define UPDATE_URL "https://github.com/stickz/Redstone/raw/build/updater/showdamage/showdamage.txt"
#include "updater/standard.sp"
public void OnPluginStart()
{
CreateConvars(); //plugin controls
AddUpdaterLibrary(); //auto-updater support
AddClientPrefs(); //client pref support (toggle on/off)
LoadTranslations("showdamage.phrases"); //translation phrase support
AutoExecConfig(true, "showdamage");
SetupEvents(); //add needed event hooks and damage things
}
public void OnClientConnected(int client)
{
block_timer[client] = false;
}
public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
// The syntax is shortened from block_timer[client]
block_timer[GetClientOfUserId(event.GetInt("userid"))] = false;
return Plugin_Continue;
}
public Action ShowDamage(Handle timer, int client)
{
block_timer[client] = false;
if (player_damage[client] <= 0 || !client || !IsClientInGame(client))
return Plugin_Continue;
switch (gcvar_text_area.IntValue)
{
case 1:
{
if (option_show_thermal[client] && GetEntProp(client, Prop_Send, "m_nPlayerCond") & COND_THERMAL)
{
Handle HudText = CreateHudSynchronizer();
SetHudTextParams(-1.0, 0.25, 0.1, 255, 255, 255, 255);
ShowSyncHudText(client, HudText, "%t", "CenterText Damage Text", player_damage[client]);
CloseHandle(HudText);
}
else if (option_show_damage[client])
{
PrintCenterText(client, "%t", "CenterText Damage Text", player_damage[client]);
}
}
case 2: PrintHintText(client, "%t", "HintText Damage Text", player_damage[client]);
case 3: PrintToChat(client, "%t", "Chat Damage Text", player_damage[client]);
}
player_damage[client] = 0;
return Plugin_Continue;
}
public Action Event_PlayerHurt(Event event, const char[] name, bool dontBroadcast)
{
int attacker = GetClientOfUserId(event.GetInt("attacker")),
client = GetClientOfUserId(event.GetInt("userid")),
damage = event.GetInt(DamageEventName);
CalcDamage(client, attacker, damage);
return Plugin_Continue;
}
public Action Event_InfectedHurt(Event event, const char[] name, bool dontBroadcast)
{
int attacker = GetClientOfUserId(event.GetInt("attacker")),
damage = event.GetInt("amount");
CalcDamage(0, attacker, damage);
return Plugin_Continue;
}
void CalcDamage(int client, int attacker, int damage)
{
if (!gcvar_enabled.BoolValue || attacker == 0 || IsFakeClient(attacker) || !IsClientInGame(attacker) || damage > MaxDamage)
return;
//If client == 0 than skip this verifying. It can be an infected or something else without client index.
if (client != 0)
{
if (client == attacker && !gcvar_own_dmg.BoolValue)
return;
else if (GetClientTeam(client) == GetClientTeam(attacker) && !gcvar_ff.BoolValue)
return;
}
player_damage[attacker] += damage;
if (block_timer[attacker])
return;
CreateTimer(0.01, ShowDamage, attacker);
block_timer[attacker] = true;
}
void CreateConvars()
{
gcvar_enabled = CreateConVar("sm_show_damage", "1", "Enabled/Disabled show damage functionality, 0 = off/1 = on", _, true, 0.0, true, 1.0);
gcvar_ff = CreateConVar("sm_show_damage_ff", "0", "Show friendly fire damage, 0 = off/1 = on", _, true, 0.0, true, 1.0);
gcvar_own_dmg = CreateConVar("sm_show_damage_own_dmg", "0", "Show your own damage, 0 = off/1 = on", _, true, 0.0, true, 1.0);
gcvar_text_area = CreateConVar("sm_show_damage_text_area", "1", "Defines the area for damage text:\n 1 = in the center of the screen\n 2 = in the hint text area \n 3 = in chat area of screen", _, true, 1.0, true, 3.0);
}
void SetupEvents()
{
HookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Post);
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
char gameName[80];
GetGameFolderName(gameName, 80);
if (StrEqual(gameName, "left4dead") || StrEqual(gameName, "left4dead2"))
{
HookEvent("infected_hurt", Event_InfectedHurt, EventHookMode_Post);
MaxDamage = 2000;
}
DamageEventName = StrEqual(gameName, "dod") || StrEqual(gameName, "hidden")
? "damage"
: "dmg_health";
}