1. #1

    [lua] slash Command on player_login possible?

    I currently have a small problem with an Addon....
    aka. Bartender2

    whenever I use it, the bar1 changes it rows and can only be fixed by typing
    /bar bar1 rows 2
    /bar bar1 rows 1
    or I can put this in a macro and press it everytime I relog/reloadui.
    Since I hate pressing macros for stuff like that, I tried to create a small addon for myself to execute these commands on PLAYER_LOGIN

    My head is about to explode....

    It looks like this:

    local Frame = CreateFrame("Frame")
    Frame:RegisterEvent("PLAYER_LOGIN")

    Frame:SetScript("OnEvent", function(...)

    slashCommand("/bar bar1 rows 2")
    slashCommand("/bar bar1 rows 1")

    end)


    I am stuck
    could you plx halp? :O
    Last edited by Treeston; 2012-12-27 at 11:46 AM.

  2. #2
    local Frame = CreateFrame("Frame");
    Frame:RegisterEvent("PLAYER_LOGIN");
    Frame:SetScript("OnEvent",function(...) //FIND BARTERNDER API 1 HERE//; //FIND BARTENDER API 2 HERE//; end);

    There is no simple way to execute a slash command. You could look up inspiration here, but I suggest finding the API inside the addon.
    http://www.wowinterface.com/forums/s...ad.php?t=45097

  3. #3
    try this

    Code:
    local Frame = CreateFrame("Frame")
    Frame:RegisterEvent("PLAYER_LOGIN")
    
    Frame:SetScript("OnEvent", function(...)
    
    SlashCmdList["BAR"]("bar1 rows 2")
    SlashCmdList["BAR"]("bar1 rows 1")
    
    end)


    AddOn Author of: SpellNotReadyYet, Rune of Powa

  4. #4
    Code:
    local function runSlashCommand(command,arguments)
        local c,s
        for key,func in pairs(SlashCmdList) do
            c = 1
            s = _G[("SLASH_%s%d"):format(key,c)]
            while s do
                if s == command then
                    return func(arguments)
                end
                c = c+1
                s = _G[("SLASH_%s%d"):format(key,c)]
            end
        end
    end
    
    -- use it like this:
    -- runSlashCommand("/bar","bar1 rows 2")
    Drycoded.
    UI & AddOns expert | Interface & Macros moderator - My work

  5. #5
    I would go with SpaceDuck's solution. Short, to the point and does everything OP asked for with minimal extra effort required.

    Once the SlashCmdList is populated you can just call them like SlashCmdList["SLASHCMD"]("arguments here") from an AddOn.

    Edit: Though, I'd probably suggest just trying to fix your Bartender first, rather than this disparate solution.

    @Cracked I'm pretty sure what you were reading about slash commands not being callable from AddOns only applied to protected functions. Slash commands added by other addons obviously aren't protected :P
    Last edited by Lothrik; 2012-12-27 at 01:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •