I've started to mess around with LuaNinja and my first creation is a bot to prospect all my Saronite Ore. I works pretty well but it does have one known issue. Sometimes after it finishes a stack I think the bag data gets out of sync and it tries to target something invalid. You get an error message and it stops the bot. I'm going to work on fixing that next. Now on to the code...
DISCLAIMER: I don't write much Lua code so this might not be the best way to do this. Constructive comments are welcome...
Step #1 - Create a directory in your Interface/AddOns folder.
Step #2 - Create a file called bot1.toc and paste in the following code.
Code:
## Interface: 30200
## Title: Bot1
## Notes: Prospects your ore.
## Dependencies:
bot1.lua
bot1.xml
Step #3 - Create a file called bot1.xml and paste in the following code.
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\..\FrameXML\UI.xsd">
<Script File="bot1.lua"/>
<Frame name="Bot1Frame">
<Scripts>
<OnLoad function="Bot1_OnLoad"/>
<OnEvent function="Bot1_OnEvent"/>
</Scripts>
</Frame>
</Ui>
Step #4 - Create a file called bot1.lua and paste in the following code.
Code:
Bot1_CurrentlyProspecting = false;
function Bot1_OnLoad()
print("Bot1_OnLoad");
this:RegisterEvent("VARIABLES_LOADED");
this:RegisterEvent("LOOT_CLOSED");
end
function Bot1_OnEvent(self, event, ...)
local eventPrefix, eventSuffix = event:match("^(.-)_?([^_]*)$");
if event == "LOOT_CLOSED" then
if Bot1_CurrentlyProspecting == true then
for bag = 0,4,1 do
for slot = 1, GetContainerNumSlots(bag), 1 do
local name = GetContainerItemLink(bag,slot);
if name and string.find(name,"Saronite Ore") then
local texture, itemCount, locked, quality, readable = GetContainerItemInfo(bag,slot);
if not locked then
if itemCount >= 5 then
CastSpellByName("Prospecting")
if( SpellIsTargeting() ) then
UseContainerItem(bag,slot);
end
return
end
end
end
end
end
-- didn't find anything to prospect
Bot1_CurrentlyProspecting = false;
DEFAULT_CHAT_FRAME:AddMessage("Finished prospecting.");
end
end
end
SLASH_BOT11 = '/bot1';
local function bot1_handler(msg, editbox)
DEFAULT_CHAT_FRAME:AddMessage("Prospecting...");
for bag = 0,4,1 do
for slot = 1, GetContainerNumSlots(bag), 1 do
local name = GetContainerItemLink(bag,slot);
if name and string.find(name,"Saronite Ore") then
local texture, itemCount, locked, quality, readable = GetContainerItemInfo(bag,slot);
if not locked then
if itemCount >= 5 then
Bot1_CurrentlyProspecting = true;
CastSpellByName("Prospecting")
if( SpellIsTargeting() ) then
UseContainerItem(bag,slot);
end
return
end
end
end
end
end
end
SlashCmdList["BOT1"] = bot1_handler;
Just type "/bot1" to kick off the bot.