Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

ACS count and linedef trigger

Recommended Posts

Posted (edited)

I thought I'd share some learning I just went though - hopefully it might help someone else...


So on a level for my Hellbreach wad, I wanted a trap with a demon cage opened by W1 linedefs. I wanted it to be triggered from one of several lines (so it would trigger from any direction):






Originally, I had floor_lowerbyvalue action attached to each line and specifying an argument such that a lip still protruded. This worked fine if only ONE line was ever crossed. Crossing other lines with the same action special re-triggered the lowering so the lip disappeared on the second line cross, and all other lines (on first crossing) triggered as well.


So to achieve what I wanted I needed a flag of is_opened (or something) with a wider scope than the linedef. Therefore, I played around with a simple ACS script with a variable outside of the numbered script. As an aside, I also discovered that ACS does not use a true boolean type - it uses 'truthy' or 'falsy' (https://zdoom.org/wiki/Data_types#Boolean).


Anyway, I made a test WAD which detects and acts on a flag being truthy or not, and also uses a counter to sequentially lower four platforms, regardless of which order you cross the triggering linedefs:

#include "zcommon.acs"

bool triggered = 0;
int counter = 0;

script 1 (void){
    if(triggered == 0){
        print(s:"already triggered");
    lower plats on each increment:
    int tagnum = -1;
        case 1:
        case 2:
        case 3:
        case 4:

The linedefs now use an action special of 80 with a single param of the script number (with WR so you can see the counter increment). 


As you can see, I set two map-level variables for the if/else clause and the switch/case clause and each is set regardless of which lines on the map I cross and in what order. I still eventually use the action special floor_lowerbyvalue to lower the four platforms in tag order (yes, it should be inside a condition for 2<=tagnum<=5, but hey, this was a test...).


Hopefully this will be of use to someone else.


You can get the test WAD from my github site here.








Share this post

Link to post

Personally my approach for this kind of things is to have the lines that can trigger the effect all have the same lineID, and to have the script clear all specials from the lines with that lineid. As a result, when one line is crossed and the effect is activated, all other lines get cleared too, and it's impossible to retrigger the effect.


A variant of this approach is to have the effect not triggered by lines, but by a sector action, typically SecActEnter or SecActExit. If your lines correspond to the entire perimeter of a sector, so that the trap is triggered when the player enters (or leaves, if they got here via a teleporter) then the sector action can be a simpler implementation of the effect. As a bonus, the lines can still have their own separate effect, for example you could make a teleport pad where the lines will teleport you (as usual) but there's also a sector action when you leave the pad.

Share this post

Link to post

@Gez, that is very helpful, thank you. This answers my other post here too... The scripted clearing of the action is exactly what I need.

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now