[Request] Stackable backpacks in ZScript?

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.

[Request] Stackable backpacks in ZScript?

Postby DabbingSquidward » Wed Nov 14, 2018 6: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
DabbingSquidward
 
Joined: 08 Nov 2017
Location: Germany

Re: [Request] Stackable backpacks in ZScript?

Postby Apeirogon » Wed Nov 14, 2018 7: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;
}

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

Re: [Request] Stackable backpacks in ZScript?

Postby DabbingSquidward » Wed Nov 14, 2018 3: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
DabbingSquidward
 
Joined: 08 Nov 2017
Location: Germany


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest