Weapon giving armor?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
Spaceshiporion
Posts: 78
Joined: Sun Dec 03, 2023 6:58 pm

Weapon giving armor?

Post by Spaceshiporion »

I want to make a weapon, and I'd like to add a little armor to the player when I pick it up.

What code do I need? I already tried adding

Code: Select all

A_GiveInventory("BlueArmorForMegasphere", 1)
as well as

Code: Select all

  Armor.SavePercent 50
  Armor.SaveAmount 200
I put both of these in the actor description of the weapon, below pickup sound.

But the former does nothing, and the latter isn't recognized for some reason?
User avatar
Average Raven Fan
Posts: 27
Joined: Sat Oct 05, 2024 12:00 am

Re: Weapon giving armor?

Post by Average Raven Fan »

Alright, let's start by going over why those two didn't work : A_GiveInventory is an action, it has to be associated with a state and can't be put into an actor's properties. Meanwhile, Armor.SavePercent and SaveAmount are properties, but they're Armor properties, so they're only available when used with items that inherit from Armor!

Try this instead :

Code: Select all

class ArmorShotgun : CustomInventory replaces Shotgun
{
	States
	{
	Spawn:
		SHOT A -1;
		Stop;
	Pickup:
		TNT1 A 0 A_GiveInventory("Shotgun");
		TNT1 A 0 A_GiveInventory("GreenArmor");
		Stop;
	}
}
ZScript but easy enough to convert to DECORATE if you want. This replaces the Shotgun with a custom pickup that will give you a Shotgun and a Green Armor when you grab it. Replacing like this is not entirely recommended and it'd be better to manually place it in maps or spawn it from a RandomSpawner instead, or hijack the pickup virtual function if you're using ZScript, but it should work.

Give it a go and see if it's what you wanted!
Spaceshiporion
Posts: 78
Joined: Sun Dec 03, 2023 6:58 pm

Re: Weapon giving armor?

Post by Spaceshiporion »

Average Raven Fan wrote: Mon May 11, 2026 4:39 am Alright, let's start by going over why those two didn't work : A_GiveInventory is an action, it has to be associated with a state and can't be put into an actor's properties. Meanwhile, Armor.SavePercent and SaveAmount are properties, but they're Armor properties, so they're only available when used with items that inherit from Armor!

Try this instead :

Code: Select all

class ArmorShotgun : CustomInventory replaces Shotgun
{
	States
	{
	Spawn:
		SHOT A -1;
		Stop;
	Pickup:
		TNT1 A 0 A_GiveInventory("Shotgun");
		TNT1 A 0 A_GiveInventory("GreenArmor");
		Stop;
	}
}
ZScript but easy enough to convert to DECORATE if you want. This replaces the Shotgun with a custom pickup that will give you a Shotgun and a Green Armor when you grab it. Replacing like this is not entirely recommended and it'd be better to manually place it in maps or spawn it from a RandomSpawner instead, or hijack the pickup virtual function if you're using ZScript, but it should work.

Give it a go and see if it's what you wanted!
Thank you so much for answering! I will check out later!
Spaceshiporion
Posts: 78
Joined: Sun Dec 03, 2023 6:58 pm

Re: Weapon giving armor?

Post by Spaceshiporion »

Average Raven Fan wrote: Mon May 11, 2026 4:39 am Alright, let's start by going over why those two didn't work : A_GiveInventory is an action, it has to be associated with a state and can't be put into an actor's properties. Meanwhile, Armor.SavePercent and SaveAmount are properties, but they're Armor properties, so they're only available when used with items that inherit from Armor!

Try this instead :

Code: Select all

class ArmorShotgun : CustomInventory replaces Shotgun
{
	States
	{
	Spawn:
		SHOT A -1;
		Stop;
	Pickup:
		TNT1 A 0 A_GiveInventory("Shotgun");
		TNT1 A 0 A_GiveInventory("GreenArmor");
		Stop;
	}
}
ZScript but easy enough to convert to DECORATE if you want. This replaces the Shotgun with a custom pickup that will give you a Shotgun and a Green Armor when you grab it. Replacing like this is not entirely recommended and it'd be better to manually place it in maps or spawn it from a RandomSpawner instead, or hijack the pickup virtual function if you're using ZScript, but it should work.

Give it a go and see if it's what you wanted!

Hey buddy! I tried putting your code in my Decorate script, and it didn't seem to recongize "class" I think?
I think I'm doing something wrong.

The word actor turn blue, but using "class" goes wrong, and won't let me open my wad in Gzdoom.

I think I should also mention:
I want to add specific amounts of armor. I don't want the BlueArmor itself

I tried defining a custom pickup with my own numbers, but ultimately I haven't figured it out yet.
Spaceshiporion
Posts: 78
Joined: Sun Dec 03, 2023 6:58 pm

Re: Weapon giving armor?

Post by Spaceshiporion »

I figured everything out! Yes!!

I had to define an actor that gave the correct amount of armor I wanted,
then I made a CustomInventory Actor that would give me both that item and the weapon I made.
Post Reply

Return to “Scripting”