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
 
(3 intermediate revisions by the same user not shown)
Line 838: Line 838:
 
{{Collapse bottom}}
 
{{Collapse bottom}}
  
{{Collapse top|title=New Raeli Oven Monitor (IN TESTING)}}
+
{{Collapse top|title=New Raeli Oven Monitor (IN TESTING v3)}}
 
<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.1a (edit by Selune) --
+
   Raeli Color Monitor v1.1c (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, 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/247;
rgb_b = (math.floor(px/256) % 256);
+
rgb_g = ((math.floor(px/256/256) % 256) - 7) * 255/247;
 +
rgb_b = ((math.floor(px/256) % 256) - 5.5) * 255/247;
 
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 = (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
+
if (offset < best_offset) then
best_name = color_names[i] .. "  Hex: " .. DEC_HEX(color_values[i]);
+
next_best_offset = best_offset;
best_offset = 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
 
return false;
 
 
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, "Best guess: " .. color_guess);
+
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Confidence: " .. confidence .. " (higher is better)");
y = y + 30;
 
lsPrintWrapped(0, y, 1, lsScreenX, 0.7, 0.7, px, "Dec: " .. math.floor((px/256) % 16777216) .. "  Hex: " .. DEC_HEX(math.floor((px/256) % 16777216)));
 
 
 
 
-- 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
 
 
y = y + 30;
 
 
if not color_found then
 
if not color_found then
lsPrint(10, y, z, 0.7, 0.7, 0xFF0000ff, "No such color");
+
lsPrint(130, y - 20, z, 0.7, 0.7, 0xFF0000ff, "No such color (Remove any spaces)");
 
end
 
end
 
 
srReadScreen();
+
y = y + 35;
+
lsPrint(5, y, 0, 0.6, 0.6, 0xffffffff, "Confidence Required:");
y = y + 30;
+
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,153: Line 1,167:
 
function doit()
 
function doit()
 
askForWindow(askText);
 
askForWindow(askText);
while lsShiftHeld() do
 
-- Make user release shift key
 
lsCheckBreak();
 
end
 
 
 
askForPixel();
 
askForPixel();
 
 
Line 1,163: Line 1,172:
 
local px = 0;
 
local px = 0;
 
local index=0;
 
local index=0;
 +
local color_name, confidence;
 +
local do_screenshot, do_end_burn;
 
while 1 do
 
while 1 do
 +
local y = 0;
 +
do_screenshot = false;
 
checkBreak();
 
checkBreak();
 
lsSleep(100);
 
lsSleep(100);
 
srReadScreen();
 
srReadScreen();
new_px = srReadPixel(mouse_x, mouse_y);
+
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,173: Line 1,186:
 
if not (new_px == px) then
 
if not (new_px == px) then
 
index = index+1;
 
index = index+1;
 +
px = new_px;
 +
color_name, confidence = nearestColor(px);
 
if take_screenshots then
 
if take_screenshots then
srSaveLastReadScreen("screen_" .. index .. "_" .. t_string .. ".png");
+
do_screenshot = true;
 
end
 
end
px = new_px;
+
 
if stop_at_CB then
 
if stop_at_CB then
if checkColor(px) then
+
if (color_name:upper() == stop_at_color:upper()) then
clickAllText("Interrupt");
+
if confidence > confidence_threshold then
lsPlaySound("Complete.wav");
+
do_end_burn = true;
break;
+
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
 +
 +
 +
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();
 +
srReadScreen();
 +
if do_screenshot then
 +
srSaveLastReadScreen("screen_" .. index .. "_" .. t_string .. ".png");
 +
end
 +
 +
if do_end_burn then
 +
clickAllText("Interrupt");
 +
lsPlaySound("Complete.wav");
 +
error ("Stopped burn at: " .. stop_at_color .. "  Confidence: " .. confidence);
 +
end
 +
end
 +
end
 +
</pre>
 +
{{Collapse bottom}}
 +
 +
{{Collapse top|title=Food Timer (IN TESTING v1)}}
 +
<pre>
 +
-- Food stat timer, made by Selune. Version 1.
 +
 +
loadfile("luaScripts/screen_reader_common.inc")();
 +
loadfile("luaScripts/ui_utils.inc")();
 +
 +
per_click_delay = 10;
 +
log_lines = {};
 +
num_log_lines = 10;
 +
food_name = "Blocker";
 +
function log(msg)
 +
lsPrintln(msg);
 +
if #log_lines == num_log_lines then
 +
for i=1,num_log_lines-1 do
 +
log_lines[i] = log_lines[i+1];
 +
end
 +
log_lines[num_log_lines] = msg;
 +
else
 +
log_lines[#log_lines+1] = msg;
 +
end
 +
end
 +
 +
local last_time = 0;
 +
function timedLog(new_time)
 +
local timeDiff;
 +
 +
timeDiff = new_time - last_time;
 +
last_time = new_time;
 +
 +
log(food_name .. " -- Duration: " .. math.floor(timeDiff / 1000 / 60) .. ":" .. math.mod(timeDiff / 1000, 60));
 +
end
 +
 +
function askForImage()
 +
haveCoords = false;
 +
go_now = false;
 +
while not go_now do
 +
checkBreak();
 +
srReadScreen();
 +
mouse_x, mouse_y = srMousePos();
 +
local y = 10;
 +
local x = 40;
 +
 +
if not have_coords then
 +
lsPrintWrapped(x, y, 1, lsScreenX - x - 10, 0.7, 0.7, 0xFFFFFFff,
 +
"Put your mouse in the top left of the Strength stat NUMBER. You should see all stat values in the preview. It doesn't have to be perfect!");
 +
 +
srMakeImage("CUSTOM", mouse_x, mouse_y, 10, 100);
 +
if lsShiftHeld() then
 +
saved_x = mouse_x;
 +
saved_y = mouse_y;
 +
have_coords = true;
 +
end
 +
else
 +
lsPrintWrapped(x, y, 1, lsScreenX - x - 10, 0.7, 0.7, 0xFFFFFFff,
 +
"Coords chosen, press 'Reset' to change or 'Do It' to start.");
 +
srMakeImage("CUSTOM", saved_x, saved_y, 10, 100);
 +
end
 +
 +
if have_coords then
 +
if lsButtonText(10, lsScreenY - 30, 0, 80, 0xFFFFFFff, "Do It") then
 +
go_now = true;
 
end
 
end
 
 
lsPlaySound("Clank.wav");
+
if lsButtonText(100, lsScreenY - 30, 0, 80, 0xFFA500ff, "Reset") then
 +
have_coords = false;
 +
end
 +
end
 +
 +
if lsButtonText(lsScreenX - 100, lsScreenY - 30, 0, 80, 0xFFFFFFff, "Exit") then
 +
error "Canceled";
 
end
 
end
 
 
lsPrintWrapped(0, 0, 1, lsScreenX, 1, 1, 0xFFFFFFff,
+
srShowImageDebug("CUSTOM", 8, 8, 1, 3);
" Color: " .. DEC_HEX(new_px) .. " screen: " .. index .. " timer: " .. t_string);
+
lsDoFrame();
lsPrintWrapped(0, 60, 1, lsScreenX, 0.7, 0.7, 0xFFFFFFff,
+
end
"(" .. (math.floor(px/256/256/256) % 256) .. "," .. (math.floor(px/256/256) % 256) .. "," .. (math.floor(px/256) % 256) .. "," .. (px % 256) .. ")" );
+
end
 +
 
 +
function doit()
 +
askForWindow("Food Timer - Records how long a particular meal lasts, down to the half-second. Works even with aqueduct or other already-running food buffs (So eat blocker first!) Made by Selune!");
 +
askForImage();
 +
srMakeImage("CUR_STATS", saved_x, saved_y, 10, 100);
 +
 +
for i=1, 20 do
 +
log("...");
 +
end
 +
 +
local t0 = lsGetTimer();
 +
local new_time;
 +
while 1 do
 +
local i = 0;
 +
local y = 5;
 +
local x = 40;
 +
local is_done = false;
 +
new_time = lsGetTimer();
 +
checkBreak();
 +
lsSleep(100);
 +
srReadScreen();
 +
 +
lsPrintWrapped(x, y, 1, lsScreenX - x - 10, 1, 1, 0xFFFFFFff,
 +
"Now recording, eat up!");
 +
 +
y = y + 25;
 +
lsPrintWrapped(x, y, 1, lsScreenX - x - 10, 1, 1, 0xFF2020ff,
 +
"Remember to block first!");
 +
 +
y = y + 30;
 +
lsPrintWrapped(x, y, 1, lsScreenX - x - 10, 0.7, 0.7, 0xC0C0C0ff,
 +
"Name (for log):");
 +
 +
y = y + 20;
 +
is_done, food_name = lsEditBox("Food Name:", x, y, z, 250, 30, 0.7, 0.7, 0x000000ff, food_name);
 +
 +
if not srFindImageInRange("CUR_STATS", saved_x, saved_y, 10, 100) then
 +
lsSleep(500);
 +
srReadScreen();
 +
srMakeImage("CUR_STATS", saved_x, saved_y, 10, 100);
 +
for i = 1, 3 do
 +
lsPlaySound("Clank.wav");
 +
lsSleep(100);
 +
end
 +
timedLog(new_time - t0);
 +
end
 +
 +
y = y + 30;
 +
if #log_lines then
 +
for i=1, #log_lines do
 +
lsPrint(x + 10, y, 1, 0.7, 0.7, 0x808080ff, log_lines[i]);
 +
y = y + 15;
 +
end
 +
end
 
 
 
if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100, 0xFFFFFFff, "Exit") then
 
if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100, 0xFFFFFFff, "Exit") then
 
error "Canceled";
 
error "Canceled";
 
end
 
end
 +
 +
srShowImageDebug("CUR_STATS", 8, 8, 1, 3);
 
lsDoFrame();
 
lsDoFrame();
 
end
 
end

Latest revision as of 21:04, 9 February 2013

Selune's Macros have been updated to the TaleScripts repository. Please leave any ideas for improvements or new macros here.