The Wiki for Tale 6 is in read-only mode and is available for archival and reference purposes only. Please visit the current Tale 11 Wiki in the meantime.
If you have any issues with this Wiki, please post in #wiki-editing on Discord or contact Brad in-game.
Difference between revisions of "User:Selune"
From ATITD6
Jump to navigationJump to search| Line 840: | Line 840: | ||
{{Collapse top|title=New Raeli Oven Monitor (IN TESTING)}} | {{Collapse top|title=New Raeli Oven Monitor (IN TESTING)}} | ||
<pre> | <pre> | ||
| − | |||
loadfile("luaScripts/screen_reader_common.inc")(); | loadfile("luaScripts/screen_reader_common.inc")(); | ||
loadfile("luaScripts/common.inc")(); | loadfile("luaScripts/common.inc")(); | ||
| Line 846: | Line 845: | ||
askText = singleLine([[ | askText = singleLine([[ | ||
| − | Raeli Color Monitor v1. | + | Raeli Color Monitor v1.1b (edit by Selune) -- |
Make sure the Raeli Oven is pinned, then select the ATITD window and press shift. | Make sure the Raeli Oven is pinned, then select the ATITD window and press shift. | ||
]]); | ]]); | ||
| Line 853: | Line 852: | ||
take_screenshots = true; | take_screenshots = true; | ||
stop_at_color = "White"; | stop_at_color = "White"; | ||
| + | confidence_threshold = 15; | ||
saved_x = 0; | saved_x = 0; | ||
saved_y = 0; | saved_y = 0; | ||
| Line 987: | Line 987: | ||
local lab_l, lab_a, lab_b, lab_tst_l, lab_tst_a, lab_tst_b; | local lab_l, lab_a, lab_b, lab_tst_l, lab_tst_a, lab_tst_b; | ||
local hsl_h, hsl_s, hsl_l, hsl_tst_h, hsl_tst_s, hsl_tst_l; | local hsl_h, hsl_s, hsl_l, hsl_tst_h, hsl_tst_s, hsl_tst_l; | ||
| − | local offset, best_name, best_offset; | + | local offset, best_name, best_offset, next_best_offset, confidence; |
best_offset = 100000; | best_offset = 100000; | ||
| − | rgb_r = (math.floor(px/256/256/256) % 256); | + | next_best_offset = 1000000; |
| − | rgb_g = (math.floor(px/256/256) % 256); | + | rgb_r = ((math.floor(px/256/256/256) % 256) - 7) * 255/248; |
| − | rgb_b = (math.floor(px/256) % 256); | + | rgb_g = ((math.floor(px/256/256) % 256) - 7) * 255/248; |
| + | rgb_b = ((math.floor(px/256) % 256) - 6) * 255/248; | ||
lab_l, lab_a, lab_b = rgb2lab(rgb_r, rgb_g, rgb_b); | lab_l, lab_a, lab_b = rgb2lab(rgb_r, rgb_g, rgb_b); | ||
hsl_h, hsl_s, hsl_l = rgb2hsl(rgb_r, rgb_g, rgb_b); | hsl_h, hsl_s, hsl_l = rgb2hsl(rgb_r, rgb_g, rgb_b); | ||
| Line 1,008: | Line 1,009: | ||
--offset = math.abs(rgb_r - tst_r) + math.abs(rgb_g - tst_g) + math.abs(rgb_b - tst_b); | --offset = math.abs(rgb_r - tst_r) + math.abs(rgb_g - tst_g) + math.abs(rgb_b - tst_b); | ||
--offset = math.max(math.max((math.abs(rgb_r - tst_r)), math.abs(rgb_g - tst_g)), math.abs(rgb_b - tst_b)); | --offset = math.max(math.max((math.abs(rgb_r - tst_r)), math.abs(rgb_g - tst_g)), math.abs(rgb_b - tst_b)); | ||
| − | + | offset = (rgb_r - tst_r)^2 + (rgb_g - tst_g)^2 + (rgb_b - tst_b)^2; | |
| + | --offset = math.abs(lab_l - lab_tst_l) + math.abs(lab_a - lab_tst_a) + math.abs(lab_b - lab_tst_b); | ||
--offset = (lab_l - lab_tst_l)^2 + (lab_a - lab_tst_a)^2 + (lab_b - lab_tst_b)^2; | --offset = (lab_l - lab_tst_l)^2 + (lab_a - lab_tst_a)^2 + (lab_b - lab_tst_b)^2; | ||
| − | offset = math.max(math.max((math.abs(lab_l - lab_tst_l)), math.abs(lab_a - lab_tst_a)), math.abs(lab_b - lab_tst_b)); | + | --offset = math.max(math.max((math.abs(lab_l - lab_tst_l)), math.abs(lab_a - lab_tst_a)), math.abs(lab_b - lab_tst_b)); |
| + | --offset = math.abs(hsl_h - hsl_tst_h) + math.abs(hsl_s - hsl_tst_s) + math.abs(hsl_l - hsl_tst_l); | ||
--offset = (hsl_h - hsl_tst_h)^2 + (hsl_s - hsl_tst_s)^2 + (hsl_l - hsl_tst_l)^2; | --offset = (hsl_h - hsl_tst_h)^2 + (hsl_s - hsl_tst_s)^2 + (hsl_l - hsl_tst_l)^2; | ||
--offset = math.max(math.max((math.abs(hsl_h - hsl_tst_h)), math.abs(hsl_s - hsl_tst_s)), math.abs(hsl_l - hsl_tst_l)); | --offset = math.max(math.max((math.abs(hsl_h - hsl_tst_h)), math.abs(hsl_s - hsl_tst_s)), math.abs(hsl_l - hsl_tst_l)); | ||
| − | + | if (offset < next_best_offset) then | |
| − | + | if (offset < best_offset) then | |
| − | + | next_best_offset = best_offset; | |
| − | + | best_offset = offset; | |
| + | best_name = color_names[i]; -- .. " Hex: " .. DEC_HEX(color_values[i]); | ||
| + | else | ||
| + | next_best_offset = offset; | ||
| + | end | ||
| + | confidence = ((next_best_offset - best_offset) / best_offset) * 100; | ||
end | end | ||
| − | |||
end | end | ||
| − | return best_name; | + | return best_name, math.floor(confidence); |
end | end | ||
--Check pixel against target | --Check pixel against target | ||
function checkColor(px) | function checkColor(px) | ||
| − | local color_name = nearestColor(px); | + | local color_name, confidence; |
| + | color_name, confidence = nearestColor(px); | ||
| + | |||
if (color_name:upper() == stop_at_color:upper()) then | if (color_name:upper() == stop_at_color:upper()) then | ||
| − | return true; | + | return true, confidence; |
| + | else | ||
| + | return false, 0; | ||
end | end | ||
| − | |||
| − | |||
end | end | ||
| Line 1,041: | Line 1,050: | ||
local color_guess = "NONE"; | local color_guess = "NONE"; | ||
local tst_r, tst_g, tst_b, rgb_r, rgb_g, rgb_b; | local tst_r, tst_g, tst_b, rgb_r, rgb_g, rgb_b; | ||
| + | local confidence = 0; | ||
-- Display message until shift is held | -- Display message until shift is held | ||
while not go_now do | while not go_now do | ||
checkBreak(); | checkBreak(); | ||
| + | srReadScreen(); | ||
y = 0; | y = 0; | ||
mouse_x, mouse_y = srMousePos(); | mouse_x, mouse_y = srMousePos(); | ||
| Line 1,071: | Line 1,082: | ||
y = y + 15; | y = y + 15; | ||
| − | color_guess = nearestColor(px); | + | color_guess, confidence = nearestColor(px); |
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, | lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, | ||
| − | "(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ") Hex: " .. DEC_HEX(px)); | + | "(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ") Hex: " .. DEC_HEX(math.floor((px/256) % 16777216))); |
| + | y = y + 20; | ||
| + | lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Best guess: " .. color_guess); | ||
y = y + 15; | y = y + 15; | ||
| − | lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, " | + | lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Confidence: " .. confidence .. " (higher is better)"); |
| − | |||
| − | |||
-- Testing other methods of grabbing the pixel, making sure RGBA values match | -- Testing other methods of grabbing the pixel, making sure RGBA values match | ||
| Line 1,114: | Line 1,125: | ||
end | end | ||
| − | |||
if not color_found then | if not color_found then | ||
| − | lsPrint( | + | lsPrint(130, y - 20, z, 0.7, 0.7, 0xFF0000ff, "No such color"); |
end | end | ||
| − | + | y = y + 35; | |
| − | + | lsPrint(5, y, 0, 0.6, 0.6, 0xffffffff, "Confidence Required:"); | |
| − | + | is_done, confidence_threshold = lsEditBox("confthresh", 150, y, 0, 50, 30, 0.7, 0.7, 0x000000ff, confidence_threshold); | |
| − | + | confidence_threshold = tonumber(confidence_threshold); | |
| + | if not confidence_threshold then | ||
| + | lsPrint(10, y+17, 10, 0.4, 0.4, 0xFF2020ff, "MUST BE A NUMBER"); | ||
| + | confidence_threshold = 10; | ||
| + | end | ||
else | else | ||
is_done = true; | is_done = true; | ||
| Line 1,163: | Line 1,177: | ||
local px = 0; | local px = 0; | ||
local index=0; | local index=0; | ||
| + | local color_name, confidence; | ||
while 1 do | while 1 do | ||
| + | local y = 0; | ||
checkBreak(); | checkBreak(); | ||
lsSleep(100); | lsSleep(100); | ||
srReadScreen(); | srReadScreen(); | ||
| − | new_px = srReadPixel( | + | new_px = srReadPixel(saved_x, saved_y); |
local t = (lsGetTimer() - t0) / 1000 / 60; | local t = (lsGetTimer() - t0) / 1000 / 60; | ||
t = math.floor(t*10 + 0.5)/10; | t = math.floor(t*10 + 0.5)/10; | ||
| Line 1,177: | Line 1,193: | ||
end | end | ||
px = new_px; | px = new_px; | ||
| + | |||
if stop_at_CB then | if stop_at_CB then | ||
| − | if | + | color_name, confidence = nearestColor(px); |
| − | clickAllText("Interrupt"); | + | if (color_name:upper() == stop_at_color:upper()) then |
| − | lsPlaySound(" | + | if confidence > confidence_threshold then |
| − | + | clickAllText("Interrupt"); | |
| + | lsPlaySound("Complete.wav"); | ||
| + | error ("Stopped burn at: " .. stop_at_color .. " Confidence: " .. confidence); | ||
| + | else | ||
| + | for i = 1, 3 do | ||
| + | lsPlaySound("Clank.wav"); | ||
| + | lsSleep(50); | ||
| + | end | ||
| + | end | ||
| + | else | ||
| + | lsPlaySound("Clank.wav"); | ||
end | end | ||
| + | else | ||
| + | lsPlaySound("Clank.wav"); | ||
end | end | ||
| − | |||
| − | |||
end | end | ||
| − | lsPrintWrapped( | + | |
| − | " | + | y = y + 5; |
| − | lsPrintWrapped( | + | lsPrintWrapped(5, y, 1, lsScreenX - 10, 0.7, 0.7, 0xFFFFFFff, |
| − | "(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ")" ); | + | "Screen: " .. index .. " Timer: " .. t_string); |
| + | y = y + 15; | ||
| + | lsPrintWrapped(5, y, 1, lsScreenX - 10, 0.7, 0.7, 0xFFFFFFff, | ||
| + | "Color: " .. color_name .. " Confidence: " .. confidence); | ||
| + | |||
| + | y = y + 30; | ||
| + | lsPrintWrapped(5, y, 1, lsScreenX - 10, 0.7, 0.7, 0xFFFFFFff, | ||
| + | "(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ") Hex: " .. DEC_HEX(math.floor((new_px/256) % 16777216))); | ||
if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100, 0xFFFFFFff, "Exit") then | if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100, 0xFFFFFFff, "Exit") then | ||
Revision as of 00:16, 16 January 2013
Selune's Macros have been updated to the TaleScripts repository. Please leave any ideas for improvements or new macros here.
| Paint Reaction Template |
|---|
Cabbage | RedSand | G | -11 | 26 Cabbage | Iron | W | 27 | 27 Cabbage | Copper | W | -20 | -60 Cabbage | Potash | B | 19 | -63 Carrot | RedSand | B | 32 | -26 Carrot | Lead | W | -17 | 61 Carrot | Potash | W | -59 | 56 Carrot | Lime | G | 0 | 23 Clay | Lead | B | 32 | -16 Clay | Copper | R | 20 | -12 Clay | Sulfur | G | -55 | -41 Clay | Saltpeter | B | 54 | 35 Lead | Iron | B | 4 | 14 Lead | Copper | W | -25 | -40 Lead | Saltpeter | G | -7 | 47 Iron | Sulfur | G | -17 | 0 Iron | Saltpeter | W | -55 | 7 Copper | Sulfur | W | -25 | -12 Copper | Saltpeter | B | 42 | 4 |
| Fishing Macro for Testing |
|---|
-- Pin up your Lures menu 'Self Click, Skills, Fishing, Use Lure' (no other pinned up windows can exist)
-- Should have (Chat-Related): 'Chat and Inventory can be minimized' AND 'Minimized chat-channels are still visible'.
-- You must have Main Chat tab showing at all times and window is long/wide enough so no lines don't wrap.
-- Yes, this macro reads your MAIN chat screen, so make sure you read the above statement for it to work correctly.
-- Each line of text must not scroll/wrap to the next line. If it does, then drag your chat window wider so it doesn't wrap.
-- You want to make your chat very wide. Note: It is possible to see a LONG message like "Though you lost your lure, you did catch a 15 deben Orange Spongefish"
-- Another long message is "You didn't catch anything. You also lost your lure. Try different lures and locations"
-- At 1280x1024 your chat screen should reach at least to the mid point of your screen to avoid having a chat line wrap to next line, for a long message, like above.
-- Higher resolutions may not have to reach quite to the mid point.
-- ********** This macro writes to a log file (Fishlog.txt) for most actions, so you can review later! ******
-- ********** This also macro writes to a log file (Fishstats.txt) showing stats of your last fishing session, so you can review later! ******
--You can delete any of the log files if you wish. It will automatically create new ones if they dont exist.
--The fishlog.txt file gets appended everytime you fish, so the file can grow quite long over time.
--The fishstats.txt file gets overwritten everytime your gui program window updates, so it doesn't 'grow' over time.
-- "Main chat tab is not showing" and other errors can usually be overcome by adjusting the main chat window size and restarting, assuming main chat is showing.
-- And also verify the lines aren't wrapping.
-- The very first thing this macro does is to Self Click, Special, What Time is it? option. This will then display the time in main chat window.
-- The macro then parses time displayed, in main chat tab, so it can use it while the macro runs (Log files and on screen display).
-- Thats what the mysterious Self Click is doing, its not a bug, it is suppose to do that and thats why, to fetch the time.
-- Note: These are currently refered to as Common Fish in the below 'SkipCommon' type of fishes (True or False), in the 'Custom Variables' section.
--Abdju
--Chromis
--Catfish
--Carp
--Perch
--Phagrus
--Tilapia
--CUSTOM VARIABLES -- EDIT HERE To Change Fishing Casts, Skips, Updates.
TotalCasts=3; --Total Casts per lure, if a fish caught. If no fish then it skips.
SkipCommon = false; --Skips to next lure if fish caught is a common (Choose True or False).
LureChangesToUpdateTimer = 7; --Total lures used before time is updated. Zero updates every new lure.
IgnoreUnknown = false; --Continues the script if fish is not recognized
--AlmostCaughtAttempts = 0; --Adds additional attempts to the current lure if Unusual, Strange fish are seen;
-- Note: AlmostCaughtAttempts above was already commented out upon arriving to Talescripts.
-- It is also commented out during the script, so uncommenting above will NOT activate the feature.
-- Additional reporting in the log file
-- Choose True or False.
-- Note 'LogStrangeUnusual' and 'LogOdd' (below) overrides LogFails setting. ie if LogStrange true, then it would still log even if LogFails = False
--If LogFails = false and LogStrangeUnusual or LogOdd = true, then failed catches those would still be included in the log file.
LogFails = true; -- Do you want to add Failed Catches to log file? 'Failed to catch anything' or 'No fish bit'. Note the log will still add an entry if you lost lure.
LogStrangeUnusual = true; -- Do you want to add Strange and Unusual fish to the log file? Note the log will still add an entry if you lost lure.
LogOdd = true; -- Do you want to add Odd fish to the log file? Note the log will still add an entry if you lost lure.
-- END CUSTOM VARIABLES
loadfile("luaScripts/screen_reader_common.inc")();
loadfile("luaScripts/ui_utils.inc")();
loadfile("luaScripts/Fishing_Func.inc")();
function SetupLureGroup()
TLures = {};
FirstLure="";
LastLure = "";
srReadScreen();
FindPin = srFindImage("UnPin.png");
if FindPin then
--Click the pinup to refresh the lures window
srClickMouseNoMove(FindPin[0]+5,FindPin[1]+30);
lsSleep(500);
srReadScreen();
DownPin = srFindImageInRange("Fishing/Menu_DownArrow.png",FindPin[0]-10,FindPin[1],50,500);
if DownPin then
--Just Incase
UpArrow = srFindImageInRange("Fishing/Menu_UpArrow.png",FindPin[0]-10,FindPin[1],50,50);
if UpArrow then
srClickMouseNoMove(UpArrow[0]+5,UpArrow[1]+5);
lsSleep(1000);
srReadScreen();
end
-- srClickMouseNoMove(DownPin[0]+5,DownPin[1]+5);
LastLure=FindLureName(DownPin[0]-150,DownPin[1]-10,150,25);
--error(LastLure);
FirstLure = FindLureName(FindPin[0]-150,FindPin[1]-10,150,25);
-- error(FirstLure);
else
--No Arrows on lure menu?
FirstLure=FindLureName(FindPin[0]-150,FindPin[1]-10,150,25);
LastLure=nil;
end
else
error("Didn\'t find Lures pinned window - Self Click->Skills, Fishing -> Use Lure, PIN THIS WINDOW!");
end
if LastLure ~= nil then
--We have last lure, and arrows showing
ChangeLureMenu = LastLure;
FirstLurLoc = srFindImage("fishing/" .. FirstLure);
LastLurLoc = srFindImage("fishing/" .. LastLure);
for i = 1, #Lures,1 do
test = srFindImageInRange(("fishing/" .. Lures[i]),FirstLurLoc[0]-5,FirstLurLoc[1]-5,175,500);
if test then
--Add Lure
table.insert(TLures,Lures[i]);
if Lures[i] == LastLure then
--End of Menu, Use Down Arrow
arrow=srFindImageInRange("Fishing/menu_downarrow.png",test[0],test[1]-5,175,50);
if arrow then
DownArrowLocs = arrow;
srClickMouseNoMove(arrow[0]+5,arrow[1]+5);
lsSleep(1000);
srReadScreen();
lsSleep(1000);
else
error("no arrow found");
end
end
LastLureMenu = Lures[i];
end
end
--Reset Lure Menu
UpArrow = srFindImageInRange("Fishing/Menu_UpArrow.png",FindPin[0]-10,FindPin[1],50,50);
if UpArrow then
srClickMouseNoMove(UpArrow[0]+5,UpArrow[1]+5);
end
else
--No arrows, just get lures
for i = 1, #Lures, 1 do
test = srFindImage("Fishing/" .. Lures[i]);
if test then
table.insert(TLures,Lures[i]);
end
end
end
return TLures;
end
function FindLureName(x,y,w,h)
for i = 1, #Lures, 1 do
Lure = srFindImageInRange("Fishing/" .. Lures[i], x,y,w,h);
if Lure then
return Lures[i]
end
end
end
function GetLure()
srReadScreen();
if CurrentLureIndex == LastLureIndex then
-- Use Down Menu
srClickMouseNoMove(DownArrowLocs[0]-5,DownArrowLocs[1]-5);
srReadScreen();
end
lure = srFindImage("Fishing/" .. PlayersLures[CurrentLureIndex]);
if not lure then
--Failed to find lure
error("Can\'t find a lure!");
else
slure = Lures[PlayersLures[CurrentLureIndex]];
slure = string.sub(slure,string.find(slure,"_")+1,string.len(slure) - 4);
--statusScreen("Using Lure " .. slure);
return slure
end
end
function UseLure()
-- Uses lure according to CurrentLureIndex, which is used in PlayersLures which contains each lure the player has.
if #TLures == 0 then
error 'Can\'t find any lures on the pinned window. Did you run out of lures?'
end
srReadScreen();
lure = srFindImage("Fishing/" .. PlayersLures[CurrentLureIndex]);
if lure then
srClickMouseNoMove(lure[0]+3,lure[1]+3);
lsSleep(500);
srReadScreen();
-- Find Lure Type
for i = 1, #Lure_Types, 1 do
test = srFindImage("Fishing/" .. Lure_Types[i]);
if test then
--Click it!
srClickMouseNoMove(test[0]+3,test[1]+3);
gui_refresh();
break;
end
end
end
if PlayersLures[CurrentLureIndex] == ChangeLureMenu then
down = srFindImage("Fishing/Menu_DownArrow.png");
srClickMouseNoMove(down[0]+5,down[1]+5);
lsSleep(1000);
elseif PlayersLures[CurrentLureIndex] == LastLureMenu then
up = srFindImage("Fishing/Menu_UpArrow.png");
srClickMouseNoMove(up[0]+5,up[1]+5);
CurrentLureIndex=1;
lsSleep(1000);
end
end
function ChatReadFish()
--Find the last line of chat
lsSleep(100);
srReadScreen();
imgs = findAllImages("fishing/chatlog_reddots.png");
Coords = imgs[#imgs];
-- Look for the ** red dots in main chat to see if they exist.
if #imgs == 0 then
error 'Main chat tab is not showing or the chat window needs to be adjusted!'
end
--Caught Something.. Find Fish Details
Sfish = "";
for i = 1, #CL_Fish do
ChatFish = srFindImageInRange("Fishing/" .. CL_Fish[i],Coords[0] ,Coords[1],500,25);
if ChatFish then
Sfish = string.sub(CL_Fish[i],string.find(CL_Fish[i],"Fish_") + 5,string.len(CL_Fish[i]) - 4);
GrandTotalCaught = GrandTotalCaught + 1
break;
end
end
if string.len(Sfish) < 1 then
-- This fish name and fishname.png file likely needs to be added to Fishing_Func.inc, under the CL_Fish array and the .png added to /Images/Fishing folder
if IgnoreUnknown then
Sfish = "Unknown";
SNum = "1";
else
error("Unknown Fish! PLEASE, Take screenshot (Alt+C) of main chat tab, share with Talescripts team!");
end
else
--Find Size
for i = #CL_Number,1,-1 do
ChatSize = srFindImageInRange("fishing/" .. CL_Number[i],Coords[0],Coords[1],500,25);
if ChatSize then
SNum = string.sub(CL_Number[i],string.find(CL_Number[i],"_") + 1, string.len(CL_Number[i]) - 4);
break;
end
end
GrandTotaldb = GrandTotaldb + SNum;
end
return(Sfish .. " (" .. SNum .. "db)");
end
function findchat(line)
--Reads a chat line and returns a basic string for better processing
-- Odd fish means your fly fishing skill is not high enough. Raise it with enormous amounts of fishing.
-- Strange fish means you need a better rod to catch the rish. You may succeed on future attempts.
-- Unusual fish means your speed skill was not high enough to catch this type of fish. If it is almost enough, you may catch them on future casts.
--Possible fishing messages
-- Caught A (SIZE) Deben (FISH)
-- You almost caught a strange fish
-- (You almost caught a strange fish. You also lost your lure.)
-- You almost caught an unusual fish
-- (You almost caught an unusual fish. You also lost your lure.)
-- You almost caught an odd fish
-- (You almost caught an odd fish. You also lost your lure.)
-- Although you lost your lure (Caught a fish)
-- Using a (LURE) (TYPE) lure.
-- You are carrying more than you can manage.
-- You are carrying too much bulk.
-- You didn't catch anything.
-- (You didn't catch anything. You also lost your lure.)
-- No Fish Bit.
-- (No Fish Bit. You also lost your lure.)
--Find the last line of chat
lsSleep(100);
srReadScreen();
imgs = findAllImages("Fishing/chatlog_reddots.png");
Coords = imgs[#imgs];
-- Look for the ** red dots in main chat to see if they exist.
if #imgs == 0 then
error 'Main chat tab is not showing or the chat window needs to be adjusted!'
end
if line and line > 0 then
Coords = imgs[(#imgs) - line];
if not Coords then
error 'Main chat tab is not showing or the chat window needs to be adjusted!'
end
end
--Find What Happened
ChatType = "";
for i = 1, #Chat_Types -1,2 do
test = srFindImageInRange("Fishing/" .. Chat_Types[i],Coords[0],Coords[1],500,30);
if test then
--Found Chat
ChatType = Chat_Types[i + 1];
break;
end
end
--Break down!
if ChatType then
--if ChatType == "lure" then
--elseif ChatType == "nofishlostlure" then
--elseif ChatType == "nofish" then
--elseif ChatType == "strange" then
--elseif ChatType == "unusual" then
return ChatType;
else
error(ChatType);
end
end
function GetTime()
--Reads time stamp using special->what time menu
winsize = srGetWindowSize();
--Open Menu, Press the Esc key to open the Self Click menu
-- Move mouse to center of screen before Sending the Esc key, to get the Self Click menu. We dont want it self clicking near the edge of screen causing an error.
srSetMousePos(winsize[0]/2,winsize[1]/2);
lsSleep(100); -- This delay is critical for any srSetMousePos. Without it, the mouse will not have time to actually move!
srKeyEvent(string.char(27)); -- Send Esc Key
lsSleep(500);
--Find Special Menu
srReadScreen();
menu = srFindImage("Fishing/Menu_Special.png");
if menu then
--Click it!
srClickMouseNoMove(menu[0]+3,menu[1]+3);
lsSleep(500);
srReadScreen();
-- Look for the What Time Is It? option in menu
menu = srFindImage("Fishing/Menu_WhatTime.png");
if menu then
--Click it!
srClickMouseNoMove(menu[0]+3,menu[1]+3);
lsSleep(500);
end
end
srReadScreen();
imgs = findAllImages("Fishing/chatlog_reddots.png");
Coords = imgs[#imgs];
-- Look for the ** red dots in main chat to see if they exist.
if #imgs == 0 then
error 'Main chat tab is not showing or the chat window needs to be adjusted!'
end
for i = #CL_Time, 1, -1 do
Stime = srFindImageInRange("Fishing/" .. CL_Time[i],Coords[0],Coords[1],400,25);
if Stime then
Hour = string.sub(CL_Time[i],string.find(CL_Time[i],"ime_")+4,string.len(CL_Time[i])-4);
AM = srFindImageInRange("Fishing/Chatlog_Time_AM.png",Coords[0],Coords[1],400,25);
if AM then
CurrentTime=(Hour .. "AM");
return (Hour .. "AM");
else
PM = srFindImageInRange("Fishing/chatlog_time_PM.png",Coords[0],Coords[1],400,25);
if PM then
CurrentTime=(Hour .. "PM");
return (Hour .. "PM");
end
end
end
end
end
function gui_refresh()
lsDoFrame();
if GrandTotalCaught < 10 then
last10 = GrandTotalCaught .. "/10";
else
last10 = 10;
end
--Stats (On Screen Display)
--CurrentLureIndex out of PlayersLures
winsize = lsGetWindowSize();
lsPrintWrapped(10, 0, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Lure Index: " .. CurrentLureIndex .. " out of " .. #PlayersLures .. " " .. PlayersLures[CurrentLureIndex]);
lsPrintWrapped(10, 20, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Time: " .. CurrentTime);
lsPrintWrapped(10, 40, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Last [" .. last10 .. "] Fish Caught:");
--Reset this string before showing last 10 fish below. Else the entries will multiply with entries from previous loops/call to this function
last10caught = "";
if #gui_log_fish > 10 then
table.remove(gui_log_fish,1);
end
for i = 1, #gui_log_fish,1 do
lsPrintWrapped(10, 50 + (12*i), 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, gui_log_fish[i]);
last10caught = last10caught .. gui_log_fish[i] .. "\n";
end
lsPrintWrapped(10, winsize[1]-133, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Odd Fish Seen: " .. GrandTotalOdd);
lsPrintWrapped(10, winsize[1]-121, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Unusual Fish Seen: " .. GrandTotalUnusual);
lsPrintWrapped(10, winsize[1]-109, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Strange Fish Seen: " .. GrandTotalStrange);
lsPrintWrapped(10, winsize[1]-97, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "-----------------------------");
lsPrintWrapped(10, winsize[1]-85, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Lures Clicked: " .. GrandTotalLuresUsed);
lsPrintWrapped(10, winsize[1]-73, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Lures Lost: " .. GrandTotalLostLures);
lsPrintWrapped(10, winsize[1]-61, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "-----------------------------");
lsPrintWrapped(10, winsize[1]-49, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Total Casts: " .. GrandTotalCasts);
lsPrintWrapped(10, winsize[1]-37, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Failed Catches: " .. GrandTotalFailed);
lsPrintWrapped(10, winsize[1]-25, 0, lsScreenX - 20, 0.5, 0.5, 0xFFFFFFff, "Fish Caught: " .. GrandTotalCaught .. " (" .. GrandTotaldb .. "db)");
-- Write stats to log file. Everytime the GUI screen is updated, so is the log file.
WriteFishStats("Last Session Hour: " .. CurrentTime .. "\n\nOdd Fish Seen: " .. GrandTotalOdd .. "\nUnusual Fish Seen: " .. GrandTotalUnusual .. "\nStrange Fish Seen: " .. GrandTotalStrange .. "\n---------------------\nLures Clicked: " .. GrandTotalLuresUsed .. "\nLures Lost: " .. GrandTotalLostLures .. " \n---------------------\nTotal Casts: " .. GrandTotalCasts .. "\nFailed Catches: " .. GrandTotalFailed .. "\nFish Caught: " .. GrandTotalCaught .. " (" .. GrandTotaldb .. "db)\n---------------------\n\nLast 10 Fish Caught:\n\n".. last10caught);
end
function doit()
askForWindow("MAIN chat tab MUST be showing and wide enough so that each lines doesn't wrap. Pin up Lures Menu (Self, Skills, Fishing, Use Lures). No other pinned menus can exist. More detailed instructions are included inside the script as comments at top. There are options you can set in the script such as how many casts per lure, what gets written to the log file and more! History will be recorded in FishLog.txt and stats in FishStats.txt. Most errors can be fixed by slightly adjusting/moving your chat screen! Press Shift to continue.");
--Gui_Main();
--Variables Used By Program -- Don't Edit Unless you know what you're doing!
CurrentLure = ""; --Don't Edit
gui_log_fish = {}; --Don't Edit, holds log display
log_fish = {};
CurrentLureIndex=0; -- 1 = First Lure Player Owns in alphabetical order
ChangeLureMenu="";
LastLureMenu="";
DownArrowLocs=nil;
PlayersLures={}; --Don't Edit, Holds Current Player Lures
CurrentTime=""; --Don't Edit, Holds Time Check Value
TotalLuresUsed = 0;
castcount = 0;
--strangecounter = 0;
--These variables were later added for displaying additional info on the screen.
-- Used for the extra reporting/statistics, on screen.
-- Dont Edit Unless you know what you're doing!
GrandTotalCaught = 0;
GrandTotalCasts = 0;
GrandTotaldb = 0;
GrandTotalStrange = 0;
GrandTotalOdd = 0;
GrandTotalUnusual = 0;
GrandTotalLuresUsed = 0;
GrandTotalLostLures = 0;
GrandTotalFailed = 0;
PlayersLures = SetupLureGroup();
CurrentTime = GetTime();
lsSleep(1500);
--Write an entry into log file to show this is a new session
WriteFishLog("[New Session]\n");
while 1 do
checkBreak();
srReadScreen();
--cast = srFindImage("Fishing/Button_Fish.png");
cast = srFindImage("fishicon.png");
if not cast then
error("cannot find fishing button");
end
if castcount == 0 then
--Update counters
castcount = 1;
CurrentLureIndex = CurrentLureIndex +1;
if CurrentLureIndex > #PlayersLures then
--Refresh the Lure window, and reindex it, in case some were lost.
PlayersLures = SetupLureGroup();
CurrentLureIndex = 1;
end
--Update the time if ready, always update before new lure to keep chat/log proper
if TotalLuresUsed == LureChangesToUpdateTimer then
--Update Time
CurrentTime = GetTime();
TotalLuresUsed = 0;
end
--Since no casts been made at all, use a lure
UseLure();
lsSleep(2000);
TotalLuresUsed = TotalLuresUsed + 1;
GrandTotalLuresUsed = GrandTotalLuresUsed + 1;
--update log
gui_refresh();
elseif castcount > TotalCasts then
-- if strangecounter > 0 and strangecounter < AlmostCaughtAttempts then
--we don't reset yet!
-- else
--Reset
castcount=0;
strangecounter = 0;
-- end
else
--Cast
srClickMouseNoMove(cast[0]+3,cast[1]+3);
lsSleep(1000);
checkBreak();
while findchat(castcount - 1) == "lure" do
lsSleep(1000);
checkBreak();
end
castcount = castcount + 1;
GrandTotalCasts = GrandTotalCasts + 1;
--Read Chat
ChatType = findchat();
lsSleep(200);
CurrentLure = string.sub(PlayersLures[CurrentLureIndex],string.find(PlayersLures[CurrentLureIndex],"_")+1,string.len(PlayersLures[CurrentLureIndex])-4);
if ChatType == "nobitlostlure" then
--No fish bit. You also lost your lure.
GrandTotalLostLures = GrandTotalLostLures + 1;
GrandTotalFailed = GrandTotalFailed + 1;
--Reset, skip to next lure
castcount=0;
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "No fish bit. You also lost your lure." .. "\n");
elseif ChatType == "nobit" then
--No fishbit
GrandTotalFailed = GrandTotalFailed + 1;
if LogFails == true then
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "No fish bit." .. "\n");
end
elseif ChatType == "nocatchlostlure" then
--You didn't catch anything. You also lost your lure.
GrandTotalLostLures = GrandTotalLostLures + 1;
GrandTotalFailed = GrandTotalFailed + 1;
--Reset, skip to next lure
castcount=0;
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "You didn\'t catch anything. You also lost your lure." .. "\n");
elseif ChatType == "nocatch" then
--You didn't catch anything.
GrandTotalFailed = GrandTotalFailed + 1;
if LogFails == true then
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "You didn\'t catch anything." .. "\n");
end
elseif ChatType == "alreadyfishing" then
--castcount = castcount-1;
lsSleep(15000); -- Long pause to wait for fishing queue to stop. Somehow it pushed the Fish button twice and now you will cast 2 times in a row.
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "You are already fishing!" .. "\n");
elseif ChatType == "strange" then
--Strange Fish
GrandTotalStrange = GrandTotalStrange + 1;
GrandTotalFailed = GrandTotalFailed + 1;
if LogStrangeUnusual == true then
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "You almost caught a STRANGE fish, but your rod was just too clumbsy." .. "\n");
end
-- if AlmostCaughtAttempts > 0 then
-- strangecounter = strangecounter +1;
-- end
elseif ChatType == "strangelostlure" then
-- Strange Fish and lost lure
GrandTotalStrange = GrandTotalStrange + 1;
GrandTotalLostLures = GrandTotalLostLures + 1;
GrandTotalFailed = GrandTotalFailed + 1;
--Reset, skip to next lure
castcount=0;
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "You almost caught a STRANGE fish, but your rod was just too clumbsy. You also lost your lure." .. "\n");
-- if AlmostCaughtAttempts > 0 then
-- strangecounter = strangecounter +1;
-- end
elseif ChatType == "unusual" then
-- Unusual Fish
GrandTotalUnusual = GrandTotalUnusual + 1;
GrandTotalFailed = GrandTotalFailed + 1;
if LogStrangeUnusual == true then
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "You almost caught an UNUSUAL fish, but you were not quick enough." .. "\n");
end
-- if AlmostCaughtAttempts > 0 then
-- strangecounter = strangecounter +1;
-- end
-- Can't uncomment below elseif statement until we get a screenshot of a message of you were not quick enough. You also lost your lure.
-- This would need to be added to Fishing_Func.inc , in the Chat_Types {array} along with adding Chatlog_AlmostUnusualLostlure.png). Add above "unusual" line in the array
--elseif ChatType == "unusuallostlure" then
-- Unusual Fish
--GrandTotalUnusual = GrandTotalUnusual + 1;
--GrandTotalLostLures = GrandTotalLostLures + 1;
--GrandTotalFailed = GrandTotalFailed + 1;
--if LogStrangeUnusual == true then
--WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "You almost caught an UNUSUAL fish, but you were not quick enough." .. "\n");
--end
-- if AlmostCaughtAttempts > 0 then
-- strangecounter = strangecounter +1;
-- end
elseif ChatType == "odd" then
-- Odd Fish
GrandTotalOdd = GrandTotalOdd + 1;
GrandTotalFailed = GrandTotalFailed + 1;
if LogOdd == true then
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "You almost caught an ODD fish, but were too late recognizing the bite." .. "\n");
end
elseif ChatType == "oddlostlure" then
-- Odd Fish and lost lure
GrandTotalOdd = GrandTotalOdd + 1;
GrandTotalLostLures = GrandTotalLostLures + 1;
GrandTotalFailed = GrandTotalFailed + 1;
--Reset, skip to next lure
castcount=0;
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "You almost caught an ODD fish, but were too late recognizing the bite. You also lost your lure." .. "\n");
elseif ChatType == "carry" then
--chat lines are messed up now
castcount=0;
elseif ChatType == "caught" or ChatType == "caughtlostlure" then
Fish = ChatReadFish();
table.insert(gui_log_fish,Fish);
if ChatType == "caughtlostlure" then
GrandTotalLostLures = GrandTotalLostLures + 1;
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "Though you lost your lure, you did catch a " .. Fish .. "\n");
-- This Needs Check for new lure. This will cause a error if not.
--Reset, skip to next lure
castcount=0;
else
WriteFishLog("[" .. CurrentTime .. "]\t[" .. CurrentLure .. "]\t" .. "Caught a " .. Fish .. "\n");
end
--gui_refresh();
if SkipCommon == true then
FishType = string.sub(Fish,string.find(Fish,",") + 1);
if FishType == "Abdju" or FishType == "Chromis" or FishType == "Catfish" or FishType == "Carp" or FishType == "Perch" or FishType == "Phagrus" or FishType == "Tilapia" then
--Skip it
castcount=0;
end
end
gui_refresh();
end
gui_refresh();
end
gui_refresh();
end
end
|
| New Raeli Oven Monitor (IN TESTING) |
|---|
loadfile("luaScripts/screen_reader_common.inc")();
loadfile("luaScripts/common.inc")();
loadfile("luaScripts/ui_utils.inc")();
askText = singleLine([[
Raeli Color Monitor v1.1b (edit by Selune) --
Make sure the Raeli Oven is pinned, then select the ATITD window and press shift.
]]);
stop_at_CB = false;
take_screenshots = true;
stop_at_color = "White";
confidence_threshold = 15;
saved_x = 0;
saved_y = 0;
go_now = false;
color_names = {"AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "Burlywood", "CadetBlue", "Carrot", "Chartreuse", "Chocolate", "Coral", "CornflowerBlue", "Cornsilk", "Crimson", "DarkBlue", "DarkCyan", "DarkGoldenrod", "DarkGray", "DarkGreen", "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "DarkOrange", "DarkOrchid", "DarkRed", "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue", "DarkSlateGray", "DarkTurquoise", "DarkViolet", "DeepPink", "DeepSkyBlue", "DimGray", "DodgerBlue", "Feldspar", "FireBrick", "FloralWhite", "ForestGreen", "Fuchsia", "Gainsboro", "GhostWhite", "Gold", "Goldenrod", "Gray", "Green", "GreenYellow", "Honeydew", "HotPink", "IndianRed", "Indigo", "Ivory", "Khaki", "Lavender", "LavenderBlush", "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral", "LightCyan", "LightGoldenrodYellow", "LightGreen", "LightGrey", "LightPink", "LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateBlue", "LightSlateGray", "LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Maroon ", "MediumAquamarine", "MediumBlue ", "MediumOrchid", "MediumPurple", "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise", "MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose", "Moccasin", "NavajoWhite", "Navy ", "OldLace", "Olive", "OliveDrab", "Orange", "OrangeRed", "Orchid", "PaleGoldenrod", "PaleGreen", "PaleTurquoise", "PaleVioletRed", "PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple ", "Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown", "SeaGreen", "Seashell", "Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGray", "Snow", "SpringGreen", "SteelBlue ", "Tan", "Teal", "Thistle", "Tomato", "Turquoise", "Violet", "VioletRed", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen"};
color_values = {0xF0F8FF, 0xFAEBD7, 0x00FFFF, 0x7FFFD4, 0xF0FFFF, 0xF5F5DC, 0xFFE4C4, 0x000000, 0xFFEBCD, 0x0000FF, 0x8A2BE2, 0xA52A2A, 0xDEB887, 0x5F9EA0, 0xE07020, 0x7FFF00, 0xD2691E, 0xFF7F50, 0x6495ED, 0xFFF8DC, 0xDC143C, 0x00008B, 0x008B8B, 0xB8860B, 0xA9A9A9, 0x006400, 0xBDB76B, 0x8B008B, 0x556B2F, 0xFF8C00, 0x9932CC, 0x8B0000, 0xE9967A, 0x8FBC8F, 0x483D8B, 0x2F4F4F, 0x00CED1, 0x9400D3, 0xFF1493, 0x00BFFF, 0x696969, 0x1E90FF, 0xD19275, 0xB22222, 0xFFFAF0, 0x228B22, 0xFF00FF, 0xDCDCDC, 0xF8F8FF, 0xFFD700, 0xDAA520, 0x808080, 0x008000, 0xADFF2F, 0xF0FFF0, 0xFF69B4, 0xCD5C5C, 0x4B0082, 0xFFFFF0, 0xF0E68C, 0xE6E6FA, 0xFFF0F5, 0x7CFC00, 0xFFFACD, 0xADD8E6, 0xF08080, 0xE0FFFF, 0xFAFAD2, 0x90EE90, 0xD3D3D3, 0xFFB6C1, 0xFFA07A, 0x20B2AA, 0x87CEFA, 0x8470FF, 0x778899, 0xB0C4DE, 0xFFFFE0, 0x00FF00, 0x32CD32, 0xFAF0E6, 0x800000, 0x66CDAA, 0x0000CD, 0xBA55D3, 0x9370DB, 0x3CB371, 0x7B68EE, 0x00FA9A, 0x48D1CC, 0xC71585, 0x191970, 0xF5FFFA, 0xFFE4E1, 0xFFE4B5, 0xFFDEAD, 0x000080, 0xFDF5E6, 0x808000, 0x6B8E23, 0xFFA500, 0xFF4500, 0xDA70D6, 0xEEE8AA, 0x98FB98, 0xAFEEEE, 0xDB7093, 0xFFEFD5, 0xFFDAB9, 0xCD853F, 0xFFC0CB, 0xDDA0DD, 0xB0E0E6, 0x800080, 0xFF0000, 0xBC8F8F, 0x4169E1, 0x8B4513, 0xFA8072, 0xF4A460, 0x2E8B57, 0xFFF5EE, 0xA0522D, 0xC0C0C0, 0x87CEEB, 0x6A5ACD, 0x708090, 0xFFFAFA, 0x00FF7F, 0x4682B4, 0xD2B48C, 0x008080, 0xD8BFD8, 0xFF6347, 0x40E0D0, 0xEE82EE, 0xD02090, 0xF5DEB3, 0xFFFFFF, 0xF5F5F5, 0xFFFF00, 0x9ACD32};
-- Decimal to Hex conversion
function DEC_HEX(IN)
local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
while IN>0 do
I=I+1
IN,D=math.floor(IN/B),math.mod(IN,B)+1
OUT=string.sub(K,D,D)..OUT
end
return OUT
end
--Color Conversions
function rgb2hsl(src_r, src_g, src_b)
local h, s, l, d;
src_r = src_r / 255;
src_g = src_g / 255;
src_b = src_b / 255;
local max_rgb = math.max(src_r, src_g, src_b);
local min_rgb = math.min(src_r, src_g, src_b);
l = (max_rgb + min_rgb) / 2;
if(max_rgb == min_rgb) then
h = 0; --achromatic
s = 0;
else
d = max_rgb - min_rgb;
if l > 0.5 then
s = d / (2 - max_rgb - min_rgb);
else
s = d / (max_rgb + min_rgb);
end
if src_g > src_b then
if src_r > src_g then
h = (src_g - src_b) / d;
else
h = (src_b - src_r) / d + 2;
end
else
if src_r > src_g then
h = (src_g - src_b) / d + 6;
else
h = (src_r - src_g) / d + 4;
end
end
h = h / 6;
end
if h == nil then
error "NO H";
end
if s == nil then
error ("NO S D:" .. d);
end
if l == nil then
error "NO L";
end
return h, s, l;
end
function rgb2lab(src_r, src_g, src_b)
--R from 0 to 255
--G from 0 to 255
--B from 0 to 255
local r = src_r/255;
local g = src_g/255;
local b = src_b/255;
if (r > 0.04045) then
r = math.pow((r + 0.055) / 1.055, 2.4);
else
r = r / 12.92;
end
if ( g > 0.04045) then
g = math.pow((g + 0.055) / 1.055, 2.4);
else
g = g / 12.92;
end
if (b > 0.04045) then
b = math.pow((b + 0.055) / 1.055, 2.4);
else
b = b / 12.92;
end
r = r * 100;
g = g * 100;
b = b * 100;
local x = r * 0.4124 + g * 0.3576 + b * 0.1805;
local y = r * 0.2126 + g * 0.7152 + b * 0.0722;
local z = r * 0.0193 + g * 0.1192 + b * 0.9505;
x = x / 95.047;
y = y / 100.000;
z = z / 108.883;
if ( x > 0.008856 ) then
x = math.pow( x , 1/3 );
else
x = ( 7.787 * x ) + ( 16/116 );
end
if ( y > 0.008856 ) then
y = math.pow( y , 1/3 );
else
y = ( 7.787 * y ) + ( 16/116 );
end
if ( z > 0.008856 ) then
z = math.pow( z , 1/3 );
else
z = ( 7.787 * z ) + ( 16/116 );
end
local lab_l = ( 116 * y ) - 16;
local lab_a = 500 * ( x - y );
local lab_b = 200 * ( y - z );
return lab_l, lab_a, lab_b;
end
--Get nearest color name
function nearestColor(px)
local rgb_r, rgb_g, rgb_b, tst_r, tst_g, tst_b, test_px;
local lab_l, lab_a, lab_b, lab_tst_l, lab_tst_a, lab_tst_b;
local hsl_h, hsl_s, hsl_l, hsl_tst_h, hsl_tst_s, hsl_tst_l;
local offset, best_name, best_offset, next_best_offset, confidence;
best_offset = 100000;
next_best_offset = 1000000;
rgb_r = ((math.floor(px/256/256/256) % 256) - 7) * 255/248;
rgb_g = ((math.floor(px/256/256) % 256) - 7) * 255/248;
rgb_b = ((math.floor(px/256) % 256) - 6) * 255/248;
lab_l, lab_a, lab_b = rgb2lab(rgb_r, rgb_g, rgb_b);
hsl_h, hsl_s, hsl_l = rgb2hsl(rgb_r, rgb_g, rgb_b);
for i=1, #color_names do
checkBreak();
test_px = color_values[i];
tst_r = (math.floor(test_px/256/256) % 256);
tst_g = (math.floor(test_px/256) % 256);
tst_b = (math.floor(test_px) % 256);
lab_tst_l, lab_tst_a, lab_tst_b = rgb2lab(tst_r, tst_g, tst_b);
hsl_tst_h, hsl_tst_s, hsl_tst_l = rgb2hsl(tst_r, tst_g, tst_b);
---- Different methods to determine "distance" from the ideal colors. Change these to test different options.
--offset = math.abs(rgb_r - tst_r) + math.abs(rgb_g - tst_g) + math.abs(rgb_b - tst_b);
--offset = math.max(math.max((math.abs(rgb_r - tst_r)), math.abs(rgb_g - tst_g)), math.abs(rgb_b - tst_b));
offset = (rgb_r - tst_r)^2 + (rgb_g - tst_g)^2 + (rgb_b - tst_b)^2;
--offset = math.abs(lab_l - lab_tst_l) + math.abs(lab_a - lab_tst_a) + math.abs(lab_b - lab_tst_b);
--offset = (lab_l - lab_tst_l)^2 + (lab_a - lab_tst_a)^2 + (lab_b - lab_tst_b)^2;
--offset = math.max(math.max((math.abs(lab_l - lab_tst_l)), math.abs(lab_a - lab_tst_a)), math.abs(lab_b - lab_tst_b));
--offset = math.abs(hsl_h - hsl_tst_h) + math.abs(hsl_s - hsl_tst_s) + math.abs(hsl_l - hsl_tst_l);
--offset = (hsl_h - hsl_tst_h)^2 + (hsl_s - hsl_tst_s)^2 + (hsl_l - hsl_tst_l)^2;
--offset = math.max(math.max((math.abs(hsl_h - hsl_tst_h)), math.abs(hsl_s - hsl_tst_s)), math.abs(hsl_l - hsl_tst_l));
if (offset < next_best_offset) then
if (offset < best_offset) then
next_best_offset = best_offset;
best_offset = offset;
best_name = color_names[i]; -- .. " Hex: " .. DEC_HEX(color_values[i]);
else
next_best_offset = offset;
end
confidence = ((next_best_offset - best_offset) / best_offset) * 100;
end
end
return best_name, math.floor(confidence);
end
--Check pixel against target
function checkColor(px)
local color_name, confidence;
color_name, confidence = nearestColor(px);
if (color_name:upper() == stop_at_color:upper()) then
return true, confidence;
else
return false, 0;
end
end
-- optional message
function askForPixel()
local is_done = false;
local have_coords = false;
local color_found = false;
local color_guess = "NONE";
local tst_r, tst_g, tst_b, rgb_r, rgb_g, rgb_b;
local confidence = 0;
-- Display message until shift is held
while not go_now do
checkBreak();
srReadScreen();
y = 0;
mouse_x, mouse_y = srMousePos();
if not have_coords then
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, 0xFFFFFFff,
"Mouse over one of the Raeli Oven color pixels and press Shift.");
if lsShiftHeld() then
saved_x = mouse_x;
saved_y = mouse_y;
have_coords = true;
end
else
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, 0xFFFFFFff,
"Coords chosen, press 'Reset' to change or 'Do It' to start.");
end
y = y + 40;
if have_coords then
px = srReadPixel(saved_x, saved_y);
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, 0xffffff,
saved_x .. ", " .. saved_y);
else
px = srReadPixel(mouse_x, mouse_y);
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, 0xB0B0B0ff,
mouse_x .. ", " .. mouse_y);
end
y = y + 15;
color_guess, confidence = nearestColor(px);
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px,
"(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ") Hex: " .. DEC_HEX(math.floor((px/256) % 16777216)));
y = y + 20;
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Best guess: " .. color_guess);
y = y + 15;
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Confidence: " .. confidence .. " (higher is better)");
-- Testing other methods of grabbing the pixel, making sure RGBA values match
-- srReadScreen();
-- px2 = srReadPixelFromBuffer(mouse_x, mouse_y);
-- lsPrintWrapped(0, 80, 1, lsScreenX, 0.7, 0.7, 0xB0B0B0ff,
-- mouse_x .. ", " .. mouse_y .. " = " .. (math.floor(px2/256/256/256) % 256) .. "," .. (math.floor(px2/256/256) % 256) .. "," .. (math.floor(px2/256) % 256) .. "," .. (px2 % 256) );
-- lsButtonText(lsScreenX - 110, lsScreenY - 90, 0, 100, px, "test1");
-- lsButtonText(lsScreenX - 110, lsScreenY - 60, 0, 100, px2, "test2");
y = y + 20;
take_screenshots = lsCheckBox(15, y, z, 0xffffffff, " Take Screenshots", take_screenshots);
y = y + 20;
stop_at_CB = lsCheckBox(15, y, z, 0xffffffff, " Stop at Color", stop_at_CB);
if stop_at_CB then
y = y + 25;
is_done = false;
color_found = false;
-- Edit box and text display
lsPrint(10, y, z, 0.7, 0.7, 0xFFFFFFff, "Desired Color:");
y = y + 20;
-- lsEditBox returns two different things (a state and a value)
is_done, stop_at_color = lsEditBox("Desired Color:", 10, y, z, 250, 30, 0.7, 0.7, 0x000000ff, "White");
--dropdown_color_cur_value = lsDropdown("ColorDropDown1", 5, y, 0, 200, dropdown_color_cur_value, color_names);
for i=0, #color_names do
if stop_at_color and color_names[i] then
if (stop_at_color:upper() == (color_names[i]):upper()) then
color_found = true;
end
end
end
if not color_found then
lsPrint(130, y - 20, z, 0.7, 0.7, 0xFF0000ff, "No such color");
end
y = y + 35;
lsPrint(5, y, 0, 0.6, 0.6, 0xffffffff, "Confidence Required:");
is_done, confidence_threshold = lsEditBox("confthresh", 150, y, 0, 50, 30, 0.7, 0.7, 0x000000ff, confidence_threshold);
confidence_threshold = tonumber(confidence_threshold);
if not confidence_threshold then
lsPrint(10, y+17, 10, 0.4, 0.4, 0xFF2020ff, "MUST BE A NUMBER");
confidence_threshold = 10;
end
else
is_done = true;
color_found = true;
end
if have_coords then
if color_found then
if lsButtonText(10, lsScreenY - 30, 0, 80, 0xFFFFFFff, "Do It") then
go_now = true;
end
end
if lsButtonText(100, lsScreenY - 30, 0, 80, 0xFFA500ff, "Reset") then
have_coords = false;
end
end
if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100, 0xFFFFFFff, "Exit") then
error "Canceled";
end
lsDoFrame();
end
-- Wait for shift to be released
while lsShiftHeld() do end;
xyWindowSize = srGetWindowSize();
end
function doit()
askForWindow(askText);
while lsShiftHeld() do
-- Make user release shift key
lsCheckBreak();
end
askForPixel();
local t0 = lsGetTimer();
local px = 0;
local index=0;
local color_name, confidence;
while 1 do
local y = 0;
checkBreak();
lsSleep(100);
srReadScreen();
new_px = srReadPixel(saved_x, saved_y);
local t = (lsGetTimer() - t0) / 1000 / 60;
t = math.floor(t*10 + 0.5)/10;
local t_string = t;
if not (new_px == px) then
index = index+1;
if take_screenshots then
srSaveLastReadScreen("screen_" .. index .. "_" .. t_string .. ".png");
end
px = new_px;
if stop_at_CB then
color_name, confidence = nearestColor(px);
if (color_name:upper() == stop_at_color:upper()) then
if confidence > confidence_threshold then
clickAllText("Interrupt");
lsPlaySound("Complete.wav");
error ("Stopped burn at: " .. stop_at_color .. " Confidence: " .. confidence);
else
for i = 1, 3 do
lsPlaySound("Clank.wav");
lsSleep(50);
end
end
else
lsPlaySound("Clank.wav");
end
else
lsPlaySound("Clank.wav");
end
end
y = y + 5;
lsPrintWrapped(5, y, 1, lsScreenX - 10, 0.7, 0.7, 0xFFFFFFff,
"Screen: " .. index .. " Timer: " .. t_string);
y = y + 15;
lsPrintWrapped(5, y, 1, lsScreenX - 10, 0.7, 0.7, 0xFFFFFFff,
"Color: " .. color_name .. " Confidence: " .. confidence);
y = y + 30;
lsPrintWrapped(5, y, 1, lsScreenX - 10, 0.7, 0.7, 0xFFFFFFff,
"(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ") Hex: " .. DEC_HEX(math.floor((new_px/256) % 16777216)));
if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100, 0xFFFFFFff, "Exit") then
error "Canceled";
end
lsDoFrame();
end
end
|