New weapon that replaces weapon in players inventory?

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.

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
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

New weapon that replaces weapon in players inventory?

Post 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.)
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: New weapon that replaces weapon in players inventory?

Post by Jarewill »

How about using a CustomInventory actor that takes away the old weapon and gives the new one?
For example:
Spoiler:
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: New weapon that replaces weapon in players inventory?

Post 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.
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Re: New weapon that replaces weapon in players inventory?

Post 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.
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Re: New weapon that replaces weapon in players inventory?

Post 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.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: New weapon that replaces weapon in players inventory?

Post 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).
Post Reply

Return to “Scripting”