Jump to content

How to add a key press/ keybind?


Recommended Posts

Hello, 

I'm just wrapping up my mod and this is the last thing I need to do. 

My character is going to have an ability to 'pull up' the hood on their back to gain insulation and damage resistance. I've made all the builds needed but I have no idea how to make it so that you can pull the hood up and down with the press of a key (like 'G')? How would I do that if it is possible?

Many thanks.

Link to comment
Share on other sites

I am not sure if this version works for both client and server, i.e., whether the function only executes on the client registering the key press, and you then have to do something special if you want to change things on the server (remember, the client prefabs don't have any components on them).

local MY_BOUND_KEY = GetModConfigData("Key")

local MyKeyFunction = function()
	-- Do something
end

-- Note that you can also use AddKeyUpHandler instead, which fires the even when the key is released.
-- KeyDown may fire each frame it is being held. I don't know, but if it does, using KeyUp is a solution.
GLOBAL.TheInput:AddKeyDownHandler(MY_BOUND_KEY, MyKeyFunction)

Also, @YakumoYukari has a marvelous write-up of how to create and toggle netvars using key presses.

What you need to do, is change the anim build between the one with the hood and the one without it, and simultaneously change the settings you want to change.

Honestly, if I were you, I'd find another character mod which uses key presses, and see how they did it. I'd post examples, but the Steam workshop seems to be down atm.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...