A_DropItem Not Working on First Try [SOLVED]

Ask about editing graphics, sounds, models, music, etc here!
Shaders (GLSL) and SNDINFO questions also go here!

Moderators: GZDoom Developers, Raze 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.

A_DropItem Not Working on First Try [SOLVED]

Postby Inferon » Wed Jan 05, 2022 3:53 pm

Hello,

In the mod that I am working on, I am making larger capacity ammo pickups drop lower capacity versions upon pick-up. For example, below is what I have modified for the "cell kit" by Dreadopp that I found on Realm 667:

ACTOR CellKit : CellA
{
Inventory.PickupMessage "Picked up an energy cell kit."
Inventory.Amount 40
States
{
Spawn:
CELK A -1
Stop
HoldAndDestroy:
TNT1 A 0 A_DropItem(CellA)
Stop
}
}

The weird thing is that it only seems to not drop a "CellA" the first time a "CellKit" is picked up. Any time after the first "CellKit" is picked up during a play-through, they correctly drop the "CellA". This behavior continues across levels, in that if I pick up a "CellKit" on level 1, the next "CellKit" on level 2 will correctly drop "CellA" as intended. I have also tried A_SpawnItemEx but I get the same results.

This only seems to happen for ammo pick-ups. I have the same thing set up for health pick-ups, but it functions as intended with those.

Any help would be greatly appreciated.
Last edited by Inferon on Thu Jun 23, 2022 3:00 pm, edited 1 time in total.
User avatar
Inferon
 
Joined: 05 Jan 2022
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: A_DropItem Not Working on First Try

Postby Inferon » Thu Jun 09, 2022 6:27 pm

I'm still having this issue, but I have found that nothing I put in an ammo actor's "HoldAndDestroy" state happens on the first time the ammo is picked up. Only on second and subsequent times will the ammo actor go to it's "HoldAndDestroy" state.

Any help or suggestions would be greatly appreciated.
User avatar
Inferon
 
Joined: 05 Jan 2022
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: A_DropItem Not Working on First Try

Postby 7Soul » Fri Jun 10, 2022 6:23 am

I'm not sure but try replacing that TNT1 A 0 with TNT1 A 1
7Soul
 
Joined: 13 Mar 2021

Re: A_DropItem Not Working on First Try

Postby Inferon » Fri Jun 10, 2022 5:18 pm

Thanks for the suggestion. Unfortunately, it's still behaving the same.
User avatar
Inferon
 
Joined: 05 Jan 2022
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: A_DropItem Not Working on First Try

Postby Hellser » Tue Jun 14, 2022 11:15 pm

Quick question, I know it's been 5 days but hey.

What exactly is the purpose of HoldAndDestroy?

A_Dropitem (and by extent, A_SpawnItemEx) should always work. I don't think it's not so much the action isn't working, but the state being called. I never heard of HoldAndDestroy before, and the Wiki is only showing one instance of it.

If your intention is to drop CellA upon pickup, try using the "Pickup" state instead?

Code: Select allExpand view
ACTOR CellKit : CellA
{
   Inventory.PickupMessage "Picked up an energy cell kit."
   Inventory.Amount 40
      States
         {
         Spawn:
            CELK A -1
            Stop
         Pickup:
            TNT1 A 0 A_DropItem(CellA)
            Stop
         }
}


Should work?
User avatar
Hellser
Remember Citadel
Global Moderator
 
Joined: 25 Jun 2006
Location: Citadel Station
Discord: Hellser#8156
Operating System: Windows 11
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD with Vulkan Support

Re: A_DropItem Not Working on First Try

Postby Graf Zahl » Wed Jun 15, 2022 12:23 am

No. Pickup state only works for CustomInventory items.

'HoldAndDestroy' is the state a picked up inventory item is set to if it is no longer needed. This also requires the state has a one tic duration (0-duration may cause some very unpleasant things, actually!)
But doing anything in this state is pretty much undefined behavior. There is zero guarantee it will be entered, and it may also be entered at times when it's not expected, and it may be called for copies of the item that spawn elsewhere in the map (namely at position 0,0.) It is absolutely not a safe place to spawn stuff.

The proper way here would be to override TryPickup in ZScript. And since I expect the inevitable response "But how do I do this in DECORATE?" my answer is "There is no reliable way!"
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: A_DropItem Not Working on First Try

Postby Hellser » Wed Jun 15, 2022 3:10 am

Huh. Alrighty then. Thanks for clearing that up. :)
User avatar
Hellser
Remember Citadel
Global Moderator
 
Joined: 25 Jun 2006
Location: Citadel Station
Discord: Hellser#8156
Operating System: Windows 11
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD with Vulkan Support

Re: A_DropItem Not Working on First Try

Postby Inferon » Fri Jun 17, 2022 1:12 pm

Thank you both for the help. As predicted, I'm going to be sticking to DECORATE, so I'll have to find another way around the issue. I think I will make a CustomInventory item that will drop the required ammo on Pickup state rather than using an Actor inheriting from an ammo type. I'll post what I end up doing here once I have it working as intended.

Thanks again!
User avatar
Inferon
 
Joined: 05 Jan 2022
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: A_DropItem Not Working on First Try

Postby Inferon » Fri Jun 17, 2022 5:37 pm

This is the solution I went with:

Actor CellKit:CustomInventory
{
+CastSpriteShadow
Inventory.PickupMessage "Picked up an energy cell kit."
Inventory.PickupSound "misc/ammo_pkup"
States
{
Spawn:
CELK A -1
Loop
Pickup:
TNT1 A 0 A_JumpIfInventory(Backpack,1,"IfBackpack")
TNT1 A 0 A_JumpIfInventory(Cell,300,"Spawn")
TNT1 A 0 A_GiveInventory(Cell,40)
TNT1 A 0 A_SpawnItemEx(CellA)
Stop
IfBackpack:
TNT1 A 0 A_JumpIfInventory(Cell,600,"Spawn")
TNT1 A 0 A_GiveInventory(Cell,40)
TNT1 A 0 A_SpawnItemEx(CellA)
Stop
}
}
User avatar
Inferon
 
Joined: 05 Jan 2022
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support


Return to Assets (and other stuff)

Who is online

Users browsing this forum: No registered users and 0 guests