• 0

    posted a message on Detect wether a class can use an item?
    Thanks a lot, will try this when I get home.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Detect wether a class can use an item?
    Okay, been reading the wowwiki documentation on the gametooltip item.

    So I need to do:

     
    local Scan_Tooltip = CreateFrame("GameTooltip", nil, nil, "GameTooltipTemplate")
    Scan_Tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")


    at that point I am stuck, what do I use to set the tooltip object? The API provides me with SetInventorySlot, SetBagItem, SetAction, SetUnitBuff etc. all which point to things the player should have access to, all I have is an itemlink.

    Edit:
    I think I found it, http://www.wowwiki.com/API_GameTooltip_SetHyperlink


    Sorry for all the questions :(
    Posted in: Lua Code Discussion
  • 0

    posted a message on Detect wether a class can use an item?
    Is it possible to provide a sample on how to do this?
    Posted in: Lua Code Discussion
  • 0

    posted a message on Detect wether a class can use an item?
    The person running the addon should be verified. The masterlooter sends a addonmessage with the item being bid on; all players with the addon receive a need/greed/pass dialog.
    So it would be sufficient to check on the player's addon to check if the item can be used and return a pass message to the masterlooter. That way I can keep the code I have for the masterlooter as it is and have each in the raid do the checking for themselves.

    This is the code I was thinking about earlier (without tooltip scanning):
     
    local ClassCanUse = {
      ["Warlock"]["Armor"]["Cloth"] = true, 
      ["Warlock"]["Weapon"]["Dagger"] = true, 
      ["Warlock"]["Weapon"]["Swords"] = true, 
      ["Warlock"]["Weapon"]["Staves"] = true, 
      ["Warlock"]["Weapon"]["Wands"] = true
     
      --etc. etc.
    }
    local ClassTokens = {
      [40625] = true  -- Breastplate of the Lost Conqueror
      [40625]["Warlock"] = true, 
      [40625]["Priest"] = true, 
      [40625]["Paladin"] = true, 
      
      --etc. etc.
    }
     
    local function Can_I_Use(item) -- return false when we're sure you cannot use it, return true when in doubt
     -- Get Item info
     local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(iteminfo);
     
     -- Get Item number
     local item_id = select(3, sLink:find("item:(%d+):"))
     if not item_id then return true
     item_id = tonumber(item_id:trim())
     if not item_id then return true
     
     local sClass = UnitClass("player")
    
     --is it a tier token?
     if ClassTokens[item_id] ~= nil then
      --yes
      
      --is it for my class?
      if ClassTokens[item_id][sClass] then
       -- yes, we can use it!
       return true
      end
      
      -- it is a class token but not for me.
      return false
     end
     if sType == "Armor" or sType == "Weapon" then
      -- it is one of the types we should be able to detect:
      if ClassCanUse[sClass][sType][sSubType] ~= nil then
       return true -- it is one of the types usable by my class
      end
      
      return false -- it failed the check, we are not able to use it.
     end
     
     return true -- no clue what this item is, allow the player to bid on it.
    end


    Note that the code is not tested - it's just my initial thought on how to do it. Comments are appreciated. (I just noticed how the copy/paste messes up indention- sorry).

    So as a final check I would need a tooltip check to verify if the class is mentioned in the 'usable' line (if any exists)
    Posted in: Lua Code Discussion
  • 0

    posted a message on how to spread code over files?
    Thanks for the great info! *hurries back to the drawingboard*
    Posted in: Lua Code Discussion
  • 0

    posted a message on how to spread code over files?
    So, now I am confused. I cannot call functions in other files in my own addon unless they are defined global. However defining stuff global is discouraged.

    I understand the concept of keeping things local when there is no need for globals.

    file1.lua
    myaddon_i=1
     
    local function myaddon_DoSomeThing()
         return myaddon_foo(2)
    end


    file2.lua
    function myaddon_foo(j)
       return myaddon_i + myaddon_bar(j)    
    end
     
    local function myaddon_bar(k)
       return k*2
    end

    so if file2.lua contains foo() and bar() where bar() is there to support foo() only, bar() should be a local function. Thus file1.lua can and should only call foo().

    In the above sample, how would you define the functions as you describe? I really want to learn how to do this proper.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Detect wether a class can use an item?
    It should be possible - the slots in my inventory show wether I can equip an item or not; however the [FONT=Courier New]IsEquippableItem [FONT=Verdana]function seems to return true for plate items even while I am a clothie.[/FONT][/FONT]

    I've wrote an EPGP need/greed addon for my guild. I got it to the point that it works like a charm, so now I'm finetuning it. To speed up the need/greed/pass process I would like to check if a player can actually use the BoP item, if not then automatically pass on it.
    Posted in: Lua Code Discussion
  • 0

    posted a message on how to spread code over files?
    One question about 'global', how global is it? Does WoW keep all globally defined functions and variables within one addon or do I risk conflicting names betweens addons?
    So if one addon defines a global function foo() and another also has a global function foo() does that cause problems?
    Posted in: Lua Code Discussion
  • 0

    posted a message on how to spread code over files?
    ah, I also found why I didn't get any results; a /reloadui isn't enough to have the addon load extra files it seems.
    Posted in: Lua Code Discussion
  • 0

    posted a message on how to spread code over files?
    Hi,

    I've been tinkering with my own addon. In fact I've been tinkering so much that I have a lot of code in one single lua file. So I've been looking at other addons how to spread code in seperate files to keep it nice and tidy.
    So far; I've created a new lua file and added the file to the .toc. I receive no errors upon loading but I can't seem to call functions between the two files.
    So I have a couple of questions;

    1. how do I call a function in another file?

    2. how do I create a global variable that is available across all files?

    3. where can I read on stuff like this? Wowwiki is a good source for the API, and I've read some basic lua language tutorials but I couldn't find anything about structuring the code.

    Thanks for all the help so far!
    Posted in: Lua Code Discussion
  • 0

    posted a message on Show item icon?
    Is there an easy way to add an icon (preferably with tooltip) to a dialog?
    I catch the LOOT_OPENED event to show a dialog with the names of the items on the corpse. I send the itemlink to other members in the raid to show a epgp need/greed window. I put the itemlink into a fontstring and it displays nicely. I would also like to add the icon to that frame... but how?

    So basically this is what I have; and itemlink-string and a frame I would like to add an icon to.
    I've looked at the xloot addon but I couldn't figure out how that one does it :(

    Also is there an easy way to connect the item tooltip to the mouseover event?
    Posted in: Lua Code Discussion
  • 0

    posted a message on How to change text on buttons and or frames?
    Thanks it worked!
    Posted in: Lua Code Discussion
  • 0

    posted a message on How to change text on buttons and or frames?
    So if I understand correctly the '$parent' part in the XML translates to the parent node which is makes it one word ithe lua?
    Posted in: Lua Code Discussion
  • 0

    posted a message on How to change text on buttons and or frames?
    I couldn't find any sample that shows me how to do this...

    I have an XML definition much like this (I left out details like size for clarity):
    <Ui xmlns="[URL]http://www.blizzard.com/wow/ui[/URL]" xmlns:xsi="[URL]http://www.w3.org/2001/XMLSchema-instance[/URL]">
      <Frame name="SampleForm" hidden="true">
         <Frames>
            <Frame name="$Label1">
     
              <Layers>
                <Layer>
                  <FontString name="$Label" setAllPoints="true" font="Fonts\FRIZQT__.TTF" text="Lorem Ipsum">
                 </Layer>
              </Layers>
     
            <Button name="$Button1" text="buttontext">
            </Button>
     
         </Frames>
      </Frame>
    </Ui>


    In my lua I have a slashcommand that calls
    SampleForm:Show();
    and ingame the form shows. So that part works. I also catch the buttonclick event and handle it.

    But I can't figure out how to change the text on the button or the frame... So how do I change this? I know I need to use the SetText() function but how do I access the elements inside the frame?

    To clarify; I want to change the text on buttons runtime, not by simply typing the message in the XML file.

    Any help would be appreciated!
    Posted in: Lua Code Discussion
  • 0

    posted a message on Surpress outgoing addon whispers
    Aaah! Thanks! Missed that one!
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.