Thread Tools Display Modes
05-01-13, 03:14 PM   #1
Anja
A Fallenroot Satyr
 
Anja's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 27
SwapRaidSubgroup with String...

hi, i work on a little function that sorts my raid from a string that i give...

Code:
function doRaid()
	local msg = URLFrameEditBox:GetText();
	URLFrameEditBox:SetText("")
	URLFrame:Hide();
	rs = {}
	gr = {}
	cg = {}
	local num = GetRealNumRaidMembers();
			
		for i = 1, 40 do
			local u = "raid"..i;
			name, rank, subgroup, level, class, fileName, zone, online, isDead, role, isML, combatRole = GetRaidRosterInfo(i);
			if UnitExists(u) then
				rs[UnitName(u)] = { index = i, subgroup = subgroup };
				if cg[subgroup] then
					grpc = cg[subgroup];
				else
					grpc = 0;
				end
				cg[subgroup] = tonumber(grpc)+1;
			end
		end
		
		local positions = { strsplit("&", msg) }
		if msg ~= "" then
			for i,ine in ipairs(positions) do
				local ois = { strsplit(":", ine) }
				local name = ois[1];
				local group = ois[2];
				
				if rs[name] then					
					if tonumber(rs[name]['subgroup']) ~= tonumber(group) then
						if cg[group] == 5 then
							for i, irs in pairs(rs) do
								if tonumber(irs.subgroup) == tonumber(group) then
									if rs[i].subgroup ~= group then
										SwapRaidSubgroup(rs[name]['index'],irs.index);
										return true
									end
								end
							end
						else 
							SetRaidSubgroup(rs[name]['index'],group);
						end 
					end
				end
			end
		end

end
the string is like that: Ikuria:4&Achot:2
it came from this page: http://absence-gilde.com/?p=raidposi&b=1&s=1&g=1&u=0&e

to swap Ikuria in Group 4 and Achot to 2, but now the problem - if the group is full, it doesnt work - so i test it to count the group and if full then use swap, but... hmmm i have not the skill to do it right... can someone help?
  Reply With Quote
05-01-13, 07:51 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Not tested at all, but something like this should work. I think your main problems are that (1) you're not updating the current raid state table when you make a swap, and (2) you're quitting after making one swap.

Code:
local current, numInGroup = {}, {}

local function UpdateRaidState()
	wipe(raidState)
	wipe(numInGroup)
	for i = 1, GetNumGroupMembers() do
		local _, _, group = GetRaidRosterInfo(i)
		current[name] = { index = i, group = group }
		numInGroup[group] = (numInGroup[group] or 0) + 1
	end
end

function SortRaid(str)
	-- Get a snapshot of the current raid layout:
	UpdateRaidState()

	local wanted = {}
	-- Build a map of the desired raid layout:
	for name, group in string.gmatch(str, "([^&:]):(%d)") do
		-- Ignore named players not in the raid.
		if current[name] then
			wanted[name] = group
		end
	end

	-- Look for players not in the wanted group and move them:
	for name, group in pairs(wanted) do
		if current[name].group ~= group then
			if numInGroup[group] < 5 then
				-- Just move them:
				SetRaidSubgroup(current[name].index, group)
			else
				-- Look for someone to swap with:
				for xname, xdata in pairs(current) do
					if xdata.group == group and wanted[xname] ~= group then
						-- Do the swap:
						SwapRaidSubgroup(current[name].index, xdata.index)
						-- Update the snapshot:
						UpdateRaidState()
					end
				end
			end
		end
	end
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 05-02-13 at 12:04 AM.
  Reply With Quote
05-01-13, 11:36 PM   #3
Anja
A Fallenroot Satyr
 
Anja's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 27
theres is a problem with

Code:
local raidState, numInGroup = {}, {}
local function UpdateRaidState()
	wipe(raidState)
	wipe(numInGroup)
	for i = 1, GetNumGroupMembers() do
		local _, _, group = GetRaidRosterInfo(i)
		current[name] = { index = i, group = group }
		numInGroup[group] = (numInGroup[group] or 0) + 1
	end
end
index of current and numInGroup are nil or dont know...

testing with 2 other people in raid, and it doesnt work
  Reply With Quote
05-02-13, 12:04 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Fixed; edited my previous post.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-02-13, 07:45 AM   #5
Anja
A Fallenroot Satyr
 
Anja's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 27
thanks for help, but it doesnt work... i always find errors,

wipe(raidstate) raidstate is old array right?
current undefined index (name?) so there is no name in the updateraidstate funktion, same on numInGroup key (group) i think... so, if you have time, can you check this addon ingame?
  Reply With Quote
05-02-13, 12:35 PM   #6
Anja
A Fallenroot Satyr
 
Anja's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 27
okay i killed the most errors, but now i think the regex is wrong, can you help with that?

name:2&name:5&name:1

name:group


[edit]
found:
Code:
"([^&:]+):(%d+)"
Next error:
3x Raidstring\Raidstring.lua:51: attempt to compare nil with number

Last edited by Anja : 05-02-13 at 12:39 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » SwapRaidSubgroup with String...

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