|
Post by Exilereven on Apr 2, 2018 14:46:02 GMT
I was noticing a need for basic script setup for people wanting to venture into writing there own scripts. This is the basic barbies setup for beginning a script. This will show you how to find/click on specific image with region.
-----THIS EXAMPLE IS FOR PORTRAIT MODE ONLY-----
REG = {}
-- Ankulua TIMEOUT = 3 SIMILAR = 0.8 WIDTH = 1080 HEIGHT = 1920
--Sets root folder structure(so that it runs from whatever folder your script is ran from. ROOT = scriptPath()
--Sets a custom path for my images folder, make sure your imagename.png is in yoyr images folder DIR_IMAGES = ROOT .. "images/" DIR_LIBS = ROOT .. "libs/" setImagePath(DIR_IMAGES)
-- Ankulua settings -- --------------------------------------- Settings:setCompareDimension(true, WIDTH) Settings:setScriptDimension(true, WIDTH) Settings:set("AutoWaitTimeout", TIMEOUT) Settings:set("MinSimilarity", SIMILAR)
-- --this a collection of functions from ankulua members, it will pre-load and add a lot of extra/common functions for us to use. --
luaLib = loadstring(httpGet("https://raw.githubusercontent.com/mercobots/luaLib/master/luaLib.lua")) luaLib()
commonLib = loadstring(httpGet("https://raw.githubusercontent.com/AnkuLua/commonLib/master/commonLib.lua")) commonLib()
--be sure to set your Region(x,y,h,w) according to where YOU need to locate image. REG.image = { image_region = Region(560, 210, 93, 44), }
function clickTest() --first if, will look for our image.png for 1 second, change to whatever you need to kind of (wait) 3 secs looking for image, or 1 sec, etc... if REG.image.image_region:existsClick("image.png", 1) then toast("found image") else toast("not found") end end --end of clickTest()
-----Main Script Start-----
clickTest()
|
|
|
Post by sonatta on Apr 3, 2018 11:53:29 GMT
can i ask how to get the Region(x,y,h,w)? i know how to get x,y but how to get h,w?
|
|
|
Post by notpeople on Apr 3, 2018 12:41:27 GMT
can i ask how to get the Region(x,y,h,w)? i know how to get x,y but how to get h,w? do you try getW() and getH() ?
|
|
|
Post by Mercobots on Apr 3, 2018 12:52:01 GMT
|
|
|
Post by Exilereven on Apr 3, 2018 16:06:01 GMT
SnapYourScript is something I've used on a daily basis. You go into your game 1 time, get every loc, image, and region, nice and neat already in tables for you. It's a very handy tool.
|
|
|
Post by sonatta on Apr 4, 2018 12:59:41 GMT
thank you it works! however it seems its too slow because its waiting for image to appear
is there way to not to wait for image to appear specially if im searching for multiple images and regions?
i tried if REG.image.image_region:existsClick("image.png", 0) but still slow
|
|
|
Post by Exilereven on Apr 4, 2018 14:15:37 GMT
Speed all depends on your resolution for comparing images. And your device/computer processor/ram. If you in 1920x1080, like me. I take all screenshots, locs, regions, everything in 1280x720 (so things run faster). You can still right everything for loc, region, etc... in 1920x1080, then take of screenshots in 1280x720, use 1920 for script reso, and 1280 for image compare reso. Now you can use correct stuff on your own device reso, still get the lower reso pics (for speed), and gain a little speed. I do zero exists checks like this. function imagecheck() if region:exists("image.png", 0) then return true end return false end end ---main start--- while true do if imagecheck() then click(getLastMatch()) end end This will loop forever on speed zero and if pic is there it will return true, then it will click last possible match made, which is the exists check we just did. Try some different resolutions and different techniques. I know when I started everything seemed slow, till I figured out it was my own fault for not finding ways for speeding up my code .
|
|
|
Post by sonatta on Apr 4, 2018 16:37:17 GMT
its working fine, but im getting random error every few loops or few minutes running the script any ideas? heres my code regionsearch.lua: REG = {}
-- Ankulua
TIMEOUT = 3
SIMILAR = 0.8
WIDTH = 1024
HEIGHT = 600
--Sets root folder structure(so that it runs from whatever folder your script is ran from.
ROOT = scriptPath()
--Sets a custom path for my images folder, make sure your imagename.png is in yoyr images folder
DIR_IMAGES = ROOT .. "images/"
DIR_LIBS = ROOT .. "libs/"
setImagePath(DIR_IMAGES)
-- Ankulua settings
-- ---------------------------------------
Settings:setCompareDimension(true, WIDTH)
Settings:setScriptDimension(true, WIDTH)
Settings:set("AutoWaitTimeout", TIMEOUT)
Settings:set("MinSimilarity", SIMILAR)
--
--this a collection of functions from ankulua members, it will pre-load and add a lot of extra/common functions for us to use.
--
--be sure to set your Region(x,y,h,w) according to where YOU need to locate image.
REG.image = {
image_region = Region(112, 96, 811, 462),
}
REG.image2 = {
image_region2 = Region(934, 503, 81, 83),
}
REG.image3 = {
image_region3 = Region(934, 503, 81, 83),
}
REG.image4 = {
image_region4 = Region(496, 331, 32, 24),
}
function clickTest()
--first if, will look for our image.png for 1 second, change to whatever you need to kind of (wait) 3 secs looking for image, or 1 sec, etc...
if REG.image2.image_region2:existsClick("loot1.png", 0) then
wait(1)
else
if REG.image3.image_region3:existsClick("loot2.png", 0) then
wait(1)
else
if REG.image.image_region:existsClick("violet2.png", 0) then
wait(1)
else
toast("telporting")
click(Location(999, 180))
wait(1)
click(Location(315, 243))
wait(1)
end
end
end
end
-----Main Script Start-----
while true do
clickTest()
end
|
|
|
Post by Exilereven on Apr 4, 2018 19:12:07 GMT
You only need one table for REG
and I cleaned up your if statements to what I think your wanting.
REG = {}
-- Ankulua
TIMEOUT = 3
SIMILAR = 0.8
WIDTH = 1024
HEIGHT = 600
--Sets root folder structure(so that it runs from whatever folder your script is ran from.
ROOT = scriptPath()
--Sets a custom path for my images folder, make sure your imagename.png is in yoyr images folder
DIR_IMAGES = ROOT .. "images/"
DIR_LIBS = ROOT .. "libs/"
setImagePath(DIR_IMAGES)
-- Ankulua settings
-- ---------------------------------------
Settings:setCompareDimension(true, WIDTH)
Settings:setScriptDimension(true, WIDTH)
Settings:set("AutoWaitTimeout", TIMEOUT)
Settings:set("MinSimilarity", SIMILAR)
REG.image = {
image_region = Region(112, 96, 811, 462), image_region2 = Region(934, 503, 81, 83), image_region3 = Region(934, 503, 81, 83), }
function clickTest()
--first if, will look for our image.png for 1 second, change to whatever you need to kind of (wait) 3 secs looking for image, or 1 sec, etc...
if REG.image.image_region2:existsClick("loot1.png", 0) then
wait(1)
elseif REG.image.image_region3:existsClick("loot2.png", 0) then
wait(1)
elseif REG.image.image_region:existsClick("violet2.png", 0) then
wait(1)
else
toast("telporting")
click(Location(999, 180))
wait(1)
click(Location(315, 243))
wait(1)
end end -----Main Script Start-----
while true do clickTest() end
|
|
|
Post by sonatta on Apr 4, 2018 20:01:39 GMT
thank you so much. errors are gone forever
|
|
|
Post by samlemx on Sept 11, 2018 17:20:42 GMT
Hey exile! Hoping you (or anyone) can assist me. I saw your code on creating a separate function to do the image checking. Not a bad way to go. Do you know how to pass values to the function? I saw an example in another thread but I couldn't make it work. I have many image checks so I figured passing values was a good choice. I tried something like:
--main Imagecheck("CW1.png",Region(250,400,220,210)) ........
Function Imagecheck(I, R) --looping goes here.
But I always get an issue with passing a nil value? I mean both are static, not variables that could have not had a value assigned. Any thoughts?
Thanks all, Sam
|
|
|
Post by jirenn on Jan 9, 2019 14:46:23 GMT
thanks for your help this solve my problem
|
|
|
Post by yusufyyy on Mar 20, 2020 6:19:35 GMT
Hi there, is there any guide for this script language? Or can I use other language like Java or Python?
|
|
|
Post by Exilereven on Mar 20, 2020 11:03:13 GMT
Hi there, is there any guide for this script language? Or can I use other language like Java or Python? Ankulua uses 3 different languages in one. Android/java Sikuli Lua The main structure your looking to practice is Lua, most of the script will be in semi lua format with some java bits thrown in. Just my opinion, I would start by looking up how things work in lua, like loops, for, if then, start small work your way up, just good learn lua.
|
|
|
Post by shrimp on Apr 10, 2020 11:13:44 GMT
Hi, I would like to know what this line of code does: REG.image.image_region:existsClick("image.png", 1) Does it search for the image at the region from REG.image.image_region, I know existclick kind of searches the whole screen for it? If so does make ankulua search for the image again before clicking?
|
|