Page 1 of 1

New weapon that replaces weapon in players inventory?

Posted: Sun May 10, 2020 2:50 am
by Graaicko
So I was wondering in my project you will aquire a weapon that is semi only. later if you find it there is a modded version of this weapon that is converted to fire in full-auto. I was wondering how it would be possible to replace the old semi weapon with this new modded weapon? (No sense in having both, I'm looking at this in a realistic point of view.)

Re: New weapon that replaces weapon in players inventory?

Posted: Sun May 10, 2020 3:10 am
by Jarewill
How about using a CustomInventory actor that takes away the old weapon and gives the new one?
For example:
Spoiler:

Re: New weapon that replaces weapon in players inventory?

Posted: Sun May 10, 2020 12:08 pm
by wildweasel
Bear in mind that if you find another of the original weapon, it will be added back to your inventory - you will probably want to do a similar CustomInventory for the weapon that is being replaced, that detects the upgraded version and gives only the ammo.

Re: New weapon that replaces weapon in players inventory?

Posted: Mon Jul 24, 2023 9:28 am
by Graaicko
Sorry for the bump, I am just now working on this particular issue. And I've been taking a break from building my mod. I set up an additional pickup I would put ontop of the upgraded weapon in doom builder, it works for me. Now how would I make the older weapon act as somekind of ammo pickup once the player aqcuired this upgraded weapon? I played around a bit and couldn't really figure this one out.
Again, sorry for the bump Didn't feel like making a new topic about something I've asked before.

Re: New weapon that replaces weapon in players inventory?

Posted: Mon Jul 24, 2023 9:30 am
by Graaicko
Something to keep in mind aswell is that this upgraded weapon is a secret weapon, so depending on the players exploration not all players will acquire this weapon, but will definitely acquire the older weapon.

Re: New weapon that replaces weapon in players inventory?

Posted: Wed Nov 08, 2023 1:35 pm
by Player701
If you can use ZScript, here is a way that does not require any extra classes:

Code: Select all

class NormalWeapon : Weapon
{
    // TODO: Your normal weapon code here
}

class UpgradedWeapon : NormalWeapon
{
    override bool TryPickup(in out Actor toucher)
    {
        bool result = Super.TryPickup(toucher);
        
        if (result)
        {
            // If picked up successfully, remove the normal weapon
            toucher.TakeInventory('NormalWeapon', 1);
        }

        return result;
    }
    
    override bool HandlePickup(Inventory item)
    {
        // If picking up a NormalWeapon, only attempt to pick it up for ammo.
        if (item.GetClass() == 'NormalWeapon')
        {
            item.bPickupGood = Weapon(item).PickupForAmmo(self);
            return true;
        }

        return Super.HandlePickup(item);
    }
}
Note that it is not required for UpgradedWeapon to derive from NormalWeapon, they only have to use the same types of ammo (which I guess is true in your scenario).