Page 1 of 1

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

Posted: Sat May 14, 2022 8:22 am
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

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

Posted: Sat May 14, 2022 2:35 pm
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 1092 times

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

Posted: Sat May 14, 2022 3:19 pm
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.

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

Posted: Sat May 14, 2022 4:16 pm
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.

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

Posted: Sun May 15, 2022 2:17 pm
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!