|
Post by jacquelefacque on May 8, 2019 14:25:02 GMT
I'm kinda new to coding and Ankulua. I started building my first bot for a game I play. The problem is that it has a lot of different images to click and only few of them are on the screen at one given time. On my v1 I made a function for each image and in main I put if x.png found do function and then it searches again. Is there a way to make it more compact? So that it uses somekind of a list that can be run through with a variable (in example MOB_NAME) that can be inserted in function? like this
function fight() waitClick("MOB_NAME"+".png", 5) end
So that I dont have to write the function for each mob?
Also is there a way to set region globaly? Like so I dont have to write it before each click?
|
|
|
Post by AnkuLua on May 8, 2019 22:01:59 GMT
you can use regionWaitMulti() in commonLib.lua ankulua.boards.net/thread/169/common-library-autoresize
snap and play script uses regionWaitMulti() ankulua.boards.net/thread/169/common-library-autoresize
The basic idea is to take one snapshot and scan for many images with regions.
|
|
|
Post by Unknown on May 10, 2019 2:57:34 GMT
Maybe something like this?
function fight() max = 2 for i = 0, max, 1 do existsClick(Pattern("MOB_NAME"..i..".png"),5) end end fight()
|
|
|
Post by Exilereven on May 10, 2019 10:29:45 GMT
Maybe something like this? function fight() max = 2 for i = 0, max, 1 do existsClick(Pattern("MOB_NAME"..i..".png"),5) end end fight() existsClick(MOB_NAME.. '.png') Your already telling it how many times to run with your: for i = 1, max, 1 This would run twice with max being set to 2.
|
|
docbt
New Member
Posts: 10
|
Post by docbt on Jun 17, 2021 15:13:46 GMT
you can use regionWaitMulti() in commonLib.lua ankulua.boards.net/thread/169/common-library-autoresize snap and play script uses regionWaitMulti() ankulua.boards.net/thread/169/common-library-autoresize The basic idea is to take one snapshot and scan for many images with regions. Why do we have a timeout here? Wouldn't it be better/faster if we make sure, that all images were checked once and return or take a new snapshot one time, if all were checked? If the timeout value is too high, it will check the screen more than once. If it's too low, it will not check a new Screenshot.
|
|
|
Post by Exilereven on Jun 17, 2021 21:47:05 GMT
you can use regionWaitMulti() in commonLib.lua ankulua.boards.net/thread/169/common-library-autoresize snap and play script uses regionWaitMulti() ankulua.boards.net/thread/169/common-library-autoresize The basic idea is to take one snapshot and scan for many images with regions. Why do we have a timeout here? Wouldn't it be better/faster if we make sure, that all images were checked once and return or take a new snapshot one time, if all were checked? If the timeout value is too high, it will check the screen more than once. If it's too low, it will not check a new Screenshot. --This is just one way to do what your wanting, hopefully this is helpful. try different stuff till it suites your needs. --pre load our list of mobs we are searching for, before we try to call them in a function. MOBS = { "image_1", "image_2", "image_3", --add your image names here } function searchImageMulti() local _found = {} --setup table for matches found snapshot() --we snapshot here and then check entire list very quickly using 0 search speed if it finds any of the images it will highlight them and add them to your founds list. for i,t in ipairs(MOBS) do if exists(t.. '.png', 0) then table.insert(_found, t) getLastMatch():highlight(1) --highlight last match found so you can visually see the matches as they go by. remove this to get full speed match finding end end usePreviousSnap(false) --make sure we turn off our snapshot() so ankulua will use a new refreshed screenshot for next try around. print(_found) --prints out a table of found imageatches. end searchImageMulti() --call our new function once. out this into a while loop like this if you want to run non stop so you can switch screens manually while its running to see if it picks up images. --while true do --searchImageMulti() --end
|
|
docbt
New Member
Posts: 10
|
Post by docbt on Jun 18, 2021 16:01:04 GMT
Thanks mate!
The regionWaitMulti function starts at the last found array index (example: image 10 of 50). So in my example image 1-9 are only checked in the second while loop run and don't need a new screenshot.
I added
local cycles = 0
at the beginning of the while loop and after the for loop I added
cycles = cycles + 1 If cycles > 1 then return -1 end
This makes sure every image was checked once. No need for a timeout exit condition.
|
|