[Request] Stackable backpacks in ZScript?

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.

[Request] Stackable backpacks in ZScript?

Postby StroggVorbis » Wed Nov 14, 2018 5:08 am

The wiki contains an example method on how to take advantage of SetAmmoCapacity to do this, but it consists of a combination of ACS & Decorate. Could someone show me how to do this in ZScript instead?

Here's the link to the article I mentioned for anyone curious:
https://zdoom.org/wiki/SetAmmoCapacity

Thx in advance.
User avatar
StroggVorbis
Donut eat me pls!
 
Joined: 08 Nov 2017
Location: Germany
Discord: StroggVorbis#2466
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: [Request] Stackable backpacks in ZScript?

Postby Apeirogon » Wed Nov 14, 2018 6:52 am

You mean backpack which "double" amount of max ammo capacity?

Anyway, here it is.
Code: Select allExpand view
version "2.4"

class packback : backpack
{

override bool HandlePickup (Inventory item)
{
   if(owner.FindInventory("backpack", true) == null) return super.HandlePickup(item);
   
   if(owner.FindInventory("backpack", true) != null)
   {//assuming that if player already have backpack in pocket it already have all necessary ammo
      for (let probe = Owner.Inv; probe != NULL; probe = probe.Inv)
      {
         if (probe.GetParentClass() == 'Ammo')
         {
            probe.MaxAmount += Ammo(probe).Default.BackpackMaxAmount;

            if (probe.Amount < probe.MaxAmount || sv_unlimited_pickup)
            {
               int amount = Ammo(probe).Default.BackpackAmount;
               // extra ammo in baby mode and nightmare mode
               if (!bIgnoreSkill)
               {
                  amount = int(amount * G_SkillPropertyFloat(SKILLP_AmmoFactor));
               }
               probe.Amount += amount;
               if (probe.Amount > probe.MaxAmount && !sv_unlimited_pickup)
               {
                  probe.Amount = probe.MaxAmount;
               }
            }
         }
      }
   }
   item.bPickupGood = true;
   return true;
}

}
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: [Request] Stackable backpacks in ZScript?

Postby StroggVorbis » Wed Nov 14, 2018 2:49 pm

Stackable as in each additional backpack further increases max ammo by a specified configurable amount.

Also, thanks for the response, will test it out later :)
User avatar
StroggVorbis
Donut eat me pls!
 
Joined: 08 Nov 2017
Location: Germany
Discord: StroggVorbis#2466
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: [Request] Stackable backpacks in ZScript?

Postby spectrefps » Sat Jun 20, 2020 5:10 pm

Sorry for the necro, but I am also trying to create a stacking backpack. I used your code, and it seems to work *if* I spawn in a "packback" item first (then any subsequent 'normal' backpacks found will stack). However, it doesn't work if I collect a normal backpack first (even if I summon/give a "packback" afterwards, max ammo will never increase beyond the vanilla caps). After looking at the wiki, it looks like you are overriding the backpack base class correctly. Any idea how to override the default backpack's behavior (so you don't need to summon a "packback" first)?
spectrefps
 
Joined: 21 Jun 2020
Operating System: Windows 10/8.1/8/201x 64-bit

Re: [Request] Stackable backpacks in ZScript?

Postby spectrefps » Sat Jun 20, 2020 8:08 pm

Hugh Honeyridge wrote:Sorry for the necro, but I am also trying to create a stacking backpack. I used your code, and it seems to work *if* I spawn in a "packback" item first (then any subsequent 'normal' backpacks found will stack). However, it doesn't work if I collect a normal backpack first (even if I summon/give a "packback" afterwards, max ammo will never increase beyond the vanilla caps). After looking at the wiki, it looks like you are overriding the backpack base class correctly. Any idea how to override the default backpack's behavior (so you don't need to summon a "packback" first)?


This previous post was mine before I created my account, as I felt inclined to do so considering how much I've been enjoying various doom mods from here. I'm not sure how to 'claim' that post, so it will forever be that randomly generated name I guess >_<. But I managed to use a zmapinfo script to replace backpacks with the "packback" item you created in your code snippet.

Code: (in zmapinfo, edited with notepad++)
Code: Select allExpand view
DoomEdNums
{
      8 = packback
}



This replaces the item with DoomEdNum 8 (the default Backpack) with "packback" (the item that increases max ammo capacity for each additional backpack found). However, there seems to be a bug with it. Once found, it will indeed double the max ammo capacity. After that, grabbing *ANY* ammo pickup will then double the max ammo capacity. So every clip, shell, cellpack, etc, will each increase your max ammo capacity. I think it may be due to the "if (probe.GetParentClass() == 'Ammo')" if statement, since it seems to trigger the max capacity increase on every ammo item pickup after grabbing a backpack. Anyone have more insight on this?

Here's my current code (it also has a menu option to enable/disable it:

Code: Select allExpand view
Class packback : backpack
{

override bool HandlePickup (Inventory item)
{
   if(owner.FindInventory("backpack", true) == null) return super.HandlePickup(item);
   
   if(owner.FindInventory("backpack", true) != null && (GetCVar("ZD_StackingBackpacks")))
   {//assuming that if player already have backpack in pocket it already have all necessary ammo
      for (let probe = Owner.Inv; probe != NULL; probe = probe.Inv)
      {
         if (probe.GetParentClass() == 'Ammo')
         {
            probe.MaxAmount += Ammo(probe).Default.BackpackMaxAmount;

            if (probe.Amount < probe.MaxAmount || sv_unlimited_pickup)
            {
               int amount = Ammo(probe).Default.BackpackAmount;
               // extra ammo in baby mode and nightmare mode
               if (!bIgnoreSkill)
               {
                  amount = int(amount * G_SkillPropertyFloat(SKILLP_AmmoFactor));
               }
               probe.Amount += amount;
               if (probe.Amount > probe.MaxAmount && !sv_unlimited_pickup)
               {
                  probe.Amount = probe.MaxAmount;
               }
            }
         }
      }
   }
   item.bPickupGood = true;
   return true;
}

}


Any help with this would be appreciated, as I like the idea of backpacks from certain mods (like GunCaster) that add 10% to your max ammo capacity for each one after the first, but trying to implement it seems like a nightmare to far. XD
spectrefps
 
Joined: 21 Jun 2020
Operating System: Windows 10/8.1/8/201x 64-bit

Re: [Request] Stackable backpacks in ZScript?

Postby Blue Shadow » Sat Jun 20, 2020 8:54 pm

spectrefps wrote:This previous post was mine before I created my account, as I felt inclined to do so considering how much I've been enjoying various doom mods from here. I'm not sure how to 'claim' that post, so it will forever be that randomly generated name I guess >_<.

You have ownership now.
User avatar
Blue Shadow
 
 
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests