WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Adding char names to addon via slash command (https://www.wowinterface.com/forums/showthread.php?t=58187)

Believe82 09-02-20 09:46 AM

Adding char names to addon via slash command
 
Hi so I have addon that helps me distribute mounts and loot in aq40 and I would like to create an exemption table using a slash command.

At the moment I call the slash command via:
Code:

SLASH_NLOOT1 = "/nl"

SlashCmdList.NLOOT = function(input)
        input = string.lower(input)
        if input == "log" then
                NL_LOGGING = not NL_LOGGING
                local word = "Disabled"
                if NL_LOGGING then
                        word = "Enabled"
                end
                print("NLoot: Logging " .. word)
                return
        elseif input == "resetmount" then
                mountList = {}
                lootList = {}
                mountDistributed = 0
                print("NLoot: Mount list and all history have also been reset")
                return
        elseif input == "history" then
                local lootCount = 0
                for i,v in pairs(lootList) do
                        print(i .. ": " .. v)
                        lootCount = lootCount + 1
                end
                if lootCount == 0 then
                        print("No items have been distributed yet")
                end
                return
        elseif input == "masteraq" then
                NL_Master = true
                local playerName = UnitName("player")
                SetLootMethod("Master",playerName,"1")
                return       
        elseif input == "master" then
                NL_Master = true
                local playerName = UnitName("player")
                SetLootMethod("Master",playerName,"2")
                return
        elseif input == "" then
        else
                print("NLoot: Invalid Command, Input '/nl help' to get a list of available commands")
                return
        end

        if NL_ENABLED then
                NL_ENABLED = false
                print("NLoot: Disabled")
        else
                NL_ENABLED = true
                print("NLoot: Enabled")
        end
end

I wonder if I can add a slash command "/nl hasmount Playername"
where the lua would handle the Player name and pass it to an array or table. this way I could then make the addon check if the player is on that list or not.

Thank you for your help.

Fizzlemizz 09-02-20 10:22 AM

Why not replace:
Code:

else
        print("NLoot: Invalid Command, Input '/nl help' to get a list of available commands")
        return

with:

Code:

else
        -- if required check if input is a player in your group/raid
                TableOfPlayers[input] = true
        -- else
        --        print("NLoot: Invalid Command, Input '/nl help' to get a list of available commands")
        -- end
        return

Otherwise:
Code:

else
        local command, param1 = string.split(" ", input)
        if command = "hm" then -- hm for hasmount
                TableOfPlayers[param1] = true
        else
                print("NLoot: Invalid Command, Input '/nl help' to get a list of available commands")
        end


Believe82 09-02-20 02:05 PM

Quote:

Originally Posted by Fizzlemizz (Post 336755)
Why not replace:
Code:

else
        print("NLoot: Invalid Command, Input '/nl help' to get a list of available commands")
        return

with:

Code:

else
        -- if required check if input is a player in your group/raid
                TableOfPlayers[input] = true
        -- else
        --        print("NLoot: Invalid Command, Input '/nl help' to get a list of available commands")
        -- end
        return

Otherwise:
Code:

else
        local command, param1 = string.split(" ", input)
        if command = "hm" then -- hm for hasmount
                TableOfPlayers[param1] = true
        else
                print("NLoot: Invalid Command, Input '/nl help' to get a list of available commands")
        end


So I adapted to what you said:

Code:

elseif input == "print" then
                for i,v in ipairs(mountList) do print(i,v) end
                return
        elseif input == "" then
        else
                local command, param1 = string.split(" ", input)
                if command == "hm" then -- hm for hasmount
                        mountList[param1] = time()
                else
                        print("NLoot: Invalid Command, Input '/nl help' to get a list of available commands")
                end

also added a print to try if the table was correct but when i do the print command nothing happens.

Fizzlemizz 09-02-20 03:11 PM

Use pairs()
Code:

for i,v in pairs(mountList) do print(i,v) end

Seerah 09-02-20 09:03 PM

ipairs() is only for indexed tables (arrays), and will only work if there are no gaps in the table.

If your table uses keys in place of indices, or there are gaps in your table, use pairs() as Fizzlemizz suggested.

http://lua-users.org/wiki/TablesTutorial


All times are GMT -6. The time now is 12:46 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI