Quantcast
Just a quick question about pet range - WoWInterface
Thread Tools Display Modes
01-30-12, 05:37 AM   #1
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Just a quick question about pet range

I've been trying to use IsSpellInRange for my pet, but I'm not sure I'm doing it correctly. For the life of me I can't figure out how to get Kill Command to not show up when out of range.

IsSpellInRange(16827, "pet", "target") is what I've been trying to use, since my pet has to be in Range for claw to show up. c.c
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
01-30-12, 06:58 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Try IsSpellInRange(16827, "pet", "pettarget")... though if your pet's target is the same as yours it shouldn't make a difference. If that doesn't work, please elaborate on "trying to use". Where are you using this code? What is it doing (or not doing) that you think it should be doing?
  Reply With Quote
01-30-12, 08:44 PM   #3
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
xD Well, I was making a feature for RDX out of the script that you gave me in the other thread for CLCInfo (It makes my life so much happier this way... ._.), but one of the largest personal problems I had was that I didn't like how it would show Kill Command when my pet was out of range. <.<

Sooo, well, I modified it a bit.

Oh, on a side note, when using IsSpellInRange(), the first number isn't the spell id, it's the spellbook ID, so in the original case claw would've been IsSpellInRange(2,"pet","pettarget"). >.> So the reason it wasn't working is because I'm retarded.

Either way, once I figured out that little problem it became abundantly easier to make my feature work the way I wanted it to, just, since I don't know how spell book ID's work (like if they change based on certain talents, because another ability takes it's former spot, etc.), I saw a function used on Pastie.org to get the spellbook id by name, so I made that into a RDX feature too. This actually helps a lot too, because now if I'm ever smart enough to create more advanced features I'll have it already. xD

lua Code:
  1. -- Given a spell's full name and Booktype (BOOKTYPE_SPELL or BOOKTYPE_PET), return spell's book numerical ID.
  2. function RDXSS.GetSpellBookId(sname, bkt)
  3.     if not sname then return nil; end
  4.     if not bkt then return nil; end
  5.     for i = 1, MAX_SKILLLINE_TABS do
  6.         local name, texture, offset, numSpells = GetSpellTabInfo(i);
  7.         if not name then break; end
  8.         for s = offset + 1, offset + numSpells do
  9.             if (sname == GetSpellBookItemName(s,bkt)) then
  10.                 return s;
  11.             end
  12.         end
  13.     end
  14.     return 0;
  15. end
  16.  
  17. -- Hunter 4.3 Priorities for CLCinfo (modified for OpenRDX) by Phanx @ [url]http://www.wowinterface.com/forums/showpost.php?p=251728&postcount=2[/url]
  18. RDX.RegisterFeature({
  19.     name = "BM Priority Icon";
  20.     title = VFLI.i18n("Icon BM Priority");
  21.     category = VFLI.i18n("Textures");
  22.     test = true;
  23.     IsPossible = function(state)
  24.         if not state:Slot("DesignFrame") then return nil; end
  25.         if not state:Slot("Base") then return nil; end
  26.         return true;
  27.     end;
  28.     ExposeFeature = function(desc, state, errs)
  29.         if not RDXUI.DescriptorCheck(desc, state, errs) then return nil; end
  30.         if desc.owner == "Base" then desc.owner = "decor"; end
  31.         local flg = true;
  32.         flg = flg and RDXUI.UFFrameCheck_Proto("Frame_", desc, state, errs);
  33.         flg = flg and RDXUI.UFAnchorCheck(desc.anchor, state, errs);
  34.         flg = flg and RDXUI.UFOwnerCheck(desc.owner, state, errs);
  35.         if flg then state:AddSlot("Frame_" .. desc.name); end
  36.         return flg;
  37.     end;
  38.     ApplyFeature = function(desc, state)
  39.         local objname = "Frame_" .. desc.name;
  40.         local ebsflag, ebs, ebsos = "false", "bs_default", 0;
  41.         if desc.externalButtonSkin then
  42.             ebsflag = "true";
  43.             ebs = desc.externalButtonSkin;
  44.             if desc.ButtonSkinOffset then ebsos = desc.ButtonSkinOffset; end
  45.         end
  46.       ------------------ On frame creation
  47.         local createCode = [[      
  48. local btn, owner = nil, ]] .. RDXUI.ResolveFrameReference(desc.owner) .. [[;
  49. if ]] .. ebsflag .. [[ then
  50.     btn = VFLUI.SkinButton:new();
  51.     btn:SetButtonSkin("]] .. ebs ..[[", true, true, false, true, true, true, false, true, true, true);
  52. else
  53.     btn = VFLUI.AcquireFrame("Frame");
  54. end
  55. btn:SetParent(owner);
  56. btn:SetFrameLevel(owner:GetFrameLevel());
  57. btn:SetPoint(]] .. RDXUI.AnchorCodeFromDescriptor(desc.anchor) .. [[);
  58. btn:SetWidth(]] .. desc.w .. [[); btn:SetHeight(]] .. desc.h .. [[);
  59. btn._t = VFLUI.CreateTexture(btn);
  60. btn._t:SetDrawLayer("]] .. (desc.drawLayer or "ARTWORK") .. [[", 2);
  61. btn._t:SetPoint("CENTER", btn, "CENTER");
  62. btn._t:SetWidth(]] .. desc.w .. [[ - ]] .. ebsos .. [[); btn._t:SetHeight(]] .. desc.h .. [[ - ]] .. ebsos .. [[);
  63. btn._t:SetVertexColor(1,1,1,1);
  64. btn._t:SetTexture("Interface\\InventoryItems\\WoWUnknownItem01.blp");
  65. btn._t:Show();
  66. btn:Hide();
  67. frame.]] .. objname .. [[ = btn;
  68. ]];
  69.         state:Attach(state:Slot("EmitCreate"), true, function(code) code:AppendCode(createCode); end);
  70.  
  71.         ------------------ On frame destruction.
  72.         state:Attach(state:Slot("EmitDestroy"), true, function(code) code:AppendCode([[
  73. VFLUI.ReleaseRegion(frame.]] .. objname .. [[._t); frame.]] .. objname .. [[._t = nil;
  74. frame.]] .. objname .. [[:Destroy(); frame.]] .. objname .. [[ = nil;
  75. ]]); end);
  76.         state:Attach(state:Slot("EmitCleanup"), true, function(code) code:AppendCode([[
  77. frame.]] .. objname .. [[:Hide();
  78. ]]); end);
  79.  
  80.         ------------------ On paint.
  81.         state:Attach(state:Slot("EmitPaint"), true, function(code)
  82.         if desc.test then
  83.             code:AppendCode([[
  84. frame.]] .. objname .. [[._t:SetTexture(GetSpellTexture("Kill Command"));
  85. frame.]] .. objname .. [[:Show();
  86. ]]);
  87.         else
  88.             code:AppendCode([[
  89. function IconBMPriority()
  90.     local gcd = 1.5
  91.     local level = UnitLevel("player")
  92.     local focus = UnitPower("player")
  93.     local duration, _
  94.  
  95.     if not UnitCanAttack("player", "target") then
  96.         return
  97.     end
  98.  
  99.     -- 1. If your pet is on the target, Kill Command
  100.     if UnitExists("pet") and UnitHealth("pet") > 1 and IsSpellInRange(RDXSS.GetSpellBookId("Growl", BOOKTYPE_PET),"pet","pettarget") == 1 and focus > 50 then
  101.         _, duration = GetSpellCooldown("Kill Command")
  102.         if duration <= gcd then
  103.             return GetSpellTexture("Kill Command")
  104.         end
  105.     end
  106.  
  107.     -- 2. If the mob is going to live long enough, apply Serpent Sting.
  108.     if focus > 25 then
  109.         if not UnitDebuff("target", "Serpent Sting") then
  110.             _, duration = GetSpellCooldown("Serpent Sting")
  111.             if duration <= gcd then
  112.                 return GetSpellTexture("Serpent Sting")
  113.             end
  114.         end
  115.     end
  116.  
  117.     -- 3. If mob is below 20% health, Kill Shot
  118.     _, duration = GetSpellCooldown("Kill Shot")
  119.     if duration <= gcd and ( UnitHealth("target") / UnitHealthMax("target") < 0.2 ) then
  120.         return GetSpellTexture("Kill Shot")
  121.     end
  122.  
  123.     -- 4. If you will have enough focus to use Kill Command on cooldown, use Arcane Shot
  124.     if focus > 85 then
  125.         return GetSpellTexture("Arcane Shot")
  126.     end
  127.  
  128.     -- 5. Cobra Shot or Steady Shot.
  129.     if level < 81 then
  130.         return GetSpellTexture("Steady Shot")
  131.     else
  132.         return GetSpellTexture("Cobra Shot")
  133.     end
  134. end
  135.  
  136. frame.]] .. objname .. [[._t:SetTexture(IconBMPriority());
  137. frame.]] .. objname .. [[:Show();
  138. ]]);
  139.         end
  140.         end);
  141.         return true;
  142.     end;
  143.     UIFromDescriptor = function(desc, parent, state)
  144.         local ui = VFLUI.CompoundFrame:new(parent);
  145.        
  146.         -- Name/width/height
  147.         local ed_name, ed_width, ed_height = RDXUI.GenNameWidthHeightPortion(ui, desc, state);
  148.        
  149.         -- Owner
  150.         local owner = RDXUI.MakeSlotSelectorDropdown(ui, VFLI.i18n("Owner"), state, "Subframe_");
  151.         if desc and desc.owner then owner:SetSelection(desc.owner); end
  152.        
  153.         -- Drawlayer
  154.         local er = VFLUI.EmbedRight(ui, VFLI.i18n("Draw layer"));
  155.         local drawLayer = VFLUI.Dropdown:new(er, RDXUI.DrawLayerDropdownFunction);
  156.         drawLayer:SetWidth(100); drawLayer:Show();
  157.         if desc and desc.drawLayer then drawLayer:SetSelection(desc.drawLayer); else drawLayer:SetSelection("ARTWORK"); end
  158.         er:EmbedChild(drawLayer); er:Show();
  159.         ui:InsertFrame(er);
  160.        
  161.         -- Anchor
  162.         local anchor = RDXUI.UnitFrameAnchorSelector:new(ui); anchor:Show();
  163.         anchor:SetAFArray(RDXUI.ComposeAnchorList(state));
  164.         if desc and desc.anchor then anchor:SetAnchorInfo(desc.anchor); end
  165.         ui:InsertFrame(anchor);
  166.        
  167.         local chk_bs = VFLUI.CheckEmbedRight(ui, VFLI.i18n("Use Button Skin"));
  168.         local dd_buttonSkin = VFLUI.Dropdown:new(chk_bs, VFLUI.GetButtonSkinList);
  169.         dd_buttonSkin:SetWidth(150); dd_buttonSkin:Show();
  170.         if desc and desc.externalButtonSkin then
  171.             chk_bs:SetChecked(true);
  172.             dd_buttonSkin:SetSelection(desc.externalButtonSkin);
  173.         else
  174.             chk_bs:SetChecked();
  175.             dd_buttonSkin:SetSelection("bs_default");
  176.         end
  177.         chk_bs:EmbedChild(dd_buttonSkin); chk_bs:Show();
  178.         ui:InsertFrame(chk_bs);
  179.        
  180.         local ed_bs = VFLUI.LabeledEdit:new(ui, 50); ed_bs:Show();
  181.         ed_bs:SetText(VFLI.i18n("Button Skin Size Offset"));
  182.         if desc and desc.ButtonSkinOffset then ed_bs.editBox:SetText(desc.ButtonSkinOffset); end
  183.         ui:InsertFrame(ed_bs);
  184.        
  185.         function ui:GetDescriptor()
  186.         local name = ed_name.editBox:GetText();
  187.         local ebs = nil;
  188.         if chk_bs:GetChecked() then ebs = dd_buttonSkin:GetSelection(); end
  189.         return {
  190.             feature = "BM Priority Icon", name = name, owner = owner:GetSelection();
  191.             drawLayer = drawLayer:GetSelection();
  192.             w = ed_width:GetSelection();
  193.             h = ed_height:GetSelection();
  194.             anchor = anchor:GetAnchorInfo();
  195.             externalButtonSkin = ebs;
  196.             ButtonSkinOffset = VFL.clamp(ed_bs.editBox:GetNumber(), 0, 50);
  197.         };
  198.         end
  199.        
  200.         return ui;
  201.     end;
  202.     CreateDescriptor = function()
  203.         return {
  204.             feature = "BM Priority Icon", name = "bmpi", owner = "decor", drawLayer = "ARTWORK";
  205.             w = 14; h = 14;
  206.             anchor = { lp = "TOPLEFT", af = "Base", rp = "TOPLEFT", dx = 0, dy = 0};
  207.             ButtonSkinOffset = 5;
  208.         };
  209.     end;
  210. });

AND IT'S ALL BECAUSE OF YOU PHANX, MY BEAUTIFUL CREATION IS COMING TO LIFEE. T____T
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **

Last edited by unlimit : 01-30-12 at 09:34 PM.
  Reply With Quote
02-01-12, 05:55 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
For efficiency, I'd suggest putting the UnitCanAttack check before the other variable definitions; if you're quitting early because UnitCanAttack returns nil/false, there's no point in defining those variables, especially the ones that require function calls. I may not have done that in the other thread, but if not, I probably should have.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Just a quick question about pet range

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off