So i was trying to reproduce an E2 in SF and this E2 used an input to trigger , so i tried using input.KEY_ but it seems this function is totally broke with like examples when i use
if ents.owner():keyDown(input.KEY_B) then
whatever()
It would do return a value only when pressing the W key or the CTRL key. The keys seems totally scrambled , i asked Link320 and arrived at the same conclusion , is that a bug or something ?
If it is , let me know that and could you fix it ? Thank you
The17thDoctor: Server take me to the most handsome person srcds_linux: I cant send people to themselves...
the specific inputs such as any letter are for clientside input and it's not a bug, the server only listens to the buttons you have bound in your settings so you'll have to either use one of those or the bind hook and then set a custom bind that key.
I might be wrong tho so someone correct me if I am.
The player keyDown() and keyUp() methods only accept input.IN_* values, as they only track bound keys as T-18 said. It even says that in the documentation.
(25-06-2017, 10:07 AM)Person8880 Wrote: This is not a bug.
The player keyDown() and keyUp() methods only accept input.IN_* values, as they only track bound keys as T-18 said. It even says that in the documentation.
Ok thanks.
The17thDoctor: Server take me to the most handsome person srcds_linux: I cant send people to themselves...
25-06-2017, 03:56 PM, (This post was last modified: 25-06-2017, 04:12 PM by 4N0NYM.)
Well but still there is something strange, Keys like "W" or "S" works fine but when i want to use keys like "B" it dont work.
oh with key W S or B i mean : input.KEY_W input.KEY_S input.KEY_B
Both the KEY_* and IN_* values are numbers. In the case of the IN_*, it's actually powers of 2 which are used as a bitflag to check for keys pressed. Thus when you pass KEY_W in (whose value is 33), you're actually checking if either input 1 (primary attack) or input 32 (use button) are down.
If you want to be extra fancy you could record all pressed buttons using the "playerbuttondown" hook (which should run on the server too). For the client you can obviously use "input.isButtonDown".
Without ever having used custom player functions (except for testing this code), here's how I imagine it would look (you're encouraged to modify this so it only tracks the buttons you need):
Code:
local Player = starfall.getTypeDef("Player")
function Player:buttonDown(btn)
local buttons = self[Player.buttonDown]
if not buttons then return false end
return buttons[btn] or false
end
hook.add("PlayerButtonDown", tostring(Player.buttonDown), function(plr, btn)
local buttons = plr[Player.buttonDown]
if not buttons then
buttons = {}
plr[Player.buttonDown] = buttons
end
buttons[btn] = true
end)
hook.add("PlayerButtonUp", tostring(Player.buttonDown), function(plr, btn)
local buttons = plr[Player.buttonDown]
if buttons then buttons[btn] = nil end
end)
hook.add("think", "", function()
if ents.owner():buttonDown(input.KEY_B) then
error("LEL")
end
end)