How to set a specific address to a certain value after IF condition with LUA

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
Dante_IT
What is cheating?
What is cheating?
Posts: 3
Joined: Sat May 14, 2022 8:00 am
Reputation: 0

How to set a specific address to a certain value after IF condition with LUA

Post by Dante_IT »

Hello, I'm using a table for PES 2021 by xAranaktu.
I want to set a specific address to a certain value, only if a specific condition is met.

I do something like this:

Code: Select all

NameAddress = 0x7FF4FD277A78

StatAddress = 0x7FF4FD277A4C

Name = readString(NameAddress)
--I get the name L. MESSI
print (Name)
if string.find(Name, "L. MESSI") then
	--??
  
The problem is that the value of the address for the Heading stat of Messi, is a binary type, from 0 to 6.
How can I set values in that range, without modifying other areas of the memory (in this case the Ball Winning stat, on the same address)?

Image

User avatar
Messy6666
Table Makers
Table Makers
Posts: 719
Joined: Fri Sep 25, 2020 5:45 pm
Reputation: 741

Re: How to set a specific address to a certain value after IF condition with LUA

Post by Messy6666 »

Dante_IT wrote:
Sat May 14, 2022 8:22 am
The problem is that the value of the address for the Heading stat of Messi, is a binary type, from 0 to 6.
How can I set values in that range, without modifying other areas of the memory (in this case the Ball Winning stat, on the same address)?
Hey there
You have to save the other bit(s) and combine it with the 7 bits of the new value.
So you have todo some [Link] like:

Code: Select all

[ENABLE]
{$LUA}
if syntaxcheck then return end

local a = readShortInteger("[ptrHealth]")
local NewValue = 99

a = bAnd(a, 128)                  -- 010000000 save bit 8
a = bOr(a, bAnd(NewValue, 127))   -- put in the other 7 bits

writeShortInteger("[ptrHealth]", a)  -- write the combined byte
printf(" a = %08x", a )
{$ASM}
[DISABLE]
Bitwise operations with Tutorial-x86_64.CT
(3.55 KiB) Downloaded 298 times

Dante_IT
What is cheating?
What is cheating?
Posts: 3
Joined: Sat May 14, 2022 8:00 am
Reputation: 0

Re: How to set a specific address to a certain value after IF condition with LUA

Post by Dante_IT »

SinGul4ritY wrote:
Sat May 14, 2022 2:35 pm
Hey there
You have to save the other bit(s) and combine it with the 7 bits of the new value.
Thanks, I'll try this way.

GreenHouse
Expert Cheater
Expert Cheater
Posts: 857
Joined: Fri Oct 12, 2018 10:25 pm
Reputation: 889

Re: How to set a specific address to a certain value after IF condition with LUA

Post by GreenHouse »

Otherwise the easier way is to use "getMemoryRecordByDescription".
AddressList.getMemoryRecordByDescription('Heading').Value = '99'
That way it will automatically use the value type that you chose. So you don't need to deal with binary calculations.

Dante_IT
What is cheating?
What is cheating?
Posts: 3
Joined: Sat May 14, 2022 8:00 am
Reputation: 0

Re: How to set a specific address to a certain value after IF condition with LUA

Post by Dante_IT »

GreenHouse wrote:
Sat May 14, 2022 4:16 pm
Otherwise the easier way is to use "getMemoryRecordByDescription".
AddressList.getMemoryRecordByDescription('Heading').Value = '99'
That way it will automatically use the value type that you chose. So you don't need to deal with binary calculations.
So much easier this way, thanks a lot!

Post Reply

Who is online

Users browsing this forum: No registered users