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.
A_DropItem Not Working on First Try [SOLVED]
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.
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.
-
- Posts: 5
- Joined: Wed Jan 05, 2022 3:29 pm
- Graphics Processor: nVidia with Vulkan support
A_DropItem Not Working on First Try [SOLVED]
Last edited by Inferon on Thu Jun 23, 2022 3:00 pm, edited 1 time in total.
-
- Posts: 5
- Joined: Wed Jan 05, 2022 3:29 pm
- Graphics Processor: nVidia with Vulkan support
Re: A_DropItem Not Working on First Try
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.
Any help or suggestions would be greatly appreciated.
-
- Posts: 42
- Joined: Sat Mar 13, 2021 6:47 pm
Re: A_DropItem Not Working on First Try
I'm not sure but try replacing that TNT1 A 0 with TNT1 A 1
-
- Posts: 5
- Joined: Wed Jan 05, 2022 3:29 pm
- Graphics Processor: nVidia with Vulkan support
Re: A_DropItem Not Working on First Try
Thanks for the suggestion. Unfortunately, it's still behaving the same.
-
- Global Moderator
- Posts: 2742
- Joined: Sun Jun 25, 2006 4:43 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Manjaro Linux
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
- Location: Citadel Station
Re: A_DropItem Not Working on First Try
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?
Should work?
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 all
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
}
}
-
- Lead GZDoom+Raze Developer
- Posts: 49194
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: A_DropItem Not Working on First Try
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!"
'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!"
-
- Global Moderator
- Posts: 2742
- Joined: Sun Jun 25, 2006 4:43 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Manjaro Linux
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
- Location: Citadel Station
Re: A_DropItem Not Working on First Try
Huh. Alrighty then. Thanks for clearing that up. 

-
- Posts: 5
- Joined: Wed Jan 05, 2022 3:29 pm
- Graphics Processor: nVidia with Vulkan support
Re: A_DropItem Not Working on First Try
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!
Thanks again!
-
- Posts: 5
- Joined: Wed Jan 05, 2022 3:29 pm
- Graphics Processor: nVidia with Vulkan support
Re: A_DropItem Not Working on First Try
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
}
}
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
}
}