[DECORATE] Weapon alt fire is normal fire if no ammo for alt

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.

[DECORATE] Weapon alt fire is normal fire if no ammo for alt

Postby NaturalTvventy » Thu Dec 03, 2020 11:57 pm

Hi everyone, I'm wondering if there's a way in DECORATE to have a custom weapon which does its normal shot if the alt fire button if pressed but the ammo for the alt fire is zero.

What I can think of is performing some sort of check, but I don't think there's IF statements in DECORATE....

AltFire:
if "AltAmmoCount" > 0:
MARG B 0 A_FireCustomMissile("AltMissile")
else:
goto Fire

Is this doable, with something like my method or any other method?

EDIT: I see that A_JumpIf is what I'm after. Now I just need to figure out how to get an ammo count for the expression.
NaturalTvventy
 
Joined: 22 May 2010

Re: [DECORATE] Weapon alt fire is normal fire if no ammo for

Postby Player701 » Fri Dec 04, 2020 12:33 am

You could use A_JumpIfInventory, but what you're attempting will not work properly in DECORATE without gross hacks. This is because when you press any of the fire buttons, the engine checks if the weapon has enough ammo for the corresponding fire mode (normal/alt), and if it doesn't, the weapon will not jump to its Fire/AltFire state but will get deselected instead.

The one way to avoid this problem without using advanced features is to set +WEAPON.AMMO_OPTIONAL / +WEAPON.ALT_AMMO_OPTIONAL to bypass ammo checks on the engine side. You will then have to manually check that you have enough ammo before firing, this can also be done via A_JumpIfInventory. However, you will lose the auto-switching functionality (though you could also try to hack it in via A_JumpIfInventory and A_SelectWeapon), and it will also be possible to switch to your weapon even when you don't have enough ammo for it, regardless of the gameplay options. Unfortunately, there is no way to mitigate the latter issue in DECORATE.

Code: Select allExpand view
AltFire:
    MARG A 0 A_JumpIfInventory("YourAmmoType", 1, "RealAltFire") // <-- Replace YourAmmoType with the actual name of your ammo type class
    Goto Fire
RealAltFire:
    // TODO: Your alt fire code here
    Goto Ready
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: [DECORATE] Weapon alt fire is normal fire if no ammo for

Postby Dan_The_Noob » Fri Dec 04, 2020 6:40 am

can you describe the wepaon to us so maybe we can offer an alternative route altogether? as Player701 said, it's kind of messy because of limitations/restrictions in the engine itself.
User avatar
Dan_The_Noob
 
Joined: 07 May 2019
Twitch ID: Dan_The_Noob
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia with Vulkan support

Re: [DECORATE] Weapon alt fire is normal fire if no ammo for

Postby NaturalTvventy » Fri Dec 04, 2020 4:00 pm

Thanks for getting me pointed in the right direction! I believe I have it working. Here's relevant code:

Code: Select allExpand view
  Weapon.AmmoUse1 0 //remove ammo later with A_TakeInventory
  Weapon.AmmoUse2 0 //remove ammo later with A_TakeInventory
  Weapon.AmmoType1 "DemonBlood"
  Weapon.AmmoType2 "HectePlasma"
  +AMMO_OPTIONAL //not needed since AmmoUse = 0?
  +ALT_AMMO_OPTIONAL //not needed since AmmoUse = 0?

  Fire:
   MARG A 0 A_JumpIfInventory("DemonBlood", 1, "RealFire") //check for regular ammo
    MARG A 0 A_JumpIfInventory("HectePlasma", 1, "RealAltFire") //check for alt ammo
   Goto NoAmmo //no ammo
  AltFire:
    MARG A 0 A_JumpIfInventory("HectePlasma", 1, "RealAltFire") //check for alt ammo
   MARG A 0 A_JumpIfInventory("DemonBlood", 1, "RealFire") //check for regular ammo
    Goto NoAmmo //no ammo
  RealFire:
    MARG B 0 A_FireCustomMissile("MancubusShot")
    TNT1 A 8 A_GunFlash
    MARG B 10
    Goto Ready
  RealAltFire:
   MARG B 0 A_FireCustomMissile("HectebusShot")
    TNT1 A 8 A_GunFlash
    MARG B 10
    Goto Ready
  NoAmmo:
    Goto Ready //will update with weapon switching
  Flash:
   MARG A 0 A_JumpIfInventory("DemonBlood", 1, "RealFlash") //check for regular ammo
    MARG A 0 A_JumpIfInventory("HectePlasma", 1, "RealAltFlash") //check for alt ammo
  AltFlash:
    MARG A 0 A_JumpIfInventory("HectePlasma", 1, "RealAltFlash") //check for alt ammo
   MARG A 0 A_JumpIfInventory("DemonBlood", 1, "RealFlash") //check for regular ammo
 
  RealFlash:
   MARF A 0 A_TakeInventory ("DemonBlood", 1) //remove 1 ammo
    MARF A 3 Bright A_Light1
    MARF B 5 Bright A_Light2
    Goto LightDone
  RealAltFlash:
   GRNA A 0 A_TakeInventory ("HectePlasma", 1) //remove 1 ammo
    GRNA A 3 Bright A_Light1
    GRNA B 5 Bright A_Light2
    Goto LightDone
NaturalTvventy
 
Joined: 22 May 2010

Re: [DECORATE] Weapon alt fire is normal fire if no ammo for

Postby Player701 » Sat Dec 05, 2020 12:28 am

NaturalTvventy wrote:
Code: Select allExpand view
//not needed since AmmoUse = 0?

Indeed, I believe you do not need to set AmmoUse to 0 if you have AMMO_OPTIONAL. You can then also get rid of A_TakeInventory. By itself, AMMO_OPTIONAL does not prevent ammo from being deducted automatically (if you have any).
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support


Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests