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 


Problematic Lua Script

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

Joined: 19 Aug 2018
Posts: 1

PostPosted: Thu Aug 23, 2018 2:27 am    Post subject: Problematic Lua Script Reply with quote

I've ran into a problem regarding a Lua script. I want it to overwrite a value every 10ms when enabled and write a different value as well as destroy the previous timer so it behaves as usual when disabled. It keeps writing the value on it when its disabled. Found no possible causes after checking the script multiple times and figured I'd ask help from more experienced people.

Code:

[ENABLE]

aobscanmodule(health,MadMax.exe,F3 0F 11 6B 1C 44)
alloc(newmem,$1000,"MadMax.exe"+1F3E324)
globalalloc(my_health,8)

label(code)
label(return)

newmem:

code:
  mov [my_health],rbx
  //movss [rbx+1C],xmm5
  jmp return

health:
  jmp newmem
return:
registersymbol(health)

{$lua}

htimer = createTimer()
htimer.setInterval(10)
htimer.onTimer = function(p_health)
writeFloat('["my_health"]+1C',1200)
end

{$asm}
[DISABLE]

{$lua}

htimer.destroy()
writeFloat('["my_health"]+1C',1000)

{$asm}

health:
  db F3 0F 11 6B 1C

unregistersymbol(health)
dealloc(newmem)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Thu Aug 23, 2018 9:15 am    Post subject: Reply with quote

You may have clicked "disable script without executing disable section" or something similar when developing and/or testing the script.

Make the code more resilient to outside factors like this:
Code:
[enable]
{$lua}
if syntaxcheck or htimer or not memrec then return end
htimer = createTimer()
htimer.Interval = 10
htimer.OnTimer = function(t)
  local addr, enabled = getAddressSafe('["my_health"]+1C'), memrec.Active
  if addr then
    writeFloat(addr, enabled and 1200. or 1000.)
  end
  if not enabled then
    t.destroy()
  end
end
{$asm}

[disable]
{$lua}
if syntaxcheck or not htimer then return end
htimer.destroy()
htimer = nil
local a = getAddressSafe('["my_health"]+1C')
if a then
  writeFloat(a, 1000.)
end
{$asm}

_________________
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
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