Items that can be picked up by monsters?

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
Heisanevilgenius
Posts: 100
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Items that can be picked up by monsters?

Post by Heisanevilgenius »

I know inventory can be given to monsters but can items be set so that monsters can pick them up?

I can think of some hacky ways to make it work that seem problematic. For instance, I can use A_RadiusGive on an item to give the item to the closest monster but then I have to find a way to despawn the item if the item is successfully transferred, but not despawn if the monster doesn't pick it up. I can also see issues where the RadiusGive can potentially give the item to the wrong monster if multiple monsters are within range. Seems like the cleanest way is if I could somehow make it so that a monster can just step over the item and collect it.
User avatar
phantombeta
Posts: 2182
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Items that can be picked up by monsters?

Post by phantombeta »

You can give a monster the [url=https://zdoom.org/wiki/Actor_flags#PICKUP]PICKUP[/wiki] flag to make it able to pick up items. It'll be able to pick up any items, though, so YMMV. Not all built-in items work for monsters, also, some work, some don't. They also can't use usable items.

If you're replacing all items and/or, both of those issues can be dealt with, by:
In specific items you don't want to be picked up by monsters, either by any monsters or just specific types of monsters you can:
  • Overriding the void Actor::Touch (Actor toucher) virtual to bypass the default behaviour (i.e., check if it's a monster you want ignored and return instead of calling Super::Touch)
  • Override the bool Inventory::CanPickup (Actor toucher) to return false if it's a monster you don't want it to be picked up by instead of calling the original version (may want to also set the RESTRICTABSOLUTELY flag in that case)
In monsters you don't want picking up certain types of items, you can override the bool CanTouchItem (Inventory item) virtual to return false and they won't be able to pick it up.
Heisanevilgenius
Posts: 100
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Items that can be picked up by monsters?

Post by Heisanevilgenius »

phantombeta wrote: Sun Oct 08, 2023 4:03 pm You can give a monster the [url=https://zdoom.org/wiki/Actor_flags#PICKUP]PICKUP[/wiki] flag to make it able to pick up items. It'll be able to pick up any items, though, so YMMV. Not all built-in items work for monsters, also, some work, some don't. They also can't use usable items.

If you're replacing all items and/or, both of those issues can be dealt with, by:
In specific items you don't want to be picked up by monsters, either by any monsters or just specific types of monsters you can:
  • Overriding the void Actor::Touch (Actor toucher) virtual to bypass the default behaviour (i.e., check if it's a monster you want ignored and return instead of calling Super::Touch)
  • Override the bool Inventory::CanPickup (Actor toucher) to return false if it's a monster you don't want it to be picked up by instead of calling the original version (may want to also set the RESTRICTABSOLUTELY flag in that case)
In monsters you don't want picking up certain types of items, you can override the bool CanTouchItem (Inventory item) virtual to return false and they won't be able to pick it up.
Thank you! That seems to work. I didn't think it would be that easy. It's not working flawlessly but that may be because of other issues in the monster states I still have to work out. Much appreciated.
Post Reply

Return to “Scripting”