[PoC/WIP] Last Weapon Used button (ala Half-Life)
Posted: Sat Apr 30, 2016 9:05 am
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.
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.