-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_player_hud_sprite.as
181 lines (160 loc) · 5.31 KB
/
game_player_hud_sprite.as
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
174
175
176
177
178
179
180
181
#include "utils"
namespace GamePlayerHudSprite {
enum X_POS_TYPES {
X_RELATIVE_LEFT,
X_RELATIVE_RIGHT,
X_RELATIVE_CENTER,
X_ABSOLUTE_LEFT,
X_ABSOLUTE_RIGHT,
X_ABSOLUTE_CENTER
}
enum Y_POS_TYPES {
Y_RELATIVE_TOP,
Y_RELATIVE_BOTTOM,
Y_RELATIVE_CENTER,
Y_ABSOLUTE_TOP,
Y_ABSOLUTE_BOTTOM,
Y_ABSOLUTE_CENTER
}
enum SPAWN_FLAGS {
FL_ALL_PLAYERS = 1
}
// Flags that are controlled by a keyvalue other than spawnflags
const int SPAWN_FLAGS_MASK = HUD_ELEM_ABSOLUTE_X | HUD_ELEM_ABSOLUTE_Y | HUD_ELEM_SCR_CENTER_X | HUD_ELEM_SCR_CENTER_Y;
class game_player_hud_sprite : ScriptBaseEntity
{
int channel;
string spritePath;
uint8 top;
uint8 left;
int16 width; // Range: 0-512 (0 = auto)
int16 height; // Range: 0-512 (0 = auto)
float x;
float y;
RGBA color1;
RGBA color2;
uint8 numframes;
float framerate;
float fadeInTime;
float fadeOutTime;
float holdTime;
float fxTime;
uint8 effect;
uint flags;
bool invertX = false;
bool invertY = false;
bool allPlayers = false;
bool KeyValue( const string& in szKey, const string& in szValue )
{
if (szKey == "channel") channel = atoi(szValue);
else if (szKey == "spritePath") spritePath = szValue;
else if (szKey == "region") {
array<string> values = szValue.Split(" ");
if (values.length() > 0) left = atoi( values[0] );
if (values.length() > 1) top = atoi( values[1] );
if (values.length() > 2) width = atoi( values[2] );
if (values.length() > 3) height = atoi( values[3] );
}
else if (szKey == "numframes") numframes = atoi(szValue);
else if (szKey == "fadein") fadeInTime = atof(szValue);
else if (szKey == "fadeout") fadeOutTime = atof(szValue);
else if (szKey == "holdtime") holdTime = atof(szValue);
else if (szKey == "effecttime") fxTime = atof(szValue);
else if (szKey == "effect") effect = atoi(szValue);
else if (szKey == "x") x = atof(szValue);
else if (szKey == "y") y = atof(szValue);
else if (szKey == "xtype") {
flags &= ~(HUD_ELEM_ABSOLUTE_X | HUD_ELEM_SCR_CENTER_X);
invertX = false;
switch(atoi(szValue)) {
case X_RELATIVE_LEFT: break;
case X_RELATIVE_RIGHT: invertX = true; break;
case X_RELATIVE_CENTER: flags |= HUD_ELEM_SCR_CENTER_X; break;
case X_ABSOLUTE_LEFT: flags |= HUD_ELEM_ABSOLUTE_X; break;
case X_ABSOLUTE_RIGHT: invertX = true; flags |= HUD_ELEM_ABSOLUTE_X; break;
case X_ABSOLUTE_CENTER: invertX = true; flags |= HUD_ELEM_SCR_CENTER_X | HUD_ELEM_ABSOLUTE_X; break;
}
}
else if (szKey == "ytype") {
flags &= ~(HUD_ELEM_ABSOLUTE_Y | HUD_ELEM_SCR_CENTER_Y);
invertY = false;
switch(atoi(szValue)) {
case Y_RELATIVE_TOP: break;
case Y_RELATIVE_BOTTOM: invertY = true; break;
case Y_RELATIVE_CENTER: flags |= HUD_ELEM_SCR_CENTER_Y; break;
case Y_ABSOLUTE_TOP: flags |= HUD_ELEM_ABSOLUTE_Y; break;
case Y_ABSOLUTE_BOTTOM: invertY = true; flags |= HUD_ELEM_ABSOLUTE_Y; break;
case Y_ABSOLUTE_CENTER: invertY = true; flags |= HUD_ELEM_SCR_CENTER_Y | HUD_ELEM_ABSOLUTE_Y; break;
}
}
else if (szKey == "color1") color1 = UtilEnts::parseRgba(szValue);
else if (szKey == "color2") color2 = UtilEnts::parseRgba(szValue);
else return BaseClass.KeyValue( szKey, szValue );
return true;
}
void Spawn()
{
Precache();
}
void Precache()
{
if (spritePath.Length() > 0)
g_Game.PrecacheModel(spritePath);
}
void Use(CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue = 0.0f)
{
array<CBaseEntity@> targets;
// calculating flags here since KeyValue ignores 'spawnflags'
int sflags = self.pev.spawnflags;
flags = (flags & SPAWN_FLAGS_MASK) | (sflags & ~SPAWN_FLAGS_MASK);
allPlayers = sflags & FL_ALL_PLAYERS != 0;
if (allPlayers) {
CBaseEntity@ ent = null;
do {
@ent = g_EntityFuncs.FindEntityByClassname(ent, "player");
if (ent !is null)
{
targets.insertLast(ent);
}
} while (ent !is null);
}
else {
targets = UtilEnts::getTargetsByName(pActivator, pCaller, self.pev.target);
}
for (uint i = 0; i < targets.size(); i++) {
CBasePlayer@ plr = cast<CBasePlayer@>(targets[i]);
if (plr is null or !plr.IsConnected())
continue;
if (useType == USE_OFF) {
g_PlayerFuncs.HudToggleElement(plr, channel, false);
continue;
}
HUDSpriteParams params;
params.channel = channel;
params.flags = flags;
params.spritename = spritePath;
params.left = left;
params.top = top;
params.width = width;
params.height = height;
params.x = invertX ? -x : x;
params.y = invertY ? -y : y;
params.color1 = color1;
params.color2 = color2;
params.frame = int(self.pev.frame);
params.numframes = numframes;
params.framerate = self.pev.framerate;
params.fadeinTime = fadeInTime;
params.fadeoutTime = fadeOutTime;
params.holdTime = holdTime;
params.fxTime = fxTime;
params.effect = effect;
g_PlayerFuncs.HudCustomSprite(plr, params);
}
}
};
void Register()
{
g_CustomEntityFuncs.RegisterCustomEntity( "GamePlayerHudSprite::game_player_hud_sprite", "game_player_hud_sprite" );
}
}