-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzscript.zs
158 lines (137 loc) · 3.35 KB
/
zscript.zs
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
version 4.7
class GGWPDeathMessageHandler : StaticEventHandler
{
private Array<string> _DeathMessages;
private Array<string> _DeathSubtitles;
private bool _PlayingMusic;
private string _Message;
private string _Subtitle;
private string _DMCache;
private string _DSCache;
private int _MsgIndex;
private int _SubIndex;
private int _MsgTimer;
private int _SubTimer;
private ui HUDFont _MainFont;
private ui HUDFont _SubFont;
override void OnRegister()
{
Array<string> messages;
Array<string> subtitles;
int lump = -1;
while (-1 != (lump = Wads.FindLump("deathmessages", lump + 1)))
{
string s = Wads.ReadLump(lump);
s.Replace("\r\n", "\n");
s.Split(messages, "\n");
}
lump = -1;
while (-1 != (lump = Wads.FindLump("deathsubtitles", lump + 1)))
{
string s = Wads.ReadLump(lump);
s.Replace("\r\n", "\n");
s.Split(subtitles, "\n");
}
// Remove blanks
for (int i = 0; i < messages.Size(); i++) if (messages[i] != "") _DeathMessages.Push(messages[i]);
for (int i = 0; i < subtitles.Size(); i++) if (subtitles[i] != "") _DeathSubtitles.Push(subtitles[i]);
}
override void WorldTick()
{
if (Players[ConsolePlayer].mo.Health > 0)
{
_Message = "";
_Subtitle= "";
_MsgIndex = 0;
_SubIndex = 0;
_MsgTimer = 0;
_SubTimer = 0;
if (_PlayingMusic)
{
_PlayingMusic = false;
S_ChangeMusic("*", 0, true, true);
SetMusicVolume(1);
}
return;
}
if (!_PlayingMusic)
{
_PlayingMusic = true;
if (_DeathMessages.Size() > 0) _DMCache = _DeathMessages[Random(0, _DeathMessages.Size() - 1)];
if (_DeathSubtitles.Size() > 0) _DSCache = _DeathSubtitles[Random(0, _DeathSubtitles.Size() - 1)];
S_ChangeMusic("hddead", 0, true, true);
SetMusicVolume(ggwp_volume);
}
string c;
int i;
if (_MsgIndex < _DMCache.Length())
{
if (_MsgTimer <= ggwp_deathmessagedelay)
{
_MsgTimer++;
return;
}
[c, i] = GetChar(_DMCache, _MsgIndex);
_Message = AppendString(_Message, c);
_MsgIndex += i;
_MsgTimer = 0;
}
else if (_SubIndex < _DSCache.Length())
{
if (_SubTimer <= ggwp_deathsubtitledelay)
{
_SubTimer++;
return;
}
[c, i] = GetChar(_DSCache, _SubIndex);
_Subtitle = AppendString(_Subtitle, c);
_SubIndex += i;
_SubTimer = 0;
}
}
override void RenderOverlay(RenderEvent e)
{
StatusBar.FullScreenOffsets = true;
if (!_MainFont) _MainFont = HUDFont.Create(BigFont);
if (!_SubFont) _SubFont = HUDFont.Create(SmallFont);
if (Players[ConsolePlayer].mo.Health > 0) return;
StatusBar.DrawString(
_MainFont,
_Message,
(0, 0),
StatusBar.DI_SCREEN_CENTER | StatusBar.DI_TEXT_ALIGN_CENTER
);
StatusBar.DrawString(
_SubFont,
_Subtitle,
(0, -40),
StatusBar.DI_SCREEN_CENTER_BOTTOM | StatusBar.DI_TEXT_ALIGN_CENTER,
scale: (0.5, 0.5)
);
}
// Returns a char and an int incrementing the index
string, int GetChar(string text, int index)
{
int oldIndex = index;
string c = text.Mid(index, 1);
if (c == '\')
{
index++;
if (index >= text.Length()) return c;
string l = text.Mid(index, 1);
if (l == "c" && index + 1 < text.Length())
{
// Get colour and text
c = AppendString("\c", text.Mid(index + 1, 1));
index++;
}
else c = AppendString('\', l);
}
index++;
return c, index - oldIndex;
}
string AppendString(string a, string b)
{
return string.Format("%s%s", a, b);
}
}