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 script lags Cheat Engine and no longer works properly

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

Joined: 25 Jul 2021
Posts: 9
Location: Earth

PostPosted: Sat Dec 11, 2021 2:29 am    Post subject: Lua script lags Cheat Engine and no longer works properly Reply with quote

This script worked perfectly until it stopped working for no apparent reason.
Code:

function readvalue()
local al = getAddressList()
local xvelstr = memoryrecord_getValue(al['X Velocity'])
local yvelstr = memoryrecord_getValue(al['Y Velocity'])
local zvelstr = memoryrecord_getValue(al['Z Velocity'])
local healthstr = memoryrecord_getValue(al['Current Rings'])
local booststr = memoryrecord_getValue(al['Boost Gauge'])
      if healthstr ~= "??" then
      health = tonumber(healthstr)
      else health = 0 end
      if booststr ~= "??" then
      boost = tonumber(booststr)
      else boost = 0 end
      if (xvelstr ~= "??") and (yvelstr ~= "??") and (zvelstr ~= "??") then
      xvel = tonumber(xvelstr)
      yvel = tonumber(yvelstr)
      zvel = tonumber(zvelstr)
      speed = math.sqrt(xvel^2 + yvel^2 + zvel^2)
      else speed = 0 end
end
function amyform()
      if speed <= 500 then
      AmyHUD.Speed.Width = 992 * speed/500
      else AmyHUD.Speed.Width = 992 end
      if boost <= 300 then
      AmyHUD.Boost.Width = 1008 * boost/300
      else AmyHUD.Boost.Width = 1008 end
      healthbase = 100
      healthmod = 1014 * (health % healthbase) / healthbase
      if healthmod == 0 then healthmod = 1014 end
      mode = math.ceil(health / healthbase)
      if mode == 0 then
      AmyHUD.Health1.Visible = false
      AmyHUD.Health1d.Visible = false
      AmyHUD.Health2.Visible = false
      AmyHUD.Health2d.Visible = false
      AmyHUD.Health3.Visible = false
      AmyHUD.Health3d.Visible = false
      AmyHUD.Health4.Visible = false
      elseif mode == 1 then
      AmyHUD.Health1.Visible = true
      AmyHUD.Health1d.Visible = false
      AmyHUD.Health2.Visible = false
      AmyHUD.Health2d.Visible = false
      AmyHUD.Health3.Visible = false
      AmyHUD.Health3d.Visible = false
      AmyHUD.Health4.Visible = false
      AmyHUD.Health1.Width = healthmod
      elseif mode == 2 then
      AmyHUD.Health1.Visible = false
      AmyHUD.Health1d.Visible = true
      AmyHUD.Health2.Visible = true
      AmyHUD.Health2d.Visible = false
      AmyHUD.Health3.Visible = false
      AmyHUD.Health3d.Visible = false
      AmyHUD.Health4.Visible = false
      AmyHUD.Health2.Width = healthmod
      elseif mode == 3 then
      AmyHUD.Health1.Visible = false
      AmyHUD.Health1d.Visible = false
      AmyHUD.Health2.Visible = false
      AmyHUD.Health2d.Visible = true
      AmyHUD.Health3.Visible = true
      AmyHUD.Health3d.Visible = false
      AmyHUD.Health4.Visible = false
      AmyHUD.Health3.Width = healthmod
      elseif mode == 4 then
      AmyHUD.Health1.Visible = false
      AmyHUD.Health1d.Visible = false
      AmyHUD.Health2.Visible = false
      AmyHUD.Health2d.Visible = false
      AmyHUD.Health3.Visible = false
      AmyHUD.Health3d.Visible = true
      AmyHUD.Health4.Visible = true
      AmyHUD.Health4.Width = healthmod
      elseif mode < 10 then
      AmyHUD.Health1.Visible = false
      AmyHUD.Health1d.Visible = false
      AmyHUD.Health2.Visible = false
      AmyHUD.Health2d.Visible = true
      AmyHUD.Health3.Visible = false
      AmyHUD.Health3d.Visible = true
      AmyHUD.Health4.Visible = true
      AmyHUD.Health4.Width = 1014
      end
end
function sonicform()
      if speed <= 500 then
      SonicHUD.Speed.Width = 977 * speed/500
      else SonicHUD.Speed.Width = 977 end
      if boost <= 300 then
      SonicHUD.Boost.Width = 988 * boost/300
      else SonicHUD.Boost.Width = 988 end
      healthbase = 100
      healthmod = 996 * (health % healthbase) / healthbase
      if healthmod == 0 then healthmod = 996 end
      mode = math.ceil(health / healthbase)
      if mode == 0 then
      SonicHUD.Health1.Visible = false
      SonicHUD.Health1d.Visible = false
      SonicHUD.Health2.Visible = false
      SonicHUD.Health2d.Visible = false
      SonicHUD.Health3.Visible = false
      SonicHUD.Health3d.Visible = false
      SonicHUD.Health4.Visible = false
      elseif mode == 1 then
      SonicHUD.Health1.Visible = true
      SonicHUD.Health1d.Visible = false
      SonicHUD.Health2.Visible = false
      SonicHUD.Health2d.Visible = false
      SonicHUD.Health3.Visible = false
      SonicHUD.Health3d.Visible = false
      SonicHUD.Health4.Visible = false
      SonicHUD.Health1.Width = healthmod
      elseif mode == 2 then
      SonicHUD.Health1.Visible = false
      SonicHUD.Health1d.Visible = true
      SonicHUD.Health2.Visible = true
      SonicHUD.Health2d.Visible = false
      SonicHUD.Health3.Visible = false
      SonicHUD.Health3d.Visible = false
      SonicHUD.Health4.Visible = false
      SonicHUD.Health2.Width = healthmod
      elseif mode == 3 then
      SonicHUD.Health1.Visible = false
      SonicHUD.Health1d.Visible = false
      SonicHUD.Health2.Visible = false
      SonicHUD.Health2d.Visible = true
      SonicHUD.Health3.Visible = true
      SonicHUD.Health3d.Visible = false
      SonicHUD.Health4.Visible = false
      SonicHUD.Health3.Width = healthmod
      elseif mode == 4 then
      SonicHUD.Health1.Visible = false
      SonicHUD.Health1d.Visible = false
      SonicHUD.Health2.Visible = false
      SonicHUD.Health2d.Visible = false
      SonicHUD.Health3.Visible = false
      SonicHUD.Health3d.Visible = true
      SonicHUD.Health4.Visible = true
      SonicHUD.Health4.Width = healthmod
      elseif mode < 10 then
      SonicHUD.Health1.Visible = false
      SonicHUD.Health1d.Visible = false
      SonicHUD.Health2.Visible = false
      SonicHUD.Health2d.Visible = true
      SonicHUD.Health3.Visible = false
      SonicHUD.Health3d.Visible = true
      SonicHUD.Health4.Visible = true
      SonicHUD.Health4.Width = 996
      end
end
function update()
         timer = createTimer()
         timer.Interval = 15
         timer.OnTimer = function(timer)
               if pcall(sonicform) then     --if pcall(amyform) then
                   if pcall(readvalue) then
                   readvalue()
                   else
                   health = 0
                   speed = 0
                   boost = 0
                   end
                --amyform()
                sonicform()
                else sleep(1000)
                end
         end

end
createThread(update)

Does anyone have any idea on why this happens?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Dec 11, 2021 2:57 am    Post subject: Reply with quote

Timers run in the main thread
therefore you're freezing the interface of CE for 1 second every 0.015 seconds

also no need for pcall, you should just be able to call the functions else you're calling them twice

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

Joined: 25 Jul 2021
Posts: 9
Location: Earth

PostPosted: Sat Dec 11, 2021 5:18 am    Post subject: Reply with quote

Kinda afraid removing those pcalls because they are the ones preventing the lua engine dialog from spamming errors in case the code goes haywire. Is there any other way to disable those error messages?
Nevermind, I figured it out myself. Thanks for the heads-up, DB!
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