View previous topic :: View next topic |
Author |
Message |
vng21092 Grandmaster Cheater Reputation: 15
Joined: 05 Apr 2013 Posts: 644
|
Posted: Sat Jul 18, 2015 9:32 pm Post subject: Need some advice |
|
|
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 |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sat Jul 18, 2015 9:46 pm Post subject: |
|
|
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.
Code: | writeInteger("perk", readInteger("perk") + 0x8000) |
|
|
Back to top |
|
|
vng21092 Grandmaster Cheater Reputation: 15
Joined: 05 Apr 2013 Posts: 644
|
Posted: Sat Jul 18, 2015 10:17 pm Post subject: |
|
|
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
|
|
Back to top |
|
|
|