Thread Tools Display Modes
03-26-12, 02:45 PM   #1
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
Exclamation Need help with a minimap buton

Hi friends


I want to a minimap buton that on left click ,I want to write in console /rtk gui
On right click say in console /rc gui - It's an addon for my guild

I have a script with a minimap buton alrealy from an Addon , but I can't find the way to edit it to work like I want, and I don't want to change the entire addon just that part with minimap,

I have these files, I think the core.lua is the file with minimap links

http://www.wowinterface.com/forums/a...1&d=1332794622

I will be verry thankfull if anybody can help me with it
Attached Files
File Type: lua core.lua (29.7 KB, 663 views)
File Type: xml backup.xml (15.0 KB, 618 views)
File Type: xml MainFrame.xml (32.3 KB, 532 views)
File Type: lua globals.lua (788 Bytes, 569 views)

Last edited by ElkAddons : 03-26-12 at 03:53 PM.
  Reply With Quote
03-26-12, 08:59 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The minimap button would need to call the same function(s) as the slash command, rather than trying to make it work the same as a user typing a command. However, neither of the slash commands you listed (/rtk and /rc) are defined in any of the files you posted, so I can't tell you which code you need to use.
  Reply With Quote
03-27-12, 01:12 AM   #3
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
Originally Posted by Phanx View Post
The minimap button would need to call the same function(s) as the slash command, rather than trying to make it work the same as a user typing a command. However, neither of the slash commands you listed (/rtk and /rc) are defined in any of the files you posted, so I can't tell you which code you need to use.
You mean that a code for this doesn't exist? Because I realy need something like that, this addon is for my guild we use multiple addons in our package, And this command is useful for us in raids.

/rtk gui comes from RaidToolKit and /rc gui comes from RaidCore

And I don't try to get author of any addon.
  Reply With Quote
03-27-12, 02:47 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by ElkAddons View Post
You mean that a code for this doesn't exist?
No. It means that the code you need to call from your minimap button is not in one of the files you posted. If it was in one of those files, I could find it for you and show you which code to use, and how to use it. However, since it is not in one of those files, I cannot see it, because I cannot magically see files on your computer's hard drive.

Originally Posted by ElkAddons View Post
/rtk gui comes from RaidToolKit and /rc gui comes from RaidCore
Then you will need to look inside those addons' files and find the code they run when you type a slash command, or post the files here so someone other than yourself can see them.
  Reply With Quote
03-27-12, 03:53 AM   #5
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
Is a code that say " Put your code that you want on a minimap button click here. " There I wanted to put on left click code /rtk gui ( to activate the RaidtoolKit ) and eventualy on right click /rc gui ( Raid Core addon)

-- Only while the button is dragged this is called every frame
function RIO_Mod_MinimapButton_DraggingFrame_OnUpdate()

local xpos,ypos = GetCursorPosition()
local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()

xpos = xmin-xpos/UIParent:GetScale()+70 -- get coordinates as differences from the center of the minimap
ypos = ypos/UIParent:GetScale()-ymin-70

RIO_MinimapPos = math.deg(math.atan2(ypos,xpos)) -- save the degrees we are relative to the minimap center
RIO_Mod_MinimapButton_Reposition() -- move the button
end

-- Put your code that you want on a minimap button click here. arg1="LeftButton", "RightButton", etc
function RIO_Mod_MinimapButton_OnClick()
if arg1 == "LeftButton" then
if RIO_MainFrame:IsVisible() then
RIO_MainFrame:Hide();
else
RIO_MainFrame:Show();
end
end
end

function RIO_Mod_MinimapButton_OnEnter(self)
if (self.dragging) then
return
end
GameTooltip:SetOwner(self or UIParent, "ANCHOR_LEFT")
GameTooltip:SetText("Raid Invite Organiser");
end
Bassicaly all I want to do is to make this code what when I click minimap is say these commands ( like i do myself )

Last edited by ElkAddons : 03-27-12 at 06:06 AM.
  Reply With Quote
03-27-12, 04:35 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That's not how addons work.

When you type "/rtk gui" in chat and press enter, here is what happens:

1. The game looks for "/gtk" in its list of registered slash commands.
2. The game looks for the function that is registered to handle that command.
3. The game calls that function, passing "gui" to the function as an argument.
4. The function does something based on the argument received.

When you want to do the same thing by clicking a button, here is what happens:

1. You look for the function that the game would call if you typed "/gtk".
2. You call that function, passing "gui" as an argument.
3. The function does something based on the argument received.

The addon does not actually open the chat box, type "/gtk gui", and press Enter.

Here is how an addon defines a slash command:

Code:
-- These lines define the actual commands that the user can type:
SLASH_MYADDON1 = "/myaddon"
SLASH_MYADDON2 = "/ma"

-- These lines define what function is called when the user types one of those commands:
SlashCmdList["MYADDON"] = function(arg)
    if arg = "hello" then
        DEFAULT_CHAT_FRAME:AddMessage("Hello!")
    else
        DEFAULT_CHAT_FRAME:AddMessage("No command entered.")
    end
end
You can either type "/myaddon hello", or do this in an addon:

Code:
MyAddonButton:SetScript("OnClick", function(self, button)
    if button == "LeftButton" then
        SlashCmdList["MYADDON"]("hello")
    else
        SlashCmdList["MYADDON"]()
    end
end
Alternatively, you could copy the code out of the addon's slash command handler, and do something like this:

Code:
MyAddonButton:SetScript("OnClick", function(self, button)
    if button == "LeftButton" then
        DEFAULT_CHAT_FRAME:AddMessage("Hello!")
    else
        DEFAULT_CHAT_FRAME:AddMessage("No command entered.")
    end
end
So, as I already said, you will need to look inside the files for the addon whose slash command you want to emulate, and find how it handles its slash commands, and either call its slash command handler function, or copy the code out of that function.

If you cannot find the code, or cannot figure out how to call it from your own addon, then you will need to post the files from that addon, so that someone else can find the code for you.
  Reply With Quote
03-28-12, 01:46 AM   #7
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
So, as I already said, you will need to look inside the files for the addon whose slash command you want to emulate, and find how it handles its slash commands, and either call its slash command handler function, or copy the code out of that function.

If you cannot find the code, or cannot figure out how to call it from your own addon, then you will need to post the files from that addon, so that someone else can find the code for you.[/quote]

---------------------------------------------------------------------

Thank you verry much..

But I still have problems fiding this code, I searched in all files this code but I didn't find , I don't know were I can edit can you help me finding and compile it?

I added in a package all those 3 Addons... that I want to combine , One is called RaidInviteOrganizer , this have the minimap that I want to use for this Addon the other too RaidTool Kit and Raid Compact Are the Addons that I need Activate ( The reason I want to use minimap RaidInviteOrganizer is that minimap doesn't work and I like how it looks ).

<snip>

( the website says that you need account to download , but you don't you can download free )

I need help, when you have time

Last edited by Seerah : 03-28-12 at 12:19 PM. Reason: removed link to off-site download
  Reply With Quote
03-29-12, 01:33 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by ElkAddons View Post
But I still have problems fiding this code, I searched in all files this code but I didn't find , I don't know were I can edit can you help me finding and compile it?
Again, I cannot help you unless you show me the code you need help with. At this point, you have two choices:

1. Search inside the files for the addon's slash command handler. You can usually find it by searching for the word "SlashCmdList" or "RegisterChatCommand". If you can find it, post the files that contain those words.

2. If you cannot figure out how to search for text in a file, post a link to a reputable website where I can download the addon. If the addon is only hosted on some guy's personal web site, or on some guild's forums, I am not going to download it; see #1.

Last edited by Phanx : 03-29-12 at 01:37 AM.
  Reply With Quote
03-29-12, 10:26 AM   #9
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
Gosh, verry useful your tips I find them


Code:
self:RegisterChatCommand("rtk", "onSlashCommand")
    self:RegisterChatCommand("raidtoolkit", "onSlashCommand")




-- Code that you want to run when the addon is first loaded goes here.
function addon:OnInitialize()
    -- AceDB
    self.db = LibStub("AceDB-3.0"):New("RaidCompDB", addon.dbDefaults)
    addon.options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
    
    -- If the database version is too old then wipe the lot and start again
    -- This should only happen if there's a fundamental change to the structure of the database or if changes
    -- to the game itself render all the data obsolete (i.e. a complete redesign of the talent trees)
    if not addon.db.factionrealm.versionDB or addon.db.factionrealm.versionDB < addon.VERSIONDB then
        addon.db.factionrealm.raidDB = wipe(addon.db.factionrealm.raidDB)
        addon.db.factionrealm.altDB = wipe(addon.db.factionrealm.altDB)
        addon.db.factionrealm.fakeDB = wipe(addon.db.factionrealm.fakeDB)
        addon.db.factionrealm.overrideDB = wipe(addon.db.factionrealm.overrideDB)
        addon.db.factionrealm.customDB = wipe(addon.db.factionrealm.customDB)
        addon.db.factionrealm.ignoreDB = wipe(addon.db.factionrealm.ignoreDB)
        addon.db.factionrealm.petDB = wipe(addon.db.factionrealm.petDB)
        addon.db.factionrealm.fakeNextID = 1
        addon.db.factionrealm.versionDB = addon.VERSIONDB
    end
    
    -- AceConfig/AceConsole
    LibStub("AceConfig-3.0"):RegisterOptionsTable(ADDONNAME, addon.options, {"raidcomp", "rc"})
    
    -- Add to Blizzard Options
    LibStub("AceConfigDialog-3.0"):AddToBlizOptions(ADDONNAME, ADDONTITLE)
On Attachements I have the addon with minimap, that doesnt work can you compile it?
Attached Files
File Type: lua core.lua (29.7 KB, 554 views)
File Type: lua globals.lua (788 Bytes, 545 views)
File Type: xml MainFrame.xml (32.3 KB, 539 views)

Last edited by ElkAddons : 03-30-12 at 03:49 AM.
  Reply With Quote
03-29-12, 03:55 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Post the contents of the addon's onSlashCommand function.
  Reply With Quote
03-30-12, 12:08 AM   #11
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
Code:
-- Addon Declaration
-- =================
local ADDONNAME = "RaidComp"
RaidComp = LibStub("AceAddon-3.0"):NewAddon(ADDONNAME, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
local addon = RaidComp
addon.ADDONNAME = ADDONNAME
addon.VERSION = "4.25"
addon.VERSIONDB = 40000

local LibDB = LibStub:GetLibrary("LibDataBroker-1.1")

-- Addon constants
local ADDONTITLE = "RaidComp"
addon.ADDONTITLE = ADDONTITLE
addon.IMAGEPATH = "Interface\\AddOns\\RaidComp\\images\\"

-- Locale
local L = LibStub("AceLocale-3.0"):GetLocale(ADDONNAME, true)


-- Addon OnInitialize, OnEnable, OnDisable
-- =======================================

-- Code that you want to run when the addon is first loaded goes here.
function addon:OnInitialize()
    -- AceDB
    self.db = LibStub("AceDB-3.0"):New("RaidCompDB", addon.dbDefaults)
    addon.options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
    
    -- If the database version is too old then wipe the lot and start again
    -- This should only happen if there's a fundamental change to the structure of the database or if changes
    -- to the game itself render all the data obsolete (i.e. a complete redesign of the talent trees)
    if not addon.db.factionrealm.versionDB or addon.db.factionrealm.versionDB < addon.VERSIONDB then
        addon.db.factionrealm.raidDB = wipe(addon.db.factionrealm.raidDB)
        addon.db.factionrealm.altDB = wipe(addon.db.factionrealm.altDB)
        addon.db.factionrealm.fakeDB = wipe(addon.db.factionrealm.fakeDB)
        addon.db.factionrealm.overrideDB = wipe(addon.db.factionrealm.overrideDB)
        addon.db.factionrealm.customDB = wipe(addon.db.factionrealm.customDB)
        addon.db.factionrealm.ignoreDB = wipe(addon.db.factionrealm.ignoreDB)
        addon.db.factionrealm.petDB = wipe(addon.db.factionrealm.petDB)
        addon.db.factionrealm.fakeNextID = 1
        addon.db.factionrealm.versionDB = addon.VERSIONDB
    end
    
    -- AceConfig/AceConsole
    LibStub("AceConfig-3.0"):RegisterOptionsTable(ADDONNAME, addon.options, {"raidcomp", "rc"})
    
    -- Add to Blizzard Options
    LibStub("AceConfigDialog-3.0"):AddToBlizOptions(ADDONNAME, ADDONTITLE)
    
    -- DataBroker
    local LDB = LibDB:NewDataObject(ADDONNAME, {
        type = "launcher",
        label = addon.ADDONTITLE,
        icon = addon.IMAGEPATH.."icon",
        OnClick = function(clickedframe, button)
            addon:OpenGUI()
        end,
        OnTooltipShow = function(tooltip)
            addon:Tooltip_LDB(tooltip)
        end,
    })
    
    addon.playerfaction = "Alliance"
    
--    addon:PrDebug("OnInitialize")
end

-- Populates the LDB tooltip
function addon:Tooltip_LDB(tooltip)
    tooltip:AddLine(addon.ADDONTITLE)
    
    -- Only add talent scan data to the tooltip if the GUI has been built, as otherwise the addon is "dormant"
    if addon:IsGUIReady() then
        local talentsgot, talentsmissing = addon:GetTalentCount()
        
        if talentsgot and talentsmissing then
            tooltip:AddLine( format( L["format_scanspending"], tostring(talentsmissing), tostring(talentsgot + talentsmissing) ), HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b )
        end
    end
    
    tooltip:AddLine(" ")
    tooltip:AddLine( addon:ColorCode(GREEN_FONT_COLOR_CODE, "Left-click").." to open the GUI", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b )
end

-- Called when the addon is enabled
function addon:OnEnable()
    addon.playerfaction = UnitFactionGroup('player')

--    addon:PrDebug("OnEnable")
end

-- Called when the addon is disabled
function addon:OnDisable()
    -- Destroy GUI
    addon:DestroyGUI()

--    addon:PrDebug("OnDisable")
end
Code:
function RaidToolkit:initializeGui()
    local frame = RaidToolkit:getInviteListFrame()
    frame:redrawInviteList()
end

function RaidToolkit:createFrame()
    if self.frame then
        return self.frame
    end

    local AceGUI = LibStub("AceGUI-3.0")
    local frame = AceGUI:Create("Frame")
    frame:Hide()

    frame:SetWidth(235)
    frame:SetHeight(420)
    frame.frame:SetMinResize(235, 420)
    frame:SetTitle("RaidToolkit")
    frame:SetStatusText("")
    frame:SetCallback("OnClose", 
                      function (widget) 
                          --AceGUI:Hide(widget) 
                          widget:Hide()
                      end)
    
    frame:SetLayout("Flow")

    local tabGroup = AceGUI:Create("TabGroup")
    tabGroup:SetWidth(200)
        
    local tabs = {}

    function addCommandButton(container, label, fn)
        local button = AceGUI:Create("Button")
        button:SetText(label)
        button:SetWidth(200)
        button:SetCallback("OnClick", function () fn() end)
        container:AddChild(button)
    end

    function addHeading(label)
        local group = AceGUI:Create("SimpleGroup")
        group:SetWidth(200)
        group:SetLayout("Flow")

        local heading = AceGUI:Create("Heading")
        heading:SetText(label)
        heading:SetWidth(200)
        group:AddChild(heading)
        tabGroup:AddChild(group)
        
        return group
    end

    table.insert(
        tabs,
        {name = "basic",
         title = "Basic",
         f = function ()
                 local heading = addHeading("Basic")
                 self:map(function (info)
                              local title, command = unpack(info)
                              addCommandButton(heading, title, command)
                          end,
                          {{"Promote all", self.commands.promote},
                           {"Demote all", self.commands.demote},
                           {"Kick offline", self.commands.kickoffline},
                           {"Mark tanks", self.commands.marktanks},
                           {"Role check", self.commands.rolecheck},
                           {"Ready check", self.commands.readycheck},
                           {"Raid roll", self.commands.raidroll},
                           {"Info", self.commands.info},
                           {"Size", self.commands.size},
                           {"Role stats", self.commands.roles},
                       })
             end})
    
    table.insert(
        tabs,
        {name = "layout",
         title = "Layout",
         f = function ()
                 local heading = addHeading("Manage raid layout")
                 self:map(function (info)
                              local title, command = unpack(info)
                              addCommandButton(heading, title, command)
                          end,
                          {{"Compress", self.commands.compress},
                           {"Reverse", self.commands.reverse},
                           {"Shift down", self.commands.shift},
                           {"Shift up", self.commands.unshift},
                           {"Random", self.commands.random},
                           {"Sort by class", function () self.commands.sort("class") end},
                           {"Save subgroups", self.commands.store},
                           {"Restore subgroups", self.commands.restore},
                       })
             end})

    table.insert(
        tabs,
        {name = "misc",
         title = "Misc",
         f = function ()
                 local heading = addHeading("Miscellaneous")
                 self:map(function (info)
                              local title, command = unpack(info)
                              addCommandButton(heading, title, command)
                          end,
                          {{"Disband", self.commands.disband},
                           {"Reform", self.commands.reform},
                           {"Convert to party", self.commands.party},
                           {"Leave", self.commands.leave},
                           {"Reset instances", self.commands.reset},
                           {"Clear roles", self.commands.clearrole},
                       })

                 local heading = addHeading("Other windows")
                 self:map(function (info)
                              local title, command = unpack(info)
                              addCommandButton(heading, title, command)
                          end,
                          {{"Configuration", self.commands.config},
                           {"Invite list", self.commands.invlist},
                           {"Toggle Raid UI", self.commands.toggleraidui},
                       })
             end})
    

    --addCommandButton("Multi invite", nil)

    tabGroup:SetTabs(self:mapToArray(
                         function (tabInfo)
                             return {text = tabInfo.title, value = tabInfo.name}
                         end,
                         tabs))
    tabGroup:SetLayout("Flow")
    tabGroup:SetCallback("OnGroupSelected", 
                    function (container, event, group)
                        container:ReleaseChildren()
                        for k, tabInfo in pairs(tabs) do
                            if group == tabInfo.name then
                                tabInfo.f(subcontainer)
                            end
                        end
                            --tabs[group](subcontainer)
                    end)
    tabGroup:SelectTab("basic")
    frame:AddChild(tabGroup)


    self.frame = frame
    return self.frame
end

function RaidToolkit:getInviteListFrame()
    if self.inviteListFrame then
        return self.inviteListFrame
    end

    local AceGUI = LibStub("AceGUI-3.0")
    local frame = AceGUI:Create("Frame")
    frame:Hide()

    frame:SetWidth(250)
    frame:SetHeight(450)
    frame.frame:SetMinResize(200, 100)
    frame:SetTitle("RTK invite list")
    frame:SetStatusText("")
    frame:SetCallback("OnClose", 
                      function (widget) 
                          widget:Hide()
                      end)
    
    frame:SetLayout("List")

    local helpText = "Left click to invite the person.\n"
    helpText = helpText .. "Shift + Left click to invite a person while keeping him/her on the list.\n"
    helpText = helpText .. "Right click to remove a person from the list.\n"
    
    local helpTextFrame = AceGUI:Create("Label")
    helpTextFrame:SetFullWidth(true)
    helpTextFrame:SetText(helpText)
    frame:AddChild(helpTextFrame)

    local heading = AceGUI:Create("Heading")
    heading:SetText("Invite list")
    heading:SetFullWidth(true)
    frame:AddChild(heading)

    local group = AceGUI:Create("ScrollFrame")
    group:SetFullWidth(true)
    group:SetLayout("List")
    frame:AddChild(group)

    function frame:addPerson(entry, counter)
        local color = {0.7, 0.7, 0.7}
        local highlightColor = {1, 0, 0}
        local label = AceGUI:Create("InteractiveLabel")
        local name, requestedBy, fn = entry.name, entry.requestedBy, entry.fn
        
        local text = tostring(counter) .. ". " .. name

        if (entry.class) then
            -- text = text .. " [" .. entry.class .. "]"

            local className = RaidToolkit:tfind(LOCALIZED_CLASS_NAMES_MALE, entry.class)
            local tmpcolors = RAID_CLASS_COLORS[className]
            if className and tmpcolors then
                color = {tmpcolors.r, tmpcolors.g, tmpcolors.b}
            end
        end

        if (RaidToolkit:tcount(requestedBy) > 0) then
            text = text .. "   (by " .. strjoin(",", unpack(RaidToolkit:toArray(requestedBy))) .. ")"
        end
        
        label:SetText(text)


        label:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE)
        label:SetFullWidth(true)
        label:SetColor(unpack(color))
        label:SetCallback(
            "OnClick", 
            function (widget, sometable, button)
                RaidToolkit:Debug("Click. Button is " .. tostring(button))
                if "LeftButton" == button then
                    if fn then
                        fn()
                    end
                    InviteUnit(name)
                    if not IsShiftKeyDown() then
                        RaidToolkit:removeFromInviteList(name)
                    end
                elseif "RightButton" == button then
                    RaidToolkit:removeFromInviteList(name)
                end
            end)
        label:SetCallback(
            "OnEnter",
            function (widget, sometable)
                label:SetColor(unpack(highlightColor))
            end)
        label:SetCallback(
            "OnLeave",
            function (widget, sometable)
                label:SetColor(unpack(color))
            end)
        
        group:AddChild(label)
    end

    function addCommandButton(container, label, fn)
        local button = AceGUI:Create("Button")
        button:SetText(label)
        button:SetWidth(90)
        button:SetCallback("OnClick", fn)
        container:AddChild(button)
    end

    local commandsGroup = AceGUI:Create("SimpleGroup")
    commandsGroup:SetFullWidth(true)
    commandsGroup:SetLayout("Flow")
    frame:AddChild(commandsGroup)

    addCommandButton(commandsGroup, "Clear",
                     function ()
                         self.p.inviteList = {}
                         frame:redrawInviteList()
                     end)
    addCommandButton(commandsGroup, "Invite all",
                     function ()
                         self:map(
                             function (v)
                                 if v.fn then
                                     v.fn()
                                 end
                                 InviteUnit(v.name)
                             end,
                             self.p.inviteList)
                                  
                         frame:redrawInviteList()
                     end)

    function frame:redrawInviteList()
        group:ReleaseChildren()

        local counter = 0
        for k, v in pairs(RaidToolkit.p.inviteList) do
            counter = counter + 1
            frame:addPerson(v, counter)
        end
    end

    self.inviteListFrame = frame
    return self.inviteListFrame
end
I take Entire file with these commands

Last edited by ElkAddons : 03-30-12 at 03:07 AM.
  Reply With Quote
03-30-12, 02:47 AM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1. Please use CODE tags around code blocks, not QUOTE tags. Using CODE tags will preserve the indentation, and not make people have to scroll through 5000 lines to get past your post.

2. None of the code you posted contains the phrase "RegisterChatCommand" or "onSlashCommand". In one of the addon's files, there should be something that looks like this:

Code:
function addon:onSlashCommand(something)
    -- some code here
end
That is what I need to see.

Honestly, I'm seeing two problems here:

(1) There seems to be a language barrier, and you are not completely understanding what I'm asking you to do. If that is the case, and you do not understand something I've said, please tell me that you didn't understand it, so I can try to make it clearer.

(2) It seems like you have never seen any form of computer code before attempting this project. I would suggest reading some basic "introduction to programming" books or web pages to help you better understand what you are looking at when you're reading addon code. For example, if you do not know what the term "function" means, it is going to be extremely difficult for you to accomplish anything here.
  Reply With Quote
03-30-12, 03:18 AM   #13
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
RaidToolKit :


Code:
function RaidToolkit:onSlashCommand(str)
    self:handleCommand(str, self.commands)
end
Code can be found down below:
Code:
function RaidToolkit:initializeCommands()
    local commands = {}

    local function checkLeader()
        if not self:isLeader() then
            self.dyn.Print("Only raid leaders can do that")
            return false
        else
            return true
        end
    end

    local function checkRaidRights()
        if not self:hasRaidRights() then
            self.dyn.Print("Only raid leaders/assistants can do that")
            return false
        else
            return true
        end
    end

    local stats = {
        class = {name = "Classes",
                 fn = UnitClass,
                 keys = LOCALIZED_CLASS_NAMES_MALE,
                 unknown = "Unknown"},
        role = {name = "Roles",
                fn = function (unit)
                         local groupRole = UnitGroupRolesAssigned(unit)
                         local talentRole = self.groupTalents:GetUnitRole(unit)
                         if groupRole and "NONE" ~= groupRole then
                             return getglobal(groupRole)
                         elseif talentRole then
                             return self:ucfirst(talentRole) .. " (by talent spec)"
                         else
                             return nil
                         end
                     end,
                unknown = "Unknown"},
        zone = {name = "Zones",
                fn = UnitClass,
                unknown = "Unknown"},
        race = {name = "Races",
                fn = UnitRace,
                unknown = "Unknown"},
        guild = {name = "Guilds",
                 fn = function (unit)
                          return (GetGuildInfo(unit))
                      end,
                 unknown = "Unknown"},
        status = {name = "Status",
                  fn = function (unit)
                           if UnitIsAFK(unit) then return "AFK" end
                           if UnitIsDND(unit) then return "DND" end
                           if UnitIsConnected(unit) then
                               return "Online"
                           else
                               return "Offline"
                           end

                           return nil
                       end,
                  unknown = "Unknown"},
        server = {name = "Servers",
                  fn = function (unit)
                           local _, server = UnitName(unit)
                           if server and "" ~= server then
                               return server
                           else
                               return GetRealmName()
                           end
                       end,
                  unknown = "Unknown"},
    }
    self.stats = stats

    self.commandHelp = {
        {"gui", "open the command window"},
        {"invlist", "open the invite list"},
        {"config", "open the configuration window"},
        {"announce", "toggle announcing messages to the group"},

        {"promote", "promote raid members"},
        {"promotetanks", "promote the maintanks"},
        {"demote", "demote raid members"},
        {"setrole", "set role for raid members"},
        {"together", "Move people together in the same group"},
        {"invite", "invite one or more people"},        
        {"kickoffline", "kick offline people"},
        {"kickgroup", "kick subgroup(s)"},
        {"marktanks", "Mark tanks with an icon"},
        {"ora", "synchronize/remove oRA2 maintank list with Blizzard maintank/mainassist"},

        {"whisperleader", "Sends a whisper to the leader"},

        {"leave", "leave the raid group"},
        {"reset", "Reset all instances"},

        {"convert", "converts a party to a raid group"},
        {"disband", "disbands the raid group"},
        {"reform", "disband the raid and recreate the raid"},
        {"party", "convert to party"},

        {"compress", "moves members to the top groups"},
        {"random", "ranomly move people around in the raid"},
        {"swap", "swaps two groups (/rtk swap 1 2)"},
        {"layout", "sets a raid layout"},
        {"shiftdown", "shifts groups down"},
        {"shiftup", "shifts groups up"},
        {"sort", "Sort the raid (/rtk sort class"},
        {"save", "Save the subgroups"},
        {"restore", "Restore the subgroups"},

        {"rc", "starts a ready check"},
        {"rolecheck", "starts a role check"},
        {"rr", "Make a raid roll"},

        {"size", "display current raid size"},
        {"info", "display information about the current raid"},
        {"stat", "Raid statistics (/rtk stat class"},
        {"difficulty", "set the raid size and difficulty"},
        {"loot", "set the loot threshold"},
        {"lootmethod", "set the loot method"},
        {"lootmaster", "set the loot master"},

        -- classes, roles, 
    }

    function commands.test()
        self.dyn.Print("test")
    end

    function commands.shorthelp()
        self.dyn.Print("  USAGE  ")
        self.dyn.Print("/rtk [command]")
        self.dyn.Print("gui, promote, demote, convert, disband, leave, reform, party, compress, random, swap, rc, kickoffline, kickgroup, whisperleader, layout, difficulty, size, info")
        self.dyn.Print("Type  /rtk help  for a description of each command")
        self.dyn.Print("Type  /rtk gui  for the GUI window")
        self.dyn.Print("Type  /rtk config  to set some options")
        self.dyn.Print("Type  /rtk_options  to change configuration options from a macro")
    end

    function commands.more()
        self.dyn.Print("  USAGE  ")
        self.dyn.Print("/rtk [command]")
        
        for command, helpText in pairs(self.commandHelp) do
            local command, text = unpack(helpText)
            self.dyn.Print(command .. ": " .. text)
        end

        self.dyn.Print("")
        self.dyn.Print("Or use abbreviations: rc (readycheck), pro (promote), dem (demote), "
                       .. "inv (invite), ann (announce toggle), ml (lootmaster), tog (together)")
    end

    function commands.help()
        commands.more()

        -- self.dyn.Print("TODO:")
        -- self.dyn.Print("report: show raid layout in guild/channel")
        -- self.dyn.Print("officers: promote your guild's officers")
        -- self.dyn.Print("friends: promote your friends")

        -- self.dyn.Print("kickdeserter: Kick people with pvp deserter buff")
        -- self.dyn.Print("kickignore: Kick people that you have ignored")
    end

    function commands.gui()
        local frame = self:createFrame()
        frame:Show()
    end

    function commands.invlist()
        local frame = self:getInviteListFrame()
        frame:Show()
    end

    function commands.showinvlist()
        local names = self:mapToArray(
            function (v)
                local name, invitedBy = unpack(v)
                local str = name
                if invitedBy then 
                    str = str .. " (by " .. invitedBy .. ")"
                end
                return str
            end,
            self.p.inviteList)
        local namesStr = strjoin(", ", unpack(names))
        self.dyn.Announce("Invite list: ")
        self.dyn.Announce(namesStr)
    end

    function commands.config()
        self:showConfigWindow()
    end

    function commands.disband()
        if not checkLeader() then return end
        self.dyn.Announce("Disbanding raid")
        self:disband()
    end
    
    function commands.leave()
        self.dyn.Print("Leaving raid")
        LeaveParty()
    end
    
    function commands.demote(...)
        if not checkLeader() then return end
        local units = {...}
        if #units > 0 then
            self.dyn.Announce("Demoting " .. strjoin(", ", unpack(units)))
            self:patch(self:demoteUnits(units))
        else
            self.dyn.Announce("Demoting everyone")
            self:demoteAll()
        end
    end
    
    function commands.promote(...)
        if not checkLeader() then return end
        local units = {...}
        if #units > 0 then
            self.dyn.Announce("Promoting " .. strjoin(", ", unpack(units)))
            self:patch(self:promoteUnits(units))
        else
            self.dyn.Announce("Promoting everyone")
            self:promoteAll()
        end
    end
    
    function commands.promotetanks()
        if not checkLeader() then return end
        self.dyn.Announce("Promoting tanks")

        local leader, assistants, perRole = self:getLeader()
        if perRole then
            self:patch(self:promoteUnits(perRole.MAINTANK))
        end
    end

    function commands.clearrole(...)
        if not checkRaidRights() then return end
        local units = {...}
        if #units > 0 then
            self.dyn.Announce("Clearing roles for " .. strjoin(", ", unpack(units)))
            self:patch(self:clearRoleUnits(units))
        else
            self.dyn.Announce("Clearing all roles")
            self:clearAllRoles()
        end
    end

    function commands.setrole(role, ...)
        if not checkRaidRights() then return end
        local units = {...}

        if role then
            if #units > 0 then
                self.dyn.Announce("Setting " .. role .. " role for " .. strjoin(", ", unpack(units)))
                self:patch(self:setRoleUnits(units, role))
            else
                local units = self:getUnits()
                self.dyn.Announce("Setting everybody's role to " .. role)
                self:patch(self:setRoleUnits(units, role))
            end
        else
            self.dyn.Announce("Try one of tank, healer, damager, none")
        end
    end

    function commands.compress()
        if not checkRaidRights() then return end
        self.dyn.Announce("Compressing raid groups")
        self:patch(self:compress())
    end

    function commands.reverse()
        if not checkRaidRights() then return end
        self.dyn.Announce("Reversing raid groups")
        self:patch(self:reverse())
    end

    function commands.shift()
        if not checkRaidRights() then return end
        self.dyn.Announce("Shifting raid groups down")
        self:patch(self:shift())
    end

    function commands.unshift()
        if not checkRaidRights() then return end
        self.dyn.Announce("Shifting raid groups up")
        self:patch(self:unshift())
    end

    function commands.layout(...)
        if not checkRaidRights() then return end
        self.dyn.Announce("Setting group layout to: " .. strjoin("-", ...))
        local layoutPattern = self:map(tonumber, {...})
        self:patch(self:compress(layoutPattern))
    end
    
    function commands.swap(groupAstr, groupBstr)
        if not checkRaidRights() then return end
        local groupA = tonumber(groupAstr)
        local groupB = tonumber(groupBstr)

        if groupA and groupB then
            self.dyn.Announce("Swapping groups " .. tostring(groupA) .. " and " 
                   .. tostring(groupB))
            self:patch(self:swapGroup(groupA, groupB))
        else
            self.dyn.Print("Error, type two group numbers")
        end
    end

    function commands.together(groupStr, ...)
        if not checkRaidRights() then return end
        local names = self:map("toName", {...})
        local group = tonumber(groupStr)
        
        if group then
            self.dyn.Announce("Moving " .. strjoin(", ", unpack(names))
                          .. " together in group " .. tostring(group))
            self:patch(self:putTogether(group, names))
        end
    end
    
    function commands.convert()
        if not checkLeader() then return end
        self.dyn.Announce("Converting party to a raid group")
        self:convert()
    end

    function commands.readycheck()
        if not checkRaidRights() then return end
        self.dyn.Announce("Starting ready check")
        self:readycheck()
    end

    function commands.rolecheck()
        if not checkRaidRights() then return end
        self.dyn.Announce("Starting raid role check")
        InitiateRolePoll()
    end

    function commands.reform()
        if not checkRaidRights() then return end
        self.dyn.Announce("Recreating raid")
        if not self:reform() then
            self.dyn.Print("Recreating failed. Earlier recreate is still in progress")
        end
    end

    function commands.party()
        if not checkLeader() then return end
        self.dyn.Announce("Converting to party")
        ConvertToParty()
        -- if not self:reformAsParty() then
        --     self.dyn.Print("Recreating failed. Earlier recreate is still in progress")
        -- end
    end

    function commands.invite(...)
        if not checkRaidRights() then return end
        self.dyn.Announce("Inviting " .. strjoin(", ", ...))
        self:invite(...)
    end

    function commands.reset()
        if not checkLeader() then return end
        ResetInstances()
        self.dyn.Announce("Instances have been reset")
    end

    function commands.kickoffline()
        if not checkRaidRights() then return end
        self.dyn.Announce("Kicking offline people")
        self:applyIf(self.actions.kick, self:invert(UnitIsConnected))
    end

    function commands.kickgroup(...)
        if not checkRaidRights() then return end
        self.dyn.Announce("Kicking group(s): " .. strjoin(", ", ...))
        local subgroups = self:map(tonumber, {...})
        self:patch(self:kickSubgroups(subgroups))
    end

    function commands.whisperleader(...)
        self:whisperLeader(strjoin(" ", ...))
    end

    function commands.random()
        if not checkRaidRights() then return end
        self.dyn.Announce("Randomizing raid setup")
        self:patch(self:randomize())
    end

    function commands.debug()
        RaidToolkit.db.profile.isDebug = not RaidToolkit.db.profile.isDebug

        if RaidToolkit.db.profile.isDebug then
            self.dyn.Print("Debug enabled")
        else
            self.dyn.Print("Debug disabled")
        end
    end

    function commands.announce()
        RaidToolkit.db.profile.isAnnounce = not RaidToolkit.db.profile.isAnnounce

        if RaidToolkit.db.profile.isAnnounce then
            self.dyn.Print("Announce enabled")
        else
            self.dyn.Print("Announce disabled")
        end
    end

    function commands.difficulty(size, mode)
        if not checkLeader() then return end
        if size and mode then
            mode = string.gsub(mode, "(h%a+)", "heroic")
            mode = string.gsub(mode, "(n%a+)", "normal")
            local difficulties = {}
            difficulties["10normal"] = 1
            difficulties["25normal"] = 2
            difficulties["10heroic"] = 3
            difficulties["25heroic"] = 4
            local difficulty = difficulties[size .. mode]
            if difficulty then
                RaidToolkit:SetRaidDifficulty(difficulty)
            else
                self.dyn.Print("Unknown difficulty. Try one of '10 normal', '10 hard', '25 normal', '25 hard'.")
            end
        else
            self.dyn.Print("Unknown difficulty. Try one of '10 normal', '10 hard', '25 normal', '25 hard'.")            
        end
    end

    function commands.loot(threshold)
        if not checkLeader() then return end
        local itemQualities = {}
        --itemQualities["poor"] = 0
        --itemQualities["common"] = 1
        itemQualities["uncommon"] = 2
        itemQualities["rare"] = 3
        itemQualities["epic"] = 4
        itemQualities["legendary"] = 5
        itemQualities["artifact"] = 6
        --itemQualities["heirloom"] = 7

        if not threshold or nil == itemQualities[threshold] then
            self.dyn.Print("/rtk loot <loottype>  loottype is one of: uncommon, rare, epic, legendary, artifact")
        else
            SetLootThreshold(itemQualities[threshold])
        end
    end

    function commands.lootmethod(method)
        if not checkLeader() then return end
        lootmethods = {"group", "freeforall", "master", "needbeforegreed", "roundrobin"}

        if not method or not self:tContains(lootmethods, method) then
            self.dyn.Print("/rtk lootmethod <method>  method is one of: " .. strjoin(", ", unpack(lootmethods)))
        else
            SetLootMethod(method)
        end
    end

    function commands.lootmaster(person)
        if not checkLeader() then return end
        SetLootMethod("master", person, 1)
    end

    function commands.size()
        local size = self:GetGroupSize()

        if size == 1 then
            self.dyn.Print("You are not in a group")
        else
            self.dyn.Announce("There are " .. tostring(size) .. " people in your raid/party")
        end
    end

    function commands.info()
        -- Raid size
        self.dyn.Announce("Raid size: " .. self:GetGroupSize())

        -- Raid Leader
        local leader, assistants, perRole = self:getLeader()
        if leader then
            self.dyn.Announce("Raid leader: " .. leader)
        end
        if assistants and #assistants > 0 then
            self.dyn.Announce("Raid assistants: " .. strjoin(", ", unpack(assistants)))
        end
        if perRole then
            if #(perRole.MAINTANK) > 0 then
                self.dyn.Announce("Maintanks: " .. strjoin(", ", unpack(perRole.MAINTANK)))
            end
            if #(perRole.MAINASSIST) > 0 then
                self.dyn.Announce("Main assists: " .. strjoin(", ", unpack(perRole.MAINASSIST)))
            end
        end                

        -- Raid difficulty
        local difficulty = getglobal("RAID_DIFFICULTY"..GetCurrentRaidDifficulty())
        self.dyn.Announce("Raid difficulty: " .. difficulty)

        -- Loot threshold
        local itemQualities = {}
        itemQualities[1] = "Poor"
        itemQualities[2] = "Common"
        itemQualities[3] = "Rare"
        itemQualities[4] = "Epic"
        itemQualities[5] = "Legendary"
        itemQualities[6] = "Artifact"
        itemQualities[7] = "Heirloom"
        local lootThreshold = GetLootThreshold()
        self.dyn.Announce("Loot threshold: " .. itemQualities[lootThreshold])

        -- Loot type
        local method, partyMaster, raidMaster = GetLootMethod()
        self.dyn.Announce("Loot method: " .. method)
        if raidMaster then
            local raidMasterName = GetRaidRosterInfo(raidMaster)
            self.dyn.Announce("Loot master: " .. raidMasterName)
        elseif partyMaster then
            if 0 == partyMaster then
                self.dyn.Announce("Loot master: " .. UnitName("player"))
            else
                local partyMasterName = self:getUnitName("party" .. partyMaster)
                self.dyn.Announce("Loot master: " .. partyMasterName)
            end
        end
    end

    function commands.roles()
        commands.stats("role")
    end

    function commands.classes()
        commands.stats("class")
    end

    function commands.stats(statStr)
        local statInfo = stats[statStr]
        if statInfo then
            self.dyn.Announce(statInfo.name .. " found in this raid")
            self:announceBreakdown(statInfo.fn, statInfo.keys, statInfo.unknown)
        else
            self.dyn.Announce("Use one of: " 
                              .. strjoin(", ", unpack(self:tkeys(stats))))
        end
    end

    function commands.sort(statStr)
        if not checkRaidRights() then return end
        local statInfo = stats[statStr]
        if statInfo then
            self.dyn.Announce("Sorting by " .. statInfo.name)
            self:patch(self:sortRaidBy(statInfo.fn))
        else
            self.dyn.Announce("Use one of: " 
                              .. strjoin(", ", unpack(self:tkeys(stats))))
        end
    end

    function commands.sortclass()
        if not checkRaidRights() then return end
        self.dyn.Announce("Sorting by class")
        self:patch(self:sortRaidBy(UnitClass))
    end

    function commands.marktanks()
        if not checkRaidRights() then return end
        self.dyn.Announce("Marking tanks")
        local leader, assistants, perRole = self:getLeader()
        local icons = {6, 2, 4}
        if perRole then
            for i, tank in ipairs(perRole.MAINTANK) do
                local icon = icons[i]
                if icon then
                    SetRaidTarget(tank, icon)
                end
            end
        end
    end

    function commands.raidroll()
        self.dyn.Announce("Raid Rolling")
        self:raidRoll()
    end

    function commands.fakeroll(...)
        self.dyn.Announce("Raid Rolling")
        self:fakeRoll(...)
    end

    function commands.store()
        self.dyn.Announce("Saving raid setup")
        self.p.storedLayouts["default"] = self:getLayout()
    end

    function commands.restore()
        if not checkRaidRights() then return end
        layout = self.p.storedLayouts["default"]
        if layout then
            self.dyn.Announce("Restoring saved raid setup")
            self:patch(self:diff(self:getLayout(), layout))
        else
            self.dyn.Announce("No saved raid setup found")
        end
    end

    commands.ora = {}
    function commands.ora.mt()
        self.dyn.Announce("Setting oRA2 maintanks")
        local leader, assistants, perRole = self:getLeader()
        local i = 1
        self:oraClear()
        if perRole then
            for _, tank in pairs(perRole.MAINTANK) do
                self:oraSet(i, tank)
                i = i + 1
            end
        end
    end

    function commands.ora.ma()
        self.dyn.Announce("Setting oRA2 maintanks and assists")
        local leader, assistants, perRole = self:getLeader()
        local i = 1
        self:oraClear()
        if perRole then
            for _, tank in pairs(perRole.MAINTANK) do
                self:oraSet(i, tank)
                i = i + 1
            end
            for _, mainassist in pairs(perRole.MAINASSIST) do
                self:oraSet(i, mainassist)
                i = i + 1
            end
        end
    end

    function commands.showraidui()
        self:showRaidFrame(true)
    end

    function commands.hideraidui()
        self:hideRaidFrame()
    end
    
    function commands.toggleraidui()
        self:toggleRaidFrame(true)
    end

    function commands.ora.clear()
        self.dyn.Announce("Clearing oRA2 maintank list")
        self:oraClear()
    end

    function commands.ora.fun()
        self.dyn.Announce("Messing up the oRA2 maintank list")
        local numMembers = GetNumRaidMembers()
        for i = 1, numMembers do
            local name = GetRaidRosterInfo(i)
            self:oraSet(i, name)
        end
    end
    function commands.ora.help()
        self.dyn.Print("Usage: /rtk ora [command] (e.g. /rtk ora mt")
        self.dyn.Print("mt: set oRA MT list according to current Blizzard maintanks")
        self.dyn.Print("ma: set oRA MT list according to current Blizzard maintanks and mainassists")
        self.dyn.Print("clear: clears the oRA mt list")
    end

    function commands.showconfig()
        local function yesno(value)
            if value then
                return "yes"
            else
                return "no"
            end
        end
        local function array(value)
            if not value then 
                return ""
            elseif 0 == self:tcount(value) then
                return "(empty)"
            else
                return "[" .. strjoin(", ", unpack(value)) .. "]"
            end
        end

        -- Shows all configuration settings.
        local settings = 
            {{"Enabled", yesno(self:getEnabled())},
             {"Announce", yesno(self.p.isAnnounce)},
             {"Remove chat prefix", yesno(self.p.noAdvertising)},
             {"Invite words", yesno(self.p.autoInvite)},
             {"Invite list", yesno(self.p.useInviteList)},
             {"Invite words", array(self.p.inviteWords)},
             {"Invite other", yesno(self.p.autoInviteOther)},
             {"Inform other", yesno(self.p.autoInviteInform)},
             {"Reply invite errors", yesno(self.p.notifyInviteError)},
             {"Invite other words", array(self.p.inviteOtherPatterns)},
             {"Standby request", yesno(self.pautoStandby)},
             {"Standby words", array(self.p.standbyWords)},
             {"Group move", yesno(self.p.groupRequest)},
             {"Group move patterns", array(self.p.groupRequestPatterns)},
             {"Swap request patterns", array(self.p.swapRequestPatterns)},
             {"Auto convert", yesno(self.p.autoConvert)},
             {"Move to bottom", yesno(self.p.autoMoveOnJoin)},
             {"Auto promote", yesno(self.p.autoPromoteAll)},
             {"Auto promote list", yesno(self.p.useAutoPromoteList)},
             {"Auto promote list", array(self.p.autoPromoteList)},
             {"Remote control", yesno(self.p.remoteControl)},
             {"Remote control word", self.p.remoteControlWord},
             {"RC any raidmember", yesno(self.p.remoteControlAny)},
             {"RC leader/assist", yesno(self.p.remoteControlRaid)},
             {"RC priv list", yesno(self.p.useRcPrivilegedList)},
             {"RC priv list", array(self.p.rcPrivilegedList)},
         }
        for _, settingInfo in pairs(settings) do
            local name, setting = unpack(settingInfo)
            self.dyn.Announce(name .. ": " .. setting)
        end
    end

    -- Abbreviations
    commands.rc = commands.readycheck
    commands.pro = commands.promote
    commands.dem = commands.demote
    commands.inv = commands.invite
    commands.ann = commands.announce
    commands.ml = commands.lootmaster
    commands.tog = commands.together
    commands.sw = commands.swap
    commands.wl = commands.whisperleader
    commands.diff = commands.difficulty
    commands.rr = commands.raidroll
    commands.roll = commands.raidroll
    commands.stat = commands.stats
    commands.st = commands.stats

    commands.shiftup = commands.unshift
    commands.shiftdown = commands.shift

    self.commands = commands
end

function RaidToolkit:onSlashCommand(str)
    self:handleCommand(str, self.commands)
end

function RaidToolkit:handleCommand(str, commandsTable, printfn, announcefn)
    local commandsTable = commandsTable or {}
    local inArgs = {self:GetArgs(str, 100)}
    local fn, args, helpfn, commands, command = self:getCommand(inArgs, commandsTable)
    
    if fn then
        fn(unpack(args))
    elseif helpfn and not command then
        helpfn()
    else
        self.dyn.Print("No such command \"" .. strjoin(" ", unpack(commands)) .. "\"")
    end
end

function RaidToolkit:initializeRemoteCommands()
    local commands = {}
    setmetatable(commands, {__index = self.commands})
    
    function commands.shorthelp()
        self.dyn.Print("RaidToolkit, the swiss army knife for raid leaders - Try typing one of these:")
        self.dyn.Print(self.p.remoteControlWord .. " help")
        self.dyn.Print(self.p.remoteControlWord .. " marktanks")
        self.dyn.Print(self.p.remoteControlWord .. " swap 1 2")
        self.dyn.Print("more: promote, demote, compress, swap, rc, info, size, raidroll, shiftup, shiftdown")
    end

    function commands.more()
        self.dyn.Print("  USAGE  ")
        
        for command, helpText in pairs(self.commandHelp) do
            local command, text = unpack(helpText)
            -- Skip disabled commands.
            if commands[command] then
                self.dyn.Print(self.p.remoteControlWord .. " " .. command .. ": " .. text)
            end
        end

        self.dyn.Print("")
        self.dyn.Print("Or use abbreviations: rc (readycheck), pro (promote), dem (demote), "
                   .. "inv (invite), ann (announce toggle), ml (lootmaster)")
    end
    
    commands.help = commands.more

    -- Disable meaningless commands
    commands.gui = false
    commands.invlist = false
    commands.config = false
    commands.announce = false
    commands.debug = false
    commands.showraidui = false
    commands.hideraidui = false
    
    -- Kick may only be called in response to a hardware event.
    commands.kick = false
    commands.kickoffline = false
    commands.kickgroup = false
    commands.disband = false
    commands.reform = false

    -- Other things you don't want others to allow
    commands.leave = false
    
    self.remoteCommands = commands
end

function RaidToolkit:getCommand(args, commandsTable)
    local commandsTable = commandsTable or {}
    local currentCommands = {}

    while true do
        local command = table.remove(args, 1)
        if command then
            table.insert(currentCommands, command)
        end
        local helpfn = commandsTable.shorthelp or commandsTable.help
        
        if commandsTable[command] then
            local theType = type(commandsTable[command])
            if "function" == theType then
                return commandsTable[command], args, helpfn, currentCommands, command
            elseif "table" == theType then
                -- continue
                commandsTable = commandsTable[command]
            else
                return nil, args, helpfn, currentCommands, command
            end
        else
            return nil, args, helpfn, currentCommands, command
        end
    end
end
I can't find the Raid Comp CODE: It seems that is written in other way.
Please take a look at atachements maybe you can find it
Attached Files
File Type: lua Core.lua (3.6 KB, 537 views)
File Type: lua Options.lua (3.9 KB, 530 views)
File Type: lua GUI.lua (37.6 KB, 534 views)
File Type: lua RaidCheck.lua (17.7 KB, 532 views)
File Type: lua Support.lua (4.9 KB, 525 views)
File Type: lua Calculate.lua (10.6 KB, 539 views)
File Type: lua Calendar.lua (6.2 KB, 529 views)

Last edited by ElkAddons : 03-30-12 at 03:32 AM.
  Reply With Quote
03-30-12, 03:26 AM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Okay, so based on my earlier example, when you see this function:
Code:
function RaidToolkit:onSlashCommand(str)
    self:handleCommand(str, self.commands)
end
... you should be able to figure out that when you type "/rtk gui", the above function is called with "gui" as its argument. If you don't understand how I came to this conclusion, you should really read some basic programming tutorials so you can understand what you're looking at, but basically, you need to call this inside your minimap button's OnClick function:
Code:
RaidToolkit:onSlashCommand("gui")
If you get an error about an attempt to index a global "RaidToolkit" which is nil, then you will need to find where in the RaidToolkit files it defines this as a local variable, and post that. It should be at or near the top of the first non-library file listed in the addon's TOC file, and it look something like this:
Code:
local RaidToolkit = something
  Reply With Quote
03-30-12, 03:39 AM   #15
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
RaidToolkit Works! Look this is the new minimap button CODE:
Code:
-- Author      : Matthew Enthoven (Alias: Blacksen)

local sortMethod = "asc"
local currSortIndex = 0;
local displayingGuild = true;
local displayOnline = true;
local validSortCall;
local RIO_displayRanks = {true, true, true, true, true, true, true, true, true, true};
local RIO_ShowOffline = true;
local invitingParty = false;
local invitingRaid = false;
local raidMode = false;
local waitingOnRaidConversion = false;
local partyCount = 0;
local partySpots = 0;

local AcceptedList = {};
local PendingList = {};
local RejectList = {};
local NeedToInvite = {};
local TestInviteError = {};
local codeTimerActive = false;
local codewordString = "Invite";
local totalTimeNum = 0;
local absoluteGuildList = {};
local timerRunning = true;
local needToBeRaid = true;
local needToToggleRaid = true;
local notSetRaidDifficulty = true;
local thisHasLoaded = false;
local numChecked = 0;

local RIO_ColorTable = {
	["DEATH KNIGHT"] = "C41F36",
	["DRUID"] = "FF7D0A",
	["HUNTER"] = "ABD473",
	["MAGE"] = "69CCF0",
	["PALADIN"] = "F58CBA",
	["PRIEST"] = "FFFFFF",
	["ROGUE"] = "FFF569",
	["SHAMAN"] = "2459FF",
	["WARLOCK"] = "9482C9",
	["WARRIOR"] = "C79C6E",
};

SLASH_RIO1 = "/rio";
SLASH_RIO2 = "/raidinviteorganizer";
SlashCmdList["RIO"] = function(msg)
	local cmd, arg = string.split(" ", msg, 2);
	cmd = cmd:lower()
	if cmd == "show" then
		RIOMain_Browser.showMainFrame();
	elseif cmd == "hide" then
		RIOMain_Browser.hideMainFrame()
	elseif cmd == "reset" then
		RIO_MainFrame:SetPoint("CENTER", "UIParent", "CENTER", 0, 0);
		RIO_MainFrame:SetScale(1);
		RIO_MainFrameScale = 1;
		RIO_ScaleInputThing:SetNumber(1);
		RIO_MainFrame:Hide()
		RIO_MainFrame:Show()
	elseif cmd == "" then
		print("|cFFFF0000Raid Invite Organizer|r:");
		print("prefix: /rio");
		print(" - show - shows the main frame")
		print(" - hide - hide the main frame")
		print(" - reset - resets the scale / position of the main frame")
	else
		print(""..msg.." is not a valid command for /rio");
	end
end

function RIOMain_Browser.showMainFrame()
	RIO_MainFrame:Show();
end

function RIOMain_Browser.hideMainFrame()
	RIO_MainFrame:Hide();
end

function RIO_EventHandler(self, event, ...)
	if event == "VARIABLES_LOADED" then
		for ci=1, 10 do
			 _G["RIO_ShowRank"..ci]:SetChecked(RIO_displayRanksMaster[ci]);
		end
		RIO_displayRanks = RIO_displayRanksMaster;
		RIO_ShowOffline = RIO_ShowOfflineMaster;
		_G["RIO_ShowOfflineBox"]:SetChecked(RIO_ShowOfflineMaster);
		codewordString = RIO_CodeWordString;
		RIOMain_Browser.updateCodeWords();
		_G["RIO_CodeWordEditBox"]:SetText(RIO_CodeWordString);
		_G["RIO_NotifyWhenTimerDone"]:SetChecked(RIO_NotifyWhenDone);
		_G["RIO_OnlyGuildMembers"]:SetChecked(RIO_GuildWhispersOnly);
		_G["RIO_GuildMessageAtStart"]:SetChecked(RIO_SendGuildMsg);
		_G["RIO_AlwaysInviteListen"]:SetChecked(RIO_AlwaysOn);
		
		if RIO_AlwaysOn then
			RIOMain_Browser.loginCodewordStart()
		end
		
		RIO_ShowMinimapIconConfig:SetChecked(RIO_MinimapShow);
		if RIO_MinimapShow then
			RIO_Mod_MinimapButton_Reposition()
		else
			RIO_Mod_MinimapButton:Hide();
		end
		
		RIO_AutoSetDifficultyBox:SetChecked(RIO_AutoSetDifficulty);
		RIO_AutoSet25manBox:SetChecked(RIO_AutoSet25man)
		
		if RIO_AutoSetDifficulty then
			RIO_AutoSetDifficultyHeroicRadio:Enable();
			RIO_AutoSetDifficultyNormalRadio:Enable();
			if RIO_AutoDifficultySetting == 1 then
				RIO_AutoSetDifficultyNormalRadio:SetChecked(false);
				RIO_AutoSetDifficultyHeroicRadio:SetChecked(true);
			else
				RIO_AutoSetDifficultyNormalRadio:SetChecked(true);
				RIO_AutoSetDifficultyHeroicRadio:SetChecked(false);
			end	
		else
			_G["RIO_AutoSetDifficultyNormalRadioText"]:SetText("|cFF888888Normal|r");
			_G["RIO_AutoSetDifficultyHeroicRadioText"]:SetText("|cFF888888Heroic|r");
			RIO_AutoSetDifficultyHeroicRadio:Disable();
			RIO_AutoSetDifficultyNormalRadio:Disable();
		end
		
		
		RIO_AutoSetMasterLooter:SetChecked(RIO_MasterLooter)
		RIO_ScaleInputThing:SetNumber(RIO_MainFrameScale);
		RIO_MainFrame:SetScale(RIO_MainFrameScale);
		
	elseif event == "GUILD_ROSTER_UPDATE" then
		RIOMain_Browser.buildGuildList();
	elseif event == "CHAT_MSG_WHISPER" and codeTimerActive then
		local msg, author, theRest = ...;
		local inviteThem = false;
		if RIO_GuildWhispersOnly then
			if absoluteGuildList[author] then 
				inviteThem = RIOMain_Browser.checkFilters(msg);
			end
		else
			inviteThem = RIOMain_Browser.checkFilters(msg);
			
		end
		
		if inviteThem then
			InviteUnit(author);
			if NeedToInvite[author] and NeedToInvite[author] == 1 then 
				NeedToInvite[author] = 0;
				numToInvite = numToInvite - 1;
				TestInviteError[author] = 1;
			end
			if RIO_AutoSet25man then
				if needToToggleRaid then
					if GetNumRaidMembers() > 17 then
						needToToggleRaid = false;
						if notSetRaidDifficulty and RIO_AutoDifficultySetting == 1 then
							SetRaidDifficulty(4)
							notSetRaidDifficulty = false;
						else
							SetRaidDifficulty(2)
							notSetRaidDifficulty = false;
						end
					end
				end
			end
		end
	elseif event == "CHAT_MSG_SYSTEM" then
		local msg = ...;
		if string.find(msg, string.gsub(ERR_ALREADY_IN_GROUP_S, "%%s", "(%%S+)")) then -- This person is already in a group
			local playerName = string.match(msg, string.gsub(ERR_ALREADY_IN_GROUP_S, "%%s", "(%%S+)"));
			TestInviteError[playerName] = 0;
			if (not ((PendingList[playerName] and PendingList[playerName] == 1) or (AcceptedList[playerName] and AcceptedList[playerName] == 1))) then -- Check to make sure this isn't a "repeat" invite
				RejectList[playerName] = 1;
				PendingList[playerName] = 0;
				AcceptedList[playerName] = 0;
				partySpots = partySpots + 1;
			end
		elseif string.find(msg, string.gsub(ERR_JOINED_GROUP_S, "%%s", "%%S+")) then -- Player joined group
			partyCount = partyCount + 1;
			local playerName = string.match(msg, string.gsub(ERR_JOINED_GROUP_S, "%%s", "(%%S+)"));
			AcceptedList[playerName] = 1;
			RejectList[playerName] = 0;
			PendingList[playerName] = 0;
			TestInviteError[playerName] = 0;
			
		elseif string.find(msg, string.gsub(ERR_LEFT_GROUP_S, "%%s", "%%S+")) then -- Player left group
			local playerName = string.match(msg, string.gsub(ERR_LEFT_GROUP_S, "%%s", "(%%S+)"));
			AcceptedList[playerName] = 0;
			RejectList[playerName] = 1;
			PendingList[playerName] = 0;
			TestInviteError[playerName] = 0;
		elseif string.find(msg, string.gsub(ERR_INVITE_PLAYER_S, "%%s", "%%S+")) then -- sent Valid Invitation
			local playerName = string.match(msg, string.gsub(ERR_INVITE_PLAYER_S, "%%s", "(%%S+)"));
			AcceptedList[playerName] = 0;
			RejectList[playerName] = 0;
			PendingList[playerName] = 1;
			TestInviteError[playerName] = 0;
		elseif string.find(msg, string.gsub(ERR_RAID_MEMBER_ADDED_S, "%%s", "%%S+")) then -- Player joined raid group
			local playerName = string.match(msg, string.gsub(ERR_RAID_MEMBER_ADDED_S, "%%s", "(%%S+)"));
			AcceptedList[playerName] = 1;
			RejectList[playerName] = 0;
			PendingList[playerName] = 0;
			TestInviteError[playerName] = 0;
		elseif string.find(msg, string.gsub(ERR_RAID_MEMBER_REMOVED_S, "%%s", "%%S+")) then -- Player left raid group
			local playerName = string.match(msg, string.gsub(ERR_RAID_MEMBER_REMOVED_S, "%%s", "(%%S+)"));
			AcceptedList[playerName] = 0;
			RejectList[playerName] = 1;
			PendingList[playerName] = 0;
			TestInviteError[playerName] = 0;
		elseif string.find(msg, string.gsub(ERR_BAD_PLAYER_NAME_S, "%%s", "%%S+")) then -- Player was not online
			local playerName = string.match(msg, string.gsub(ERR_BAD_PLAYER_NAME_S, "%%s", "(%%S+)"));
			partySpots = partySpots + 1;
			AcceptedList[playerName] = 0;
			RejectList[playerName] = 1;
			PendingList[playerName] = 0;
			TestInviteError[playerName] = 0;
		elseif string.find(msg, string.gsub(ERR_DECLINE_GROUP_S, "%%s", "%%S+")) then -- Player joined group
			partySpots = partySpots + 1;
			local playerName = string.match(msg, string.gsub(ERR_DECLINE_GROUP_S, "%%s", "(%%S+)"));
			AcceptedList[playerName] = 0;
			RejectList[playerName] = 1;
			PendingList[playerName] = 0;
			TestInviteError[playerName] = 0;
		elseif string.find(msg, ERR_LEFT_GROUP_YOU) or string.find(msg, ERR_RAID_YOU_LEFT) then -- Player left group
			AcceptedList = {};
			RejectList = {};
			PendingList = {};
			invitingParty = false;
			invitingRaid = false;
			NeedToInvite = {};
			RIO_MainFrame:SetScript("OnUpdate", nil);
			if codeTimerActive then
				RIOMain_Browser.toggleCodewordInvites()
			end
		end
		
		RIOMain_Browser.updateListing();
	end
end
	

function RIOMainFrame_OnLoad()
	RIO_MainFrame:SetScript("OnEvent", RIO_EventHandler);
	RIO_MainFrame:RegisterEvent("VARIABLES_LOADED");
	RIO_MainFrame:RegisterEvent("GUILD_ROSTER_UPDATE");
	RIO_MainFrame:RegisterEvent("CHAT_MSG_SYSTEM");
	RIO_MainFrame.TimeSinceLastUpdate = 0
	RIO_TabPage2.TimeSinceLastUpdate = 0
	local entry = CreateFrame("Button", "$parentEntry1", RIO_GuildMemberFrame, "RIO_GuildEntry"); -- Creates the first entry
	entry:SetID(1); -- Sets its id
	entry:SetPoint("TOPLEFT", 4, -28) --Sets its anchor
	entry:Show()
	for ci = 2, 20 do --Loops through to create more rows
		local entry = CreateFrame("Button", "$parentEntry"..ci, RIO_GuildMemberFrame, "RIO_GuildEntry");
		entry:SetID(ci);
		entry:SetPoint("TOP", "$parentEntry"..(ci-1), "BOTTOM") -- sets the anchor to the row above
		entry:Show()
	end
	
	_G["RIO_GuildMessageAtStartText"]:SetText("Send Guild Message at Start");
	_G["RIO_NotifyWhenTimerDoneText"]:SetText("Notify When Timer Ends");
	_G["RIO_OnlyGuildMembersText"]:SetText("Only Accept Whispers From Guild");
	_G["RIO_AlwaysInviteListenText"]:SetText("Start Codeword Invites at Login");
	_G["RIO_ShowOfflineBoxText"]:SetText("Show Offline");
	_G["RIO_ShowOfflineBox"]:SetChecked(RIO_ShowOffline);
end

function RIOMainFrame_OnShow()
	if displayingGuild then
		local numRanks = GuildControlGetNumRanks();
		for ci=1, 10 do
			if ci <= numRanks then
				_G["RIO_ShowRank"..ci]:Show();
				_G["RIO_ShowRank"..ci.."Text"]:SetText(GuildControlGetRankName(ci));
				_G["RIO_ShowRank"..ci]:SetChecked(RIO_displayRanks[ci]);
			else
				_G["RIO_ShowRank"..ci]:Hide();
			end
		end
		RIOMain_Browser.buildGuildList();
	end
end

-- Function: buildGuildList
-- Purpose: Builds data for listing guild members
function RIOMain_Browser.buildGuildList() 
	local numMembers = GetNumGuildMembers(true);
	RIO_totalGuildNumber = 0;
	RIO_FullGuildList = {};
	RIO_totalNumber = 0;
	absoluteGuildList = {};
	for ci=1, numMembers do
		local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName = GetGuildRosterInfo(ci);
		
		absoluteGuildList[name] = 1;
		
		local classReal = string.upper(class);
		
		
		local color = "";
		if RIO_ColorTable[classReal] then
			color = "|cFF" .. RIO_ColorTable[classReal];
		end
		
		if RIO_ShowOffline == true or online then
			if RIO_displayRanks[(rankIndex+1)] == true then
				RIO_totalGuildNumber = RIO_totalGuildNumber+1;
				table.insert(RIO_FullGuildList, {
							 name,
							 rank,
							 rankIndex,
							 color,
							 online
						});
				thisHasLoaded = true;
			end
		end
	end
	
	if RIO_totalGuildNumber > 20 then
		local newVal = RIO_totalGuildNumber-20;
		_G["RIO_SliderContainer"]:Show();
		_G["RIO_GuildSlider"]:SetValueStep(1);
		if RIO_totalGuildOffset > newVal then
			RIO_totalGuildOffset = newVal;
		else
			RIO_totalGuildOffset = _G["RIO_GuildSlider"]:GetValue();
		end
		_G["RIO_GuildSlider"]:SetMinMaxValues(0, newVal);
		_G["RIO_GuildSlider"]:SetValue(RIO_totalGuildOffset);
	else
		RIO_totalGuildOffset = 0;
		_G["RIO_SliderContainer"]:Hide();
		_G["RIO_GuildSlider"]:SetValue(RIO_totalGuildOffset);
	end
	
	if displayingGuild then
		validSortCall = false;
		RIOMain_Browser.sortTable(currSortIndex);
		RIOMain_Browser.updateListing();
	end
end

-- Function: updateListing
-- Purpose: Displays the data for the faux
--		scrolling table.
function RIOMain_Browser.updateListing() 
	for ci = 1, 20 do
		local theRow = RIO_FullGuildList[ci+RIO_totalGuildOffset];
		if theRow then
			_G["RIO_GuildMemberFrameEntry"..ci.."Name"]:SetText(theRow[4] .. theRow[1]);
			if theRow[5] then
				_G["RIO_GuildMemberFrameEntry"..ci.."Rank"]:SetText(theRow[2]);
			else
				_G["RIO_GuildMemberFrameEntry"..ci.."Rank"]:SetText(GRAY_FONT_COLOR_CODE .. theRow[2]);
			end
			_G["RIO_GuildMemberFrameEntry"..ci]:Show();
			local theName = theRow[1];
			if RIO_SelectedList[theName] and RIO_SelectedList[theName] == 1 then
				_G["RIO_GuildMemberFrameEntry"..ci.."Check"]:Show();
			else
				_G["RIO_GuildMemberFrameEntry"..ci.."Check"]:Hide();
			end
			
			local seen = true;
			if PendingList[theName] and PendingList[theName] == 1 then
				_G["RIO_GuildMemberFrameEntry"..ci.."Status"]:SetTexture("Interface\\RAIDFRAME\\ReadyCheck-Waiting");
				seen = false;
			end
			
			if AcceptedList[theName] and AcceptedList[theName] == 1 then
				_G["RIO_GuildMemberFrameEntry"..ci.."Status"]:SetTexture("Interface\\RAIDFRAME\\ReadyCheck-Ready");
				seen = false;
			end
			
			if RejectList[theName] and RejectList[theName] == 1 then
				_G["RIO_GuildMemberFrameEntry"..ci.."Status"]:SetTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady");
				seen = false;
			end
			
			if seen then
				_G["RIO_GuildMemberFrameEntry"..ci.."Status"]:SetTexture("");
			end
			
		else
			_G["RIO_GuildMemberFrameEntry"..ci]:Hide();
		end
	end
end


-- Function: sortTable
-- Input: Column Header to sort by
-- Purpose: Sorts the guild member listing table
--		so that it's easily viewable
function RIOMain_Browser.sortTable(id)
	if currSortIndex == id and validSortCall then -- if we're already sorting this one
		if sortMethod == "asc" then -- then switch the order
			sortMethod = "desc"
		else
			sortMethod = "asc"
		end
	elseif id then -- if we got a valid id
		currSortIndex = id -- then initialize our sort index
		sortMethod = "asc" -- and the order we're sorting in
	end
	
	if validSortCall == false then
		validSortCall = true;
	end
	
	if (id == 1) then -- Char Name sorting (alphabetically)
		table.sort(RIO_FullGuildList, function(v1, v2)
			if sortMethod == "desc" then
				return v1 and v1[1] > v2[1]
			else
				return v1 and v1[1] < v2[1]
			end
		end)
	elseif (id == 2) then -- Guild Rank sorting (numerically)
		table.sort(RIO_FullGuildList, function(v1, v2)
			if sortMethod == "desc" then
				return v1 and v1[3] > v2[3]
			else
				return v1 and v1[3] < v2[3]
			end
		end)
	elseif (id == 3) then
		if thisHasLoaded then
			table.sort(RIO_FullGuildList, function(v1, v2)
					if v1 == nil then return false end
					if v2 == nil then return true end
					if RIO_SelectedList[v1[1]] then
						if RIO_SelectedList[v2[1]] then
							return RIO_SelectedList[v1[1]] < RIO_SelectedList[v2[1]] 
						else
							return true
						end
					else
						return false
					end
			end)
		end
	end
end

function RIOMain_Browser.selectRow(rowNum)
	local theRow = RIO_FullGuildList[rowNum+RIO_totalGuildOffset];
	if theRow then
		local theName = theRow[1];
		if theName then
			if RIO_SelectedList[theName] and RIO_SelectedList[theName] == 1 then
				RIO_SelectedList[theName] = 0;
			else
				RIO_SelectedList[theName] = 1;
			end
		end
	end
	
	RIOMain_Browser.updateListing();
	
end

function RIOMain_Browser.rankBoxToggle(numID)
	local toggleCheck = _G["RIO_ShowRank"..numID]:GetChecked();
	if toggleCheck == nil then
		RIO_displayRanks[numID] = false;
		RIO_displayRanksMaster[numID] = false;
	elseif toggleCheck == 1 then
		RIO_displayRanks[numID] = true;
		RIO_displayRanksMaster[numID] = true;
	end
	RIOMain_Browser.buildGuildList();
end

function RIOMain_Browser.offlineBoxToggle()
	local toggleCheck = _G["RIO_ShowOfflineBox"]:GetChecked();
	if toggleCheck == nil then
		RIO_ShowOffline = false;
		RIO_ShowOfflineMaster = false;
	elseif toggleCheck == 1 then
		RIO_ShowOffline = true;
		RIO_ShowOfflineMaster = true;
	end
	RIOMain_Browser.buildGuildList();
end

function RIOMain_Browser.sliderButtonPushed(dir)
	local currValue = _G["RIO_GuildSlider"]:GetValue();
	if (dir == 1) and currValue > 0 then
		newVal = currValue-3;
		if newVal < 0 then
			newVal = 0;
		end
		_G["RIO_GuildSlider"]:SetValue(newVal);
	elseif (dir == 2) and (currValue < (RIO_totalGuildNumber-20)) then
		newVal = currValue+3;
		if newVal > (RIO_totalGuildNumber-20) then
			newVal = (RIO_totalGuildNumber-20);
		end
		_G["RIO_GuildSlider"]:SetValue(newVal);
	end
end

function RIOMain_Browser.quickScroll(self, delta)
	local currValue = _G["RIO_GuildSlider"]:GetValue();
	if (delta > 0) and currValue > 0 then
		newVal = currValue-1;
		if newVal < 0 then
			newVal = 0;
		end
		_G["RIO_GuildSlider"]:SetValue(newVal);
	elseif (delta < 0) and (currValue < (RIO_totalGuildNumber-20)) then
		newVal = currValue+1;
		if newVal > (RIO_totalGuildNumber-20) then
			newVal = (RIO_totalGuildNumber-20);
		end
		_G["RIO_GuildSlider"]:SetValue(newVal);
	end
end

function RIOMain_Browser.clearSelection()
	RIO_SelectedList = {};
	RIOMain_Browser.updateListing() 
end

function RIOMain_Browser.selectAll()
	RIO_SelectedList = {};
	local numMembers = GetNumGuildMembers(true);
	for ci=1, numMembers do
		local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName = GetGuildRosterInfo(ci);
		if RIO_ShowOffline == true or online then
			if RIO_displayRanks[(rankIndex+1)] == true then
				RIO_SelectedList[name] = 1;
			end
		end
	end
	RIOMain_Browser.updateListing() 
end

function RIOMain_Browser.sendMassGuildInvite()
	local playerName = UnitName("player");
	numToInvite = 0;
	NeedToInvite = {};
	invitingRaid = false;
	notSetRaidDifficulty = RIO_AutoSetDifficulty;
	numChecked = 0;
	for k,v in pairs(RIO_SelectedList) do
		if v == 1 then
			NeedToInvite[k] = 1;
			numToInvite = numToInvite + 1;
			numChecked = numChecked+1;
		end
	end
	if NeedToInvite[playerName] and NeedToInvite[playerName] == 1 then
		NeedToInvite[UnitName("player")] = 0;
		numToInvite = numToInvite - 1;
	end
	
	AcceptedList[UnitName("player")] = 1;
	PendingList = {};
	RejectList = {};
	
	if (# RIO_SelectedList) == 0 then
		RIOMain_Browser.updateListing();
	end
	
	-- TODO: Check for people already in group/raid
	
	
	if (GetNumPartyMembers() == 0 and (not (UnitInRaid("player")))) then -- If we're solo
		waitingOnRaidConversion = false;
		RIO_MainFrame:SetScript("OnUpdate", RIO_OnUpdate);
		partySpots = 4;
		partyCount = 0;
		invitingParty = true;
		invitingRaid = false;
		local loopIndex = 0;
		for k,v in pairs(NeedToInvite) do
			if v == 1 then
				InviteUnit(k);
				TestInviteError[k] = 1;
				partySpots = partySpots - 1;
				NeedToInvite[k] = 0;
				numToInvite = numToInvite - 1;
				if (loopIndex ==3) then
					break;
				end
				loopIndex = loopIndex + 1;
			end
		end
	elseif (UnitIsPartyLeader("player") and (not (UnitInRaid("player")))) then -- If we're in a party already and we ARE the party leader.
		invitingParty = false;
		invitingRaid = true;
		ConvertToRaid();
		if (RIO_AutoSet25man and (numChecked > 17)) then
			if notSetRaidDifficulty and RIO_AutoDifficultySetting == 1 then
				SetRaidDifficulty(4)
				notSetRaidDifficulty = false;
			else
				SetRaidDifficulty(2)
				notSetRaidDifficulty = false;
			end
		else
			if notSetRaidDifficulty and RIO_AutoDifficultySetting == 1 then
				SetRaidDifficulty(3)
				notSetRaidDifficulty = false;
			else
				SetRaidDifficulty(1)
				notSetRaidDifficulty = false;
			end
		end
		
		if RIO_MasterLooter then
			SetLootMethod("master", UnitName("player"));
		end
		RIOMain_Browser.sendMassGuildInviteRaid();
	elseif IsRaidOfficer() then
		invitingRaid = true;
		invitingParty = false;
		local expectedRaidSize = numChecked + GetNumRaidMembers()
		if (RIO_AutoSet25man and (expectedRaidSize > 17)) then
			if notSetRaidDifficulty and RIO_AutoDifficultySetting == 1 then
				SetRaidDifficulty(4)
				notSetRaidDifficulty = false;
			else
				SetRaidDifficulty(2)
				notSetRaidDifficulty = false;
			end
		else
			if notSetRaidDifficulty and RIO_AutoDifficultySetting == 1 then
				SetRaidDifficulty(3)
				notSetRaidDifficulty = false;
			else
				SetRaidDifficulty(1)
				notSetRaidDifficulty = false;
			end
		end
		RIOMain_Browser.sendMassGuildInviteRaid()
	end
	
	RIOMain_Browser.updateListing();
end

function RIOMain_Browser.sendMassGuildInviteRaid()
	if IsRaidOfficer() then
		waitingOnRaidConversion = false;
		ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM",RIOMain_Browser.SystemFilter)
		for k,v in pairs(NeedToInvite) do
			if v == 1 then
				InviteUnit(k);
				TestInviteError[k] = 1;
				NeedToInvite[k] = 0;
				numToInvite = numToInvite - 1;
				NeedToInvite[k] = 0;
			end
		end
		ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM",RIOMain_Browser.SystemFilter)
		
		RIO_MainFrame:SetScript("OnUpdate", RIO_OnExtendedUpdate);
	end
end


function RIO_OnUpdate(self, elapsed)
  self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
  if (self.TimeSinceLastUpdate > RIO_UpdateInterval) then
  	if invitingParty then
		if partyCount > 0 then
			ConvertToRaid();
			invitingRaid = true;
			invitingParty = false;
			raidMode = true;
			waitingOnRaidConversion = true;
			RIOMain_Browser.sendMassGuildInviteRaid();
			if (RIO_AutoSet25man and (numChecked > 17)) then
				if notSetRaidDifficulty and RIO_AutoDifficultySetting == 1 then
					SetRaidDifficulty(4)
					notSetRaidDifficulty = false;
				else
					SetRaidDifficulty(2)
					notSetRaidDifficulty = false;
				end
			else
				if notSetRaidDifficulty and RIO_AutoDifficultySetting == 1 then
					SetRaidDifficulty(3)
					notSetRaidDifficulty = false;
				else
					SetRaidDifficulty(1)
					notSetRaidDifficulty = false;
				end
			end
			
			if RIO_MasterLooter then
				SetLootMethod("master", UnitName("player"));
			end
		else
			if partySpots > 0 then
				local loopIndex = 0;
				local haveNotFound = true
				for k,v in pairs(NeedToInvite) do
					if v == 1 then
						InviteUnit(k);
						TestInviteError[k] = 1;
						NeedToInvite[k] = 0;
						numToInvite = numToInvite - 1;
						if (loopIndex == (partySpots-1)) then
							break;
						end
						loopIndex = loopIndex + 1;
					end
				end
				partySpots = 0;
			end
		end
	end
	
	if waitingOnRaidConversion then
		RIOMain_Browser.sendMassGuildInviteRaid();
	end
	
	if numToInvite == 0 and invitingRaid then
		RIO_MainFrame:SetScript("OnUpdate", nil);
		invitingParty = false;
		invitingRaid = false;
	end
    self.TimeSinceLastUpdate = 0;
  end
end

function RIOMain_Browser.SystemFilter(chatFrame, event, message)
	return true;
end

function RIO_OnExtendedUpdate(self, elapsed)
	self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
	if (self.TimeSinceLastUpdate > RIO_UpdateIntervalExtended) then
		RIO_MainFrame:SetScript("OnUpdate", nil);
		for k,v in pairs(NeedToInvite) do
			if v == 0 then
				if TestInviteError[k] and TestInviteError[k] == 0 then
					RejectList[k] = 1;
					PendingList[k] = 0;
					AcceptedList[k] = 0;
				end
			end
		end
		self.TimeSinceLastUpdate = 0;
	end
end

function RIOMain_Browser.saveCodeWords()
	codewordString = _G["RIO_CodeWordEditBox"]:GetText()
	RIO_CodeWordString = codewordString;
	RIOMain_Browser.updateCodeWords()
end

function RIOMain_Browser.updateCodeWords()
	local swapString = gsub(codewordString, "\n", "\186");
	RIO_CodeWords = { strsplit("\186", swapString) }
end

function RIOMain_Browser.selectTab(mahID)
 -- Handle tab changes
end

function RIOMain_Browser.toggleCodewordInvites()
	if codeTimerActive then
		codeTimerActive = false;
		_G["RIO_ToggleCodewordInvites"]:SetText("Start Codeword Invitations");
		_G["RIO_TabPage2"]:SetScript("OnUpdate", nil);
		
		if RIO_NotifyWhenDone then
			for ci=1, 5 do
				print("|cFFFF0000Raid Invite Organizer:|r Codeword Invites Haulted");
			end
		end
		RIO_MainFrame:UnregisterEvent("CHAT_MSG_WHISPER");
	else
		
		RIOMain_Browser.saveCodeWords();
		RIOMain_Browser.buildGuildList();
		if # RIO_CodeWords == 0 then
			print("|cFFFF0000Cannot Start Automatic Invites|r - You haven't entered any codewords.");
		else
			codeTimerActive = true;
			
				
			if RIO_MasterLooter then
				SetLootMethod("master", UnitName("player"));
			end
			
			RIO_SecondsListener:ClearFocus();
			RIO_MinutesListener:ClearFocus();
			RIO_CodeWordEditBox:ClearFocus();
			_G["RIO_ToggleCodewordInvites"]:SetText("End Codeword Invitations");
			totalTimeNum = RIO_MinutesListener:GetNumber()*60;
			totalTimeNum = totalTimeNum + RIO_SecondsListener:GetNumber();
			if RIO_SendGuildMsg then
				local theMsg = "Raid invites started! Whisper me ";
				for ci=1, (# RIO_CodeWords - 1) do
					if (ci == 1) then
						theMsg = theMsg .. "\"" .. RIO_CodeWords[ci] .. "\"";
					else
						theMsg = theMsg .. ", " .. "\"" .. RIO_CodeWords[ci] .. "\"";
					end
				end
				if (# RIO_CodeWords) > 2 then
					theMsg = theMsg .. ", or \"" .. RIO_CodeWords[# RIO_CodeWords] .. "\"";
				elseif (# RIO_CodeWords) == 2 then
					theMsg = theMsg .. " or \"" .. RIO_CodeWords[2] .. "\"";
				else
					theMsg = theMsg ..  RIO_CodeWords[1];
				end
				
				theMsg = theMsg .. " for an invite!";
				SendChatMessage(theMsg ,"GUILD" ,nil ,nil);
			end
			RIO_MainFrame:RegisterEvent("CHAT_MSG_WHISPER")
			notSetRaidDifficulty = RIO_AutoSetDifficulty;
			needToToggleRaid = true;
			timerRunning = false;
			if (GetNumPartyMembers() == 0 and (not (UnitInRaid("player")))) then
				needToBeRaid = true;
				_G["RIO_TabPage2"]:SetScript("OnUpdate", RIO_CodewordTimer);
			end
			if totalTimeNum > 0 then
				timerRunning = true;
				if RIO_SecondsListener:GetNumber() > 59 then
					RIO_SecondsListener:SetNumber(RIO_SecondsListener:GetNumber() - 60);
					RIO_MinutesListener:SetNumber(RIO_MinutesListener:GetNumber() + 1);
				end
				_G["RIO_TabPage2"]:SetScript("OnUpdate", RIO_CodewordTimer);
			end
			
		end
	end
end

function RIO_CodewordTimer(self, elapsed)
	self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
	if (self.TimeSinceLastUpdate > 1) then
		if timerRunning then
			totalTimeNum = totalTimeNum-1;
			if totalTimeNum <= 0 then
				RIO_SecondsListener:SetNumber(0);
				RIO_MinutesListener:SetNumber(0);
				RIOMain_Browser.toggleCodewordInvites();
			else
				local dividebysixty = totalTimeNum/60;
				local minutes = math.floor(dividebysixty);
				local seconds = totalTimeNum-(minutes*60);
				RIO_SecondsListener:SetNumber(seconds);
				RIO_MinutesListener:SetNumber(minutes);
			end
		end
		if needToBeRaid then
			if GetNumPartyMembers() > 0 then
				ConvertToRaid();
				if notSetRaidDifficulty and RIO_AutoDifficultySetting == 1 then
					SetRaidDifficulty(3)
					notSetRaidDifficulty = false;
				else
					SetRaidDifficulty(1)
					notSetRaidDifficulty = false;
				end
				needToBeRaid = false;
				if (not timerRunning) then
					_G["RIO_TabPage2"]:SetScript("OnUpdate", nil);
				end
			end
		end
	self.TimeSinceLastUpdate = 0;
	end
end

function RIOMain_Browser.checkFilters(msg)
	msg = string.upper(msg);
	local numCodeWords = # RIO_CodeWords;
	for ci=1, numCodeWords do
		if string.find(msg, string.upper(RIO_CodeWords[ci])) then
			return true;
		end
	end
	return false;
end

function RIOMain_Browser.loginCodewordStart()
	codeTimerActive = true;
	RIOMain_Browser.saveCodeWords();
	RIOMain_Browser.buildGuildList();
	if # RIO_CodeWords == 0 then
		print("|cFFFF0000Cannot Start Automatic Invites|r - You haven't entered any codewords.");
	else
		codeTimerActive = true;
		_G["RIO_ToggleCodewordInvites"]:SetText("End Codeword Invitations");
		totalTimeNum = 0;
		RIO_MainFrame:RegisterEvent("CHAT_MSG_WHISPER")
		notSetRaidDifficulty = RIO_AutoSetDifficulty;
		needToToggleRaid = true;
		timerRunning = false;
		if (GetNumPartyMembers() == 0 and (not (UnitInRaid("player")))) then
			needToBeRaid = true;
			_G["RIO_TabPage2"]:SetScript("OnUpdate", RIO_CodewordTimer);
		end
	end
end


function RIO_Mod_MinimapButton_Reposition()
	RIO_Mod_MinimapButton:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-(80*cos(RIO_MinimapPos)),(80*sin(RIO_MinimapPos))-52)
end

-- Only while the button is dragged this is called every frame
function RIO_Mod_MinimapButton_DraggingFrame_OnUpdate()

	local xpos,ypos = GetCursorPosition()
	local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()

	xpos = xmin-xpos/UIParent:GetScale()+70 -- get coordinates as differences from the center of the minimap
	ypos = ypos/UIParent:GetScale()-ymin-70

	RIO_MinimapPos = math.deg(math.atan2(ypos,xpos)) -- save the degrees we are relative to the minimap center
	RIO_Mod_MinimapButton_Reposition() -- move the button
end

-- Put your code that you want on a minimap button click here.  arg1="/rtk gui", "/rc gui", etc
function RIO_Mod_MinimapButton_OnClick()RaidToolkit:onSlashCommand("gui")
	if arg1 == "LeftButton" then
		if RIO_MainFrame:IsVisible() then
			RIO_MainFrame:Hide();
		else
			RIO_MainFrame:Show();
		end
	end
end

function RIO_Mod_MinimapButton_OnEnter(self)
	if (self.dragging) then
		return
	end
	GameTooltip:SetOwner(self or UIParent, "ANCHOR_LEFT")
	GameTooltip:SetText("RAID HELPER");
end

function RIOMain_Browser.setScale()
	if RIO_ScaleInputThing:GetNumber() == 0 then
		RIO_ScaleInputThing:SetNumber(1);
		RIO_MainFrameScale = 1;
	elseif RIO_ScaleInputThing:GetNumber() < .4 then
		RIO_ScaleInputThing:SetNumber(.4);
		RIO_MainFrameScale = .4;
	elseif RIO_ScaleInputThing:GetNumber() > 2 then
		RIO_MainFrameScale = 2;
		RIO_ScaleInputThing:SetNumber(2);
	else
		RIO_MainFrameScale = RIO_ScaleInputThing:GetNumber();
	end
	
	RIO_MainFrame:SetScale(RIO_MainFrameScale);
	
	RIO_MainFrame:Hide()
	RIO_MainFrame:Show()
end
Now it works on both clicks , Can make It edit it for Left Click RaidToolkit and Right click RaidComp?

Last edited by ElkAddons : 03-30-12 at 03:47 AM.
  Reply With Quote
04-01-12, 09:07 AM   #16
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yes. First, fix your function definition so that it actually receives the correct arguments. Change:
Code:
function RIO_Mod_MinimapButton_OnClick()
to:
Code:
function RIO_Mod_MinimapButton_OnClick(self, arg1)
(Basically, just add the parts in yellow.)

As for your actual question, look at the function that's called when you click:
Code:
function RIO_Mod_MinimapButton_OnClick(self, arg1)
	RaidToolkit:onSlashCommand("gui")
	if arg1 == "LeftButton" then
		if RIO_MainFrame:IsVisible() then
			RIO_MainFrame:Hide();
		else
			RIO_MainFrame:Show();
		end
	end
end
Do you see anything in there that seems like it might be checking which mouse button was pressed? (Hint: It's highlighted in yellow.)

Try moving the RaidToolkit:onSlashCommand("gui") line into the section of code that only gets run if you use the left mouse button, and then see what happens when you use the right mouse button to click the minimap button.
  Reply With Quote
04-06-12, 03:41 PM   #17
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
It's still opening also on right click RaidToolKit
  Reply With Quote
04-06-12, 10:01 PM   #18
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I can't help you fix problems in your code if I can't see your code. I don't know why I have to keep repeating this.
  Reply With Quote
04-08-12, 11:55 AM   #19
ElkAddons
A Deviate Faerie Dragon
 
ElkAddons's Avatar
Join Date: Mar 2012
Posts: 10
ok thank you it's enought for me, cheers
  Reply With Quote
04-08-12, 11:00 PM   #20
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'm not sure why you would rather give up entirely than just post your code, but okay.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » I'm new and I verry need help with a minimap buton


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