[code request] Make this pistol have a suppressor function when altfire?

Requests go in THIS forum!
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
Graaicko
Posts: 532
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

[code request] Make this pistol have a suppressor function when altfire?

Post by Graaicko »

Hello, I was wondering if someone would be able to edit this existing code to make it when you altfire it goes into an animation where the player attaches a suppressor to it and the weapon is suppressed and is reversed when you altfire again back to its unsuppressed state. I'd prefer it being one weapon if possible, I already made the sprites for it and looks really good. (I am pretty much looking for my pistol code to be altered so it can be suppressed and unsuppressed when the player presses the right mouse button or the 'altfire' key) I have tried to do it myself but I can't for the life of me figure it out on my own.

/////Code Here/////
Spoiler:
yum13241
Posts: 853
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

Re: [code request] Make this pistol have a suppressor function when altfire?

Post by yum13241 »

First of all, please use the code tag, it makes copying your code easier.

Try this:
Spoiler: code
So in DECORATE we cannot use variables, we have to use dummy inventory items like PistolSupressor, which we give and take conditionally and perform actions based on them (A_JumpIfInventory).

So what I did here is when the user presses altfire, first check if they have PistolSupressor, this might not make sense, but remember you CANNOT check for a LACK of an item in DECORATE. If they DO NOT have the PistolSupressor item, we give it to them, then make the gun ready.
Then, when they press altfire again, our check for the PistolSupressor item succeeds, so we jump to the UnSupress state sequence, which takes the item, and readies the gun.

Then, when the player shoots, we check for the PistolSupressor. If the check succeeds (they suppressed the pistol), we go to FireSupressed and right now, we check for reloading, and then make a SUPPFIRE sound, then go back to the regular firing sequence, but we SKIP 4 FRAMES, otherwise, we'd shoot forever. If you want to make a unique firing sequence remove the Goto Fire+4 line and program it as if it were Fire:.

But if the check fails, we DO NOT jump and call A_AlertMonsters which will alert monsters. I added +WEAPON.NOALERT so that the suppressed fire doesn't alert automatically.

Also, I just realized I spelled suppressed wrong in the code, sorry! I hope this helps though!
User avatar
Hellser
Global Moderator
Posts: 2730
Joined: Sun Jun 25, 2006 4:43 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11/Manjaro
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Citadel Station

Re: [code request] Make this pistol have a suppressor function when altfire?

Post by Hellser »

yum13241 wrote: Sun Sep 01, 2024 8:16 am So in DECORATE we cannot use variables...
How... far back are you in DECORATE knowledge, buddy?
yum13241
Posts: 853
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

Re: [code request] Make this pistol have a suppressor function when altfire?

Post by yum13241 »

Not too far back. Nobody uses DECORATE "variables" because you can only modify them with A_SetUserVar. In weapons, it must be defined in the player. In CustomInventory, it must be defined by the holder.

I can guarantee you that almost all DECORATE mods are made in DECORATE for Zandronum usage, which does not have this feature. Also, if other ports get DECORATE (some cut down version of it lol), they are unlikely to port this feature, as otherwise, all ports would basically become ZDoom, and not a lot of port authors would like that.

I was just providing a solution that works in most ports, as a GZDoom-only DECORATE mod is pointless, as you may as well use what ZScript has to offer. DECORATE in its entirety will become almost-pointless once GZDoom: C/S Edition finally becomes a thing (there's a branch for it on the official Git repo), except for maybe PlayerPawns, as you can force compatibility with other player-modifiying mods with some hacks.

How far back are you in ZScript knowledge, buddy?
User avatar
Hellser
Global Moderator
Posts: 2730
Joined: Sun Jun 25, 2006 4:43 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11/Manjaro
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Citadel Station

Re: [code request] Make this pistol have a suppressor function when altfire?

Post by Hellser »

I don't use ZScript, buddy. User Variables for Actors existed since 2009. Zandronum supports it. DECORATE authors use it, because I use it for my personal project. I can tell you that Zandronum isn't crashing at the User Variables, but rather frandompick... so much for having a DECORATE only mod that works on Zandronum. And, I believe I brought up your very comment about ZScript on another thread:
DECORATE right now is a deprecated feature set and anyone who looks to use it is ushered to the "How to ZScript" pages.
Why do people code in DECORATE even though ZScript exists? Because we're comfortable with it. I am not a C-style programmer. I brute-forced my way to understanding DECORATE because I wanted to make mods and I had a good teacher to help me on the way. I'm only bringing up the fact that User Variables exist. Yes, they need to be defined on the PlayerPawn. This is fine and is a perfectly acceptable alternative to using CustomInventory actors. Weapons can modify the PlayerPawn's variable. If it's something as simple as checking to see if a weapon is suppressed, I'd be fine with using User Variables - and we should encourage others to broaden their horizons beyond making even more CustomInventory actors where as a User Var can fill in to simply ask "Hey, do I jump to this state if my weapon is suppressed?" The rest of your code, I see no problems with.

Could this be simplier with ZScript? Sure. But he's using DECORATE. Let him have fun with it.

Now, some tips for the 1911 suppressing feature: Things get a little hairy when it comes to selecting and deselecting. You will have to account that the weapon will be suppressed or not suppressed. So there will be a lot of jumping around (Select.Suppressed/Select.UnSuppressed) states for an example. But it seems that you, Graaicko, have the basic concepts down so far. Don't hesitate to experiment. Broken code and headscratching is part of the fun. :)
yum13241
Posts: 853
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

Re: [code request] Make this pistol have a suppressor function when altfire?

Post by yum13241 »

Hellser wrote: Now, some tips for the 1911 suppressing feature: Things get a little hairy when it comes to selecting and deselecting. You will have to account that the weapon will be suppressed or not suppressed. So there will be a lot of jumping around (Select.Suppressed/Select.UnSuppressed) states for an example. But it seems that you, Graaicko, have the basic concepts down so far. Don't hesitate to experiment. Broken code and headscratching is part of the fun. :)
Only if it's going to actually have a silencer attached in its sprites.
Hellser wrote: Could this be simplier with ZScript? Sure. But he's using DECORATE. Let him have fun with it.
Playing online is part of the fun, lol.
Hellser wrote: I am not a C-style programmer
Neither am I. And btw, DECORATE is also C-styled, because otherwise we'd have semantic whitespace instead of curly braces. It borrows a lot more from C than what you realize, buddy.
Hellser wrote: using CustomInventory actors
Actually, we're using regular Inventory here. CustomInventory is not needed and should only be used in DECORATE. In ZScript, the idiosyncrasies make it not worth it over just overriding TryPickup().
Hellser wrote: DECORATE right now is a deprecated feature set and anyone who looks to use it is ushered to the "How to ZScript" pages.
You said that, not me, lol. (Rachael quoted you, not me, lol) search.php?keywords=++++DECORATE+right+ ... sf=msgonly

And you can only GetUserVariable through ACS, if you don't need to A_JumpIf Other than that, it's great to learn that variables kinda exist. You can ONLY set them though, not add/subtract/divide/multiply/square root/whatever AFAIK.

Return to “Requests”