Detect different items on screen and do something.
This script is actually splitted in two.
This script has two working options:
1. If the variable "IS_SAVING_ITEMS" is true then it will just read the items on your screen and save in the table "KNOWN_ITEMS".
2. If the "IS_SAVING_ITEMS" variable is FALSE, then it will check if the items that are on your screen are also in KNOWN_ITEMS. If any different items are found, then the script can play an alert, print a message to the console, use that item and grab that item.
The script was made to work like this:
1. You set the IS_SAVING_ITEMS variable to true and then run through your cave or something. If you are going to use this script while hunting, then take a trip or two around the cave and then disable the variable.
2. Set variable IS_SAVING_ITEMS to false, so that the script can check if there is a different item and alert you about it.
I will teach two different waypoints to use this after the code!
Code to make the script read all items in your screen and save to be checked later!
Code to make the script read items in your screen and check if you already found it before!
If you don't IS_SAVING_ITEMS as true or false then the script will consider "IS_SAVING_ITEMS = true" on its very first run
Script to use while making runes
Why? This script will read the items in your screen and save in its first turn... After the first turn then it will check for different items.
It's the perfect situation while making runes.
Script to use while hunting/cavebotting
Why? This script will keep reading the items in your screen and saving until you set "IS_SAVING_ITEMS = false".
So all you need to do is creating an Action waypoint after all your waypoints that walks around the cave with the code:
So once you enable the script below, it will start reading items and after walking on all waypoints around the cavebot, it will hit the Action waypoint that you created and run the code that set "IS_SAVING_ITEMS = false" then the script will start looking for different items and alert you!
Script to use while hunting/cavebotting (Saving items during specific time)
This script will keep reading the items in your screen and saving for a random time that you setup on DisableSavingStepAfterTime (for example 800 seconds after the script started running) OR until you set "IS_SAVING_ITEMS = false".
OPTIONS -> DisableSavingStepAfterTime will simply set "IS_SAVING_ITEMS = false" instead of you doing this by another LUA script, which let's this script to be used.
For most cases OPTIONS -> DisableSavingStepAfterTime is enough, but you have two options to play with depending on complexity of your cavebot script:
1. Setup enough time to walk few rounds or so on OPTIONS -> DisableSavingStepAfterTime. You are able to reset timer to read more items using this code:
2. Create an Action waypoint after all your waypoints that walks around the cave few times or so, with the code:
So once you enable the script below, it will start reading and saving items for a random time that you setup on OPTIONS -> DisableSavingStepAfterTime then after that time, it will start playing alerts or whatever you setup when finding new items.
This script is actually splitted in two.
This script has two working options:
1. If the variable "IS_SAVING_ITEMS" is true then it will just read the items on your screen and save in the table "KNOWN_ITEMS".
2. If the "IS_SAVING_ITEMS" variable is FALSE, then it will check if the items that are on your screen are also in KNOWN_ITEMS. If any different items are found, then the script can play an alert, print a message to the console, use that item and grab that item.
The script was made to work like this:
1. You set the IS_SAVING_ITEMS variable to true and then run through your cave or something. If you are going to use this script while hunting, then take a trip or two around the cave and then disable the variable.
2. Set variable IS_SAVING_ITEMS to false, so that the script can check if there is a different item and alert you about it.
I will teach two different waypoints to use this after the code!
Code to make the script read all items in your screen and save to be checked later!
setglobal('IS_SAVING_ITEMS', true)
Code to make the script read items in your screen and check if you already found it before!
setglobal('IS_SAVING_ITEMS', false)
If you don't IS_SAVING_ITEMS as true or false then the script will consider "IS_SAVING_ITEMS = true" on its very first run
Script to use while making runes
Why? This script will read the items in your screen and save in its first turn... After the first turn then it will check for different items.
It's the perfect situation while making runes.
local IGNORE_ITEMS = { } -- Add item IDS that you don't want to trigger alarm.
local OPTIONS = {
WorkWithPlayerOnScreen = true, -- If TRUE then script will work whenever there is a player or not. If FALSE then this script will only trigger if no player on screen.
PlayAlert = true, -- Play sound and flash client?
LogConsole = true, -- Log on console?
UseItem = false, -- Use the item that you found on floor. This option will disable cavebot and targeting then enable again.
PickupItem = false, -- Pickup the item that you found on floor. This option will disable cavebot and targeting then enable again.
PauseBot = true, -- Pause bot?
}
KNOWN_ITEMS = KNOWN_ITEMS or {}
local tiles = gettiles()
local player_x = posx()
local player_y = posy()
local player_z = posz()
if IS_SAVING_ITEMS == nil then
IS_SAVING_ITEMS = true
end
local runemakerEnabled = false
for _, tile in ipairs(tiles) do
if tile.posz == player_z and math.abs(player_x - tile.posx) <= 7 and math.abs(player_y - tile.posy) <= 5 and tile.itemcount > 1 then
for __, item in ipairs(tile.items) do
if item.id > 99 and table.find(KNOWN_ITEMS, item.id) == nil and table.find(IGNORE_ITEMS, item.id) == nil then
if IS_SAVING_ITEMS then
table.insert(KNOWN_ITEMS, item.id)
else
if (OPTIONS.PlayAlert or OPTIONS.LogConsole or OPTIONS.UseItem or OPTIONS.PickupItem) and (OPTIONS.WorkWithPlayerOnScreen or (OPTIONS.WorkWithPlayerOnScreen == false and paround() == 0)) then
if OPTIONS.PlayAlert then
flashclient()
playsound('default')
end
if OPTIONS.LogConsole then
print('New item found: ' .. item.id .. ' on x/y/z: ' .. tile.posx .. ', ' .. tile.posy .. ', ' .. tile.posz)
end
if OPTIONS.UseItem or OPTIONS.PickupItem then
runemakerEnabled = getsettings('Runemaker/Enabled')
if runemakerEnabled then
setsettings('Runemaker/Enabled', false)
end
if OPTIONS.UseItem then
useitem(item.id, tile.posx, tile.posy, tile.posz)
wait(400, 800)
end
if OPTIONS.PickupItem then
moveitems(item.id, '', ground(tile.posx, tile.posy, tile.posz))
wait(400, 800)
end
end
if OPTIONS.PauseBot then
pausebot(true)
end
end
end
end
end
end
end
if runemakerEnabled then
setsettings('Runemaker/Enabled', true)
end
IS_SAVING_ITEMS = false
Script to use while hunting/cavebotting
Why? This script will keep reading the items in your screen and saving until you set "IS_SAVING_ITEMS = false".
So all you need to do is creating an Action waypoint after all your waypoints that walks around the cave with the code:
setglobal('IS_SAVING_ITEMS', false)
So once you enable the script below, it will start reading items and after walking on all waypoints around the cavebot, it will hit the Action waypoint that you created and run the code that set "IS_SAVING_ITEMS = false" then the script will start looking for different items and alert you!
local IGNORE_ITEMS = { } -- Add item IDS that you don't want to trigger alarm.
local OPTIONS = {
WorkWithPlayerOnScreen = true, -- If TRUE then script will work whenever there is a player or not. If FALSE then this script will only trigger if no player on screen.
PlayAlert = true, -- Play sound and flash client?
LogConsole = true, -- Log on console?
UseItem = false, -- Use the item that you found on floor. This option will disable cavebot and targeting then enable again.
PickupItem = false, -- Pickup the item that you found on floor. This option will disable cavebot and targeting then enable again.
PauseBot = true, -- Pause bot?
}
KNOWN_ITEMS = KNOWN_ITEMS or {}
local tiles = gettiles()
local player_x = posx()
local player_y = posy()
local player_z = posz()
if IS_SAVING_ITEMS == nil then
IS_SAVING_ITEMS = true
end
local cavebotEnabled = false
local targetingEnabled = false
for _, tile in ipairs(tiles) do
if tile.posz == player_z and math.abs(player_x - tile.posx) <= 7 and math.abs(player_y - tile.posy) <= 5 and tile.itemcount > 1 then
for __, item in ipairs(tile.items) do
if item.id > 99 and table.find(KNOWN_ITEMS, item.id) == nil and table.find(IGNORE_ITEMS, item.id) == nil then
if IS_SAVING_ITEMS then
table.insert(KNOWN_ITEMS, item.id)
else
if (OPTIONS.PlayAlert or OPTIONS.LogConsole or OPTIONS.UseItem or OPTIONS.PickupItem) and (OPTIONS.WorkWithPlayerOnScreen or (OPTIONS.WorkWithPlayerOnScreen == false and paround() == 0)) then
if OPTIONS.PlayAlert then
flashclient()
playsound('default')
end
if OPTIONS.LogConsole then
print('New item found: ' .. item.id .. ' on x/y/z: ' .. tile.posx .. ', ' .. tile.posy .. ', ' .. tile.posz)
end
if OPTIONS.UseItem or OPTIONS.PickupItem then
cavebotEnabled = getsettings('Cavebot/Enabled')
if cavebotEnabled then
setsettings('Cavebot/Enabled', false)
end
targetingEnabled = getsettings('Targeting/Enabled')
if targetingEnabled then
setsettings('Targeting/Enabled', false)
end
if OPTIONS.UseItem then
useitem(item.id, tile.posx, tile.posy, tile.posz)
wait(400, 800)
end
if OPTIONS.PickupItem then
moveitems(item.id, '', ground(tile.posx, tile.posy, tile.posz))
wait(400, 800)
end
if OPTIONS.PauseBot then
pausebot(true)
end
end
end
end
end
end
end
end
if cavebotEnabled then
setsettings('Cavebot/Enabled', true)
end
if targetingEnabled then
setsettings('Targeting/Enabled', true)
end
Script to use while hunting/cavebotting (Saving items during specific time)
This script will keep reading the items in your screen and saving for a random time that you setup on DisableSavingStepAfterTime (for example 800 seconds after the script started running) OR until you set "IS_SAVING_ITEMS = false".
OPTIONS -> DisableSavingStepAfterTime will simply set "IS_SAVING_ITEMS = false" instead of you doing this by another LUA script, which let's this script to be used.
For most cases OPTIONS -> DisableSavingStepAfterTime is enough, but you have two options to play with depending on complexity of your cavebot script:
1. Setup enough time to walk few rounds or so on OPTIONS -> DisableSavingStepAfterTime. You are able to reset timer to read more items using this code:
setglobal('IS_SAVING_ITEMS', nil)
setglobal('IS_SAVING_ITEMS', false)
So once you enable the script below, it will start reading and saving items for a random time that you setup on OPTIONS -> DisableSavingStepAfterTime then after that time, it will start playing alerts or whatever you setup when finding new items.
local IGNORE_ITEMS = { } -- Add item IDS that you don't want to trigger alarm.
local OPTIONS = {
WorkWithPlayerOnScreen = true, -- If TRUE then script will work whenever there is a player or not. If FALSE then this script will only trigger if no player on screen.
PlayAlert = true, -- Play sound and flash client?
LogConsole = true, -- Log on console?
UseItem = false, -- Use the item that you found on floor. This option will disable cavebot and targeting then enable again.
PickupItem = false, -- Pickup the item that you found on floor. This option will disable cavebot and targeting then enable again.
PauseBot = true, -- Pause bot?
DisableSavingStepAfterTime = { Min = 300, Max = 600 } -- In SECONDS. Stops reading and saving items after X seconds.
}
KNOWN_ITEMS = KNOWN_ITEMS or {}
local tiles = gettiles()
local player_x = posx()
local player_y = posy()
local player_z = posz()
if IS_SAVING_ITEMS == nil then
IS_SAVING_ITEMS = true
STOP_SAVING_TIME = runningtime() + random(OPTIONS.DisableSavingStepAfterTime.Min, OPTIONS.DisableSavingStepAfterTime.Max)
end
if IS_SAVING_ITEMS == true and runningtime() >= STOP_SAVING_TIME then
IS_SAVING_ITEMS = false
end
local cavebotEnabled = false
local targetingEnabled = false
for _, tile in ipairs(tiles) do
if tile.posz == player_z and math.abs(player_x - tile.posx) <= 7 and math.abs(player_y - tile.posy) <= 5 and tile.itemcount > 1 then
for __, item in ipairs(tile.items) do
if item.id > 99 and table.find(KNOWN_ITEMS, item.id) == nil and table.find(IGNORE_ITEMS, item.id) == nil then
if IS_SAVING_ITEMS then
table.insert(KNOWN_ITEMS, item.id)
else
if (OPTIONS.PlayAlert or OPTIONS.LogConsole or OPTIONS.UseItem or OPTIONS.PickupItem) and (OPTIONS.WorkWithPlayerOnScreen or (OPTIONS.WorkWithPlayerOnScreen == false and paround() == 0)) then
if OPTIONS.PlayAlert then
flashclient()
playsound('default')
end
if OPTIONS.LogConsole then
print('New item found: ' .. item.id .. ' on x/y/z: ' .. tile.posx .. ', ' .. tile.posy .. ', ' .. tile.posz)
end
if OPTIONS.UseItem or OPTIONS.PickupItem then
cavebotEnabled = getsettings('Cavebot/Enabled')
if cavebotEnabled then
pausewalking(10000)
setsettings('Cavebot/Enabled', false)
end
targetingEnabled = getsettings('Targeting/Enabled')
if targetingEnabled then
pausewalking(10000)
setsettings('Targeting/Enabled', false)
end
if iswalking() then
stop()
wait(200, 400)
end
if OPTIONS.UseItem then
useitem(item.id, tile.posx, tile.posy, tile.posz)
wait(400, 800)
end
if OPTIONS.PickupItem then
moveitems(item.id, '', ground(tile.posx, tile.posy, tile.posz))
wait(400, 800)
end
if OPTIONS.PauseBot then
pausebot(true)
end
end
end
end
end
end
end
end
if cavebotEnabled then
pausewalking(0)
setsettings('Cavebot/Enabled', true)
end
if targetingEnabled then
pausewalking(0)
setsettings('Targeting/Enabled', true)
end