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

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Discussions
View previous topic :: View next topic  
Author Message
Lorizzuoso
Cheater
Reputation: 0

Joined: 09 Apr 2022
Posts: 27

PostPosted: Sat Apr 09, 2022 6:13 pm    Post subject: Lua script Reply with quote

Hello,does anyone know how to make a lua script that constantly adds a value to an address?And when i press deactivate it resets the address value to 0.
Thanks.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1066
Location: 0x90

PostPosted: Sun Apr 10, 2022 1:04 am    Post subject: Reply with quote

You can achieve this with a timer that will automatically disable upon meeting certain criteria, for example:
Code:

-- If the timer exists then destroy it
if timer then timer.destroy(); timer = nil end

local timer = createTimer(getMainForm())
local address = AddressList.getMemoryRecordByDescription('address_description_here')

timer.Interval = 100
timer.OnTimer = function()
                           address.value = address.value + 10
                           if tonumber(address.value) = 100 then
                              timer.destroy()
                              timer = nil
                           end
                         end
Back to top
View user's profile Send private message
Lorizzuoso
Cheater
Reputation: 0

Joined: 09 Apr 2022
Posts: 27

PostPosted: Sun Apr 10, 2022 2:13 am    Post subject: Lua script Reply with quote

[ENABLE]
{$lua}
if timer then timer.destroy(); timer = nil end

local timer = createTimer(getMainForm())
local address = AddressList.getMemoryRecordByDescription('Head rotation')

timer.Interval = 100
timer.OnTimer = function()
0x300E4E8D = 0x300E4E8D + 10
if tonumber(0x300E4E8D) = 100 then
timer.destroy()
timer = nil
end
end
[DISABLE]
{$lua}

So 300E4E8D it's the address that write that value but there's an error,"unexpected symbol near 0x300E4E8D", it doesn't like the 0x?
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1066
Location: 0x90

PostPosted: Sun Apr 10, 2022 3:17 am    Post subject: Reply with quote

Code:

[ENABLE]
{$LUA}
if timer then timer.destroy(); timer = nil end

local timer = createTimer(getMainForm())
-- This line retrieves the entry in the table and assigns it to the variable address
local address = AddressList.getMemoryRecordByDescription('Head rotation')

timer.Interval = 100
timer.OnTimer = function()
      -- Check if the entry exists in the table, if not, destroy the timer
      if address == nil then
         timer.destroy()
         timer = nil
      else
              -- Take the value of the address and then add 10 to it
         address.value = address.value + 10
              -- Convert the value to a number and then compare it against 100, if the value equals 100 then destroy the timer
         if tonumber(address.value) = 100 then
            timer.destroy()
            timer = nil
         end
      end
{$ASM}
[DISABLE]
...
Back to top
View user's profile Send private message
Lorizzuoso
Cheater
Reputation: 0

Joined: 09 Apr 2022
Posts: 27

PostPosted: Sun Apr 10, 2022 11:28 am    Post subject: Lua script Reply with quote

My bad forgot to tell that this address might not be static and even with this an error appears:"lua error in the script at line 2:[string "local syntax check,memrec=..."]18:then expected near "="
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Discussions 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