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 


Looking for Press and Toggle Commands

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

Joined: 24 Jun 2015
Posts: 3

PostPosted: Wed Jun 24, 2015 1:29 am    Post subject: Looking for Press and Toggle Commands Reply with quote

So I have been doing some research, and I can not figure it out, will someone please guide me in the right direction.

What I am trying to do is a speed script. My is almost complete but what I have is more or less a toggle key script what i am looking for is a key press. For Example I press and hold 8 and Speed is set to 1.3, when I unpress 8 speed goes back to 1.0 Example 2 Press and hold 9 Speed is set to 0.7 unpress speed is set back to 1.0.

Here is the script I have. What I have is a toggle works great but when I unpress the hotkeys the speed stays at either 1.3 or 0.7

Thank you for any support!

speed = 1.0

function IncSpeed(hotkey)
speed = 1.3
speedhack_setSpeed(speed)
end

function DecSpeed(hotkey)
speed = 0.7
speedhack_setSpeed(speed)
end

function NoDeath(hotkey)
speed = 0.0
speedhack_setSpeed(speed)
end


function SetHotKey(func, hotkey)
local objectHotKey = createHotkey(func, hotkey)
generichotkey_setKeys(objectHotKey, hotkey)
generichotkey_onHotkey(objectHotKey, func)
end


function onOpenProcess(processid)
SetHotKey(IncSpeed, VK_8)
SetHotKey(DecSpeed, VK_9)
SetHotKey(NoDeath, VK_Q)
end
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Wed Jun 24, 2015 1:47 am    Post subject: Reply with quote

use a timer and poll the keystate
http://forum.cheatengine.org/viewtopic.php?t=538178 (the first script, not the second one which won't work)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
dread21
How do I cheat?
Reputation: 0

Joined: 24 Jun 2015
Posts: 3

PostPosted: Wed Jun 24, 2015 1:54 am    Post subject: Reply with quote

Dark Byte wrote:
use a timer and poll the keystate
(the first script, not the second one which won't work)


Thank you for the quick reply I have tried that script. And I tried a few work arounds but that script only allows 1 hotkey at a time. And I can not figure out how to add more to that script. And ideas?


This implementation only supports 1 such hotkey at a time (guess why)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Wed Jun 24, 2015 2:16 am    Post subject: Reply with quote

just add a few more if statements for other keys. and make it so when no key is down set speed to 1
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
dread21
How do I cheat?
Reputation: 0

Joined: 24 Jun 2015
Posts: 3

PostPosted: Wed Jun 24, 2015 2:32 am    Post subject: Reply with quote

Dark Byte wrote:
just add a few more if statements for other keys. and make it so when no key is down set speed to 1


Thank you for your quick reply.

Yea that is where I am running into the issue I am not sure how to tie in other keys to make the script work. The only method I know with the press key and release feature only allows 1 hot key.

=\
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Wed Jun 24, 2015 3:15 am    Post subject: Reply with quote

you can rewrite that function as:
Code:

function checkKeys(timer)
  if (isKeyPressed(VK_A)) then
    if lastspeed ~= 10 then
      speedhack_setSpeed(10)
      lastSpeed=10
    end
    return
  end

  --still here so no key pressed
  if lastspeed ~= 1 then
    speedhack_setSpeed(1)
    lastSpeed=1
  end
end

Perhaps that gives you an idea

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Alamer99
Expert Cheater
Reputation: 1

Joined: 04 Jan 2015
Posts: 136

PostPosted: Wed Jun 24, 2015 3:28 am    Post subject: Reply with quote

Code:
lastSpeed=1;

function checkKeys(timer)
   if (isKeyPressed(VK_A)) then
      if lastSpeed~=10 then
         speedhack_setSpeed(10)
         lastSpeed=10
      end
   else
      if (isKeyPressed(VK_B)) then
         if lastSpeed~=5 then
            speedhack_setSpeed(5)
            lastSpeed=5
         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)


just keep adding the same if-else statement and for each one add "end" to the end of the function

edit:
did not notice that DB posted something Neutral
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