[SOLVED] My powerup isn't going into the inventory when a player already has one.

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
yum13241
Posts: 781
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

[SOLVED] My powerup isn't going into the inventory when a player already has one.

Post by yum13241 »

PowerGunsAkimbo
Spoiler:
GunsAkimbo
Spoiler:

I want the CustomInventory item to be used instantly if the player hasn't picked up one on the map they are playing (the powerup lasts forever [OK, 2 years]) but I want the player to have it in their inventory for later use. (w/o giving clips) The problem is that it always gets activated. Since this is an addon for a mod I'm making, ZScript should be fine, since I'm not modifying an existing DECORATE actor. Maybe using the bFLAGNAME feature of ZScript?


SOLUTION: See Ac!d's post.
Last edited by yum13241 on Tue Dec 06, 2022 5:35 am, edited 2 times in total.
User avatar
Ac!d
Posts: 345
Joined: Tue Apr 02, 2019 5:13 am
Location: France

Re: My powerup isn't going into the inventory when a player already has one.

Post by Ac!d »

I remade your powerup in Zscript. Two lines are commented in order to prevent an automatic activation and the risk of waste.

Code: Select all

// ZScript
version "4.6.1"

Class PowerGunsAkimbo : PowerupGiver
{
	Default
	{
		Inventory.Amount 1;
		Inventory.MaxAmount 3;
		Inventory.InterHubAmount 3;
		Inventory.PickupSound "misc/p_pkup";
		Inventory.PickupMessage "$TXT_GUNSAKIMBO";
		Tag "$TAG_GUNSAKIMBO";
		
		+INVENTORY.INVBAR
		+INVENTORY.COUNTITEM
		//+INVENTORY.AUTOACTIVATE
		+INVENTORY.BIGPOWERUP
		//+INVENTORY.ALWAYSPICKUP

		Powerup.Type "PowerWeaponLevel2";
		Powerup.Duration 0x7FFFFFFD;
	}
	Override Bool TryPickup(In Out Actor toucher)
	{
		If(toucher && toucher.CountInv(self.GetClass()) < 3) // Prevent to pick it up if we have 3 times this item
		{
			toucher.A_GiveInventory("Clip", 50);
			Return Super.TryPickup(toucher);
		}
		Return False;
	}
        States
	{
        Spawn:
		AKIM A -1;
		Stop;
	}
}
Jarewill
 
 
Posts: 1766
Joined: Sun Jul 21, 2019 8:54 am

Re: My powerup isn't going into the inventory when a player already has one.

Post by Jarewill »

Your CustomInventory actor isn't being added to the inventory because you have the +AUTOACTIVATE flag set.
This means that it will run its Use state the moment it's added.
To fix this, you can try adding a conditional check in your Use state, like so:

Code: Select all

Use:
 TNT1 A 0 A_JumpIfInventory("PowerGunsAkimbo",1,"UseFail")
 TNT1 A 0 A_GiveInventory("PowerGunsAkimbo")
 Stop
UseFail:
 TNT1 A 0
 Fail
You might also need to remove giving the powerup in the Pickup state.
yum13241
Posts: 781
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: My powerup isn't going into the inventory when a player already has one.

Post by yum13241 »

Ac!d wrote: Mon Dec 05, 2022 10:04 am I remade your powerup in Zscript. Two lines are commented in order to prevent an automatic activation and the risk of waste.

Code: Select all

// ZScript
version "4.6.1"

Class PowerGunsAkimbo : PowerupGiver
{
	Default
	{
		Inventory.Amount 1;
		Inventory.MaxAmount 3;
		Inventory.InterHubAmount 3;
		Inventory.PickupSound "misc/p_pkup";
		Inventory.PickupMessage "$TXT_GUNSAKIMBO";
		Tag "$TAG_GUNSAKIMBO";
		
		+INVENTORY.INVBAR
		+INVENTORY.COUNTITEM
		//+INVENTORY.AUTOACTIVATE
		+INVENTORY.BIGPOWERUP
		//+INVENTORY.ALWAYSPICKUP

		Powerup.Type "PowerWeaponLevel2";
		Powerup.Duration 0x7FFFFFFD;
	}
	Override Bool TryPickup(In Out Actor toucher)
	{
		If(toucher && toucher.CountInv(self.GetClass()) < 3) // Prevent to pick it up if we have 3 times this item
		{
			toucher.A_GiveInventory("Clip", 50);
			Return Super.TryPickup(toucher);
		}
		Return False;
	}
        States
	{
        Spawn:
		AKIM A -1;
		Stop;
	}
}
Why does GZDoom error out saying +INVENTORY.COUNTITEM doesn't exist?
Jarewill
 
 
Posts: 1766
Joined: Sun Jul 21, 2019 8:54 am

Re: My powerup isn't going into the inventory when a player already has one.

Post by Jarewill »

That's because +COUNTITEM is a general flag, so it should be used without a prefix.
So it should be just +COUNTITEM.
yum13241
Posts: 781
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: My powerup isn't going into the inventory when a player already has one.

Post by yum13241 »

Thanks!
Post Reply

Return to “Scripting”