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 


I think this is so simple yet I'm struggling with it ><

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

Joined: 15 Aug 2019
Posts: 2

PostPosted: Thu Aug 15, 2019 12:20 pm    Post subject: I think this is so simple yet I'm struggling with it >< Reply with quote

Hello guys,
I'm struggling to get this done:
when R is pressed(not held down, just a key stroke) set speed to 0.5 for 7 seconds then reset it to 1 when 7 seconds pass, but if during the 7 seconds R is pressed again then set speed to 1 instantly before the 7 seconds pass.

any idea how to do that?

my current script does what I'm asking for except the last part, I tried different stuff but couldn't disable the sleep command ,here's my script:

function checkRKey(timer)
if (isKeyPressed(VK_R)) then
speedhack_setSpeed(0.5)
sleep(7000)
speedhack_setSpeed(1)
end
end

t=createTimer(nil)
timer_setInterval(t, 100)
timer_onTimer(t, checkRKey)
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 42

Joined: 09 Aug 2013
Posts: 1089

PostPosted: Thu Aug 15, 2019 1:14 pm    Post subject: Reply with quote

Code:

if hktmr then hktmr.destroy() hktmr=nil end
if hk then hk.destroy() hk=nil end
hktmr = createTimer()
hktmr.Interval = 5000
hktmr.Enabled = false
hktmr.OnTimer = function(t)
  local s = speedhack_getSpeed()
  s = s == 1 and 0.5 or 1 -- flip
  speedhack_setSpeed(s)
  t.Enabled = false
end
hk = createHotkey(function()
  local shouldenable = not hktmr.Enabled
  hktmr.OnTimer(hktmr) -- change speed immediately and stops timer
  hktmr.Enabled =  shouldenable -- change back in 7 seconds or disable
end, VK_R)
I believe this should work. The first time it's run it'll call the timer's function which will change the speed to 0.5 and start the timer which will change it back to 1 after 7 seconds and stop the timer, if you press it when it's already enabled it will immediately change the speed (to 1) and then disable the timer.
_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
pgkw2
How do I cheat?
Reputation: 0

Joined: 15 Aug 2019
Posts: 2

PostPosted: Thu Aug 15, 2019 4:27 pm    Post subject: Reply with quote

FreeER wrote:
Code:

if hktmr then hktmr.destroy() hktmr=nil end
if hk then hk.destroy() hk=nil end
hktmr = createTimer()
hktmr.Interval = 5000
hktmr.Enabled = false
hktmr.OnTimer = function(t)
  local s = speedhack_getSpeed()
  s = s == 1 and 0.5 or 1 -- flip
  speedhack_setSpeed(s)
  t.Enabled = false
end
hk = createHotkey(function()
  local shouldenable = not hktmr.Enabled
  hktmr.OnTimer(hktmr) -- change speed immediately and stops timer
  hktmr.Enabled =  shouldenable -- change back in 7 seconds or disable
end, VK_R)
I believe this should work. The first time it's run it'll call the timer's function which will change the speed to 0.5 and start the timer which will change it back to 1 after 7 seconds and stop the timer, if you press it when it's already enabled it will immediately change the speed (to 1) and then disable the timer.

Thank you Very Happy , just what I was asking for
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