Icons

Icons is a cool GUI way to create on / off switches or clickable buttons that link to bot features, it was added in version 1.8.
Icons support macro and hotkeys as a callback function, the icon can be dragged anywhere on screen by holding CTRL.

e25ebb54b0b20cfe21fd2651e8ca3710.gif

Prototypes
addIcon(id, options, callback)
Parameters
    • id: icon id on client widget, must be unique for every icon. It is used to store icon status and position in storage.
    • options: icon controling options.
    • callback: the function being called on click event. can be function() or function(icon, isOn).
      • icon: icon widget object.
      • isOn: current icon state Boolean.

Available Options:

item
: the item icon id can set item count by {id = ItemID, count = ItemCount}.
outfit: outfit object contains outfit type and colors
text: text to display below the icon
x: x location on client window (percent, 0.0-1.0 range)
y: y location on client window (percent, 0.0-1.0 range)
hotkey: hotkey to control the icon button instead of mouse clicking it.
switchable: if the logic is on/off button (like singlehotkey instead of hotkey). is it's true callback is automatically called once after icon creation (to report it's status: on/off). default is true
movable: can the item be dragged from it's place?
phantom: can the item float above game screen?

Usage
-- trash 9x9 tiles
addIcon("trash", {item={id = 3492, count = 100}, switchable=false}, function()
  for x=-3, 3 do
    for y=-3, 3 do
      local worms = findItem(3492) -- find some worms
      if worms then
        g_game.move(worms, {x = posx() + x, y = posy() + y, z = posz()}, 1) -- drop them around
      end
    end
  end
end)

Macro as Icon
addIcon("change gold", {item={id = 3043, count = 100}}--[[ icon options ]], macro(100, "change gold", function()
  local containers = getContainers()
  for i, container in pairs(containers) do
    for j, item in ipairs(container:getItems()) do
      if item:isStackable() and (item:getId() == 3035 or item:getId() == 3031) and item:getCount() == 100 then
        g_game.use(item)
        return
      end
    end
  end
end))
-- toggle macro using icon
local sdTarget = macro(1000, "SD Target", function() -- sd target macro
  local target = g_game.getAttackingCreature()
  if target then
    useWith(3155, target)
  end
end)

-- Item icon
addIcon("sdTarget", {item=3155, hotkey="F5"}--[[ icon options ]], function(icon, isOn)
  sdTarget.setOn(isOn)
end)

-- outfit icon
addIcon("sdTarget", {outfit={type = 130, head = 114, body = 114, legs = 114, feet = 114, addons = 3}, hotkey="F5"}--[[ icon options ]], function(icon, isOn)
  sdTarget.setOn(isOn)
end)

 

hotkey (from version 1.9)
-- dance when holding ctrl+D
addIcon("Dance", {item=6573}, hotkey("ctrl+D", function()
  turn(math.random(0,3))
end))
singlehotkey (from version 1.9)
addIcon("rainbow", {item=6578}, singlehotkey("f9", function()
  local outfit = outfit()
  outfit.head = (outfit.head + 1) % 133;
  outfit.body = (outfit.body + 1) % 133;
  outfit.legs = (outfit.legs + 1) % 133;
  outfit.feet = (outfit.feet + 1) % 133;
  setOutfit(outfit);
end))