Jump to content

key to activate a ability


Recommended Posts

I want to make a ability to my character that he can turn on and off the nightvision by pressing a key in the keyboard. I already have the nightvision, i just want to make a keystroke for it.

I found out that the key detection should look something like this

inst.components.keyhandler:AddActionListener("charactername", TUNING.CHARACTERNAME.KEY14, "idk")

but i can't understand it very well. could anyone help me?

Here is the code for my night vision

local NIGHTVISION_COLOURCUBES =
{
    day = "images/colour_cubes/ruins_light_cc.tex",
    dusk = "images/colour_cubes/ruins_dim_cc.tex",
    night = "images/colour_cubes/purple_moon_cc.tex",
    full_moon = "images/colour_cubes/purple_moon_cc.tex",
}

local function SetNightVision(inst, enable)
    if TheWorld.state.isnight or TheWorld:HasTag("cave") then
        inst.components.playervision:ForceNightVision(true)
        inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES)
    else
        inst.components.playervision:ForceNightVision(false)
        inst.components.playervision:SetCustomCCTable(nil)
    end
end

local function common_init(inst)
	SetNightVision(inst)
	inst:WatchWorldState( "isday", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "isdusk", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "isnight", function() SetNightVision(inst)  end)
	inst:WatchWorldState( "iscaveday", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "iscavedusk", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "iscavenight", function() SetNightVision(inst)  end)
end

There is probably a better way to do the night vision but i am a noob in programming ;(

Sorry if my english is bad

Edited by Seilakk
Link to comment
Share on other sites

39 minutes ago, ptr said:

TheInput:AddKeyDownHandler(KEY_Z, function()
  --something happens here
end)

Try this? As far as I know, keyhandler is not a built in component.

where do i have to place it? common_init? Thanks for helping me

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...