Class UseHandler : EventHandler { Override void WorldThingSpawned(WorldEvent e) { If(e.Thing is "PlayerPawn"&&!e.Thing.FindInventory("UseItemEnd")) { e.Thing.GiveInventory("UseItemEnd",1);//Important for the player to have this item } } Override void WorldLinePreActivated(WorldEvent e) { If(e.Thing is "PlayerPawn"&&(e.ActivatedLine.special==243 || e.ActivatedLine.special==244 || e.ActivatedLine.special==75)) { let item = UseItemEnd(e.Thing.FindInventory("UseItemEnd")); If(item) { If(item.ExitLine != e.ActivatedLine) { item.ExitLine = e.ActivatedLine; e.ShouldActivate = 0; e.Thing.ACS_NamedExecute("ExitAnimation");//Replace with your own script } Else { item.ExitLine=null; e.Thing.ACS_NamedExecute("UnFreezeAnimation");//Important to keep in case the player gets frozen for the animation } } } } }
Class UseItemEnd : Inventory { Line ExitLine; Override bool Use(bool pickup) { If(owner) { If(ExitLine.activation & SPAC_Use){ExitLine.Activate(owner, 1, SPAC_Use);}//You have to check for the activation types, otherwise the line won't trigger Else If(ExitLine.activation & SPAC_Cross){ExitLine.Activate(owner, 1, SPAC_Cross);} Else If(ExitLine.activation & SPAC_Push){ExitLine.Activate(owner, 1, SPAC_Push);} Else If(ExitLine.activation & SPAC_Impact){ExitLine.Activate(owner, 1, SPAC_Impact);} } Return 0; } }
NTMAI did it this way and I have adapted it to work on exit switches. Next for the scripts:
Spoiler:
At the end of your animation script, you need to add this function:
This doesn't stop the player from pressing [Use] again, which will skip the animation and jump straight to the next level. There's no way to stop the player's [Use] action as far as I know, but it might be better left like this so the player can skip them.