Page 1 of 1

how to do a different reload when no ammo

Posted: Tue Dec 10, 2024 4:03 pm
by schwipsy
Hello, I'm using decorate for the first time and having some issues with it, I'm doing a shotgun that has to be manually pumped with altfire, the thing is, pump shotguns have to be pumped when you reload and have no ammo chambered, since it removes the spent shell and chambers the next one in. I'm having issues with it, right now it doesnt need to pump if it has already been pumped before the reload.

Code: Select all

actor InsertedShell : ammo
{
    Inventory.Amount 8
    Inventory.MaxAmount 8
}

actor PumpShot : inventory
{
	Inventory.Amount 0
	Inventory.MaxAmount 1
}

actor DukeShotgun : Shotgun
{
    Scale 0.5
    AttackSound "rrwm/weapons/shotgun/fire"

    Inventory.Icon "OSH2A0"
    Inventory.PickupSound "rrwm/weapons/shotgun/pickup"
    Inventory.PickupMessage "Picked up a Duke shotgun."

	Weapon.AmmoType "InsertedShell"
	Weapon.AmmoType2 "Shell"
    Weapon.AmmoUse 0
	Weapon.Ammouse2 0
    Weapon.AmmoGive 0
	Weapon.AmmoGive2 16
    Weapon.SlotNumber 3
	Weapon.Kickback 100
	+Weapon.NoAlert
	+WEAPON.NOAUTOFIRE

    States(Actor)
    {
        Spawn:
            OSH2 A -1
            Stop
    }

    States(Weapon)
    {
        Select:
            OSHT A 1 A_Raise
            Loop
        Deselect:
            OSHT A 1 A_Lower
            Loop
        Ready:
            OSHT A 1 A_WeaponReady(WRF_ALLOWRELOAD)
            Loop
        Fire:
			OSHT B 0 A_jumpifinventory("PumpShot",1,"DryFire")
			TNT1 A 0 A_Jumpifinventory("InsertedShell",1,1)
			Goto DryFire
			TNT1 A 0 A_AlertMonsters
			OSHT B 2 BRIGHT A_FireBullets (9.6, 1, 7, 5, "BulletPuff")
			OSHT B 0 A_SetPitch(Random(pitch-4,pitch-6))
			OSHT B 0 A_Quake(5,5,0,50)
            OSHT B 2 BRIGHT A_TAKEINVENTORY("InsertedShell",1)
			OSHT A 1 Offset(0,60)
			OSHT A 1 Offset(0,45)
			OSHT A 1 Offset(0,36)
			OSHT A 1 A_giveinventory("PumpShot",1)
            Goto Ready
		AltFire:
			TNT1 A 0 A_jumpifinventory("Pumpshot",1,1)
			Goto Ready
			OSHT E 2 A_StartSound("rrwm/weapons/shotgun/pump1", CHAN_WEAPON)
            OSHT F 4
            OSHT E 2 A_StartSound("rrwm/weapons/shotgun/pump2", CHAN_WEAPON)
            OSHT DC 2 
            OSHT A 3 A_TAKEINVENTORY("PumpShot",1)
			Goto Ready
        Flash:
            TNT1 A 2 A_Light1
            TNT1 A 2 A_Light2
            TNT1 A 0 A_Light0
            Stop
        DryFire:
			TNT1 A 0 A_AlertMonsters
            OSHT A 5 A_StartSound("rrwm/weapons/shotgun/dryfire", CHAN_WEAPON)
            Goto Ready
        Reload:
			TNT1 A 0 A_JumpIfInventory("InsertedShell",8,"Ready")
			TNT1 A 0 A_JumpIfInventory("Shell",1,1)
			goto Ready
			TNT1 A 0 A_Jumpifinventory("InsertedShell",1,1)
			TNT1 A 0 A_Jumpifinventory("InsertedShell",0,"ReloadPump")
			OSHT B 0 A_TAKEINVENTORY("Shell",1)
            OSHT I 2 A_StartSound("rrwm/weapons/shotgun/reload", CHAN_WEAPON)
            OSHT I 1 A_giveinventory("InsertedShell",1)
            OSHT JK 4
            Goto Ready
		ReloadPump:
			OSHT B 4 A_giveinventory("PumpShot",1)
			OSHT B 0 A_TAKEINVENTORY("Shell",1)
            OSHT I 2 A_StartSound("rrwm/weapons/shotgun/reload", CHAN_WEAPON)
            OSHT I 1 A_giveinventory("InsertedShell",1)
            OSHT JK 4
			Goto Reload
    }
}
What am I doing wrong?

Re: how to do a different reload when no ammo

Posted: Wed Dec 11, 2024 1:00 am
by Player701
Now that looks somewhat familiar, but without any integration of the reloading system it originally came with. The problem is with this line:
schwipsy wrote: Tue Dec 10, 2024 4:03 pm

Code: Select all

TNT1 A 0 A_Jumpifinventory("InsertedShell",0,"ReloadPump")
If you carefully read the documentation on A_JumpIfInventory, you might notice the following bit:
ZDoom Wiki wrote:Note that if amount is 0, the jump is only performed if the actor is carrying the maximum number of that item.
Might seem counter-intuitive, but that's how it is. The solution here is to invert your logic. Use A_JumpIfInventory("InsertedShell", 1, ...) to jump to normal reloading animation (no pumping), and put the pumping animation directly below the jump call.

Re: how to do a different reload when no ammo

Posted: Wed Dec 11, 2024 2:12 pm
by schwipsy
Thanks a lot! I should read the wiki a bit more haha

Yeah I was using your rrwm reloading system addon to get the basic stuff down but I realized I had to do it from scratch since I wanted to change the reload mechanics and the pump stuff, but the system made me understand a lot about decorate and states. Thanks!