• How? Check if player holding flashlight key
    7 replies, posted
local flashlightKey = input.LookupBinding( "impulse 100" ) or KEY_F if self.Owner:KeyDown(flashlightKey) then print("Working") end bad argument #1 to 'KeyDown' (number expected, got string) Of course, flashlightKey is returning "f". Is there a way I can convert this into KEY_F? Or even more, if someone has flashlight bound to something that's not in the KEY_ enums, like mouse buttons, how can I check if they're holding that button down?
There's a request here to translate a string to key enum. In the meantime, you can probably write a lookup table for strings->key enums. Player:KeyDown is for IN_* enums - you should be using input.IsKeyDown, instead. You can use MOUSE enums with input.IsMouseDown for mouse bindings.
I made this as a work around a while ago. It's not perfect but it does what i needed it too. local function KeyFromString(key) local key = _G["KEY_" .. string.upper(key)]; return key or nil; end
Thank you both. Rainbow that's exactly what I was thinking I would do, but I didn't know of the _G thing? I assume that turns it into the integer represented by KEY_* ? I'll try a hybrid of both of your suggestions, trying to separate if it's mouse or key. Thanks again!
Yeah, _G is a reference to the global table, so these are equivalent: print(_G["KEY_Q"]) print(KEY_Q)
pretty sure input.IsKeyDown will only work for clientside scripts? I need this to happen shared.
Yes, and there is no way to detect arbitrary keys shared. IN_* enums and KeyDown are shared for movement keys that are networked in CUserCmds, but all other functional keys exclusively use bindings. Bindings are only sent on initial key press, so you'll have to do your own networking if you want to detect a player holding the flashlight key.
Also, the mouse thing would be easier if the keys were MOUSE1 MOUSE2 MOUSE3, not MOUSE Enumerations
Sorry, you need to Log In to post a reply to this thread.