is a value that decreases 1000 every second.
For example, if its value is 10000000, its value will be 9999000 after a second. We can use this as a timer for background music.
This timer is irrelevant to game speed, lagging, or any unfortunate circumstances. So we can use this value as a music counter.
1. Read the value of 0x0051CE8C and store that on DC of Teran Marine. This DC holds the last time music is played.
2. Play the music.
3. With preserve trigger:
3-1. Read the value of 0x0051CE8C and store that on DC of Terran Firebat.
3-2. Compare that value with DC of Terran Marine.
3-3. If the difference is larger or equal to the length of the music in milliseconds:
3-3-1. Copy DC of Terran Firebat to DC of Terran Marine.
3-3-2. Play the music again.
-- 1. Read the value of 0x0051CE8C and store that on DC of Teran Marine. This DC holds the last time music is played.
for i = 30, 0, -1 do
Trigger {
players = {P8},
conditions = {
Switch("Switch 1", Cleared);
Memory(0x0051CE8C, AtLeast, 2^i);
},
actions = {
SetMemory(0x0051CE8C, Subtract, 2^i);
SetDeaths(P8, Add, 2^i, "Terran Marine");
SetDeaths(P8, Add, 2^i, "Terran Vulture");
}
}
for i in 30, 0, -1 do
Trigger {
players = {P8},
conditions = {
Switch("Switch 1", Cleared);
Deaths(P8, AtLeast, 2^i, "Terran Vulture");
},
actions = {
SetMemory(0x0051CE8C, Add, 2^i);
SetDeaths(P8, Subtract, 2^i, "Terran Vulture");
}
}
-- 2. Play the music.
Trigger {
players = {P8},
conditions = {
Always();
},
actions = {
SetSwitch("Switch 1", Set);
PlayWAV("[path to bgm here]");
}
}
-- 3. With preserve trigger:
-- 3-1. Read the value of 0x0051CE8C and store that on DC of Terran Firebat.
for i = 30, 0, -1 do
Trigger {
players = {P8},
conditions = {
Memory(0x0051CE8C, AtLeast, 2^i);
},
actions = {
SetMemory(0x0051CE8C, Subtract, 2^i);
SetDeaths(P8, Add, 2^i, "Terran Firebat");
SetDeaths(P8, Add, 2^i, "Terran Vulture");
PreserveTrigger();
}
}
for i in 30, 0, -1 do
Trigger {
players = {P8},
conditions = {
Deaths(P8, AtLeast, 2^i, "Terran Vulture");
},
actions = {
SetMemory(0x0051CE8C, Add, 2^i);
SetDeaths(P8, Subtract, 2^i, "Terran Vulture");
PreserveTrigger();
}
}
-- 3-2. Compare that value with DC of Terran Marine.
for i = 30, 0, -1 do
Trigger {
players = {P8},
conditions = {
Deaths(P8, AtLeast, 2^i, "Terran Firebat");
},
actions = {
SetDeaths(P8, Subtract, 2^i, "Terran Firebat");
SetDeaths(P8, Subtract, 2^i, "Terran Marine");
SetDeaths(P8, Add, 2^i, "Terran Vulture");
PreserveTrigger();
}
}
-- 3-3. If the difference is larger or equal to the length of the music in milliseconds:
-- 3-3-2. Play the music again.
Trigger {
players = {P8},
conditions = {
Deaths(P8, AtLeast, (length of bgm here), "Terran Marine");
},
actions = {
SetSwitch("Switch 2", Set);
SetDeaths(P8, SetTo, 0, "Terran Marine");
PlayWAV("[path to bgm here]");
PreserveTrigger();
}
}
-- 3-3-1. Copy DC of Terran Firebat (currently in vulture) to DC of Terran Marine.
-- If condition is not met, revert DC of Terran Marine
for i in 30, 0, -1 do
Trigger {
players = {P8},
conditions = {
Deaths(P8, AtLeast, 2^i, "Terran Vulture");
},
actions = {
SetDeaths(P8, Subtract, 2^i, "Terran Vulture");
SetDeaths(P8, Add, 2^i, "Terran Marine");
PreserveTrigger();
}
}
-- Reset switch 2
Trigger {
players = {P8},
conditions = {
Always();
},
actions = {
SetSwitch("Switch 2", Clear);
}
}
var bgmTimer;
function time() {
return -dwread_epd(EPD(0x0051CE8C));
}
// Code on onPluginstart is executed only once, at the start of the game.
function onPluginStart() {
bgmTimer = time();
PlayWAV([path of bgm here]);
}
/// Code on afterPluginStart is executed every trigger loop
function afterPluginstart() {
const currentTime = time();
if(currentTime - bgmTimer > [length of bgm in millisecond here]) {
bgmTimer = currentTime;
PlayWAV([path of bgm here]);
}
}