simple force player keybind

im new to code so dont hate help instead! code might betotally off YOU HAVE BEEN WARNED!!!

so im trying to create a simple script that automaticly assigns F9 Bound to “say /calladmin” for All players on the server as default(when they join)


function GM:PlayerBindPress( ply, bind, pressed )
if ( string.find( bind, "load quick" ) ) then return true
if (true then (ply concommand.Run ("bind F9 "say /calladmin"") end
end

please reply with a more accurate solution if you know one!

I wouldn’t force them to directly BIND the key, but to automaticly make them say ‘CallAdmin’ instead, its way better than fucking up their bindings.



local antispam 	= false -- Dont edit c:
local time 		= 60 -- Set your anti spam time here

hook.Add("Think", "Call_Admin_Thingy", function()
	if input.IsKeyDown(KP_F9) and antispam == false then
		antispam = true -- Enables antispam, doesn't make them like say it 5000 times a second lol
		LocalPlayer():ConCommand("say /calladmin") -- makes them say the command

		timer.Simple(time, function() -- This part resets the antispam, making it re-useable after _N_ seconds.
			antispam = false
		end)
	end
end)


input.IsKeyDown

GM:Think

Hope that helps, its untested though.

Edit: besides your string is false, you cant have a " inside ", either have it inside or use " to mark ‘incode **"**s’

nice im making it be that way because of my f4 menu i got added support tabs and one is calladmin,
but the F9 bind connected to the tab button won’t execute the command and instead directs to the Q bind

Hello. I am working with the above poster in making a DarkRP server using your script. We are unsure where to place the lua file in the server directory. We are also unsure what would be an appropriate name for it, is ‘calladmindlc.lua’ okay? Thanks in advance.

[editline]5th April 2016[/editline]

Hello. I am working with the above poster in making a DarkRP server using your script. We are unsure where to place the lua file in the server directory. We are also unsure what would be an appropriate name for it, is ‘calladmindlc.lua’ okay? Thanks in advance.

Its a clientside script, so lets say “/addons/addonname/lua/autorun/client/script.lua” should do the trick, or simply “lua/autorun/client/script.lua”.

Get spammed with this lua error constantly when the script is in either one of your suggested locations:


[ERROR] lua/autorun/client/calladmindlc.lua:5: bad argument #1 to 'IsKeyDown' (number expected, got nil)
  1. IsKeyDown - [C]:-1
   2. fn - lua/autorun/client/calladmindlc.lua:5
    3. unknown - addons/ulib/lua/ulib/shared/hook.lua:110

try 100 instead of KEY_F9

It works, thank you very much :slight_smile: