Wednesday, April 18, 2012

Re-applying poisons Automatically

So I've searched through the forums and couldn't find anything useful, so here goes. I'm wondering if its possible to re-apply the already applied poison automatically through an addon. I've found the method GetWeaponEnchantInfo() to find how long is left on the poison enchant, and I can find out if the poison is available to be applied. But so far I can't find the name of the poison which is applied and I'm not sure if ReplaceEnchant() is the method I'm looking for to do this.

I did find this macro though, and so I can only assume it is possible to do it using an addon as well:


Code:
#showtooltip Crippling Poison II
/use Crippling Poison II
/use [button:1] 16; [button:2] 17

Any help is greatly appreciated.|||no mod can automatically do anything everything requires a button to be pressed.|||Yep, will require a button press so just stick with the macro.|||Quote:








Yep, will require a button press so just stick with the macro.




I would, but I'm trying to add it to my add-on.

Alternatively, would it be possible to have a warning fire off when the timer is close to 0, then have to press a button to actually replace the poison?|||Yep that would be possible. I'm not sure if you'll need to parse the weapon tooltip manually to detect what Poison is being used though.|||Why not just get SmartBuff? It does exactly what you're looking to do.|||Quote:








Why not just get SmartBuff? It does exactly what you're looking to do.




I looked at it, and I couldn't find anything to do with poisons. I might be overlooking it though, never used it before. I've tried to do it on my own, and so far I've got this method to find out the details of what poison is on what weapon:


Code:
function RaidRogue_poisonDetails()

RaidRogue_TT:SetOwner(WorldFrame, "ANCHOR_NONE");
local weaponSlots={"MainHandSlot","SecondaryHandSlot"};
local id, hasItem

for i=1,#weaponSlots do
Out("Checking: "..weaponSlots[i]);
id=GetInventorySlotInfo(weaponSlots[i]);
hasItem,_,_ = RaidRogue_TT:SetInventoryItem("player",id);

--Scan the Item's Description
if(hasItem) then
for i=1,RaidRogue_TT:NumLines() do
local row= getglobal("RaidRogue_TTTextLeft" .. i);
if(row) then
local text=row:GetText();
if(text) then
--Scan for Poison Information
local _,_,poison=string.find(text, "(.+) Poison");
if(poison and poison~="Anesthetic") then
local _,_rank=string.find(text, ""..poison.." Poison (.+)");
if(rank) then
Out("Poison: "..poison);
Out("Rank: "..rank);
end
elseif(poison) then
Out("Poison: "..poison);
end
end
end
end
end
end

The problem is that it only correctly detects poison and rank when it's Anesthetic. I'll admit I'm no pro at parsing strings, and I love the new Combat Log because of that, so that might be the problem.|||Quote:








I looked at it, and I couldn't find anything to do with poisons. I might be overlooking it though, never used it before. I've tried to do it on my own, and so far I've got this method to find out the details of what poison is on what weapon:


Code:
function RaidRogue_poisonDetails()

RaidRogue_TT:SetOwner(WorldFrame, "ANCHOR_NONE");
local weaponSlots={"MainHandSlot","SecondaryHandSlot"};
local id, hasItem

for i=1,#weaponSlots do
Out("Checking: "..weaponSlots[i]);
id=GetInventorySlotInfo(weaponSlots[i]);
hasItem,_,_ = RaidRogue_TT:SetInventoryItem("player",id);

--Scan the Item's Description
if(hasItem) then
for i=1,RaidRogue_TT:NumLines() do
local row= getglobal("RaidRogue_TTTextLeft" .. i);
if(row) then
local text=row:GetText();
if(text) then
--Scan for Poison Information
local _,_,poison=string.find(text, "(.+) Poison");
if(poison and poison~="Anesthetic") then
local _,_rank=string.find(text, ""..poison.." Poison (.+)");
if(rank) then
Out("Poison: "..poison);
Out("Rank: "..rank);
end
elseif(poison) then
Out("Poison: "..poison);
end
end
end
end
end
end

The problem is that it only correctly detects poison and rank when it's Anesthetic. I'll admit I'm no pro at parsing strings, and I love the new Combat Log because of that, so that might be the problem.






try this...

--Scan for Poison Information

local _,_,poison=string.find(text, "(.+) Poison");

if(poison and poison~="Anesthetic" or "PoisonName" or "PoisonName") then

local _,_rank=string.find(text, ""..poison.." Poison (.+)");

if(rank) then

Out("Poison: "..poison);

Out("Rank: "..rank);

end

... where "PoisonName" is the name of the poison you wanna track make sure to add or between each one.|||So I finally settled on this to get poison details when the combat log events, ENCHANT_APPLIED and ENCHANT_REMOVED are fired:


Code:
function RaidRogue_poisonDetails()
--This method should be able to find out which item was just poisoned, and assign the affected and poison variables properly.

RaidRogue_TT:SetOwner(WorldFrame, "ANCHOR_NONE");
local weaponSlots={"MainHandSlot","SecondaryHandSlot"};
local id, hasItem, poisonText, poisonName, poisonRank, weaponName
local MHUpdate=false;
local OHUPdate=false;

for k=1,#weaponSlots do
id=GetInventorySlotInfo(weaponSlots[k]);
hasItem,_,_ = RaidRogue_TT:SetInventoryItem("player",id);

--Scan the Item's Description
if(hasItem) then
for i=1,RaidRogue_TT:NumLines() do
local row= getglobal("RaidRogue_TTTextLeft" .. i);
if(row) then
local text=row:GetText();
if(i==1) then
weaponName=text;
end
if(text) then
--Scan for Poison Information
if(string.find(text, "Poison ")) then
poisonText=string.sub(string.gsub(text, " Poison",""),0,-9);

local divider=string.find(poisonText," ")

if(divider) then
poisonName=string.sub(poisonText,0,divider-1);
poisonRank=string.sub(poisonText,divider);
else
poisonName=poisonText;
poisonRank="";
end

--Remove any spaces.
if(string.find(poisonRank," ")) then
poisonRank=string.gsub(poisonRank," ","")
end

--Make sure we're getting valid information.
hMH,eMH,_,hOH,eOH,_=GetWeaponEnchantInfo();

--Depending on the poison, update MH and OH Variables.
if(weaponSlots[k]=="MainHandSlot" and hMH) then
MHUpdate=true
RR_MHPOISON=poisonName.." Poison";
RR_MHPOISONRANK=poisonRank;
RR_MHAFFECTED=weaponName;
RR_MHEXPIR=eMH;
elseif(weaponSlots[k]=="SecondaryHandSlot" and hOH) then
OHUpdate=true;
RR_OHPOISON=poisonName.." Poison";
RR_OHPOISONRANK=poisonRank;
RR_OHAFFECTED=weaponName;
RR_OHEXPIR=eOH;
end
end
end
end
end

if(MHUpdate==false) then
RR_MHPOISON=""
RR_MHPOISONRANK=""
RR_MHAFFECTED=""
RR_MHEXPIR=""
end

if(OHUpdate==false) then
RR_OHPOISON=""
RR_OHPOISONRANK=""
RR_OHAFFECTED=""
RR_OHEXPIR=""
end

end
end
end

It's longer than I originally thought, but after the pattern matching didn't work it I did it the simple way and through some testing it works. I've linked it to a chat command, and when the chat command is called, everything works as it should. But when the function is called through the combat log events, it's almost as if the tooltip isn't updated when it runs and so it doesn't get the right data.

Is this a known issue, or is it (most likely) that my code isn't right? Any help is appreciated.|||I could be completely off here but can't you just take the SpellName and ItemName straight from the first and third event parameters respectively?

No comments:

Post a Comment