|
Post by jacquelefacque on May 22, 2019 13:40:55 GMT
I've made a script for my favorite game but I have some questions. 1. im using a long list of sprites that im scanning from a snapshot. Looks like this: activeTable = {"1.png", "2.png", "3.png", "4.png"} and so on. list is 100+ png's long and will be longer when I finish it. and then im using this function: snapshot() for i, png in ipairs(activeTable) do reg = Region1:exists(png) if (reg ~= nil) then reg:highlight(1) continueClick(reg, 1, 1) fight() -- it executes the fighting function and then scans again It works now but I must make it more complicated: a) If I lose the fight I need to exclude that png + region (they actually move on the screen a little bit. later I will come back to this) for 5 mins. Cant figure out how to make it. b) is it possible to add an id to each png so that I can make a list when script ends of the sprites I encountered. c) the problem is that with a function like this I will get to last sprites only when there are no sprites with lower number of png's. is it possible (and how) to make it start scanning from sprite number it last found and clicked? 2. I've been using snapAndPlay to capture the sprites in blacknwhite but I noticed a neat feature - when I click on the sprite to capture image it makes a neat frame around it (like this - imgur.com/a/XZSTZ8Z - sprite is where the black box is, but you can see the frame) and even if the sprite moves the frame follows. What line of code in snapAndPlay is responsible for this? 3. how is it possible to print text on the screen during the run of the script? I know that print() gives the msg at the end of the script in that dialog box and toast() gives it onscreen when its called, but I want small numbers (sort of a timer) in one corner of the screen that update when loop is finished. I made the logic like this: while (true) do startTime = os.time(os.date('*t')) while (true) do isHour = os.time(os.date('*t')) - startTime if (isHour >= 3600) then refill() break elseif (isHour < 3600) then rutine() end end end So the logic would be that if isHour is met it would execute refill() and break out of inner while (true) loop to the outer and start outer again (thus the inside aswell). I would want to print out isHour/60 result after each rutine() so that it stays on until next time it updates.
|
|
|
Post by jacquelefacque on May 24, 2019 8:19:55 GMT
Please, can anyone help atleast with some of the questions?
|
|
|
Post by Mercobots on May 24, 2019 10:48:45 GMT
hi there so to start i recommend you to read some previous posts , because you have many examples/material here 1. im using a long list of sprites that im scanning from a snapshot. Looks like this:
use commonLib.lua ( ankulua.boards.net/thread/169/common-library-autoresize) there is a a function to handle multiples images scan regionWaitMulti()you can set a id for each image (1.b)local activeTable = { { id = 'img1', target = '1.png', region = Region1, }, { id = 'img2', target = '2.png', region = Region1, }, { id = 'img3', target = '3.png', region = Region1, }, { id = 'img4', target = '4.png', region = Region1, }, { id = 'img5', target = '5.png', region = Region1, }, { id = 'img6', target = '6.png', region = Region1, }, }
print(regionWaitMulti(activeTable, 60 * 1, true))
now is very simple to apply your code local activeTable = { { id = 'img1', target = '1.png', region = Region1, }, { id = 'img2', target = '2.png', region = Region1, }, { id = 'img3', target = '3.png', region = Region1, }, { id = 'img4', target = '4.png', region = Region1, }, { id = 'img5', target = '5.png', region = Region1, }, { id = 'img6', target = '6.png', region = Region1, }, }
local founds = {}
while #activeTable > 0 do -- repeat until there is no more image to scan local i, id, m = regionWaitMulti(activeTable, 60 * 1, true)
if id ~= '__none__' then continueClick(m, 1, 1) table.insert(founds, activeTable[i]) -- 1.c , this create a new table only whit match found table.remove(activeTable, i)-- 1.a , remove table record fight() end end 2. I've been using snapAndPlay to capture the sprites in blacknwhite but ....
i'm not 100% cuz i don't use snapAndPlay but if im not wrong this is the region highlight or math highlight 3. how is it possible to print text on the screen during the run of the script?....use this small function, this will highlight the message you pass through it local reg_log = Region(0, 0, 200, 50)
function logShow(text) text = tostring(text) reg_log:highlightOff() reg_log:highlight(text) end Use Timer() function ankulua.boards.net/thread/13/advanced-methods#Timer instead of using os.time(os.date('*t')) at the end your code should be something like this local reg_log = Region(0, 0, 200, 50)
function logShow(text) text = tostring(text) reg_log:highlightOff() reg_log:highlight(text) end
-- Q1 , Q1:B local activeTable = { { id = 'img1', target = '1.png', region = Region1, }, { id = 'img2', target = '2.png', region = Region1, }, { id = 'img3', target = '3.png', region = Region1, }, { id = 'img4', target = '4.png', region = Region1, }, { id = 'img5', target = '5.png', region = Region1, }, { id = 'img6', target = '6.png', region = Region1, }, }
local founds = {} local timer = Timer()
while (true) do
while #activeTable > 0 do local i, id, m = regionWaitMulti(activeTable, 60 * 1, true)
if id ~= '__none__' then logShow(id .. ' Found') continueClick(m, 1, 1) table.insert(founds, activeTable[i]) -- table.remove(activeTable, i) fight() end end if (timer >= 3600) then logShow('refill') refill() timer:set() else logShow('rutine') rutine() end end Warning, nothing of that has been tested
|
|
|
Post by jacquelefacque on May 26, 2019 11:28:03 GMT
hi there so to start i recommend you to read some previous posts , because you have many examples/material here 1. im using a long list of sprites that im scanning from a snapshot. Looks like this:
use commonLib.lua ( ankulua.boards.net/thread/169/common-library-autoresize) there is a a function to handle multiples images scan regionWaitMulti()you can set a id for each image (1.b)local activeTable = { { id = 'img1', target = '1.png', region = Region1, }, { id = 'img2', target = '2.png', region = Region1, }, { id = 'img3', target = '3.png', region = Region1, }, { id = 'img4', target = '4.png', region = Region1, }, { id = 'img5', target = '5.png', region = Region1, }, { id = 'img6', target = '6.png', region = Region1, }, }
print(regionWaitMulti(activeTable, 60 * 1, true))
now is very simple to apply your code local activeTable = { { id = 'img1', target = '1.png', region = Region1, }, { id = 'img2', target = '2.png', region = Region1, }, { id = 'img3', target = '3.png', region = Region1, }, { id = 'img4', target = '4.png', region = Region1, }, { id = 'img5', target = '5.png', region = Region1, }, { id = 'img6', target = '6.png', region = Region1, }, }
local founds = {}
while #activeTable > 0 do -- repeat until there is no more image to scan local i, id, m = regionWaitMulti(activeTable, 60 * 1, true)
if id ~= '__none__' then continueClick(m, 1, 1) table.insert(founds, activeTable[i]) -- 1.c , this create a new table only whit match found table.remove(activeTable, i)-- 1.a , remove table record fight() end end 2. I've been using snapAndPlay to capture the sprites in blacknwhite but ....
i'm not 100% cuz i don't use snapAndPlay but if im not wrong this is the region highlight or math highlight 3. how is it possible to print text on the screen during the run of the script?....use this small function, this will highlight the message you pass through it local reg_log = Region(0, 0, 200, 50)
function logShow(text) text = tostring(text) reg_log:highlightOff() reg_log:highlight(text) end Use Timer() function ankulua.boards.net/thread/13/advanced-methods#Timer instead of using os.time(os.date('*t')) at the end your code should be something like this local reg_log = Region(0, 0, 200, 50)
function logShow(text) text = tostring(text) reg_log:highlightOff() reg_log:highlight(text) end
-- Q1 , Q1:B local activeTable = { { id = 'img1', target = '1.png', region = Region1, }, { id = 'img2', target = '2.png', region = Region1, }, { id = 'img3', target = '3.png', region = Region1, }, { id = 'img4', target = '4.png', region = Region1, }, { id = 'img5', target = '5.png', region = Region1, }, { id = 'img6', target = '6.png', region = Region1, }, }
local founds = {} local timer = Timer()
while (true) do
while #activeTable > 0 do local i, id, m = regionWaitMulti(activeTable, 60 * 1, true)
if id ~= '__none__' then logShow(id .. ' Found') continueClick(m, 1, 1) table.insert(founds, activeTable[i]) -- table.remove(activeTable, i) fight() end end if (timer >= 3600) then logShow('refill') refill() timer:set() else logShow('rutine') rutine() end end Warning, nothing of that has been testedThanks for the great write! 1. Testing ipairs vs regionWaitMulti I get mixed results sometimes regionWaitMulti is a bit faster but the rest of the times its waaaay slower finding the same sprite. 2nd it highlights the region over and over again (probably each time it scans for a single image) when it searches. I dont like that. The region is 80% of the screen and so its quite annoying to look at. Ok, I know that the whole idea of a bot is to not look, but still. 2. Too bad that the same table doesnt work with ipairs. Or atleast I couldnt make it work. 3. I used the small function to write text but it crashes the Ankulua if I run it on loop for more than few sec. 4. Timer() is great! Thanks!
|
|
|
Post by Mercobots on May 26, 2019 17:35:27 GMT
1. Testing ipairs vs regionWaitMulti I get mixed results sometimes regionWaitMulti is a bit faster but the rest of the times its waaaay slower finding the same sprite. 2nd it highlights the region over and over again (probably each time it scans for a single image) when it searches. I dont like that. The region is 80% of the screen and so its quite annoying to look at. Ok, I know that the whole idea of a bot is to not look, but still. 2. Too bad that the same table doesnt work with ipairs. Or atleast I couldnt make it work. 3. I used the small function to write text but it crashes the Ankulua if I run it on loop for more than few sec. 4. Timer() is great! Thanks! 1- ok first you need understand how regionWaitMulti works regionWaitMulti(target, seconds, debug, skipLocation)target = i think this one is self explanatory seconds = the max time this will try to find 1 match on screen , this is, if non of your sprite was found it will continue repeat all the list until timeout debug = on/off highlights skipLocation = if need to click on a location after each sprite set here the location (not important for now)2-- yes it works local activeTable = { { id = 'img1', target = '1.png', region = Region1, }, { id = 'img2', target = '2.png', region = Region1, }, { id = 'img3', target = '3.png', region = Region1, }, { id = 'img4', target = '4.png', region = Region1, }, { id = 'img5', target = '5.png', region = Region1, }, { id = 'img6', target = '6.png', region = Region1, }, }
for i, sprite in ipairs(activeTable) do print(i..'º =======================') print('id = ' .. sprite.id) print('target = ' .. sprite.target) print('region = ' .. sprite.region) end
3- can you share a pic off the error?
|
|
|
Post by jacquelefacque on May 28, 2019 10:17:53 GMT
Thank you so much! Everything works! One last question - there can be times when there are more than one sprite of the same kind on the screen. Say I fail to kill one and now I want to ignore only this exact sprite at this exact region for 5 mins. What would be the best solution to this? Is it possible to ignore a region within a region that is scanned for images?
|
|
|
Post by Mercobots on May 28, 2019 23:55:19 GMT
i don't know if is that you need but you can add a timer on each sprite if needed like this
while (true) do for i, sprite in ipairs(activeTable) do -- if (sprite.timer and sprite.timer:check() > 60 * 5) or not sprite.timer then -- if not exists(sprite.target) then sprite.timer = Timer() end end end end
|
|