Kan3x wrote: ↑Tue Jan 16, 2024 2:12 pm
At first, I just thought that calling for S_PauseSound in InitEffect would have done the trick, but apparently I still have to give the player the timefreezer flag for the sound pausing function to work :/
This is because the engine is
coded to automatically resume sound if none of the in-game players have
timefreezer set to a non-zero value.
Kan3x wrote: ↑Tue Jan 16, 2024 2:12 pm
Not only that, but if I don't have this bit
Code: Select all
for(int i = 0; i < MAXPLAYERS; ++i) {
if (playeringame[i] && players[i].timefreezer != 0) {
return;
}
}
in my EndEffect, the game crashes whenever the powerup ends and this is making me even more confused...
I could not reproduce the crash. Are you by chance using an outdated release of GZDoom? Try 4.11.3.
Kan3x wrote: ↑Tue Jan 16, 2024 2:12 pm
Noticing that when the player has this powerup active every sound is paused (good) except for when he picks up items (?), I started to think of a way to play a specific sound when the powerup activates (or even when it's active until it ends), but for now I got no luck.
Is there a way?
I think you have to use the flag
CHANF_NOPAUSE for this to work. Item pickup sounds use this flag as well.
Kan3x wrote: ↑Tue Jan 16, 2024 2:12 pm
Any help in understanding what is going on and how to play a specific sound with this powerup is highly appreciated! thx
Well, basically, the
timefreezer field is used to track if players are allowed to move when the time-freeze effect is active. If non-zero, the player can move, otherwise they cannot. In multiplayer, when someone activates the time-freezer powerup, they
and their teammates have this field set to a non-zero value to allow movement. It also uses different bits for each player to allow multiple powerups to be active simultaneously, as well as properly handle their deactivation.
For your
Deafen powerup to work correctly, it is sufficient to set the value for the owning player only since no one actually gets frozen in the first place. Also, unless your intention is to deafen all players, you should only call
S_PauseSound for the console player only:
Code: Select all
class Deafen : Powerup
{
Default
{
Powerup.Duration -3;
}
override void InitEffect()
{
if (Owner == null || Owner.player == null)
{
return;
}
Super.InitEffect();
if (Owner.PlayerNumber() == consoleplayer)
{
S_PauseSound(false, false);
}
Owner.player.timefreezer = 1;
}
override void EndEffect()
{
if (Owner == null || Owner.player == null)
{
return;
}
Owner.player.timefreezer = 0;
if (Owner.PlayerNumber() == consoleplayer)
{
S_ResumeSound(false);
}
Super.EndEffect();
}
}
Note, however, that one way or another, you will lose compatibility with the actual time-freezer powerup, so I don't see a need to overcomplicate the code. IMO, it'd be better to suggest a feature that would allow modders to alter the player's hearing range via ZScript.