Hi, I am trying to bind keys with some sweps I added, I have overriden CHudWeaponSelection, as I didnt want it so im not sure if that is stopping my autorun script.
[code]
hook.Add("PlayerInitialSpawn", "Bind Keys", function()
RunConsoleCommand("Bind 1 SWEP.Primary")
RunConsoleCommand("Bind 2 SWEP.Secondary")
end)
[/code]
that was a bit of guess code, but atleast it gives you the right idea of what I want to do
Arguments for console commands should be passed as arguments.
Ergo:
[code]RunConsoleCommand( "cmd", "arg", "arg" )[/code]
[QUOTE=Netheous;48574103]Arguments for console commands should be passed as arguments.
Ergo:
[code]RunConsoleCommand( "cmd", "arg", "arg" )[/code][/QUOTE]
Thankyou, but do you know of a way to make it so it binds it to a primary weapon rather the slot
[QUOTE=Mattymoo14211;48574138]Thankyou, but do you know of a way to make it so it binds it to a primary weapon rather the slot[/QUOTE]
Well, bind function isn't for binding weapons anyways.
It's for binding a specific key to a specific console command.
I am certain that there isn't a command such as 'bind 1 weapon_class'.
bind 1 "use weapon_pistol"
[QUOTE=Giraffen93;48574158]bind 1 "use weapon_pistol"[/QUOTE]
Okay, I was wrong - thanks!
[QUOTE=Giraffen93;48574158]bind 1 "use weapon_pistol"[/QUOTE]
That sounds like just what I need, but is there a way to get what primary weapon I have?
[editline]30th August 2015[/editline]
-bump- I have tried:
[code]
weapons.Get( self.CurrentPrimary )
weapons.Get( self.CurrentSecondary )
[/code]
but those dont seem to return anything, it is in a playerspawn hook
also you cant bind with runconsolecommand, i tried that a year ago. it blocks it.
ok, so I have an idea, but how would I go about binding with lua as I read another post and it seems to not be as simple as ply:ConCommand
[QUOTE=Mattymoo14211;48575215]ok, so I have an idea, but how would I go about binding with lua as I read another post and it seems to not be as simple as ply:ConCommand[/QUOTE]
You can't bind keys without an unrestricted concommand module, even then the client would need it
[b]Edit:[/b]
Well, I mean you can't run commands like "bind" or "unbind".
I'm sure you could use [url=http://wiki.garrysmod.com/page/input/IsKeyDown]input.IsKeyDown[/url] in a hook like KeyPress or something
[QUOTE=stev_;48575229]You can't bind keys without an unrestricted concommand module, even then the client would need it
[b]Edit:[/b]
Well, I mean you can't run commands like "bind" or "unbind".
I'm sure you could use [url=http://wiki.garrysmod.com/page/input/IsKeyDown]input.IsKeyDown[/url] in a hook like KeyPress or something[/QUOTE]
this is the code that was on the thread I mentioned:
[code]
// ########################
// HOOK: PlayerKeyPress
// DESC: Serverside hook that's call when a player presses a key
// ARGS: PLAYER pl, NUMBER key
// AUTH: Entoros
if SERVER then
concommand.Add("cl_keypress",function(pl,cmd,args)
local n = tonumber(args[1])
hook.Call("PlayerKeyPress",GAMEMODE,pl,n)
end)
else
local keys_pressed = {}
hook.Add("Think","CheckKeyPress",function()
for i =1, 130 do
if input.IsKeyDown( i ) then
if keys_pressed[i] then return end
RunConsoleCommand( "cl_keypress", i )
hook.Call("PlayerKeyPress",GAMEMODE,LocalPlayer(),i)
keys_pressed[i] = true
elseif keys_pressed[i] then keys_pressed[i] = nil
end
end
end)
end
[/code]
Why don't you just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerButtonDown]GM/PlayerButtonDown[/url] instead of that? It pretty much does the exact same thing, and better.
[QUOTE=AK to Spray;48575403]Why don't you just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerButtonDown]GM/PlayerButtonDown[/url] instead of that? It pretty much does the exact same thing, and better.[/QUOTE]
so, am I right in thinking:
[code]
primary = weapons.Get( self.CurrentPrimary )
secondary = weapons.Get( self.CurrentSecondary )
hook.Add("PlayerButtonDown","Bind",function(ply,key)
if(ply:Alive())then
if (key == KEY_1 or key == KEY_PAD_1) then
ply:ConCommand("use", primary)
elseif(key == KEY_2 or key == KEY_PAD_2)then
ply:ConCommand("use", secondary)
end
end
end
end)
[/code]
I have tested the code and it gives me the error:
[ERROR] lua/autorun/client/bind.lua:14: ')' expected (to close '(' at line 4) near 'end'
1. unknown - lua/autorun/client/bind.lua:0
So, after testing stuff, I have this:
[code]
primaryList = {
{
"tfa_acr",
"tfa_ak47",
"tfa_ak74",
"tfa_amd65",
"tfa_an94",
"tfa_auga3",
"tfa_fal",
"tfa_g36",
"tfa_g3a3",
"tfa_l85",
"tfa_m14sp",
"tfa_m16a4_acog",
"tfa_m416",
"tfa_scar",
"tfa_tar21",
"tfa_val",
"tfa_winchester73",
"tfa_mp5",
"tfa_dragunov",
"tfa_honeybadger",
"tfa_intervention",
"tfa_m98b",
"tfa_mp5sd",
"tfa_aw50",
"tfa_bizonp19",
"tfa_usc"
}
}
hook.Add("PlayerSpawn", "Selects Weapons", function(ply)
for k,primary in pairs( primaryList )do
ply:HasWeapon( primary )
print("Variable Primary:"..primary.."!")
end
end)
[/code]
so, then I was going to do it so when key 1 is pressed it runs the command use primary, as primary should be whatever weapon the player has. is this correct? also, it is not printing to the console.
are you sure it runs serverside?
add
[CODE]
if SERVER then
stuffHere
end
[/CODE]
[QUOTE=DaRkWoRlD1337;48576546]are you sure it runs serverside?
add
[CODE]
if SERVER then
stuffHere
end
[/CODE][/QUOTE]
im running it clientside
[QUOTE=Mattymoo14211;48576576]im running it clientside[/QUOTE]
[IMG]http://i.imgur.com/jWUypau.png[/IMG]
[QUOTE=AK to Spray;48576827][IMG]http://i.imgur.com/jWUypau.png[/IMG][/QUOTE]
tbh this is really pissing me off now, im not on about you or any other people, I mean I cant figure it out, there is literally no information online and I havnt done lua in ages so ive forgotten everything, so im not asking for people to write the code for me, just a point in the right direction, such as pseudo code etc...
[QUOTE=Mattymoo14211;48576915]tbh this is really pissing me off now, im not on about you or any other people, I mean I cant figure it out, there is literally no information online and I havnt done lua in ages so ive forgotten everything, so im not asking for people to write the code for me, just a point in the right direction, such as pseudo code etc...[/QUOTE]
Just run the code serverside and it'll work.
PlayerSpawn hook is serverside, as you can see it on wiki.
So you cant run it clientside, unless you use networking, or some magic.
[QUOTE=LUModder;48579018]Just run the code serverside and it'll work.[/QUOTE]
ok, so I ran the code serverside, but I get an error saying HasWeapon expects a string not a table, but shouldn't primary be equal to each item in the table, not the actual table?
[code]
primaryList = {
{
"tfa_acr",
"tfa_ak47",
"tfa_ak74",
"tfa_amd65",
"tfa_an94",
"tfa_auga3",
"tfa_fal",
"tfa_g36",
"tfa_g3a3",
"tfa_l85",
"tfa_m14sp",
"tfa_m16a4_acog",
"tfa_m416",
"tfa_scar",
"tfa_tar21",
"tfa_val",
"tfa_winchester73",
"tfa_mp5",
"tfa_dragunov",
"tfa_honeybadger",
"tfa_intervention",
"tfa_m98b",
"tfa_mp5sd",
"tfa_aw50",
"tfa_bizonp19",
"tfa_usc"
}
}
hook.Add("PlayerSpawn", "Selects Weapons", function(ply)
for k,primary in pairs( primaryList )do
ply:HasWeapon( primary )
print("Variable Primary:"..primary.."!")
end
end)
[/code]
FIXED! primary was in the wrong place
[editline]31st August 2015[/editline]
so, this is the code so far:
[code]
primaryList = {
{
"tfa_acr",
"tfa_ak47",
"tfa_ak74",
"tfa_amd65",
"tfa_an94",
"tfa_auga3",
"tfa_fal",
"tfa_g36",
"tfa_g3a3",
"tfa_l85",
"tfa_m14sp",
"tfa_m16a4_acog",
"tfa_m416",
"tfa_scar",
"tfa_tar21",
"tfa_val",
"tfa_winchester73",
"tfa_mp5",
"tfa_dragunov",
"tfa_honeybadger",
"tfa_intervention",
"tfa_m98b",
"tfa_mp5sd",
"tfa_aw50",
"tfa_bizonp19",
"tfa_usc"
}
}
hook.Add("PlayerSpawn", "Selects Weapons", function(ply)
for primary,v in pairs( primaryList )do
ply:HasWeapon( primary )
print("PRIMARY:"..primary.."!")
end
end)
hook.Add("PlayerButtonDown", "Checks Button Press", function(ply,key)
if( key == KEY_primary or key == KEY_PAD_primary )then
ply:ConCommand("use", primaryList[primary])
end
end)
[/code]
but I have noticed primary always equals one, no matter what weapon I choose to spawn with.
Sorry, you need to Log In to post a reply to this thread.