How to make a "switch weapon if you have item" function

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
Clown_Number_42
Posts: 37
Joined: Tue Oct 04, 2022 3:19 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 10
Location: Somewhere

How to make a "switch weapon if you have item" function

Post by Clown_Number_42 »

I was wondering about how i could make a "When you have a certain inventory item, lower weapon and switch to a specific weapon immediately, switching back to the previous weapon when you lose the inventory item." function? Another question i had is if i could have a run-down on how to animate two-handed/dual wielding sprites with overlays?
yum13241
Posts: 875
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: How to make a "switch weapon if you have item" function

Post by yum13241 »

Sister weapons?
User avatar
Clown_Number_42
Posts: 37
Joined: Tue Oct 04, 2022 3:19 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 10
Location: Somewhere

Re: How to make a "switch weapon if you have item" function

Post by Clown_Number_42 »

yum13241 wrote: Mon Nov 07, 2022 11:01 am Sister weapons?
I was thinking something similar to Sister weapons, but it doesn't change any of the default weapons and the player can only equip it by pressing custom keybind.
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: How to make a "switch weapon if you have item" function

Post by Jarewill »

You should specify what exactly do you want.
From what I understand, you want a powerup of sorts?
Here's a ZScript example I quickly whipped together:
Spoiler:
User avatar
Clown_Number_42
Posts: 37
Joined: Tue Oct 04, 2022 3:19 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 10
Location: Somewhere

Re: How to make a "switch weapon if you have item" function

Post by Clown_Number_42 »

Jarewill wrote: Mon Nov 07, 2022 3:41 pm You should specify what exactly do you want.
From what I understand, you want a powerup of sorts?
Here's a ZScript example I quickly whipped together:
Spoiler:
What i had in mind was something like "press a custom keybind (like f) to give yourself a custom weapon and switch to it, press the button again to switch away from it and delete it from your inventory." like the M_Gizmos "Holster" function, but i think i can make-do with this.
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: How to make a "switch weapon if you have item" function

Post by Dan_The_Noob »

seems like you just want to give a player a weapon but have it auto-equip regardless of "switch on pickup"?
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: How to make a "switch weapon if you have item" function

Post by Jarewill »

Clown_Number_42 wrote: Mon Nov 07, 2022 5:15 pm What i had in mind was something like "press a custom keybind (like f) to give yourself a custom weapon and switch to it, press the button again to switch away from it and delete it from your inventory." like the M_Gizmos "Holster" function, but i think i can make-do with this.
In this case the previously provided code can be adapted into what you want by combining both Init- and EndEffect overrides into a single Use override.
Use gets triggered whenever an inventory item is used, so with that it's possible to check for special logic inside the inventory item and do specific things, kind of like using CustomInventory items in DECORATE.
For example:
Spoiler:
Post Reply

Return to “Scripting”