• 0

    posted a message on Need help with a function
    Allright well, everything's fine now, there's only one small function i didn't manage to 'convert', if i add it to the .lua it works as it is but all the other functions stop working.

    cTweaks:RegisterEvent('START_LOOT_ROLL')
    cTweaks:SetScript('OnEvent', function(_, _, id)
     if id
      and (select(4, GetLootRollItemInfo(id)) == 2)
      and not (select(5, GetLootRollItemInfo(id))) then
       RollOnLoot(id, 2)
     end
    end)


    I've tried the following but that didn't work unfortunately

    cTweaks:RegisterEvent('START_LOOT_ROLL')
    function cTweaks:START_LOOT_ROLL(_, _, id)
     if id
      and (select(4, GetLootRollItemInfo(id)) == 2)
      and not (select(5, GetLootRollItemInfo(id))) then
       RollOnLoot(id, 2)
     end
    end
    Posted in: Lua Code Discussion
  • 0

    posted a message on Need help with a function
    Well that's weird, now that i could try it in game, here's what's happening.

    Here's the beginning of my "tweaks" addon

    local cTweaks = CreateFrame('Frame')
    cTweaks:SetScript('OnEvent', function(self, event, ...) self[event](...) end) (LINE 2)
    --[[  Auto Turn on nameplates in combat ]]
    cTweaks:RegisterEvent('PLAYER_REGEN_ENABLED')
    function cTweaks:PLAYER_REGEN_ENABLED()
     SetCVar('nameplateShowEnemies', 0)
    end
    cTweaks:RegisterEvent('PLAYER_REGEN_DISABLED')
    function cTweaks:PLAYER_REGEN_DISABLED()
     SetCVar('nameplateShowEnemies', 1)
    end


    It's much longer but you get the point. Now if i only add

    cTweaks:RegisterEvent('MERCHANT_SHOW', 'MyEventHandler')
    cTweaks:RegisterEvent('BANKFRAME_OPENED', 'MyEventHandler')
    cTweaks:RegisterEvent('GUILDBANKFRAME_OPENED', 'MyEventHandler')
    function cTweaks:MyEventHandler(event)
      OpenAllBags(true)
    end


    It doesn't work and give an error at line 2 (\AddOns\cTweaks\cTweaks.lua:2: attempt to call field '?' (a nil value))
    Posted in: Lua Code Discussion
  • 0

    posted a message on Need help with a function
    So like this ? (can't try it atm)

    cTweaks:RegisterEvent('MERCHANT_SHOW', 'MyEventHandler')
    cTweaks:RegisterEvent('BANKFRAME_OPENED', 'MyEventHandler')
    cTweaks:RegisterEvent('GUILDBANKFRAME_OPENED', 'MyEventHandler')
    function cTweaks:MyEventHandler(event)
     if (event == 'MERCHANT_SHOW' or event == 'BANKFRAME_OPENED' or event == 'GUILDBANKFRAME_OPENED') then
      OpenAllBags(true)
     end
    end
    Posted in: Lua Code Discussion
  • 0

    posted a message on Need help with a function
    Ok so, so far to make small function with a single event i was doing like this:

     cTweaks:RegisterEvent('CHAT_MSG_WHISPER')
     function cTweaks:CHAT_MSG_WHISPER()
      if(event == 'CHAT_MSG_WHISPER') then
       PlaySoundFile('Interface\\AddOns\\cMedia\\Sounds\\whisper.mp3')
      end
     end


    My question is, how do i write it if i need to watch multiples events, here's an example:

     if (event == 'MERCHANT_CLOSED' or event == 'BANKFRAME_CLOSED' or event == 'MAIL_CLOSED' or event == 'GUILDBANKFRAME_CLOSED') then
      CloseAllBags()
     end
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code help needed
    Quote from Adirelle
    Calling EquipAmmo with no args does not do anything, so the last part with curAmmo should not change anything.


    That's what surprises me, because it did, or at least i think.

    To write it correctly how should i do, replace EquipAmmo() with EquipAmmo(primary, fallback) ?

    From what i've been able to test, it works but it's not really easy to trigger, it was switching, without retargeting, and i've tried BAG_UPDATE before, didn't make a difference.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code help needed
    What do you think about the last bit of code i posted, do you see anything going wrong with it ? because from the few i have tested it seems to work fine without any other event.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code help needed
    Allright, i think i've got it to work nicely now, tell me what you think, i didn't even have to register another event. I only did some brief testing but it seems to be ok.

    if select(2, UnitClass('player')) ~= 'HUNTER' then return end
    
    local caelAmmoSaver = CreateFrame('Frame') 
    caelAmmoSaver:SetScript('OnEvent', function(self) self:OnEvent(event) end)
    
    local SUBTYPE_GUNS = 'Guns'
    local hiBullets, loBullets = 41164, 31735 -- Mammoth Cutters, Timeless Shell
    local hiArrows, loArrows = 41165, 31737 -- Saronite Razorheads, Timeless Arrow
    
    local function EquipAmmo(primary, fallback)
        local itemid
        if GetItemCount(primary) > 0 then
            itemid = primary
        elseif GetItemCount(fallback) > 0 then
            itemid = fallback
        else
            return
        end
    
        if not GetInventoryItemLink('player', 0):match('item:'..tostring(itemid)..':') then
            EquipItemByName(itemid)
        end
    end
    
    function caelAmmoSaver:OnEvent(event)
        if not UnitCanAttack('player', 'target') or UnitIsDead('target') then
            return
        end
    
        local hiAmmo, loAmmo = hiArrows, loArrows 
        if select(2, GetItemInfo(GetInventoryItemLink('player', 18))) == SUBTYPE_GUNS then
            hiAmmo, loAmmo = hiBullets, loBullets 
        end
        if (UnitClassification('target') == 'elite' and UnitLevel('target') >= 82) or UnitClassification('target') == 'boss' or UnitClassification('target') == 'worldboss' then
            EquipAmmo(hiAmmo, loAmmo)
        else
            EquipAmmo(loAmmo, hiAmmo)
        end
    
        local curAmmo = GetInventoryItemLink("player", 0)
        if curAmmo and GetItemCount(curAmmo) == 0 then
            EquipAmmo()
        end
    end
    
    caelAmmoSaver:RegisterEvent('PLAYER_TARGET_CHANGED')
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code help needed
    I've found this, could it be the wrong event to watch for ?

    "UNIT_INVENTORY_CHANGED"

    Fired when the player equips or unequips an item. This can also be called if your target, mouseover or party member changes equipment (untested for hostile targets).
    This event is also raised when a new item is placed in the player's containers, taking up a new slot. If the new item(s) are placed onto an existing stack or when two stacks already in the containers are merged, the event is not raised. When an item is moved inside the container or to the bank, the event is not raised. The event is raised when an existing stack is split inside the player's containers.
    If multiple slots are equipped/unequipped at once it only fires once now. However it still fires many times (potentially hundreds) while zoning or logging in.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code help needed
    if select(2, UnitClass('player')) ~= 'HUNTER' then return end
    
    local caelAmmoSaver = CreateFrame('Frame') 
    caelAmmoSaver:SetScript('OnEvent', function(self) self:OnEvent(event) end)
    
    local SUBTYPE_GUNS = 'Guns' -- This could be localized
    local hiBullets, loBullets = 41164, 31735 -- Mammoth Cutters, Timeless Shell
    local hiArrows, loArrows = 41165, 31737 -- Saronite Razorheads, Timeless Arrow
    
    local function EquipAmmo(primary, fallback)
        local itemid
        if GetItemCount(primary) > 0 then
            itemid = primary
        elseif GetItemCount(fallback) > 0 then
            itemid = fallback
        else
            -- no ammo found, do not do anything
            return
        end
        -- Equip new ammo if need be
        if not GetInventoryItemLink('player', 0):match('item:'..tostring(itemid)..':') then
            EquipItemByName(itemid)
        end
    end
    
    local function SelectAmmo()
      -- Default to using arrows
      local hiAmmo, loAmmo = hiArrows, loArrows 
        -- Use bullets if a gun is equipped
        if select(2, GetItemInfo(GetInventoryItemLink('player', 18))) == SUBTYPE_GUNS then
            hiAmmo, loAmmo = hiBullets, loBullets 
        end
        if (UnitClassification('target') == 'elite' and UnitLevel('target') >= 82) or UnitClassification('target') == 'boss' or UnitClassification('target') == 'worldboss' then
            -- Use 'hi' ammo on bosses, fallback to 'lo' ammo
            EquipAmmo(loAmmo, hiAmmo)
        else
            -- Else use 'lo' ammo, fallback to 'hi' ammo
            EquipAmmo(hiAmmo, loAmmo)
        end
    end
    
    function caelAmmoSaver:OnEvent(event, arg1)
      if event == 'PLAYER_TARGET_CHANGED' then
        -- Check if the new target matches our conditions
        if UnitCanAttack('player', 'target') and not UnitIsDead('target') then
          SelectAmmo()
        end
      elseif event == 'UNIT_INVENTORY_CHANGED' and arg1 == 'player' then
        local curAmmo = GetInventoryItemLink("player", 0)
        if curAmmo and GetItemCount(curAmmo) == 0 then
          SelectAmmo()
        end
      end
    end
    
    caelAmmoSaver:RegisterEvent('PLAYER_TARGET_CHANGED')
    caelAmmoSaver:RegisterEvent('UNIT_INVENTORY_CHANGED')


    Unfortunately that didn't work, when running out of saronite razorheads on a boss i had to retarget my current target for it to switch to timeless arrows
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code help needed
    I'm gonna give it a try right now, but from what i can read, if say i run out of saronite razorheards in combat will it automatically fallback to using the timeless arrows (without a target switch) ?

    Edit: Yeah that's what i was expecting, it works great, but if i run out of SR i have to (for example) cleartarget and retarget for it to switch to TA, is there another event i should add so it does the switch instantly without retargeting ?
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code help needed
    Hi, i've written a small addon to automatically switch ammunitions on my hunter depending on my target. I did this because i was really pissed to forget to switch for bosses or trashes.

    So, it works like a charm but i would like to add some kind of failsafe in case i run out of one of the kind of ammunitions and have it switch back to the first one but i don't really know how to do that.

    if select(2, UnitClass('player')) ~= 'HUNTER' then return end
    
    local caelAmmoSaver = CreateFrame('Frame') 
    caelAmmoSaver:SetScript('OnEvent', function(self) self:OnEvent(event) end)
    
    function caelAmmoSaver:OnEvent(event)
        if(UnitCanAttack('player', 'target') and not UnitIsDead('target')) then
            if (UnitClassification('target') == 'elite' and UnitLevel('target') >= 82) or UnitClassification('target') == 'boss' or UnitClassification('target') == 'worldboss' then
                if strfind(GetInventoryItemLink('player',0)    or    '', 'Timeless Arrow') then
                    EquipItemByName('Saronite Razorheads')
                elseif strfind(GetInventoryItemLink('player',0)    or    '', 'Timeless Shell') then
                    EquipItemByName('Mammoth Cutters')
                end
            else
                if strfind(GetInventoryItemLink('player',0)    or    '', 'Saronite Razorheads') then
                    EquipItemByName('Timeless Arrow')
                elseif strfind(GetInventoryItemLink('player',0)    or    '', 'Mammoth Cutters') then
                    EquipItemByName('Timeless Shell')
                end
            end
        end
    end
    
    caelAmmoSaver:RegisterEvent('PLAYER_TARGET_CHANGED')
    Posted in: Lua Code Discussion
  • 0

    posted a message on Recount
    The "Hide when not collecting" or more the opposite, show when collecting doesn't work for me anymore since 3.0.2, i have to toggle it on manually every time.
    Posted in: General AddOns
  • 0

    posted a message on BadBoy: An extremely minimal spam blocker & reporter
    This one is being really spammy these days
    <>
    And my BadBoy is working fine for everything else
    Posted in: General AddOns
  • 0

    posted a message on Auto repair, need help please
    I use this to auto repair my gear when visiting a vendor. But when using a repair bot and having guild bank repair enabled, it ignores it and repair using my own money, could anyone tell me how to modify it to repair through the guild bank funds in priority over mine please ?

    local function CostString( cost )
     local gold = abs(cost / 10000)
     local silver = abs(mod(cost / 100, 100))
     local copper = abs(mod(cost, 100))
     
     if cost > 10000 then
      return string.format( "|cffffffff%d|r|cffffd700g|r |cffffffff%d|r|cffc7c7cfs|r |cffffffff%d|r|cffeda55fc|r", gold, silver, copper)
     elseif cost > 100 then
      return string.format( "|cffffffff%d|r|cffc7c7cfs|r |cffffffff%d|r|cffeda55fc|r", silver, copper) 
     else 
      return string.format("|cffffffff%d|r|cffeda55fc|r", copper )
     end
    end
    local function print(msg)
     DEFAULT_CHAT_FRAME:AddMessage(msg)
    end
    local f = CreateFrame("Frame", nil, UIParent)
    f:RegisterEvent("MERCHANT_SHOW")
    f:SetScript("OnEvent", function()
     if CanMerchantRepair() then
      local cost = GetRepairAllCost()
      local money = GetMoney()
      if money < cost then
       print( string.format("Autorepair failed, you need %s more.", CostString( cost - money )) )
      elseif cost > 0 then
       RepairAllItems()
       PlaySound("ITEM_REPAIR")
       print( string.format("Autorepaired for %s.", CostString( cost )) )
      end
     end
    end)
    Posted in: Lua Code Discussion
  • 0

    posted a message on Unofficial oUF - methods used for layouts
    Can't we all just stick to this one ? I mean, what's wrong with it :)

    Oh and i would like a bit of help for this btw, i would like to have my experience bar to show but only when i mouseover it.

    I've tried something like the code below but obviously it doesn't work, i know it's wrong but that's all i could come up with and unfortunately i couldn't find any better information on how to do this.

    local OnEnter = function(self)
     self.Experience_OnEnter(self)
     self.Experience:Show()
    end
    local OnLeave = function(self)
     self.Experience_OnLeave(self)
     self.Experience:Hide()
    end
    Posted in: Unit Frames
  • To post a comment, please or register a new account.