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 


[ask] how to write arithmetic properly [solved]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
icsmoke+
Cheater
Ban
Reputation: 0

Joined: 31 Aug 2020
Posts: 29

PostPosted: Tue Jan 25, 2022 2:46 am    Post subject: [ask] how to write arithmetic properly [solved] Reply with quote

hello there, just want to ask how to write arithmetic properly base from address?

here is my code
Code:

al = getAddressList()
warposition = al.getMemoryRecordByDescription('warposition')

wararea={ 'warposition+1','warposition+2','warposition+3','warposition+4',
     'warposition+5','warposition*1+2','warposition+5*5'}

function byNameandArea()
         if tonumber(mr('NPC1').getValue()) == wararea -- so i can use it here
            tostring(mr('NPCName1').getValue()) == nppcname
            then
                  mr('catchme').setValue(mr('NPC1').getValue()+a)
                  clickme()
         elseif tonumber(mr('NPC2').getValue()) == wararea --and here
            tostring(mr('NPCName2').getValue()) == npcname
            then
                  mr('catchme').setValue(mr('NPC1').getValue()+a)
                  clickme()
   end

end


thanks in advance[/code]


Last edited by icsmoke+ on Tue Jan 25, 2022 9:13 am; edited 1 time in total
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Tue Jan 25, 2022 4:31 am    Post subject: Reply with quote

You haven't really said what the base address is, but arithmetic is straightforward.

No offence but, your code is pretty messy. It's nested within if..then statements that have lines based on conditions that aren't enclosed within if..then statements and because I don't have the game I can't really say what logic is supposed to be applied here. Perhaps if you can better explain what's supposed to be happening then I can help you more.
Back to top
View user's profile Send private message
icsmoke+
Cheater
Ban
Reputation: 0

Joined: 31 Aug 2020
Posts: 29

PostPosted: Tue Jan 25, 2022 6:53 am    Post subject: Reply with quote

Thanks for replying, what i want is limit movement by area, which is describe on warposition, what i am asking for, is it corect i write only warposition+1 or warposition+2 and so on, and yes the main problem only on writing aritmethic from address variable for example if warposition value is 10 so the result should be 11 if i write warposition+1 and 12 for warposition+2, sorry my english is not good enough to describe my problem
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Tue Jan 25, 2022 7:50 am    Post subject: Reply with quote

I'll explain something
Code:

al = getAddressList()
warposition = al.getMemoryRecordByDescription('warposition')


This retrieves the memory record object, not the value. What you'll want is to get the value of warposition like so:
Code:

wararea =  {tonumber(warposition.value) + 1',
            tonumber(warposition.value) + 2',
            tonumber(warposition.value) + 3',
            tonumber(warposition.value) + 4',
            tonumber(warposition.value) + 5',
            tonumber(warposition.value) * 1 + 2',
            tonumber(warposition.value) + 5 * 5,}


Then you can access the indices like so; wararea[0] through to wararea[6].

Code:

function byNameandArea()
         local NPC1 = al.getMemoryRecordByDescription('NPC1')
         local NPC1Name = al.getMemoryRecordByDescription('NPCName1')
         local NPC2 = al.getMemoryRecordByDescription('NPC2')
         local NPC2Name = al.getMemoryRecordByDescription('NPCName2')
         local catchme = al.getMemoryRecordByDescription('catchme')
         local a = 10 -- arbitrary value

         if NPC1.value == wararea[x] and NPC1Name.value == npcname then -- where x is the index of the value you want to compare against
            catchme.value = NPC1.value + a -- I'm not sure what you want a to be but you can set its value at the beginning of the function
            clickme()
         elseif NPC2.value == wararea[x] and NPC2Name.value == npcname then -- again, x is the index of the wararea table you want to compare against
            catchme.value = NPC1.value + a
            clickme()
         end
end


Perhaps something like this is what you need.
Back to top
View user's profile Send private message
icsmoke+
Cheater
Ban
Reputation: 0

Joined: 31 Aug 2020
Posts: 29

PostPosted: Tue Jan 25, 2022 9:13 am    Post subject: [ask] how to write arithmetic properly [solved] Reply with quote

yes exactly what i want, thank you more Very Happy
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Tue Jan 25, 2022 9:40 am    Post subject: This post has 1 review(s) Reply with quote

Sure! If I helped please give rep Smile.
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