Keybinding

Avatar
narsqrd
35 Posts
Posted Aug 15, 2012
I have an idea in the back of mind, but it would really only work under one particular condition:

Is there any way to bind a player's key to trigger an entity in a map? Not necessarily trigger I suppose -- sending outputs at all would be one thing -- but that if the player presses, for example, F a particular logic_relay would be triggered.

Is this something that can be done with Hammer wizardry? Or would that take more elaborate coding?

Advertisement
Registered users don’t see ads! Register now!
Avatar
FelixGriffin
2,680 Posts
Posted Aug 15, 2012
Replied 13 minutes later
It can be done with Hammer, although in multiplayer or in challenge maps it requires cheats (since the player could use this to activate a distant button or trigger, or even summon a cube from across a pit).

To look at standard keys (fire, use, jump, crouch) you can use a game_ui or logic_playerproxy. To use other ones, you can place a point_servercommand in your level (which lets you use the console), then have a logic_auto (or a trigger, perhaps?) OnMapSpawn > servercommand > Command > bind f ent_fire f_button_pressed trigger. Then whenever f is pressed, the f_button_pressed relay triggers. If you used a trigger or something to bind the key, you can take away that power later by disabling the relay or firing > servercommand > Command > unbind f.

Avatar
Skotty
671 Posts
Posted Aug 15, 2012
Replied 2 hours later
Just for correctness, because it could maybe cause problems, use "" when using bind commands.
bind f "<COMMAND>", since the console maybe could see a space (for example between ent_fire and the targetname) as end of the whole command.
Avatar
Brainstone
401 Posts
Posted Aug 16, 2012
Replied 15 hours later
Won't using ""-tags in hammer destroy the Hammer file, as it is built using the same system?
Avatar
narsqrd
35 Posts
Posted Aug 16, 2012
Replied 19 minutes later
Trying this out I've run into trouble.

Entering bind f "ent_fire temp_relay trigger" straight into the console works fine. Pressing f then triggers temp_relay

However, when I add an output to an entity (this failed for both logic_auto and logic_relay) that goes OnTrigger > servercommand > Command > bind f "ent_fire temp_relay trigger" the console says "f" = "+mouse_menu"

I tried other letters, "q" = "+mouse_menu_taunt", "t" = "say", evidently these keys are already bound and trying to change them via in-map entities doesn't work

I tried to bind an unbound letter, it says "z" is not bound

Avatar
Alexander Bell
306 Posts
Posted Aug 16, 2012
Replied 2 hours later
q is gestures, t is say, and f (I think) is the new "play test" menu thing.
Avatar
ChickenMobile
2,460 Posts
Posted Aug 17, 2012
Replied 1 day later
I wouldn't try to bind a certain key seeing as anyone could have a custom keybinding.

I would try to use the keys available to use in a game_ui. Perhaps you could have a key-combo instead of just one key. (using logic_branch etc)

Avatar
narsqrd
35 Posts
Posted Aug 18, 2012
Replied 8 hours later
It does seem like the "s are messing things up, because an entity calling <bind f "ent_fire temp_relay trigger"> appears to ignore everything in quotes so the command ends up looking like <bind f>

Using the default bindings via game_ui and logic_playerproxy (especially multiple keys) just feels like an unpleasant solution. "Yes player, I'm going to need you to crouch-jump every time you need to activate the thing". The best that could come of that is probably having them hit both moveleft and moveright at once do it, but that still feels weird.

I've tried using escape characters, like <bind f \"...\"> but apparently vbsp doesn't like that and it crashes the compiler

My last resort would probably be kindly asking the player to open up the console and type in the thing themselves, but obviously that has its own drawbacks. I'm assuming more than half the playerbase has never used the console and it would ruin the whole immersive gameplay experience

Avatar
FelixGriffin
2,680 Posts
Posted Aug 18, 2012
Replied 2 hours later
Yeah, I only use a playerproxy because crouching is half of the behavior I need.
Avatar
DaMaGepy
361 Posts
Posted Aug 21, 2012
Replied 2 days later
"F" is my right strafe key since I use ESDF for movement in every game, and A is use, G is next weapon, etc.... I would be really pissed off if something rebinds my keys. I also have a binding for all unused key, usually for mapmaking, turning things on/off.
Avatar
Fracture
797 Posts
Posted Mar 04, 2013
Replied 6 months later
i keep trying to bind certain keys and half the keys keep coming out saying key is unbound. IF IT'S NOT IN USE, I SHOULD BE ABLE TO BIND IT!!! >:(
Avatar
portal2tenacious
393 Posts
Posted Mar 04, 2013
Replied 1 hour later
Well binding something for your map doesn't seem like a very good idea to me. I know a lot of people here have binds that help with mapping, I have many for speedrunning. I wouldn't be very happy if those were replaced with binds I would never use again :wink:
Avatar
FelixGriffin
2,680 Posts
Posted Mar 04, 2013
Replied 31 minutes later

Fracture wrote:
i keep trying to bind certain keys and half the keys keep coming out saying key is unbound. IF IT'S NOT IN USE, I SHOULD BE ABLE TO BIND IT!!! >:(

It's because the quotes are causing a problem. The parameter to the servercommand is (iirc) wrapped in quotes when it's sent, so what's interpreted is just "bind z" or whatever.

Pack a CFG script with your map if you really HAVE to use keybinds and put them in there. But as Tenacious said it's not a good idea. I just discovered that Back-Stock rebound the "r" key and screwed up some of my scripts.

Avatar
Fracture
797 Posts
Posted Mar 04, 2013
Replied 39 minutes later
curses. someone in steam has to create an entity that can bind stuff like the playerproxy and game_ui cannot
Avatar
taco
504 Posts
Posted Mar 04, 2013
Replied 23 minutes later
You should find a way to let the player know that they need to bind a key manually - it's not elegant but it works and you'll avoid making people angry for overwriting their binds.
Avatar
portal2tenacious
393 Posts
Posted Mar 05, 2013
Replied 7 hours later

narsqrd wrote:
My last resort would probably be kindly asking the player to open up the console and type in the thing themselves, but obviously that has its own drawbacks. I'm assuming more than half the playerbase has never used the console and it would ruin the whole immersive gameplay experience

Avatar
CamBen
973 Posts
Posted Mar 05, 2013
Replied 3 hours later
If its going to be a big mappack and not just one map, I wouldn't mind too much if my binds were replaced. For example, if someone were to make a story about as big as portal 1 in portal2 with custom test ideas, I could see the point of rebinding a key.
Advertisement
Registered users don’t see ads! Register now!
Avatar
Fracture
797 Posts
Posted Mar 05, 2013
Replied 2 hours later
so far i got the playerproxy and gameui being used for control certain elements, I have the duck button being used to swap out 2 items. I did notice there was a output for flashlights, but i guess that only works in half-life