[ZScript] Getting all current ammo classes

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
User avatar
Boondorl
Posts: 137
Joined: Wed Jul 11, 2018 10:57 pm

[ZScript] Getting all current ammo classes

Post by Boondorl »

Is there a way to get a list of all the current ammo classes in the game? Specifically any class that inherits from Ammo. I wanted to put together a list of all of them so I could do some stuff involving looping through them while the player is playing. The mod is meant to be compatible with others so I need to make sure custom ammo types are included as well.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: [ZScript] Getting all current ammo classes

Post by Apeirogon »

All ammo classes as "ammo defined in game at all" or "all ammo spawned/placed on map"?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: [ZScript] Getting all current ammo classes

Post by Matt »

EDIT: ignore this, see below

Something like this might do. (untested, might contain syntax errors; I also don't remember how to define an array of classes of a specific type, hence the strings)

Code: Select all

    array<string> ammoclasses;
    ammoclasses.clear();
    for(int i=0;i<allactorclasses.size();i++){
        class<actor> reff=allactorclasses[i];
        if(reff is "Ammo"){
            ammoclasses.push(reff.getclassname());
        }
    }
 
Last edited by Matt on Thu Aug 15, 2019 3:32 pm, edited 1 time in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Getting all current ammo classes

Post by Graf Zahl »

That won't work as-is. Only immediate descendants of Ammo are actual types, anything further down the line maps to the original class in the chain as an ammo type.
User avatar
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [ZScript] Getting all current ammo classes

Post by phantombeta »

Graf Zahl wrote:That won't work as-is. Only immediate descendants of Ammo are actual types, anything further down the line maps to the original class in the chain as an ammo type.
Unless you override some stuff in the descendant class. Which I believe some have done so that they can make a base class for all of their mod's ammo types.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: [ZScript] Getting all current ammo classes

Post by Matt »

I guess the viability of my solution would depend a lot on the OP's needs then - aren't all the subclasses supposed to be pickup varieties of the underlying immediate Ammo descendants which would be the actual ammo item being counted?

EDIT: I think I misread Graf's post as meaning the exact diametrical opposite of what was intended, guessing from the post below. :oops:
Last edited by Matt on Thu Aug 15, 2019 3:31 pm, edited 2 times in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Getting all current ammo classes

Post by Graf Zahl »

phantombeta wrote:
Graf Zahl wrote:That won't work as-is. Only immediate descendants of Ammo are actual types, anything further down the line maps to the original class in the chain as an ammo type.
Unless you override some stuff in the descendant class. Which I believe some have done so that they can make a base class for all of their mod's ammo types.

That's mainly irrelevant. The check must be the same, i.e. "if (type == type.GetParentAmmo()" to ensure you got a valid type.
Post Reply

Return to “Scripting”