How do I bind keys to custom (named) weapon states?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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.

How do I bind keys to custom (named) weapon states?

Postby SpancherZD » Mon Oct 23, 2017 4:16 am

Hi. How does one bind keys to activate a custom weapon state that has a name? By that I mean a weapon state that isn't called User#.
Say, for example, I wanted a state called "Reload", and to activate it I'd press R. How would I do this? I've only been able to activate them by calling them User1, User2, etc and having this in my KEYCONF lump;
Code: Select allExpand view
   AddMenuKey "Reload" reload
   Alias reload +user1
   DefaultBind R reload


(Yes, I know that "Reload" is already a state that can be used with WRF_ALLOWRELOAD, I was simply using this as an example)
It's obviously possible as nearly every gun mod I've looked at has used custom weapon states with actual names.
Probably a noob question... After all, I am a noob lol (I only started modding a few days ago).
User avatar
SpancherZD
 
Joined: 23 Oct 2017
Location: Behind you

Re: How do I bind keys to custom (named) weapon states?

Postby ZippeyKeys12 » Tue Oct 24, 2017 10:30 am

For user states it's WRF_ALLOWUSER# and # is 1 thru 4.
If you mean any generic state then I would personally have a keyconf for example "+customthingy".Then I'd setup up an EventHandler which I'd setup an InputProcess and compare e.KeyScan to KeyBindings.GetKeysForCommand(+customthingy) and set a variable in the player. Finally inside the weapon check the variable in the player and jump to state if it is true.

Sry if it doesn't make sense, writing this while walking in between classes.
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: How do I bind keys to custom (named) weapon states?

Postby SpancherZD » Wed Oct 25, 2017 1:53 am

Ah, thanks Zippey, I thought I tried that second thing originally but I must've done something wrong, it works now.

EDIT: No idea what I changed, but suddenly it doesn't work ;(
User avatar
SpancherZD
 
Joined: 23 Oct 2017
Location: Behind you

Re: How do I bind keys to custom (named) weapon states?

Postby ZippeyKeys12 » Wed Oct 25, 2017 7:58 am

If your project isn't too secretive, you could post some of the relevant code to see what's wrong.
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: How do I bind keys to custom (named) weapon states?

Postby SpancherZD » Wed Oct 25, 2017 11:05 pm

Alright, basically what I want is for a "weapon" animation/sound to play on-screen when I press F.
In the weapon decorate marker thingy I want it to play on, I've made a custom weapon state called User1 that contains the animation + sound.

Code: Select allExpand view
User1:
   TNT1 A 10
   OKAY A 1
   OKAY B 1 A_PlaySound("YEAH", 2)
   OKAY CD 1 A_AlertMonsters
   OKAY E 15
   OKAY DCBA 1
   TNT1 A 10
   Goto Ready


And, in KEYCONF, I've binded F to User1.

Code: Select allExpand view
AddKeySection "Custom Mod Controls" CustomModControls

   AddMenuKey "Signal OKAY" Okay
   Alias Okay +User1
   DefaultBind F Okay


It works, however I have two problems;
-When the animation completes, it replays the animation infinitely until I switch weapon. Switching back to the weapon will continue playing that animation, the only way to stop it is to die.
-I don't want the state to be called User1, I want it to be called "Okay".

How would I fix/accomplish these? I've read heaps of stuff about it and can't seem to figure out why it's doing that/how to call the state something else and have it still work.
User avatar
SpancherZD
 
Joined: 23 Oct 2017
Location: Behind you

Re: How do I bind keys to custom (named) weapon states?

Postby ramon.dexter » Thu Oct 26, 2017 12:03 am

Sorry to ask, but is it really big problem, that it will be "user1", instead of "okay"? Just, think: What would happen, when you dont have this weapon in inventory? What would happen, when you have the weapon in inventory, but not selected? I think it would cause a crash, beacuse with the key bound to a specififc state of specific weapon. Or nothing would ahppen at all. gzDoom has the weapon states, because, basically, it is a weapon state of the one weapon. The user states are added so user can have four other actions, besides the fire, altfire and reaload. So you have four actions, that you can bind to any key. And that's it.

Also, when you want some special action for each of the weapon you have, you have to manually specify the action for each weapon individually. That's just how gzDoom works - many things have to done manually, instead of automatics like in modern engines.
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: How do I bind keys to custom (named) weapon states?

Postby SpancherZD » Thu Oct 26, 2017 12:52 am

Yeah haha, I can't use User1-4 because I'm having more than 4 custom states, and I can't use AltFire or Reload as they're already being used as well. Like I said, it's definitely possible as I've seen it in heaps of mods, I mean look at Brutal Doom; every weapon has way more than 4 custom states, all with different names, and they even have bindings in its KEYCONF.

Also, it hasn't seemed to crash yet, and I've tried the state in every weapon I've made so far.

... Speaking of Brutal Doom, if it helps, the "okay" state I want is similar to the "offend" state in BD, except the frames/sprites are different obviously.
User avatar
SpancherZD
 
Joined: 23 Oct 2017
Location: Behind you

Re: How do I bind keys to custom (named) weapon states?

Postby Blue Shadow » Thu Oct 26, 2017 1:39 am

I'd imagine it's done by using inventory: when you press a key, an item is given to you, for which the weapon checks, jumping to the desired state.

Or something to that effect...
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: How do I bind keys to custom (named) weapon states?

Postby ramon.dexter » Thu Oct 26, 2017 2:47 am

Hey, that's no a bad idea at all...

This way you can bind scripts, that will give you these items. Weapon will have just A_JumpIfInventory checks, that will do the rest.
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: How do I bind keys to custom (named) weapon states?

Postby ZippeyKeys12 » Thu Oct 26, 2017 8:29 am

Blue Shadow wrote:I'd imagine it's done by using inventory: when you press a key, an item is given to you, for which the weapon checks, jumping to the desired state.

That's what I was recommending except using inputprocess and a player variable instead for cleanliness.

EDIT: I'll try and write an example tonight if you don't figure it out by then
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: How do I bind keys to custom (named) weapon states?

Postby ZippeyKeys12 » Thu Oct 26, 2017 10:08 pm

Something like this, haven't tested it but it has got the basic idea.

Code: Select allExpand view
version "2.5"
class SampleInput:EventHandler {
   KeyBindings myBindings;
   override void OnRegister(){
      SetOrder(666);
   }
   override void NetworkProcess(ConsoleEvent e){
      if(e.Name=="oksig"){
         let playah = CustomPlayer(players[e.Player].mo);
         playah.okaysig=true;
      }
   }
}

class CustomPlayer:DoomPlayer{
   bool okaysig;
   Default{
      Player.WeaponSlot 1, "CustomWeap";
   }
}

class CustomWeap:Chainsaw{
   Default{
      Weapon.SlotNumber 1;
   }
   States{
      Ready:
         TNT1 A 1{
            if(CustomPlayer(invoker).okaysig)
               return ResolveState("UniqueState");
            return ResolveState(null);
         }
         //EDIT:Insert Weapon functionality
      UniqueState:
         TNT1 A 0{
            console.printf("state");
            return ResolveState("Ready");
         }
   }
}

Code: Select allExpand view
AddKeySection "Custom Mod Controls" CustomModControls
AddMenuKey "Signal OKAY" Okay
Alias Okay "netevent oksig"
DefaultBind F Okay

Code: Select allExpand view
gameinfo{
   PlayerClasses = "CustomPlayer"
   AddEventHandlers="SampleInput"
}
Last edited by ZippeyKeys12 on Wed Nov 01, 2017 10:08 pm, edited 1 time in total.
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: How do I bind keys to custom (named) weapon states?

Postby SpancherZD » Fri Oct 27, 2017 6:37 pm

It worked, thanks everyone :D
User avatar
SpancherZD
 
Joined: 23 Oct 2017
Location: Behind you

Re: How do I bind keys to custom (named) weapon states?

Postby ZippeyKeys12 » Fri Oct 27, 2017 9:33 pm

Glad you worked it out! :D
ZippeyKeys12
 
Joined: 15 Jun 2016


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests