-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- include("keysym.h.lua") function widget:GetInfo() return { name = "Split group", desc = "Split the selected units in groups", author = "Masure", date = "Mar 25, 2008", license = "GNU GPL, v2 or later", layer = 0, enabled = true -- loaded by default? } end -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- local myTeam -- speedups local SetUnitGroup = Spring.SetUnitGroup local GetSelectedUnits = Spring.GetSelectedUnits local GetUnitDefID = Spring.GetUnitDefID local Echo = Spring.Echo function widget:Initialize() local _, _, spec, team = Spring.GetPlayerInfo(Spring.GetMyPlayerID()) if spec then widgetHandler:RemoveWidget() return false end myTeam = team end function widget:KeyPress(key, modifier, isRepeat) --if (modifier.ctrl and modifier.alt) then if (modifier.alt) then local grMaxCount local currentGroup local currentCount if (key == KEYSYMS.N_1) then grMaxCount = 1 end if (key == KEYSYMS.N_2) then grMaxCount = 2 end if (key == KEYSYMS.N_3) then grMaxCount = 3 end if (key == KEYSYMS.N_4) then grMaxCount = 4 end if (key == KEYSYMS.N_5) then grMaxCount = 5 end if (key == KEYSYMS.N_6) then grMaxCount = 6 end if (key == KEYSYMS.N_7) then grMaxCount = 7 end if (key == KEYSYMS.N_8) then grMaxCount = 8 end if (key == KEYSYMS.N_9) then grMaxCount = 9 end if (key == KEYSYMS.N_0) then grMaxCount = 10 end if (grMaxCount ~= nil) then currentGroup = 1 currentCount = 0 Echo("Making groups of " .. grMaxCount) for _, uid in ipairs(GetSelectedUnits()) do if currentCount >= grMaxCount then currentCount = 0 currentGroup = currentGroup + 1 if currentGroup > 10 then currentGroup = 10 break end end SetUnitGroup(uid, currentGroup) currentCount = currentCount + 1 end Echo(currentGroup .. " groups made") end end end --------------------------------------------------------------------------------