[PoC/WIP] Last Weapon Used button (ala Half-Life)

Projects that alter game functions but do not include new maps belong here.
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.
Post Reply
sarge945
Posts: 2
Joined: Sat Apr 30, 2016 8:46 am

[PoC/WIP] Last Weapon Used button (ala Half-Life)

Post by sarge945 »

Hi!

I have been part of the ZDoom scene for a while now, so even though this is my first post, I am not really new to the whole ZDoom thing - I have really just never had anything of value to contribute (until now, hopefully).

Anyway, I have been thinking for a while about a simple mod to add a "Last weapon used" button, similar to what is available in Half-Life, Killing Floor and many other FPS games. While this isn't super important for Doom, I have found it quite useful in certain mods such as Brutal Doom that tend to require a lot of fast weapon switching, especially on the higher difficulties.

Anyway, while this is by no means complete, and I am by no means an expert coder, I have quickly thrown together a proof of concept for a "last weapon used" type features, usable across any of the Doom Engine games. Expect there to be bugs, as while I have tested this it is far from a perfect implementation.

Looking through the code you will probably notice some oddities, mainly:

1. Heretic-specific overrides (powered weapons in particular). In Heretic, if you activate a Tome of Power, changing from the GoldWand to the GoldWandPowered, while instantaneous, counts as a weapon switch. As a result, having a mod like this one which requires checking for weapon changes effectively breaks - When you automatically switch to the GoldWandPowered, your "last weapon used" becomes GoldWand, which is an undesirable situation. I fix this by sanitising the weapon names by hand. I do not know of a better way to handle this, and I am definitely open to suggestions, as this is theoretically incompatible with any mod that uses the SisterWeapon DECORATE property in a similar way.

2. When you change weapons, instead of instantly registering the selected weapon (and thus setting your previous weapon to "Last Used Weapon"), the mod waits for you to have the weapon selected for at least 80 tics first. This is because there are often multiple weapons in the same slot (i.e. assigned to the same button). Without this delay, it would be impossible to have the Fist as your last weapon and the Shotgun as your current weapon if you have the Chainsaw and Double Barrel in your inventory, for example. This is even worse in mods like Project Brutality which can sometimes have 4 or 5 weapons assigned to a single slot. The 80 tics seems to be a "healthy middle ground" where you have enough time to switch to the weapons you want, but don't get unexpected behaviour if you switch weapons a lot during normal gameplay. This 80 tics rule is ignored if you switch to your last used weapon using the key, as this is considered an "intentional" weapon change rather than part of scrolling to the weapon you want.

Anyway, here is the file. I would love to see what people think and if it's a good enough idea for a project. Perhaps someone more knowledgeable can help with the first point I listed above relating to Heretic powered weapons. I apologize for the quality of the code. I am not the most proficient at ACS, and the code was thrown together in a short time as a proof of concept. The code (with comments) is provided in the PK3 file.

Anyway, I would love to hear some feedback. I would also like to know if anyone is willing to test this in multiplayer, as I have no idea if it will work and am not in a good position to test the multiplayer aspects of this mod.

Instructions: Run in ZDoom or any ZDoom-based port and set the last-weapon key in the options. The button you assign can be used to instantly switched to the last weapon you had selected. Personally, I have this in my global autoloads folder.
Attachments
LastWeapon.pk3
(2.5 KiB) Downloaded 617 times
Endless123
Posts: 1560
Joined: Wed Aug 28, 2013 1:36 pm

Re: [PoC/WIP] Last Weapon Used button (ala Half-Life)

Post by Endless123 »

That's a great idea you had there. It's crutial in the heat of action to not waste time searching for the key of the weapon we want to use.

I confirm this add-on to work even with my own mod so it's more than a "proof-of-concept" it's a proven concept for me. It's working as expected and even if you said you are not proficient at ACS coding the important thing is it doesn't matter because it works.

So a big :thumb:

:rock: :rock: :rock:
sarge945
Posts: 2
Joined: Sat Apr 30, 2016 8:46 am

Re: [PoC/WIP] Last Weapon Used button (ala Half-Life)

Post by sarge945 »

Thanks for the kind words. Even though it works, I still consider it only a PoC because of the issues I have mentioned in my original post. I would like to hopefully find a better way of doing it that can circumvent the need for the 80 tic wait altogether, as it is an inherently unreliable way of doing things. I had thought about making a weapon-bucket system similar to the one in Half Life (select weapons and press FIRE to switch to them), but it seemed like it would be a lot of work and would cause compatibility issues. I am taking compatibility very seriously for this project, as one of my ultimate goals is to place it in my autoload folder and forget about it, having it just work.
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: [PoC/WIP] Last Weapon Used button (ala Half-Life)

Post by The Zombie Killer »

There is indeed a much better way of doing this. It's pretty much just this (what I use in my stuff):

Code: Select all

#library "qswitch"
#include "zcommon.acs"

#define MAX_PLAYERS 8

str lastWeapon[MAX_PLAYERS];

script "LastWeaponHandler" enter
{
    int pn            = PlayerNumber();
    str currentWeapon = GetWeapon();
    lastWeapon[pn]    = currentWeapon;
    
    while (true)
    {
        if (StrCmp(currentWeapon, GetWeapon()))
            lastWeapon[pn] = currentWeapon;
        currentWeapon = GetWeapon();
        Delay(1);
    }
}

script "LastWeapon" (void)
{
    int pn = PlayerNumber();
    SetWeapon(lastWeapon[pn]);
}
Stuff like waiting a few tics after changing weapons etc. would be quite easy to add on to this.
If you're going for compatibility, it might be a good idea to just use a cvar to store the last weapon, rather than using up a global variable slot.
eclenaeu
Posts: 1
Joined: Tue Jan 10, 2023 6:02 pm
Operating System Version (Optional): Windows 10 pro
Graphics Processor: nVidia with Vulkan support

Re: [PoC/WIP] Last Weapon Used button (ala Half-Life)

Post by eclenaeu »

I've been looking into this feature for Raze, is there any chance to make this mod compatible with Raze?
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: [PoC/WIP] Last Weapon Used button (ala Half-Life)

Post by wildweasel »

eclenaeu wrote: Tue Jan 10, 2023 6:29 pm I've been looking into this feature for Raze, is there any chance to make this mod compatible with Raze?
Not as-is, no. This mod was made before ZScript was a thing in the ZDoom codebase, for one, and Raze does not yet have enough ZScript in it to code an equivalent to this mod's ACS (which is a Doom engine thing and won't make its way to Raze).
Post Reply

Return to “Gameplay Mods”