Detect when a player hits a weapon slot key

Discuss all aspects related to modding Zandronum here.
Post Reply
Lakai
New User
Posts: 7
Joined: Tue Feb 19, 2013 12:00 am

Detect when a player hits a weapon slot key

#1

Post by Lakai » Tue Mar 01, 2016 10:17 pm

Hello there, I wanted to know if there is any way to detect when a player hits one of the weapon slots keys. The mod I'm trying to make only has 1 weapon so I wanted to use the weapon slot keys for other binds, as it would make things easier and player won't need to bind some extra keys when the weapon keys are unused. I already checked GetPlayerInput but it doesn't seem to be able to detect weapon switches.

Note: I can't use weapons to detect the key presess. If I do that, then the main weapon the mod uses gets lowered which is exactly what I'm trying to avoid. If there is no other solution then I will have to add extra keybinds to the KEYCONF thing, but I like this method and I wanted to see if it's possible.

User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

RE: Detect when a player hits a weapon slot key

#2

Post by SwordGrunt » Wed Mar 02, 2016 3:07 am

You can avoid weapon lowering by using the instant weapon switch player property. I can't think of any possible way to detect what you want, only hacky workarounds by creating multiple versions of your weapon and using the aforementioned property.

Lakai
New User
Posts: 7
Joined: Tue Feb 19, 2013 12:00 am

RE: Detect when a player hits a weapon slot key

#3

Post by Lakai » Wed Mar 02, 2016 9:09 pm

SwordGrunt wrote: You can avoid weapon lowering by using the instant weapon switch player property. I can't think of any possible way to detect what you want, only hacky workarounds by creating multiple versions of your weapon and using the aforementioned property.
Nice, I managed to get it to work. By using the property you mentioned and by adding this to the select state of the weapon:

Code: Select all

Select:
	TNT1 A 0 A_FireCustomMissile ("Rocket")
    TNT1 A 0 A_SelectWeapon("Pistol2")
    TNT1 A 1 A_Raise
    Loop
It fires a rocket everytime I hit the slot 2, but the Pistol never lowers, so it's detecting the weapon switch without even switching the weapons. And so far it didn't crash. Thanks man.

User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

RE: Detect when a player hits a weapon slot key

#4

Post by SwordGrunt » Thu Mar 03, 2016 1:15 am

Hacky workarounds are a big part of this engine! You came up with a pretty damn good solution using A_SelectWeapon. I wonder if using tag "" would work for no tag, meaning the player wouldn't notice the weapon switch was attempted (by seeing the weapon's name in yellow text at the bottom of the screen). That's just a nitpicky thing though. I'm glad you got it to work!

Post Reply