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 


Need some advice

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
vng21092
Grandmaster Cheater
Reputation: 15

Joined: 05 Apr 2013
Posts: 644

PostPosted: Sat Jul 18, 2015 9:32 pm    Post subject: Need some advice Reply with quote

So I decided it was finally time I learned some LUA. I wanted to start with some simple stuff. I registered a symbol called "perk" in an ASM script, and I wanted to add to that value via LUA. After a bit of searching I came up with this
Code:
[Enable]

{$lua}

perkAdd=getAddress("perk")
newPerk=readInteger(perkAdd)
newPerk=newPerk+(0x00008000)
writeInteger(perkAdd,newPerk)

{$asm}

[Disable]

{$lua}

newPerk=newPerk-(0x00008000)
writeInteger(perkAdd,newPerk)

{$asm}
Now this works but, I need 5 of these. Each to add a different value, surely there must be a shorter way then to copy and paste this five times right? What can I do?
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Jul 18, 2015 9:46 pm    Post subject: Reply with quote

Could setup a little table of name-value pairs and cycle through them.
Code:
local stats = {
      ["perk"] = 0x8000,
      ["val2"] = 0x100
}
for name,value in pairs(stats) do
  local addr = getAddress(name)
  local newVal = readInteger(addr)
  newVal = newVal + value
  writeInteger(addr, newVal)
end

Or if you only wanted your code to appear simpler, put everything in one line. Smile
Code:
writeInteger("perk", readInteger("perk") + 0x8000)
Back to top
View user's profile Send private message
vng21092
Grandmaster Cheater
Reputation: 15

Joined: 05 Apr 2013
Posts: 644

PostPosted: Sat Jul 18, 2015 10:17 pm    Post subject: Reply with quote

ahh the second worked perfectly, thanks. Its funny because while I was searching for solutions, I came across those 4 lines from one of your older posts. So I just applied it to my table, and it turned out ok. so... double thanks Very Happy
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