I'm trying to make a toggle command to toggle a function where if you are holding down your attack key, it spams mouse one. I'm getting no errors, here is my code:
[CODE]
local attack = false
local function m2_toggle()
m2_toggle = !m2_toggle
if m2_toggle then
hook.Add("Think","m2_toggle",m2_on)
else
hook.Remove("Think","m2_toggle")
RunConsoleCommand("-attack")
attack = false
end
end
local function m2_on()
if LocalPlayer():KeyDown(IN_ATTACK) then
if attack then
RunConsoleCommand("-attack")
else
RunConsoleCommand("+attack")
end
attack = !attack
end
end
concommand.Add("m2_toggle",m2_toggle)
[/CODE]
Fixed:
[LUA]
local attack = false
local m2_toggleB = false
local function m2_toggle()
m2_toggleB = !m2_toggleB
if m2_toggleB then
hook.Add("Think","m2_toggle",m2_on)
else
hook.Remove("Think","m2_toggle")
RunConsoleCommand("-attack")
attack = false
end
end
local function m2_on()
if LocalPlayer():KeyDown(IN_ATTACK) then
if attack then
RunConsoleCommand("-attack")
else
RunConsoleCommand("+attack")
end
attack = !attack
end
end
concommand.Add("m2_toggle",m2_toggle)
[/LUA]
m2_toggle is the function name so it was trying to change so i made it m2_toggleB an local var
[QUOTE=rtm516;50497244]Fixed:
[LUA]
local attack = false
local m2_toggleB = false
local function m2_toggle()
m2_toggleB = !m2_toggleB
if m2_toggleB then
hook.Add("Think","m2_toggle",m2_on)
else
hook.Remove("Think","m2_toggle")
RunConsoleCommand("-attack")
attack = false
end
end
local function m2_on()
if LocalPlayer():KeyDown(IN_ATTACK) then
if attack then
RunConsoleCommand("-attack")
else
RunConsoleCommand("+attack")
end
attack = !attack
end
end
concommand.Add("m2_toggle",m2_toggle)
[/LUA]
m2_toggle is the function name so it was trying to change so i made it m2_toggleB an local var[/QUOTE]
Yeah this doesn't work. Thanks for trying though.
Worked for me
put m2_on before m2_toggle.
[QUOTE=NeatNit;50497958]put m2_on before m2_toggle.[/QUOTE]
I did that, but it's not spamming when I hold down. I commented out the check for keydown, and it worked, but when I use the keydown, it doesn't do anything when I hold down mouse 1.
[editline]11th June 2016[/editline]
I got it to work with a different key, but not the attack key.
[CODE]
local attack = false
local m2_toggleB = false
local function m2_on()
if LocalPlayer():KeyDown( IN_ATTACK2 ) then
if attack then
RunConsoleCommand("-attack")
else
RunConsoleCommand("+attack")
end
attack = !attack
else
end
end
local function m2_toggle()
m2_toggleB = !m2_toggleB
if m2_toggleB then
hook.Add("Think","m2_toggle",m2_on)
else
hook.Remove("Think","m2_toggle")
RunConsoleCommand("-attack")
attack = false
end
end
concommand.Add("m2_toggle",m2_toggle)
[/CODE]
Sorry, you need to Log In to post a reply to this thread.