Getting a player's weapon roster?
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!)
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!)
-
- Posts: 8
- Joined: Mon Jan 22, 2024 5:58 pm
- Preferred Pronouns: He/Him
Getting a player's weapon roster?
Is there any way to read get a list of a player's valid weapons or weapons that they can always switch between? In Zscript. I tried going through the weapon slots and basically validating with something like getDefaultByType(weaponClass).canReceive(player). However, with different mods some invalid weapons still get listed. Or should I just make my own lists for specific mods that I want it to be compatible with?
Re: Getting a player's weapon roster?
IDK of a way to get the whole weapon roster but you can at least check for weapons that you know of. Take a look at : https://zdoom.org/wiki/GetWeapon.
-
- Posts: 407
- Joined: Fri Feb 07, 2014 6:45 am
Re: Getting a player's weapon roster?
After reading this for like the 10th time I realized you can get to data that is set in the mapinfo lump in round about ways, and this should be defined in map info. However, it can be defined in more than one place, but that doesn't matter. ZScript compiles a list of weapon slots after parsing everything.
You can print a list of all of a player's selectable weapons this way:
(I put the above code in the CheatGive virtual function so you can test it easily.)
It takes advantage of the Weapons Slots struct. All player classes get weapon slots from 0-9 (your keyboard weapon selectors) and every slot can have an array of options. So that will effectively give you the arsenal.
Note: Some mods use weapons as a workaround to display something on screen, like a letter with quest objectives. It is not a usable weapon and it is not selectable by a slot, so it won't show up in this list, but it is technically a weapon class. Think of the map item in minecraft. They do this just to put a sprite on the screen scaled to your view.
It is also possible to pick up weapons that don't belong to your class. An example is in Hexen, picking up final weapon pieces for ammo. Unless there is a flat out class exclusion on the weapon, it technically can be picked up. Fortunately this method will only list selectable weapons, and completely exclude the odd case of extra weapons that belong to another class.
You can print a list of all of a player's selectable weapons this way:
Code: Select all
override void CheatGive (String name, int amount)
{
let player = self.player;
if (player.mo == NULL || player.health <= 0)
{
return;
}
for (let i = 0; i < 10; i++)
{
let iSize = player.weapons.SlotSize(i);
for (let x = 0; x < iSize; x++)
{
let wclassType = player.weapons.GetWeapon(i,x);
let wclassName = wclassType.GetClassName();
console.printf("Weapon:" .. i .. ", ".. x .. " " .. wclassName);
}
}
}
It takes advantage of the Weapons Slots struct. All player classes get weapon slots from 0-9 (your keyboard weapon selectors) and every slot can have an array of options. So that will effectively give you the arsenal.
Note: Some mods use weapons as a workaround to display something on screen, like a letter with quest objectives. It is not a usable weapon and it is not selectable by a slot, so it won't show up in this list, but it is technically a weapon class. Think of the map item in minecraft. They do this just to put a sprite on the screen scaled to your view.
It is also possible to pick up weapons that don't belong to your class. An example is in Hexen, picking up final weapon pieces for ammo. Unless there is a flat out class exclusion on the weapon, it technically can be picked up. Fortunately this method will only list selectable weapons, and completely exclude the odd case of extra weapons that belong to another class.