by 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++)
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 all
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
[quote="Hugh Honeyridge"]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)?[/quote]
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]
DoomEdNums
{
8 = packback
}
[/code]
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]
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;
}
}
[/code]
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