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 


Brain fog. How do I format this LUA math for CE?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Autem
Expert Cheater
Reputation: 1

Joined: 30 Jan 2023
Posts: 149

PostPosted: Wed Apr 16, 2025 6:51 pm    Post subject: Brain fog. How do I format this LUA math for CE? Reply with quote

Can't get CE to add 30 (in hex) to a value. Trying things such as the attempts below, with no luck...

value = value + 30

value = tonumber(value) + tonumber(30)

value = tonumber(value + "30")

Someone please let me know the right format to write this in, preferably using CE 6.7. If the problem is that 6.7 doesn't support my attempted math, please let me know the alternative way to write this out that will work in CE 6.7.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 150

Joined: 06 Jul 2014
Posts: 4651

PostPosted: Wed Apr 16, 2025 7:06 pm    Post subject: Reply with quote

I'd need more context to give a more specific answer.

Lua code:
Code:
value = value + 0x30


Memory record's value:
Code:
value + 0x30


In an AA script, hexadecimal is the default in most places

_________________
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
Autem
Expert Cheater
Reputation: 1

Joined: 30 Jan 2023
Posts: 149

PostPosted: Wed Apr 16, 2025 7:26 pm    Post subject: Reply with quote

Code:
[ENABLE]
{$lua}
if syntaxcheck then return end

function funk1(sender)
local AoB1 = AOBScan("3C 00 00 00 89 88 88 3C 80");
if (AoB1 == nil or AoB1.Count > 1) then --> Ends function earlier if the AoB was not found, or if multiple aobs were found.
print("ending")
   return
end
local adf = tonumber(AoB1[0], 16)
local pro = getAddress(process)
local blih = ("%8X"):format(adf-tonumber(pro))
local stripped = string.gsub(blih, '%s+', '')
io.write('|', blih, '|\r\n')
io.write('|', stripped, '|\r\n')
print("Found\r\n"..process.."+"..stripped)
end

funk1()

[DISABLE]


The above script shows the game module address+offset I need, and works perfectly. What I'm trying to do is print another line that shows the address + 30.

So for example right now I get these printed results:
Found
Game.exe+12345600


...but I also want a line that, in this case, would just add 30 to the address. The desired output would look like this:
Found
Game.exe+12345600
Second
Game.exe+12345630


And I'm just stuck not being able to figure out how to add 30 and print that second address. I thought it would be something like in my first post's attempts but the script stops when it gets to any attempt to use math to add 30 to "stripped" variable, so I'm not exactly sure what to do or where exactly to place it since anywhere I place the line causes the script to stop at that line.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 150

Joined: 06 Jul 2014
Posts: 4651

PostPosted: Wed Apr 16, 2025 7:44 pm    Post subject: This post has 1 review(s) Reply with quote

Format your code properly- specifically indentation

Get rid of that function unless you're calling it elsewhere as a global

Use `getAddress(_)` instead of `tonumber(_, 16)`

`getAddress` returns a number, no need to call `tonumber` on the result

`getNameFromAddress` is good

The stringlist returned by `aobscan` should be destroyed

Autem wrote:
So for example right now I get these printed results:
Found
Game.exe+12345600


...but I also want a line that, in this case, would just add 30 to the address. The desired output would look like this:
Found
Game.exe+12345600
Second
Game.exe+12345630


And I'm just stuck not being able to figure out how to add 30 and print that second address.
Code:
[ENABLE]
{$lua}
if syntaxcheck then return end

local result = AOBScan(...)

assert(result, 'AOBScan pattern not found')

if result.count ~= 1 then
  result.destroy()
  error'Multiple AOBScan patterns found'
end

local addr = getAddress(result[0])

result.destroy()

print'Found'
print(getNameFromAddress(addr))
print'Second'
print(getNameFromAddress(addr+0x30))

[DISABLE]

_________________
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
Autem
Expert Cheater
Reputation: 1

Joined: 30 Jan 2023
Posts: 149

PostPosted: Wed Apr 16, 2025 8:13 pm    Post subject: Reply with quote

Using your additions and removals, the script seems much more straightforward and is working perfectly now. As always, thank you for taking the time to help me out! It really means a lot!
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 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