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 


Simplifying AOB script

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

Joined: 21 Feb 2016
Posts: 104

PostPosted: Thu Mar 02, 2017 12:20 am    Post subject: Simplifying AOB script Reply with quote

I'm not very good with tables or loops yet, is there a way I could shorten this to have one function that cycles through the list of AOBs and prints out each scan result

Code:
aobList = {
a00 = "XX XX XX XX",
a01 = "XX XX XX XX",
a02 = "XX XX XX XX"
}

if openProcess("game.exe") then
  function autoUpdate()
    local a = AOBScan(aobList.a00)
      for i=0, a.Count-2, 1 do
        addr00 = (string.format("%X",getAddress(a[i])))
      end
      a.destroy()
    local a = AOBScan(aobList.a01)
      for i=0, a.Count-2, 1 do
        addr01 = (string.format("%X",getAddress(a[i])))
      end
      a.destroy()
    local a = AOBScan(aobList.a02)
      for i=0, a.Count-2, 1 do
        addr02 = (string.format("%X",getAddress(a[i])))
      end
      a.destroy()

    print(addr00)
    print(addr01)
    print(addr02)

    if a == nil then
      return
    end
  end
end

createNativeThread(autoUpdate)
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 4

Joined: 24 Feb 2017
Posts: 36
Location: Right Here Buddy.

PostPosted: Thu Mar 02, 2017 1:37 am    Post subject: Reply with quote

This should work.

Code:

local format = string.format

local aobLst = {
    a00 = 'XX XX XX XX',
    a01 = 'XX XX XX XX',
    a02 = 'XX XX XX XX',
}

if openProcess('game.exe') then
    function autoUpdate()
        if aobLst then
            for k, v in pairs(aobLst)
                local rLst = AOBScan(v)
                if rLst then
                    for i = 1, rLst.Count - 1 do
                        if rLst[i] then
                            print(format('%s: %08X', k, getAddress(rLst[i])))
                        end
                    end
                end
            end
        end
    end
    createNativeThread(autoUpdate)
end

_________________
- Code Happy, Code Freely, Be Awesome.
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 104

PostPosted: Thu Mar 02, 2017 2:05 am    Post subject: Reply with quote

Thank you very much, that's a lot more elegant than what I had. one more thing if you don't mind, if I wanted to assign each first result from a scan to a global variable how would I do it with a loop like that? Like for instance if I changed the prints in my OP example to:

Code:
var1 = addr00
var2 = addr01
var3 = addr02
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 4

Joined: 24 Feb 2017
Posts: 36
Location: Right Here Buddy.

PostPosted: Thu Mar 02, 2017 2:57 am    Post subject: Reply with quote

I would use a global table. (not lua's global table just a table)
so:
Code:


AOBsLst = { }

local format = string.format

local aobLst = {
    a00 = 'XX XX XX XX',
    a01 = 'XX XX XX XX',
    a02 = 'XX XX XX XX',
}

if openProcess('game.exe') then
    function autoUpdate()
        if aobLst then
            for k, v in pairs(aobLst)
                local rLst = AOBScan(v)
                if rLst then
                    for i = 1, rLst.Count - 1 do
                        if rLst[i] then
                            print(format('%s: %08X', k, getAddress(rLst[i])))
                            AOBsLst[k] = v
                        end
                    end
                end
            end
        end
    end
    createNativeThread(autoUpdate)
    if AOBsLst then
        print(AOBsLst.a00)
        for k, v in pairs(AOBsLst)
            print(format('%s: %08X', k, getAddress(v)))
        end
    end
end


EDIT:

Missed the first part.
Code:

AOBsLst = { }

local format = string.format

local aobLst = {
    a00 = 'XX XX XX XX',
    a01 = 'XX XX XX XX',
    a02 = 'XX XX XX XX',
}

if openProcess('game.exe') then
    function autoUpdate()
        if aobLst then
            for k, v in pairs(aobLst)
                local rLst = AOBScan(v)
                if rLst then
                    for i = 1, rLst.Count - 1 do
                        if rLst[i] then
                            print(format('%s: %08X', k, getAddress(rLst[i])))
                            if i == 1 then
                                AOBsLst[k] = v
                            end
                        end
                    end
                end
            end
        end
    end
    createNativeThread(autoUpdate)
    if AOBsLst then
        print(AOBsLst.a00)
        for k, v in pairs(AOBsLst)
            print(format('%s: %08X', k, getAddress(v)))
        end
    end
end

_________________
- Code Happy, Code Freely, Be Awesome.
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 104

PostPosted: Thu Mar 02, 2017 9:50 am    Post subject: Reply with quote

Much thanks again friend, cheers for now 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