Page 1 of 1

[ZScript] Level exit EventHandler?

PostPosted: Sun Jul 25, 2021 10:09 am
by Virathas
Hey all

I have stumbled upon a bit of an enormous problem - my newest player class is fully based on morphing into other forms, using "MorphPowerup" as the main gimmick. Thimg is, if the player does not morph into the base form (the "hub" form) and exits the level, everything breaks spectacularly - with entire inventory being cleared, including any potential "start" items.

So i figured i need to create some sort of handler to force back the transformation, however, i cannot see any sort of handler for that in ZScript, neither as a EventHandler nor as an overrideable function of an Actor(Or Inventory).

I am sure i can use ACS scripts for that, but unless there is no other way, i'd rather move out of ACS scripts if possible.

Re: [ZScript] Level exit EventHandler?

PostPosted: Sun Jul 25, 2021 10:27 am
by Jarewill
There is the WorldLinePreActivated override you can use to check if the activated line was an exit line and do stuff based on that:
Code: Select allExpand view
Override void WorldLinePreActivated(WorldEvent e)
{
    If(e.ActivatedLine.special==243||e.ActivatedLine.special==244) //If the line's special was 243 (Exit_Normal) or 244 (Exit_Secret), do stuff
    {
        
//Do stuff here
        e.ShouldActivate=1; //ShouldActivate is a toggle whenever the line's special should be executed or not
    }
}

Re: [ZScript] Level exit EventHandler?

PostPosted: Sun Jul 25, 2021 12:28 pm
by Virathas
Hmm, would this also cover the cases when a level is changed via ACS script or some other shenanigans in maps? Or would that require some additional handlers?

(Note that the spectacular break i have encountered can be corrected outside of this handler, although such handler would be of great aid)

Re: [ZScript] Level exit EventHandler?

PostPosted: Sun Jul 25, 2021 12:47 pm
by Jarewill
Virathas wrote:Hmm, would this also cover the cases when a level is changed via ACS script or some other shenanigans in maps? Or would that require some additional handlers?

Sadly no, I'm sure there are other ways to detect if a level is being changed, but I don't know them.

Re: [ZScript] Level exit EventHandler?

PostPosted: Fri Jul 30, 2021 7:04 am
by MFG38
Jarewill wrote:There is the WorldLinePreActivated override you can use to check if the activated line was an exit line and do stuff based on that:
Code: Select allExpand view
Override void WorldLinePreActivated(WorldEvent e)
{
    If(e.ActivatedLine.special==243||e.ActivatedLine.special==244) //If the line's special was 243 (Exit_Normal) or 244 (Exit_Secret), do stuff
    {
        //Do stuff here
        e.ShouldActivate=1; //ShouldActivate is a toggle whenever the line's special should be executed or not
    }


Wouldn't this not work with maps not in Hexen or UDMF format, since the line specials for exiting a map are on different numbers? Or does GZDoom do some conversion shenanigans upon loading a map?

Re: [ZScript] Level exit EventHandler?

PostPosted: Fri Jul 30, 2021 7:08 am
by Jarewill
MFG38 wrote:Wouldn't this not work with maps not in Hexen or UDMF format, since the line specials for exiting a map are on different numbers? Or does GZDoom do some conversion shenanigans upon loading a map?

Seems like GZDoom converts the special numbers somehow, because this still works on classic Doom maps.

Re: [ZScript] Level exit EventHandler?

PostPosted: Fri Jul 30, 2021 7:12 am
by MFG38
Jarewill wrote:
MFG38 wrote:Wouldn't this not work with maps not in Hexen or UDMF format, since the line specials for exiting a map are on different numbers? Or does GZDoom do some conversion shenanigans upon loading a map?

Seems like GZDoom converts the special numbers somehow, because this still works on classic Doom maps.


Right, I did sort of figure it must.