[solved] +ALT_AMMO_OPTIONAL for sisterweapon only?

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!)
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1116
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

[solved] +ALT_AMMO_OPTIONAL for sisterweapon only?

Post by Jekyll Grim Payne »

I have two versions of several weapons which work differently. Here's a basic example:

This pistol has two attacks and it uses Clip for both.

Code: Select all

Actor BD_Pistol : Pistol replaces Pistol
{
weapon.sisterweapon ModernPistol
weapon.selectionorder 190
inventory.icon "PISTZ0"
attacksound ""
weapon.ammotype2 "Clip"
weapon.ammouse2 1
weapon.slotnumber 2
...
And this pistol needs to be reloaded like in modern games. So it uses PistolClip as a magazine, and Clip is used to refill PistolClip. (It has no alt attack.)

Code: Select all

Actor ModernPistol : BD_PIstol
{
+POWERED_UP
+AMMO_OPTIONAL
+NOAUTOFIRE
weapon.sisterweapon BD_Pistol
weapon.ammotype 	"PistolClip"
weapon.ammouse 		1
weapon.ammogive 	0
weapon.ammotype2 	"Clip"
weapon.ammouse2 	0
...
The problem is, as it is, when I have 0 Clip, even if PistolClip isn't 0, as soon as I deselect ModernPistol, I can't select it again. Giving it +ALT_AMMO_OPTIONAL has no effect.
I can give BD_Pistol (the main weapon) +ALT_AMMO_OPTIONAL and then it will have the desired effect: ModernPistol will be selectable with Clip = 0 and PistolClip != 0. But the problem is, in this case BD_Pistol will also become selectable with 0 Clip which is something I definitely don't want.

Is there a way to make ALT_AMMO_OPTIONAL affect only ModernPistol and not BD_Pistol?

P.S. The problem definitely arises because ModernPistol is a POWERED_UP weapon. If I turn it into a separate weapon, it'll work just fine. But this would make a number of other things more difficult.
Last edited by Jekyll Grim Payne on Fri Aug 24, 2018 9:57 am, edited 1 time in total.
User avatar
3saster
Posts: 199
Joined: Fri May 11, 2018 2:39 pm
Location: Canada

Re: +ALT_AMMO_OPTIONAL for sisterweapon only?

Post by 3saster »

Don't have the chance to test at the moment, but could you define a clone of the BD_Pistol that obtains the ammo optional property, i.e.
Actor BD_Pistol2 : BD_Pistol
{
+AMMO_OPTIONAL
}
and then have the modern pistol inherit from this class instead? An unnecessary actor, but its a easy solution if it works. If this causes the same problem you just described, you could even just make a complete clone of BD_Pistol (copy-paste it and change the actor name) plus the ammo optional flag and inherit from that instead. I'm almost certain that would work, but it would create some ugly spaghetti code.

You could also try inheriting from Pistol instead, and manually define what would have otherwise been inherited, i.e.
Actor ModernPistol : Pistol
{
//Add the new stuff AND the stuff that would have been inherited from BD_Pistol
...
}
This is obviously a much less clean solution, but it should work if you are careful.
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1116
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: +ALT_AMMO_OPTIONAL for sisterweapon only?

Post by Jekyll Grim Payne »

Sadly this won't work. I checked, and this has nothing to do with inheritance, it's related specifically to the sisterweapon use. Here's an example of a pair of shotguns which work the way I want to:

Code: Select all

Actor BD_Shotgun : Shotgun replaces Shotgun
{
weapon.sisterweapon ModernShotgun
weapon.selectionorder 130
inventory.pickupsound "weapons/shotgun/pump"
attacksound ""
weapon.slotnumber 3
weapon.slotpriority 1
states
...

Actor ModernShotgun : BD_Shotgun
{
weapon.sisterweapon BD_Shotgun
+POWERED_UP
+AMMO_OPTIONAL +ALT_AMMO_OPTIONAL
+NOAUTOFIRE
Weapon.BobStyle InverseSmooth
weapon.bobrangex 0.2
weapon.bobrangey 0.5
weapon.bobspeed 2.0
weapon.ammotype 	"ShotgunClip"
weapon.ammouse 		1
weapon.ammogive		0
weapon.ammotype2 	"Shell"
weapon.ammogive2 	0
weapon.ammouse2 	0
weapon.upsound "weapons/shotgun/draw"
states
...
With this code, when I run out of Shell, the regular shotgun can't be selected (as it shouldn't be), yet the ModernShotgun can be selected if it still has ammo in the ShotgunClip. The only difference? The fact that BD_Shotgun doesn't have any ammotype2 assigned to it. I double-checked: regardless of inheritance, if I remove the second ammo type from BD_Pistol, ModernPistol will be selectable, just like the shotguns above.
User avatar
3saster
Posts: 199
Joined: Fri May 11, 2018 2:39 pm
Location: Canada

Re: +ALT_AMMO_OPTIONAL for sisterweapon only?

Post by 3saster »

In that case (and I hope there is a cleaner solution), you could spoof it using an ACS script. That is, make a variable like PistolSpoof and set it equal to 0 by default. Then make a script that runs every tic, where if you have Clip = 0 and PistolClip! = 0 and the pistol is not equipped, set Clip = 1 and PistolSpoof = 1 (i.e. the Clip value is fake). This would allow you to select the pistol now. Now in the pistol raise state, run another script that checks if PistolSpoof = 1, and if so, set it to zero and Clip to 0 (i.e. unspoof it).

This (or something similar to it) would allow you to do what you want, though it might make the HUD display invalid. In case you have to display clips on the inventory, you could make it display another kind of ammo (DisplayClip), and use a script to keep it in tune with the real (non-spoofed) Clip value.
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1116
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: +ALT_AMMO_OPTIONAL for sisterweapon only?

Post by Jekyll Grim Payne »

I think I found an easier solution. Since the pistol uses Clip for both primary and secondary attack. I can' just remove all ammo definitions related to secondary attack, and then just give it +ALT_USES_BOTH. In this case it will simply use its primary ammo with the secondary attack and it won't conflict with the ModernPistol :)

Return to “Scripting”