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 


Basic Lua script ( Need help)

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

Joined: 23 May 2019
Posts: 2

PostPosted: Thu May 23, 2019 6:26 pm    Post subject: Basic Lua script ( Need help) Reply with quote

I have been trying to do the auto pot function but it does not work. Here is my code

This code will cause CE not working after execute the code, after that it keeps repeating 111111 even hp is higher than 400 and keep typing 1 every where
Code:

local hp = 'nano.exe+2C67830'
local hpvalue = readInteger(hp)

print(hpvalue)
checkIntT = createTimer()
checkIntT.Interval = 100
checkIntT.OnTimer = function(sender)
  if hpvalue < 400 then
     doKeyPress("1")
    checkIntT.Enabled = false

end


Another code that does not work

Code:
local hp = 'nano.exe+2C67830'
local hpvalue = readInteger(hp)
local stop = 0
print(hpvalue)
while stop == 0 do
      sleep(50)
      if hpvalue < 400 then
      doKeyPress("1")
      end
end


What I want is just making it looks for HP then press 1 if hp below 400 and keep repeating until i press ESC

Anyone can help me?
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Thu May 23, 2019 6:36 pm    Post subject: Reply with quote

You only read the HP value once, you need to update the value in the timer function.
_________________
Back to top
View user's profile Send private message Visit poster's website
mokoroshi01
How do I cheat?
Reputation: 0

Joined: 23 May 2019
Posts: 2

PostPosted: Thu May 23, 2019 6:44 pm    Post subject: Reply with quote

TheyCallMeTim13 wrote:
You only read the HP value once, you need to update the value in the timer function.


How can I update in the timer function?
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Thu May 23, 2019 7:46 pm    Post subject: Reply with quote

Code:
local hp = 'nano.exe+2C67830'
checkIntT = createTimer()
checkIntT.Interval = 100
checkIntT.OnTimer = function(timer) -- The timer itself is passed not the sender.
   local hpvalue = readInteger(hp) -- read the value inside the timer function.
   if hpvalue < 400 then
      doKeyPress(VK_1) -- Needs to be a "Virtual Key Code"
      checkIntT.Enabled = false -- This will disable the timer.
   end -- Missing an END statement
end

https://wiki.cheatengine.org/index.php?title=Lua:Class:Timer
https://wiki.cheatengine.org/index.php?title=Lua:doKeyPress
https://wiki.cheatengine.org/index.php?title=Virtual-Key_Code

_________________
Back to top
View user's profile Send private message Visit poster's website
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