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 


Lua timer toggle script

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
xMichael
Newbie cheater
Reputation: 0

Joined: 24 Jun 2012
Posts: 20

PostPosted: Thu Apr 18, 2019 9:27 am    Post subject: Lua timer toggle script Reply with quote

Hi, this may be a noob question but how would a lua script (or Auto Assemble script if easier) that toggles my auto assembler script (code injection) every second on and off look?

Is it possible to enable the script every second but disable it shortly after, like say 200 miliseconds.

This is for AI checking for enemy script, so I want to make them check for enemies every second and shortly after they do, disable the check and go on their way, basically a loop of this. Thanks for help!
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Thu Apr 18, 2019 4:53 pm    Post subject: Reply with quote

I think it's better to implement that logic in the code injection. If you don't want to call an api, have CE periodically update an address with the current time and read from that.

The Lua approach would be to use a timer to toggle the script. If it's a memory record, use memrec.Active = not memrec.Active; otherwise, call autoAssemble. Update the timer's interval in the timer itself.
The CE wiki has general information. Documentation is in celua.txt and examples are on these forums.

_________________
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
xMichael
Newbie cheater
Reputation: 0

Joined: 24 Jun 2012
Posts: 20

PostPosted: Fri Apr 19, 2019 3:29 pm    Post subject: Reply with quote

ParkourPenguin wrote:
I think it's better to implement that logic in the code injection. If you don't want to call an api, have CE periodically update an address with the current time and read from that.


I have no idea what that means, I'm new to all of this

ParkourPenguin wrote:

The Lua approach would be to use a timer to toggle the script. If it's a memory record, use memrec.Active = not memrec.Active; otherwise, call autoAssemble. Update the timer's interval in the timer itself.
The CE wiki has general information. Documentation is in celua.txt and examples are on these forums.


I saw many topics on this forum and read the wiki and still am not sure how to do it. I think I have to use getMemoryRecordByDescription and toggle it in intervals but Im not sure how
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Fri Apr 19, 2019 10:40 pm    Post subject: Reply with quote

That means you should be using cmp and jcc instructions.
e.g.:
Code:
mov eax,[lastCheckTime]
mov ecx,[currentTime]  // Lua timer writes to currentTime
add eax,#1000
cmp eax,ecx // if 1000ms has passed, check it again
jle skip
  mov [lastCheckTime],ecx
  // do checks here
skip:
// original code


With the Lua way, the code might look like this:
Code:
local memrec = getAddressList().getMemoryRecordByDescription'My Check Script'

if checkT then checkT.destroy() end
checkT = createTimer()
checkT.Interval = 200
checkT.OnTimer = function(t)
  memrec.Active = not memrec.Active
  t.Interval = memrec.Active and 200 or 1000
end

_________________
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
xMichael
Newbie cheater
Reputation: 0

Joined: 24 Jun 2012
Posts: 20

PostPosted: Sat Apr 20, 2019 1:31 am    Post subject: Reply with quote

Thank you man, it works Smile
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