Ammo pickup tracking

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
Collegia Titanica
Posts: 83
Joined: Thu Jan 25, 2018 1:37 pm

Ammo pickup tracking

Post by Collegia Titanica »

What I'm trying to do is get the amount of ammo picked up by the player during a level. Obviously CheckInventory inside a While(cycle) doesn't work since that amount drops each shot.

Problem: Weapons and ammo for some odd reason don't have a PickUp: state like the custom inventory and they already use inheritance which must not be changed.

Thought process:
A hacky way would be to make a new text def file in which a lot of ammotrackers per pickup are defined and a couple of ammotypes

Code: Select all

4ShotgunTrack: CustomInventory              ....................                ShotGunTrackAmmo: Ammo
20ShotGunTrack: CustomInventory             ....................                CellTrackAmmo: Ammo
20CellTrack: CustomInventory                ....................                RocketTrackAmmo: Ammo
100CellTrack: CustomInventory               ....................                HeavyBulletTrackAmmo: Ammo
etc...  
and these trackers are to be spawned in every ammo and weapon pickup's Spawn state.

These CustomInventory actors
have something like this in their pickup state.

Code: Select all

[4ShotgunTrack]   A_GiveInventory("ShotGunTrackAmmo", 4)
[20ShotgunTrack]  A_GiveInventory("ShotGunTrackAmmo", 20)
[20CellTrack]     A_GiveInventory("CellTrackAmmo", 20) 
[100CellTrack]    A_GiveInventory("CellTrackAmmo", 100) 
where they raise this fakeammo amount to the same as the real ammo counterpart.When the player picks up weapons and ammo these invisible actors are also picked up.
This fakeammo doesn't get used so it's easy to set a variable to = Checkinventory ("One of the fake ammos").
At first, I wanted to do something like "Acs execute" to raise some global on every ammo and weapon upon pickup but then I realized the problem above ...

Any other more .... practical ways of solving this ?
Hardmode: Inheritance is already used on weapons and ammo actors so that's not an option.

The Goal:
[Hit at least x of the ammo you picked up on target]
Amount of ammo picked up / 2 * other factors in previously made functions
User avatar
Cherno
Posts: 1311
Joined: Tue Dec 06, 2016 11:25 am

Re: Ammo pickup tracking

Post by Cherno »

Collegia Titanica wrote:What I'm trying to do is get the amount of ammo picked up by the player during a level. Obviously CheckInventory inside a While(cycle) doesn't work since that amount drops each shot.

But what if you include a condition to only recognize if the ammo count increases, instead of merely changing? Basically, something like

Code: Select all



int ammoCollected = 0;
int ammoLast = 0;//needs to be assigned once at the start of the level, of course
while(true) 
{
     int ammoCurrent = ... (CheckInventory or whatever);
     if(ammoCurrent != ammoLast)
     {
         if(ammoCurrent > ammoLast)
          {
                 ammoCollected += ammoCurrent - ammoLast;
          }
          ammoLast = ammoCurrent;
     }
}
Just a thought. Maybe there's some error in my idea :3:

One possible problem could be the theoretical situation when the player collects ammo at the same moment that he or she is losing some i.e. firing.
Collegia Titanica
Posts: 83
Joined: Thu Jan 25, 2018 1:37 pm

Re: Ammo pickup tracking

Post by Collegia Titanica »

Thank you very much, this helped me a lot :)
User avatar
Cherno
Posts: 1311
Joined: Tue Dec 06, 2016 11:25 am

Re: Ammo pickup tracking

Post by Cherno »

Glad to be of help!
Post Reply

Return to “Scripting”