Inventory Wizardry

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
Drake Raider
Posts: 474
Joined: Fri Jul 18, 2008 12:27 pm

Inventory Wizardry

Post by Drake Raider »

So this has probably been asked. But how do I do percent based Inventory items, like in Duke Nukem's health kits? Also ones with a toggle effect like the night vision.
Additionally, is it possible to make one of the latter have an additional cost, for instance a certain amount of ammo over time? (Concept, Night Vision drains CELL ammo)
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: Inventory Wizardry

Post by Blue Shadow »

For the nightvision thing, try this: Press 'f' to turn it on and off. It runs on batteries, which you should be able to see a display for on the HUD.
Drake Raider wrote:how do I do percent based Inventory items, like in Duke Nukem's health kits?
Could you explain more? I'm not sure what "percent based Inventory items" means.
User avatar
Popsoap10
Posts: 60
Joined: Thu May 26, 2016 6:47 pm

Re: Inventory Wizardry

Post by Popsoap10 »

Blue Shadow wrote:Could you explain more? I'm not sure what "percent based Inventory items" means.
He's talking about the mechanics of build engine inventory items. Where an inventory item starts with 100 units (or 100%), and using it consumes the units until it reaches 0. Something like this.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Inventory Wizardry

Post by Matt »

That seems straightforward enough... have the use state call A_TakeInventory based on the number that you want to expend, and then always end on "fail" rather than "stop" to make sure no more is taken than actually called for.

The draining will have to call for a DoEffect override in ZScript.
User avatar
Zan
Posts: 338
Joined: Sat Oct 22, 2016 12:43 pm
Location: The depths of Hedon.
Contact:

Re: Inventory Wizardry

Post by Zan »

Here's Hedon's Nightvision code, courtesy to DoomKrakken
Maybe it helps you out for the most part :D


Decorate part

Code: Select all

ACTOR InventoryFixerGoggles: CustomInventory replaces Infrared //Thanks to DoomKrakken for helping me with the code.
{
  Scale 0.4
  Radius 15
  Height 15
  +COUNTITEM
  Inventory.Icon "IGOGA0"
  Inventory.PickupMessage "Picked up a Fixer's Dark Vision Goggles."
  Inventory.MaxAmount 300
  Inventory.Amount 100
  Inventory.InterHubAmount 300
  Inventory.PickupSound "Inventory/PickBase"
  //Inventory.UseSound "Switches/Switch2"
  Tag "Fixer's Goggles - While activated, these goggles will help you see through darkness with ease.(Consumable)"
  +INVBAR
  +INVENTORY.UNDROPPABLE
  +NOGRAVITY
  States
  {
  Spawn:
    IGOG B -1
    Stop
  Use:
    TNT1 A 0 A_JumpIfInventory("PowerNightvision", 1, "Deactivate")
    TNT1 A 0 A_GiveInventory("NightvisionGiver")
    TNT1 A 0 ACS_NamedExecuteAlways("NightvisionDepletion")   
	TNT1 A 0 A_PlaySound("Switches/Switch2")
    //[DoomKrakken]: Gotta make sure we activate the ACS Script responsible for managing it...
    Fail
  Deactivate:
    TNT1 A 0 A_TakeInventory("PowerNightvision")
	TNT1 A 0 A_PlaySound("Switches/Switch2")
    //[DoomKrakken]: Gotta make sure it's taken away when not in use...
    Fail
  }
}
And the ACS part:

Code: Select all

Script "NightvisionDepletion" (void) //Thanks to DoomKrakken for making this script for me.
{
    TakeInventory("InventoryFixerGoggles", 1); 
    while (CheckInventory("PowerNightvision"))   
    {
       TakeInventory("InventoryFixerGoggles", 1);   
       if(!CheckInventory("InventoryFixerGoggles")) 
       { 
           break;   
       } 
       delay(70);  
    }
    TakeInventory("PowerNightvision", 1);   
}
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Inventory Wizardry

Post by ramon.dexter »

And here is something basically the same as Zan provided, but completely in zscript (omitting the acs part):

Code: Select all


class rebreather_item : customInventory
{
	bool rebreatherSwitch;
	
	Default
	{
		//$Category "Powerups"
		//$Title "Rebreather"
		
		-SOLID
		+INVENTORY.INVBAR
		
		Tag "$T_REBREATHER";
		inventory.icon "I_RBRT";
		inventory.amount 100;
		inventory.maxamount 500;
		inventory.interhubamount 500;
		inventory.PickupMessage "$F_REBREATHER";
		radius 12;
		height 16;
	
	}
	
	States
	{
		Spawn:
			RBRT A -1;
			Stop;
		Use:
			TNT1 A 0
			{
				if(invoker.rebreatherSwitch == 0) {return ResolveState("Activate");}
				if(invoker.rebreatherSwitch == 1) {return ResolveState("Deactivate");}
				return ResolveState(null);
			}
		Activate:
			TNT1 A 0
			{
				invoker.rebreatherSwitch = 1;
				A_GiveInventory("RebreatherActive", 1);
				A_GiveInventory("PowerRebreather", 1);
			}
			Stop;
		Deactivate:
			TNT1 A 0
			{
				invoker.rebreatherSwitch = 0;
				A_TakeInventory("RebreatherActive");
				A_TakeInventory("PowerRebreather");
			}
			Stop;
	}
}

class PowerRebreather : PowerProtection
{
	int RebreatherCount; 

    override void attachtoowner(actor user)
    {
        RebreatherCount = 0;
        super.attachtoowner(user);
    }

    override void doeffect()
    {
		Super.doEffect();
		
        if(owner.countinv("rebreather_item") == 0) 
        {
            owner.takeinventory("PowerRebreather", 1);
            owner.takeinventory("RebreatherActive", 1);
            RebreatherCount = 0;
			return;
		}

        RebreatherCount++;

        if(RebreatherCount == 35)
        {
            owner.takeinventory("rebreather_item", 1);
            RebreatherCount = 0;
		
        }
		if (!(level.time & 0x3f))
		{
			Owner.A_PlaySound ("misc/mask", CHAN_AUTO);
		}

    }
	
	Default
	{
		Powerup.Duration 0x7FFFFFFD;
		damagefactor "drowning", 0;
		inventory.icon "I_RBRT";
	}
}

class RebreatherActive : PowerupGiver
{
	Default
	{
		+INVENTORY.AUTOACTIVATE
		inventory.pickupmessage "Rebreather";
		//powerup.color "lightblue" 0.25;
		inventory.maxamount 0;
		powerup.type "PowerRebreather";
		powerup.duration 0x7FFFFFFD;
	}
	
	States
	{
		Spawn:
			RBRT A -1;
			Stop;
	}
}
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: Inventory Wizardry

Post by Blue Shadow »

Popsoap10 wrote:He's talking about the mechanics of build engine inventory items. Where an inventory item starts with 100 units (or 100%), and using it consumes the units until it reaches 0. Something like this.
Ah, I see. Well, here's something, using ZScript, that is less A_Jump-y :p:
Spoiler:
Drake Raider
Posts: 474
Joined: Fri Jul 18, 2008 12:27 pm

Re: Inventory Wizardry

Post by Drake Raider »

First response question.

Keep in mind, I haven't read this code fully yet, due to time constraints. So if it's answered, feel free to refer me to the code.

First
Can ACS detect if a powerup is active? Like Wings of Wrath or Nightvision?

Second
Can oldschool (Decorate/ACS non-zscript) custom inventory items play hud animations? For instance, a drink potion animation.

The second isn't a mandatory effect for what I'm working on, just a curiosity that would be cool if implemented.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: Inventory Wizardry

Post by Blue Shadow »

Drake Raider wrote:Can ACS detect if a powerup is active? Like Wings of Wrath or Nightvision?
Yes, by using [wiki]CheckInventory[/wiki]. You check for the [wiki=Classes:Powerup]powerup itself[/wiki], not the [wiki=Classes:PowerupGiver]giver[/wiki].
Post Reply

Return to “Scripting”