Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


2 Speed hacks 2 binds one code.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Steelecrusher
How do I cheat?
Reputation: 0

Joined: 19 Dec 2016
Posts: 2

PostPosted: Mon Dec 19, 2016 12:25 am    Post subject: 2 Speed hacks 2 binds one code. Reply with quote

So I have this CE code that I was trying to make work together. I have a code that works but it wants to keep resetting it to 1 when I'm holding down one of them. So I was wondering how would I fix it so it wouldn't spam 1 as I tried to use one of the speed binds.

Code:
astSpeed=1;

function checkKeys(timer)
if (isKeyPressed(VK_V)) then if lastspeed ~= 10 then speedhack_setSpeed(10) lastSpeed=10 end
else if lastspeed ~= 1 then speedhack_setSpeed(1) lastSpeed=1 end

function checkKeys(timer)
if (isKeyPressed(VK_C)) then if lastspeed ~= 0.1 then speedhack_setSpeed(0.1) lastSpeed=0.1 end
else if lastspeed ~= 1 then speedhack_setSpeed(1) lastSpeed=1 end
end

end

end

t=createTimer(nil)
timer_setInterval(t, 100)
timer_onTimer(t, checkKeys)
timer_setEnabled(t, true)

_________________
-Steele
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4698

PostPosted: Mon Dec 19, 2016 9:12 am    Post subject: Reply with quote

Just so you're aware, this is what your code would look like if it were properly indented and spaced:
Code:
astSpeed=1;

function checkKeys(timer)
  if (isKeyPressed(VK_V)) then
    if lastspeed ~= 10 then
      speedhack_setSpeed(10)
      lastSpeed = 10
    end
  else
    if lastspeed ~= 1 then
      speedhack_setSpeed(1)
      lastSpeed = 1
    end

    function checkKeys(timer)
      if (isKeyPressed(VK_C)) then
        if lastspeed ~= 0.1 then
          speedhack_setSpeed(0.1)
          lastSpeed = 0.1
        end
      else
        if lastspeed ~= 1 then
          speedhack_setSpeed(1)
          lastSpeed = 1
        end
      end
    end
  end

  t=createTimer(nil)
  timer_setInterval(t, 100)
  timer_onTimer(t, checkKeys)
  timer_setEnabled(t, true)

--note: no 'end' to function checkKeys at line 3

I don't know what you're trying to do, but if you want some code to run when a key is pressed, use a hotkey instead of a timer.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Steelecrusher
How do I cheat?
Reputation: 0

Joined: 19 Dec 2016
Posts: 2

PostPosted: Mon Dec 19, 2016 4:55 pm    Post subject: Reply with quote

Okay so yes that helped organize it a lot but I got it working to an extent. Now when I hold c the slowmo works fine. But when I hold V it tries to create a timer switching the 1 to 10 and back repeatidly so if you know how to fix this It would be an amazing help.

Code:
astSpeed=1;

function checkKeys(hotkey)
  if (isKeyPressed(VK_V)) then
    if lastspeed ~= 10 then
      speedhack_setSpeed(10)
      lastSpeed = 10
    end
  else
    if lastspeed ~= 1 then
      speedhack_setSpeed(1)
      lastSpeed = 1
    end

      if (isKeyPressed(VK_C)) then
        if lastspeed ~= 0.1 then
          speedhack_setSpeed(0.1)
          lastSpeed = 0.1
        end
      else
        if lastspeed ~= 1 then
          speedhack_setSpeed(1)
          lastSpeed = 1
        end
      end
    end
  end

--note: no 'end' to function checkKeys at line 3

_________________
-Steele
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Dec 19, 2016 6:11 pm    Post subject: Reply with quote

Code:
if speedhack_fast then
  speedhack_fast.Destroy()
end
speedhack_fast = createHotkey(function()
  local speed = speedhack_getSpeed()
  if speed ~= 1.0 then
    speedhack_setSpeed(1.0)
  else
    speedhack_setSpeed(2.0)
  end
end, VK_V)
if speedhack_slow then
  speedhack_slow.Destroy()
end
speedhack_slow = createHotkey(function()
  local speed = speedhack_getSpeed()
  if speed ~= 1.0 then
    speedhack_setSpeed(1.0)
  else
    speedhack_setSpeed(0.1)
  end
end, VK_C)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites