Greetings, all, and thank you in advance once again for any help you can give me.
I'm looking to do some work with shotguns. Specifically, I would like to add in at least two additional ammo types besides standard "shot" shells - those being Slugs and FRAG-12 shotgun grenades. Is there some way to enable this concept to work? What I'm looking to do is have the weapon coded such that when the Player presses the appropriate button, they unload their shotgun (either completely or just the chambered shell) and swap to one of these two ammo types.
Originally, I wanted to have four shotguns, eventually, in my project - a pump action that takes 12 Gauge 2.75" shells only (Shot, Slug, FRAG-12), a semi-auto in 12 Gauge 3" Magnum (3" Shot & Slug, 2.75" Shot & Slug, FRAG-12), another semi-auto in 3.5" Super Magnum (3.5", 3" and 2.75" Shot and Slug, no FRAG-12), and the legendary USAS-12 (12 Gauge 2.75" Shot only - however, it will be the South Korean Military Trials version that's full automatic).
I realize this might lead to a plateful of spaghetti, but if I can at least get one stratum of this concept functional, I'll be happy, as that means I can also possibly get this to work for other weapons, giving them more options.
Multiple ammo types for a single weapon?
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: 153
- Joined: Tue Mar 14, 2017 5:18 pm
- Location: Western North Southlandia (East Side)
-
- Global Moderator
- Posts: 1117
- Joined: Mon Jul 21, 2008 4:08 am
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
Re: Multiple ammo types for a single weapon?
This has been discussed here.
The short answer is: there's no native way, but you can always simulate it by using a dummy item to jump into a specific state where a specific time of ammo is used with A_TakeInventory or something. You'll probably have to come up with custom HUD for all of this to work.
UPD: you can with ZScript, see below.
The short answer is: there's no native way, but you can always simulate it by using a dummy item to jump into a specific state where a specific time of ammo is used with A_TakeInventory or something. You'll probably have to come up with custom HUD for all of this to work.
UPD: you can with ZScript, see below.
Last edited by Jekyll Grim Payne on Fri Aug 24, 2018 9:45 am, edited 1 time in total.
-
- Posts: 153
- Joined: Tue Mar 14, 2017 5:18 pm
- Location: Western North Southlandia (East Side)
Re: Multiple ammo types for a single weapon?
Thank you. I couldn't find this thread when I attempted a Search (it didn't help that I wasn't quite sure what to look for, and looking for "ammo" returns hundreds of answers).
So, let's say I created a Dummy Item that would give the intended actual item (or say it does) on pickup. Then, I use/call for that dummy item to be used in the reload/swap ammo action, take it out of inventory (and represent it as actually taking the actual ammo from inventory), and use this to give the ammo to the player at the appropriate time (during the ammo swap action)? Is that what you're aiming at? If so, I have a general idea of what to do, though I might end up significantly paring down the list of shotguns as a result - mainly to prevent Player confusion.
So, let's say I created a Dummy Item that would give the intended actual item (or say it does) on pickup. Then, I use/call for that dummy item to be used in the reload/swap ammo action, take it out of inventory (and represent it as actually taking the actual ammo from inventory), and use this to give the ammo to the player at the appropriate time (during the ammo swap action)? Is that what you're aiming at? If so, I have a general idea of what to do, though I might end up significantly paring down the list of shotguns as a result - mainly to prevent Player confusion.
-
- Global Moderator
- Posts: 1117
- Joined: Mon Jul 21, 2008 4:08 am
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
Re: Multiple ammo types for a single weapon?
It kinda depends on how exactly you want that ammo change to happen. I imagine using a dummyitem for the actual check and then A_TakeInventory to take the required ammo.
I'm roughly seeing it kinda like this (in this case ammo is changed via AltAttack but it can be a custom state too):
It will need additional checks for whether there's enough ammo to load, how much ammo to load, more A_TakeInventory in the reload state to remove the correct amount of ammo, etc etc.
I'm roughly seeing it kinda like this (in this case ammo is changed via AltAttack but it can be a custom state too):
Code: Select all
Actor ShotgunAmmoType : Inventory
{
+UNDROPPABLE +UNTOSSABLE
-COUNTITEM
-INVBAR
+PERSISTENTPOWER
inventory.maxamount 2
}
Actor FragAmmo : Ammo
{...
}
Actor SlugAmmo : Ammo
{...
}
Actor ShellAmmo : Ammo
{...
}
Actor Spas-12 : Weapon
{...
+AMMO_OPTIONAL
...
states
...
AltFire:
TNT1 A 0 A_JumpIfInventory("ShotgunAmmoType",2,"LoadFrag")
TNT1 A 0 A_JumpIfInventory("ShotgunAmmoType",1,"LoadSlug")
goto LoadShell
LoadFrag:
TNT1 A 0 A_TakeInventory("ShotgunAmmoType",2) //0 left after this
... //FRAG loading animation
LoadSlug:
TNT1 A 0 A_GiveInventory("ShotgunAmmoType",2) //2 left after this
... //Slug loading animation
LoadShell:
TNT1 A 0 A_TakeInventory("ShotgunAmmoType",2)
TNT1 A 0 A_GiveInventory("ShotgunAmmoType",1) //1 left after this
... //shell loading animation
...
Fire:
TNT1 A 0 A_JumpIfInventory("ShotgunAmmoType",2,"FireFrag")
TNT1 A 0 A_JumpIfInventory("ShotgunAmmoType",1,"FireSlug")
goto FireShell
FireFrag:
TNT1 A 0 A_JumpIf(CountInv("FragAmmo")==0,"Reload")
TNT1 A 0 A_TakeInventory("FragAmmo",1)
... //firing animation
FireSlug:
TNT1 A 0 A_JumpIf(CountInv("SlugAmmo")==0,"Reload")
TNT1 A 0 A_TakeInventory("SlugAmmo",1)
... //firing animation
FireShell:
TNT1 A 0 A_JumpIf(CountInv("ShellAmmo")==0,"Reload")
TNT1 A 0 A_TakeInventory("ShellAmmo",1)
... //firing animation
...
-
- Global Moderator
- Posts: 1117
- Joined: Mon Jul 21, 2008 4:08 am
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
Re: Multiple ammo types for a single weapon?
I have a question to add myself, though. Is it not possible to actually change ammotype even with Zscript?
-
- Posts: 5039
- Joined: Sun Nov 14, 2010 12:59 am
Re: Multiple ammo types for a single weapon?
As far as I can see, AmmoType1, AmmoType2, Ammo1 and Ammo2 are all writable variables, which means you can change them on the fly. Do some experimentation, and see what you get.
-
- Global Moderator
- Posts: 1117
- Joined: Mon Jul 21, 2008 4:08 am
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
Re: Multiple ammo types for a single weapon?
I tried this:
The flags change properly, the bob functions execute correctly but ammotype1 stays unchanged.
The ammouse properties change normally by the way, I tested with different numbers. But the type stays Clip.
UPD:
Found a way! In short, you need to add this into the state:
"Clip" of course should be replaced with the ammo type you want.
Code: Select all
Default {
...
weapon.slotnumber 2;
weapon.ammotype "Clip";
weapon.ammouse 1;
weapon.ammogive 0;
weapon.ammotype2 "Clip";
weapon.ammouse2 1;
weapon.ammogive2 0;
}
...
states
Ready:
TNT1 A 0 A_JumpIf(GetCVAR("bdoom_weapons")==2,"Ready.Modern");
TNT1 A 0 { A_ClassicBob();
invoker.AmmoType1 = "Clip";
invoker.AmmoType2 = "Clip";
invoker.AmmoUse1 = 1;
invoker.AmmoUse2 = 1;
invoker.bAMMO_OPTIONAL = false;
invoker.bALT_AMMO_OPTIONAL = false;
invoker.bNOAUTOFIRE = false;}
PI0G A 1 A_WeaponReady();
Loop;
Ready.Modern:
TNT1 A 0 {A_ModernBob();
invoker.AmmoType1 = "PistolClip";
invoker.AmmoType2 = "Clip";
invoker.AmmoUse1 = 1;
invoker.AmmoUse2 = 0;
invoker.bAMMO_OPTIONAL = true;
invoker.bALT_AMMO_OPTIONAL = true;
invoker.bNOAUTOFIRE = true;}
PIBN A 1 A_WeaponReady(WRF_NOSECONDARY|WRF_ALLOWRELOAD);
goto ready;
...
The ammouse properties change normally by the way, I tested with different numbers. But the type stays Clip.
UPD:
Found a way! In short, you need to add this into the state:
Code: Select all
invoker.Ammo1 = ammo( FindInventory("Clip") );
-
- Posts: 153
- Joined: Tue Mar 14, 2017 5:18 pm
- Location: Western North Southlandia (East Side)
Re: Multiple ammo types for a single weapon?
I apologize to the posters on this topic, that I haven't been back in over a month. Life gets in the way. Jekyll, thank you for taking my question and running with it. I couldn't imagine this question getting much traction, but the answers seem extremely interesting, and something I can look into. Even though I've decided to narrow down my concept significantly, I'll probably use this if I can.
-
- Posts: 1668
- Joined: Sat Jul 13, 2013 10:13 pm
Re: Multiple ammo types for a single weapon?
Well, here's another example for you. I did it a few years ago, using dummies and inventory items to simulate the ammo type change and even the ammo count displayed on screen. I hope it helps.
Download me.
Download me.