Thread Tools Display Modes
09-02-20, 09:46 AM   #1
Believe82
A Murloc Raider
Join Date: Sep 2020
Posts: 9
Thumbs down 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.

Last edited by Believe82 : 09-02-20 at 09:54 AM.
  Reply With Quote
09-02-20, 10:22 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-02-20 at 10:41 AM.
  Reply With Quote
09-02-20, 02:05 PM   #3
Believe82
A Murloc Raider
Join Date: Sep 2020
Posts: 9
Originally Posted by Fizzlemizz View Post
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.
  Reply With Quote
09-02-20, 03:11 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Use pairs()
Code:
for i,v in pairs(mountList) do print(i,v) end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-02-20, 09:03 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Adding char names to addon via slash command

Thread Tools
Display Modes

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