```mod_name = "bwhittas_bonsai" function register() return { name = mod_name, hooks = {"click"} } end function init() api_create_log("init", "Bwhitta's Bonsai is logging this message.") api_set_devmode(true) --Adds items, npcs, etc create_bonsai_pot() return "Success" end function click() api_give_money(420) end function create_bonsai_pot() -- Creates a menu object api_define_menu_object({ id = "bonsai_pot", name = "Bonsai Pot", category = "Tools", tooltip = "Automatically grows and harvests wood", shop_key = false, shop_buy = 0, shop_sell = 0, layout = { {76, 17, "Output"} }, buttons = {"Help", "Target", "Close"}, info = { {"1. Bonsai Output", "RED"} }, tools = {"mouse1", "hammer1"}, placeable = true }, "sprites/bonsai_pot_item.png", "sprites/bonsai_pot_menu.png", { define = "bonsai_pot_define", -- defined below as a function draw = "bonsai_pot_draw", tick = "bonsai_pot_tick" -- defined below as a function }) end function bonsai_pot_define(menu_id) -- create initial props api_dp(menu_id, "working", true) api_dp(menu_id, "p_start", 0) api_dp(menu_id, "p_end", 1) -- create gui for the menu api_define_gui(menu_id, "progress_bar", 49, 20, "bonsai_pot_tooltip", "sprites/bonsai_pot_gui_arrow.png") -- save gui sprite ref for later api_dp(menu_id, "progress_bar_sprite", api_get_sprite("bonsai_pot_progress_bar")) -- add our p_start and p_end props to the default _fields list so the progress is saved -- any keys in _fields will get their value saved when the game saves, and loaded when the game loads again fields = {"p_start", "p_end"} fields = api_sp(menu_id, "_fields", fields) end function bonsai_pot_tick(menu_id) -- handle countdown if working if api_gp(menu_id, "working") == true then -- add to counter api_sp(menu_id, "p_start", api_gp(menu_id, "p_start") + 0.1) -- if we hit the end, i.e. 10s have passed if api_gp(menu_id, "p_start") >= api_gp(menu_id, "p_end") then -- reset the counter api_sp(menu_id, "p_start", 0) -- outputs logs local outputs = api_slot_match_range(menu_id, {"log", ""}, {1}, false) for i, v in ipairs(outputs) do if v["item"] == "log" and v["count"] < 99.0 then api_slot_incr(v["id"], 1) break end if v["item"] == "" then api_slot_set(v["id"], "log", 1) break end end end end if api_gp(menu_id, "working") == false then api_sp(menu_id, "working", true) end end -- the draw script lets us draw custom things on the menu when it's open -- here we can draw GUI elements or buttons or other things -- you should avoid putting complex logic in the draw script function bonsai_pot_draw(menu_id) -- get camera cam = api_get_cam() -- draw gui progress here gui = api_get_inst(api_gp(menu_id, "progress_bar")) spr = api_gp(menu_id, "progress_bar_sprite") -- draw arrow "progress" block then cover up with arrow hole -- arrow sprite is 47x10 gx = gui["x"] - cam["x"] gy = gui["y"] - cam["y"] progress = (api_gp(menu_id, "p_start") / api_gp(menu_id, "p_end") * 66) api_draw_sprite_part(spr, 2, 0, 0, progress, 20, gx, gy) api_draw_sprite(spr, 1, gx, gy) -- draw highlight if highlighted if api_get_highlighted("ui") == gui["id"] then api_draw_sprite(spr, 0, gx, gy) end end function bonsai_gui_tooltip(menu_id) progress = math.floor((api_gp(menu_id, "p_start") / api_gp(menu_id, "p_end")) * 100) percent = tostring(progress) .. "%" return { {"Progress", "FONT_WHITE"}, {percent, "FONT_BGREY"} } end```