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 


Pressing the buttons depending on the value -my first script

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

Joined: 01 Jan 2012
Posts: 4

PostPosted: Sun Jan 01, 2012 3:49 pm    Post subject: Pressing the buttons depending on the value -my first script Reply with quote

I would like to make a script which will uses skills in game (press key) depending of other conditions, ex. buffs, hp and so on, no address changes.
I want to make a script only in "lua script: cheat table" if possible and execute every time when i press key, not working all the time.
So purpose is to use skills depending of conditions every time i press same key.
I'm trying to make it first on tutorial step 2 to leran how to do it, so far all i have:

Code:
function check(hotkey)

local tempvar=readInteger("[0057c310]+00000458")

if (tempvar<90) then
keyDown(49)
sleep (50)
keyUp(49)
  writeInteger(("[0057c310]+00000458"), tempvar+10) -- for test
end


SetHotKey(check, VK_NUMPAD5)

end



So i want script to press "1" every time I press Num5 and hp is less then 90. Pointer and writing integer works, but i dont know how to set hotkey properly.
Can i test script on table or should I generate trainer every time i change something?


Last edited by Funeris on Sun Jan 01, 2012 5:37 pm; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Sun Jan 01, 2012 4:27 pm    Post subject: Reply with quote

6.1 has a small bug with the initial setup if you provide a function directly so:
replace SetHotkey with:
Code:

createHotkey("check", VK_NUMPAD5)


that will cause the check function to be called each time VK_NUMPAD5 is pressed

And you can test the script manually. Just go to memory view(ctrl+m or button) and press ctrl+l (or tools->lua engine)
There you can experiment with your scripts

Tip: Use print("hotkey got pressed") in your check function to confirm it's being called
Tip 2: VK_NUMPAD5 only works if numlock is on

This is confirmed working:
Code:

function check()
  print("pressed")
end
if (checkhotkey~=nil) then
  object_destroy(checkhotkey)
  checkhotkey=nil
end
checkhotkey=createHotkey("check", VK_NUMPAD5)

_________________
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
Funeris
How do I cheat?
Reputation: 0

Joined: 01 Jan 2012
Posts: 4

PostPosted: Sun Jan 01, 2012 5:32 pm    Post subject: Reply with quote

Yes, now it works almost perfect, thank You. I had few syntax errors, so i post all script again.
But, 2 more small problems, I think that all should work with them too.
First, every time i press button, script executes 3 times. 3 times prints "pressed" and press 111.

In version Without

Code:
"if (checkhotkey~=nil) then
  object_destroy(checkhotkey)
  checkhotkey=nil
end"


it was only 2 times every time. Very Happy Any ideas to make it 1?

Second. Its not problem at all, but maybe there is any easy solution to not print 5 when i press Num5? Smile
Now i get 5111 every hit button.


Code:
function check()
sleep (50)
  print("pressed")
  local tempvar=readInteger("[0057c310]+00000458")

if (tempvar<90) then

     writeInteger(("[0057c310]+00000458"), tempvar+10)
     keyDown(49)
     sleep (50)
     keyUp(49)
 
  end
end


if (checkhotkey~=nil) then
  object_destroy(checkhotkey)
  checkhotkey=nil
end

checkhotkey=createHotkey("check", VK_NUMPAD5)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Sun Jan 01, 2012 5:37 pm    Post subject: Reply with quote

In the version without the object_destroy would cause the old hotkey to also get triggered when the whole script is executed. (so the old one would call the "check" function, and the new hotkey would call "check" as well)

So if you executed the script 10 times, it would press 10 times

with object_destroy I remove the old hotkey for num5 so I can add a new one (Alternatively, I could have put in a check if it is nil, and if so create the hotkey, and if it already exists don't create a new hotkey but reuse the old one)

Try a different key to press, or do a combination of two keys. e.g CTRL+NUM5. (or try sending a backspace...)

ctrl+num5=
Code:

checkhotkey=createHotkey("check", VK_CONTROL, VK_NUMPAD5)

Or there is a keycode for the 5 key without numlock, but I have no idea what that is
Edit: Found it, it's 12 when numlock is off
Code:

checkhotkey=createHotkey("check", 12)

_________________
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
Funeris
How do I cheat?
Reputation: 0

Joined: 01 Jan 2012
Posts: 4

PostPosted: Sun Jan 01, 2012 7:17 pm    Post subject: Reply with quote

Yes, problem is in executes, if i restart CE all is fine.
Thx now all works great.
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