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

How to get the TID of the sidedef that the player just used?

Recommended Posts

I'm trying to create different ammo recharge terminals within the same level. 

5a3c89c89ae4a_Semttulo.png.76850780193d20a0236f7408e0f77596.png

Here's my code so far:
 

#include "zcommon.acs"
int rechargeLimit = 5;
int terminalUsageCount = 0;
script "AMMO_RECHARGER" (void) {
    if (CheckSight(1, 2, CSF_NOBLOCKALL)) {
        print(s:"Terminal 1");
    } else if (CheckSight(1, 3, CSF_NOBLOCKALL)) {
        print(s:"Terminal 2");
    } else if (CheckSight(1, 4, CSF_NOBLOCKALL)) {
        print(s:"Terminal 3");
    } else if (CheckSight(1, 5, CSF_NOBLOCKALL)) {
        print(s:"Terminal 4");
    }  
    str playerWeapon = getWeapon();
    if (strcmp(playerWeapon, "Shotgun") == 0 || 
        strcmp(playerWeapon, "SuperShotgun") == 0) {
        if (terminalUsageCount < 4) {
            giveInventory("Shell", 20);
            log(s:"Received 20 shells.");
            terminalUsageCount += 1;
        } else {
            print(s:"Maximum ammo recharge reached for this terminal.");
        }
    }
    else if (strcmp(playerWeapon, "Pistol") == 0 || 
        strcmp(playerWeapon, "Chaingun") == 0) {
        if (terminalUsageCount < 4) {
            giveInventory("Clip", 100);
            log(s:"Received 100 clips.");
            terminalUsageCount += 1;
        } else {
            print(s:"Maximum ammo recharge reached for this terminal.");
        }
    }
    else if (strcmp(playerWeapon, "PlasmaRifle") == 0 || 
        strcmp(playerWeapon, "BFG9000") == 0) {
        if (terminalUsageCount < 4) {
            giveInventory("Cell", 100);
            log(s:"Received 100 cells.");
            terminalUsageCount += 1;
        } else {
            print(s:"Maximum ammo recharge reached for this terminal.");
        }
    }
    else if (strcmp(playerWeapon, "RocketLauncher") == 0) {
        if (terminalUsageCount < 4) {
            giveInventory("RocketAmmo", 10);
            log(s:"Received 10 rockets.");
            terminalUsageCount += 1;
        } else {
            print(s:"Maximum ammo recharge reached for this terminal.");
        }
    }
}

As you can see, I use a global terminalUsageCount variable to count how many times the player have used a terminal, in order to limit him from taking more than what he should. The problem is that the other 3 terminals in the example use the same script, and therefore, the same global variable. Once he deplenishes one terminal, all the others also become unavailable. That can easily be solved by defining an array of terminals based on specific TID and with proper logic I can allow or disallow access to each terminal individually. The problem is that according to the reference on information functions, there's no getter that informs me what sidedef has just been "used". Giving that, I've tried to use "CheckSight" with invisible MapSpots with specific TIDs (It would work the same way). The problem is that apparently CheckSight does not treat a MapSpot as an actor. So... basically, I'll have to create a different global space / ACS file for each terminal??? 

The WAD of the example:
ammo_example.7z

 

 

Sem título.png

Edited by RederickDeathwill

Share this post


Link to post

Instead of (void) in the script definition, put something like (int which) and then add an argument 1 to each terminal line action with a different number (which will be loaded into variable "which" when the line is invoked).  Then use a switch/case block that checks against "which".

 

You probably still need four terminalUsageCount variables to track the four terminals separately, though.

Share this post


Link to post
1 minute ago, ETTiNGRiNDER said:

Instead of (void) in the script definition, put something like (int which) and then add an argument 1 to each terminal line action with a different number (which will be loaded into variable "which" when the line is invoked).  Then use a switch/case block that checks against "which".

 

You probably still need four terminalUsageCount variables to track the four terminals separately, though.

Ohhh, scripts can have input arguments. Beautiful, thanks :p

Share this post


Link to post

For future viewers, here's the working script with each terminal working independently:

#include "zcommon.acs"
int rechargeLimit = 5;
int terminalsUsageCount[4] = {
    0, 0, 0, 0
};
script "AMMO_RECHARGER" (int terminal) {
    terminal = terminal + 1;
    str playerWeapon = getWeapon();
    if (strcmp(playerWeapon, "Shotgun") == 0 || 
        strcmp(playerWeapon, "SuperShotgun") == 0) {
        if (terminalsUsageCount[terminal] < 4) {
            giveInventory("Shell", 20);
            log(s:"Received 20 shells.");
            terminalsUsageCount[terminal] += 1;
        } else {
            print(s:"Maximum ammo recharge reached for this terminal.");
        }
    }
    else if (strcmp(playerWeapon, "Pistol") == 0 || 
        strcmp(playerWeapon, "Chaingun") == 0) {
        if (terminalsUsageCount[terminal] < 4) {
            giveInventory("Clip", 100);
            log(s:"Received 100 clips.");
            terminalsUsageCount[terminal] += 1;
        } else {
            print(s:"Maximum ammo recharge reached for this terminal.");
        }
    }
    else if (strcmp(playerWeapon, "PlasmaRifle") == 0 || 
        strcmp(playerWeapon, "BFG9000") == 0) {
        if (terminalsUsageCount[terminal] < 4) {
            giveInventory("Cell", 100);
            log(s:"Received 100 cells.");
            terminalsUsageCount[terminal] += 1;
        } else {
            print(s:"Maximum ammo recharge reached for this terminal.");
        }
    }
    else if (strcmp(playerWeapon, "RocketLauncher") == 0) {
        if (terminalsUsageCount[terminal] < 4) {
            giveInventory("RocketAmmo", 10);
            log(s:"Received 10 rockets.");
            terminalsUsageCount[terminal] += 1;
        } else {
            print(s:"Maximum ammo recharge reached for this terminal.");
        }
    }
}

 

A big map could have like... 10 to 15 terminals? One could completely remove the traditional ammo-collecting like this.

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
×