Page 1 of 1

[RESOLVED] lua speedhack toggle

Posted: Sat Oct 15, 2022 5:29 pm
by isuckatall
idk lua im trying to make speedhack toggleable with the e key and made this but it fail

if (isKeyPressed(VK_E)) then cycle()
end
function cycle()
if toggle ~= 0 then speedhack_setSpeed(0.25)
toggle = 1
else speedhack_setSpeed(1)
toggle = 0
end
end

Edit: im requesting someone to fix it so it operates as I intend

Re: lua speedhack toggle

Posted: Sat Oct 15, 2022 11:19 pm
by Cas
Please don’t use clickbaity titles. I have edited it out.

Re: lua speedhack toggle

Posted: Sun Oct 16, 2022 6:09 am
by isuckatall
ok sorry Casanova

Re: lua speedhack toggle

Posted: Mon Oct 17, 2022 12:37 pm
by LeFiXER
This will work as intended:

Code: Select all

if tmr then tmr.destroy(); tmr = nil end

function ToggleSpeedHack(key, speed)
  if key == nil then key = 0x1B end             -- Escape key is default if not defined

  function setSpeed(speed)
     if speed == nil then speed = 1 end
     speedhack_setSpeed(speed)
  end

  tmr = createTimer(getMainForm())
  tmr.Interval = 20
  tmr.OnTimer = function()
                  if isKeyPressed(key) then
                     setSpeed(speed)
                  else
                     setSpeed(1)
                  end
                end
end

-- 0x45 = VK_E
ToggleSpeedHack(0x45, 3)
More VK_Key codes available [Link]