GmodLua ButtonPress Problem

Hello there, I’m going to make a script for Gmod where I need to use a Button Press function.

I want to use an If statement, when a Player press F2 Then…

I hope you guys can tell me what i should use.

Edit: No “GM:” function if it is possible.

lol why no GM functions? Those functions are default, and you cant do it without!

Is this server sided, client, or both?

use the PlayerBindPress hook checking for the thing bound to F2 (should be gm_showhelp)

GM:PlayerBindPress( Player ply, string bind, boolean pressed )

“Edit: No “GM:” function if it is possible.”

[editline]16th April 2016[/editline]

Plus its not what he wants, he probably wants to run a function when F2 is pressed – and not everyone got F2 bound, plus its ShowSpare1 if I am right, since ShowHelp is F1.

I want to make a Pointshop.
When a player is pressing F2 the frame should be opened.
And I cant use GM: functions. It shows me an error when I open the script.

do you mean, a ‘item’ for pointshop? That’d explain it further.

if so, hook into the ITEM:Think() function and use input.IsKeyDown(93)93 standing for KEY_F2

My try was :
if (input.IsKeyDown(KEY_F2)) then
–code–
end

Do i need to use 93 instead of KEY_F2?

Yes, else it’ll error a string has been passed instead of a number.

…What? KEY is an enumeration, KEY_F2 is a numerical value. That’s the whole purpose of using enumerations, if the numerical value changes in a future version, and you used an enum, it should theoretically work, as it’s dynamic. If you use a constant as you propose, it could potentially break in the future.

Also, samurai, your script may be erroring when you use “GM”, but have you tried “GAMEMODE”

You cant run Gamemode functions in pointshop if I’m right – specially no client ones? Also, when I tried using KEY_ enums recently, it didn’t work, it errored that it was a ‘string’ and not a number. Even doe I didn’t put it in "

No it’s not working.
My Code to test:
if (input.IsKeyDown(93)) then
print(“Hi”)

end

You just assumed it was for pointshop. AFAIK, from his posts, he wants to make a pointshop, that’s why he’s asking how to open a frame when he presses F2.

I asked which realm it’s meant to open from, but he never responded.

Samurai, assuming it’s to be opened from the server:


hook.Add( "ShowHelp", "...", function( Player )

    -- Network to the player. On receive, open the frame.

end )

Can I change the Button for the help?

He wants it to be F2 though :stuck_out_tongue: – And now dont use the ShowSpare hook, because others may rebind the ShowSpare key, geez.