global trigger zone events

Version:

1.0

Added on:

24 Feb 2013 18:33

Tags:

Description:
this script makes all the local trigger zones global. you need to use event ID 255 instead of trigger zone event, but you can change it and use any event. JCS.ini parameters:
|ID:5|on:1|switch:1|hold:1
"hold" is a new parameter i added that will keep trigger enabled (if on is 1) while you are standing on that tile. it will do opposite if on is 0. everything else works the same way as with a normal trigger zone. this could be very useful in co-op levels.
array<int> holder(33, 32);
array<int> holdID(33, 32);
array<int> svHoldID(33, 32);
array<int> svHolder(33, 32);
array<bool> locker(33, false);
array<bool> svLocker(33, false);
//"32" is a default value; it's not player 32 because that would be 31.

void onPlayer() {
    for(int i=0;i<32;i++) {
        if(jjEventGet(jjPlayers[i].xPos/32, jjPlayers[i].yPos/32) == 255) { //if you wish, you can change 255 here to any other event. use AREA::TRIGGERZONE or 246 for trigger zone event.
            int triggerID = jjParameterGet(jjPlayers[i].xPos/32, jjPlayers[i].yPos/32, 0, 5);
            int on = jjParameterGet(jjPlayers[i].xPos/32, jjPlayers[i].yPos/32, 5, 1);
            int svitch = jjParameterGet(jjPlayers[i].xPos/32, jjPlayers[i].yPos/32, 6, 1);
            // I used "svitch" instead of "switch" because "switch" would give me an error, because it already exists in angelscript not as a variable.
            int hold = jjParameterGet(jjPlayers[i].xPos/32, jjPlayers[i].yPos/32, 7, 1);
            if(hold == 1) {
                if(jjTriggers[triggerID] != (on == 1)) {
                    if(locker[triggerID]) if(i != holder[triggerID]) return;
                    if(!jjTriggers[triggerID]) {
                        jjTriggers[triggerID] = true;
                        if(!locker[triggerID]) {
                            locker[triggerID] = true;
                            holder[triggerID] = i;
                            holdID[i] = triggerID;
                        }
                    }
                }
            } else {
                if(svitch == 1) {
                    if(!svLocker[triggerID]) {
                        svLocker[triggerID] = true;
                        bool oldState = jjTriggers[triggerID];
                        jjTriggers[triggerID] = (true != oldState);
                        svHolder[triggerID] = i;
                        svHoldID[i] = triggerID;
                    }
                } else {
                    if(jjTriggers[triggerID] != (on == 1)) jjTriggers[triggerID] = (on == 1);
                }
            }
        } else {
            for(int j=0;j<32;j++) {
                if(i == holder[holdID[j]] && holdID[j] != 32) {
                    if(jjTriggers[holdID[j]]) jjTriggers[holdID[j]] = false;
                    if(locker[holdID[j]]) locker[holdID[j]] = false;
                    holder[holdID[j]] = 32; holdID[j] = 32;
                }
            }
            for(int k=0;k<32;k++) {
                if(svLocker[svHoldID[k]] && i == svHolder[svHoldID[k]] && svHolder[svHoldID[k]] != 32) {
                    svLocker[svHoldID[k]] = false;
                    svHolder[svHoldID[k]] = 32;
                }
            }
        }
    }
}