DECORATE: Charging Weapon Help

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
CaptainNurbles
Posts: 274
Joined: Sat Jan 27, 2018 9:12 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: The Deepest Reaches of Space
Contact:

DECORATE: Charging Weapon Help

Post by CaptainNurbles »

I'm working on making a laser weapon which can be charged up. Hold the fire button, the higher the charge meter goes the more damaging a blast becomes, at the cost of more ammo being used for stronger shots. That much is coded and satisfactorily functional.

Only issue I'm really happening is that I'm wanting it to automatically fire while charging depending on how much ammo is left in the battery.

Say for example, shooting with 75% charge will fire a pretty strong beam that costs 6 units of ammo to fire. A fully charged shot takes 10 units of ammo to shoot and has to charge to 100% charge before it can shoot a fully charged shot.

But what if you don't have 10 units of ammo? Ideally, the gun would continue to charge while the fire button is held, and as soon as it detects that you're at 75% charge and don't have enough ammo for a fully charged shot, would skip the charge phase and move directly to the mostly charged state.

I have been going at it for a while now and just haven't figured out a way to make that happen, but here's what I got so far.

Code: Select all

	Fire:
	  RCHR A 0 A_JumpIfNoAmmo("Beep") //Beep is the dry firing state, playing a sound to let the player know they're out of ammo.
	  RCHR A 1 A_PlaySound("weapons/chargeriflecharge",0)
	Proceed:
	  RCHR A 0 A_JumpIfNoAmmo("Beep")
	  RCHR A 0 A_Refire
	  RCHR A 0 A_JumpIfInventory("ChargeRifShot",10,2) //If the player has enough ammo for a fully charged shot, jump Two states
	  RCHR A 0 A_Jump(256,2) //Otherwise, skip the Fully Charged check and jump ahead to the next check
	  RCHR A 0 A_JumpIfInventory("ChargeCount",100,"Charge5") //Charge5 being the Fully Charged shot
	  RCHR A 0 A_JumpIfInventory("ChargeRifShot",6,2) //If the player has enough ammo for a mostly charged shot, jump Two states
	  RCHR A 0 A_Jump(256,2) //Otherwise, skip the Mostly Charged check and jump ahead to the next check
	  RCHR A 0 A_JumpIfInventory("ChargeCount",75,"Charge4") //Charge4 being the Mostly Charged shot
	  RCHR A 0 A_JumpIfInventory("ChargeRifShot",4,2) //You get it, yea yea
	  RCHR A 0 A_Jump(256,2)
	  RCHR A 0 A_JumpIfInventory("ChargeCount",50,"Charge3")
	  RCHR A 0 A_JumpIfInventory("ChargeRifShot",2,2)
	  RCHR A 0 A_Jump(256,2)
	  RCHR A 0 A_JumpIfInventory("ChargeCount",25,"Charge2")
	  RCHR A 0 A_JumpIfInventory("ChargeRifShot",1,2)
	  RCHR A 0 A_Jump(256,2)
	  RCHR A 0 A_JumpIfInventory("ChargeCount",1,"Charge1")
	  Goto Beep
	Hold:
	  RCHR A 0 A_JumpIfNoAmmo("Beep")
	  RCHR A 1 A_GiveInventory("ChargeCount",1) //The Counter item which determines how much the gun is charged. Goes up to 100
	  Goto Proceed
Like I said, I'd been going at it for a LONG time today and just haven't figured out how to make it automatically fire at certain charge levels depending on if you have enough ammo or not. Any help would be GREATLY appreciated!
CaptainNurbles
Posts: 274
Joined: Sat Jan 27, 2018 9:12 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: The Deepest Reaches of Space
Contact:

Re: DECORATE: Charging Weapon Help

Post by CaptainNurbles »

Bump for visibility
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: DECORATE: Charging Weapon Help

Post by Blue Shadow »

I've modified the Hold state to the following (code untested):

Code: Select all

Hold:
    RCHR A 0 A_JumpIfNoAmmo("Beep")
    RCHR A 1
    {
        if (CountInv("ChargeRifShot") >= 10)
        {
            if (CountInv("ChargeCount") == 100) return A_Jump(256, "Charge5");
        }
        else if (CountInv("ChargeRifShot") >= 6 && CountInv("ChargeRifShot") < 10)
        {
            if (CountInv("ChargeCount") == 75) return A_Jump(256, "Charge4");
        }
        else if (CountInv("ChargeRifShot") >= 4 && CountInv("ChargeRifShot") < 6)
        {
            if (CountInv("ChargeCount") == 50) return A_Jump(256, "Charge3");
        }
        else if (CountInv("ChargeRifShot") >= 2 && CountInv("ChargeRifShot") < 4)
        {
            if (CountInv("ChargeCount") == 25) return A_Jump(256, "Charge2");
        }
        else if (CountInv("ChargeRifShot") == 1)
        {
            if (CountInv("ChargeCount") == 1) return A_Jump(256, "Charge1");
        }

        A_GiveInventory("ChargeCount", 1);
        return state("");
    }
    Goto Proceed
It's butt-ugly of a code, I know, but DECORATE isn't as powerful a language as ZScript.
CaptainNurbles
Posts: 274
Joined: Sat Jan 27, 2018 9:12 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: The Deepest Reaches of Space
Contact:

Re: DECORATE: Charging Weapon Help

Post by CaptainNurbles »

That is perfectly functional, actually! I had to make a simple edit to break the "return A_Jump" lines into separate bracketed lines, otherwise it wouldn't boot, but other than that it's working exactly as I needed it, thank ya!

Only issue I'm noticing so far though is that if the gun is charged up to Charge4 strength and then automatically fires itself due to not having enough charge for full strength, the next shot doesn't play the charging up sound for some reason :o If I have enough ammo for a fully charged shot, but shoot it at 75% to 99% shot, the next shot after plays the charge shot just fine! But if it automatically fires itself due to not having enough juice for a fully charged shot no charging sound is played on the next shot. It functions perfectly fine, just doesn't play the charging up sound which starts at the beginning of the Fire state. In my brief time looking at it I haven't figured out why.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: DECORATE: Charging Weapon Help

Post by Blue Shadow »

Try calling [wiki]A_ClearReFire[/wiki] on a successful jump to a charge state.
CaptainNurbles
Posts: 274
Joined: Sat Jan 27, 2018 9:12 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: The Deepest Reaches of Space
Contact:

Re: DECORATE: Charging Weapon Help

Post by CaptainNurbles »

And that did it! Thank!
Post Reply

Return to “Scripting”