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
 
(4 intermediate revisions by the same user not shown)
Line 833: Line 833:
 
 
 
gui_refresh();
 
gui_refresh();
 +
end
 +
end
 +
</pre>
 +
{{Collapse bottom}}
 +
 +
{{Collapse top|title=New Raeli Oven Monitor (IN TESTING v3)}}
 +
<pre>
 +
loadfile("luaScripts/screen_reader_common.inc")();
 +
loadfile("luaScripts/common.inc")();
 +
loadfile("luaScripts/ui_utils.inc")();
 +
 +
askText = singleLine([[
 +
  Raeli Color Monitor v1.1c (edit by Selune) --
 +
  Make sure the Raeli Oven is pinned, 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/247;
 +
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);
 +
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 (Remove any spaces)");
 +
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);
 +
askForPixel();
 +
 +
local t0 = lsGetTimer();
 +
local px = 0;
 +
local index=0;
 +
local color_name, confidence;
 +
local do_screenshot, do_end_burn;
 +
while 1 do
 +
local y = 0;
 +
do_screenshot = false;
 +
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;
 +
px = new_px;
 +
color_name, confidence = nearestColor(px);
 +
if take_screenshots then
 +
do_screenshot = true;
 +
end
 +
 +
if stop_at_CB then
 +
if (color_name:upper() == stop_at_color:upper()) then
 +
if confidence > confidence_threshold then
 +
do_end_burn = true;
 +
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();
 +
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
 +
 +
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
 +
 +
srShowImageDebug("CUSTOM", 8, 8, 1, 3);
 +
lsDoFrame();
 +
end
 +
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
 +
error "Canceled";
 +
end
 +
 +
srShowImageDebug("CUR_STATS", 8, 8, 1, 3);
 +
lsDoFrame();
 
end
 
end
 
end
 
end
 
</pre>
 
</pre>
 
{{Collapse bottom}}
 
{{Collapse bottom}}

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.