Reordering slots

Workshop for all Mission Engineer Comrades. Home of the FA Mission Making Template.
Post Reply
User avatar
Crocuta
Posts: 136
Joined: Mon Jan 21, 2013 6:04 am

Reordering slots

Post by Crocuta »

I made my first Arma mission using the latest F3, and then published it on Steam Workshop (is that ok?) http://steamcommunity.com/sharedfiles/f ... =167978911

Because it's a small 12 player Indfor coop, I deleted everything but ASL, A1, A2, ENG1. In the slotting screen it's all muddled up, and Arma 3 likes to also give groups their own names. Ordering on slotting goes as: ASL (Alpha 1-1), A2 (Alpha 1-2), ENG1 (Alpha 1-3), A1 (Alpha 2-1).

Does anyone know how to change the order of the slots, and if possible to also get rid of (or alter) Arma 3's own naming system?

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: Reordering slots

Post by wolfenswan »

Would be stupid if it wasn't okay :D Though I'd suggest giving it a more detailed description and maybe adding "made with the F3 Mission Making Framework" at the end. Just a suggestion though.

You have to "cut" groups with CTRL-x and paste it again with CTRL-v in the order you want them to appear. Arma's stupid like that. You could also edit the unit IDs in the mission.sqm but I wouldn't recommend that.

User avatar
Ferrard Carson
Posts: 565
Joined: Sun Aug 12, 2012 6:08 am

Re: Reordering slots

Post by Ferrard Carson »

wolfenswan wrote:You could also edit the unit IDs in the mission.sqm but I wouldn't recommend that.
This is what I do. List all the GroupIDs and the units they correspond to, then go in and individual re-jigger them according to where they should be on the list. It takes a damn long time (adding units to Rook Valley SE took an hour to re-jigger the unit orderings) but it works really well if you do it correctly. If you mess up and double-assign a number, you're screwed though.

~ Ferrard
"Take a boat in the air you don't love, she'll shake you off just as sure as the turnin' of the worlds. Love keeps her in the air when she oughta fall down, tells you she's hurtin' before she keels... makes her home."

User avatar
Crocuta
Posts: 136
Joined: Mon Jan 21, 2013 6:04 am

Re: Reordering slots

Post by Crocuta »

Thank you, I have it set up properly now. For some reason I assumed that it was a problem with F3 rather than one of Arma's many idiosyncrasies. I also see how I could have done it through the mission.sqm.

User avatar
Crocuta
Posts: 136
Joined: Mon Jan 21, 2013 6:04 am

Re: Reordering slots

Post by Crocuta »

I don't know whether anything like this already exists, but I threw together a Lua 5.1 script for reordering groups in the mission.sqm

Code: Select all

local function processMission(mode)
	-- group item iterator
	local function groups(groupStr)
		local index = 1
		return function ()
			local s, e = string.find(groupStr, "class Item%d+.-%b{};", index)
			if s then
				index = e + 1
				return string.sub(groupStr, s, e)
			else return nil end
		end
	end

	-- load sqm mission into string
	local fl = io.open("mission.sqm")
	local mission = fl:read("*a")
	fl:close()

	-- make backup of mission.sqm
	local fl = io.open("mission_backup.sqm", "w")
	fl:write(mission)
	fl:close()

	-- search for group definitions segment
	local gr_start, gr_end = string.find(mission, "class Groups.-%b{};")

	if mode == "output" then
		local fl = io.open("reorder_list.txt", "w")
		-- use group iterator
		for gr in groups(string.sub(mission, gr_start, gr_end)) do
			-- if first element in group has description then write it to file
			local writeStr = gr:match("description=(.-);")
			if writeStr then fl:write(writeStr .. "\n") end
		end
		fl:close()
		print("\n ..DONE..\n")
	elseif mode == "order" then
		local orderedList = {}
		-- make numbered table of ordered groups
		for line in io.lines("reorder_list.txt") do
			if string.match(line, "(\".-\")") then table.insert(orderedList, line) end
		end

		local groupList = {}

		-- if group leader has description: add group to table with
		-- description as the key
		-- else add group with numbered key
		for gr in groups(string.sub(mission, gr_start, gr_end)) do
			local v1, v2 = string.find(gr, "description=.-;")
			if v1 then
				local desc = gr:match("description=(.-);")
				groupList[desc] = gr
			else table.insert(groupList, gr) end
		end

		-- open sqm and write everything before group item definitions
		local missionFile = io.open("mission.sqm", "w")
		local v1, v2 = string.find(mission, "items=%d+;", gr_start)
		missionFile:write(string.sub(mission, 1, v2+1))

		-- increment item number for group
		local function incItem(str, num)
			local v1, v2 = string.find(str, "class Item%d+")
			return "\n\t\tclass Item" .. string.gsub(string.sub(str, v1, v2), "class Item(%d+)", tostring(num)) .. string.sub(str, v2 + 1)
		end

		-- starting from 0, write the ordered group items to sqm
		local index = 0
		for i, v in ipairs(orderedList) do
			missionFile:write(incItem(groupList[v], index))
			index = index + 1
		end

		-- write all other undescribed groups from last index
		for i, v in ipairs(groupList) do
			missionFile:write(incItem(v, index))
			index = index + 1
		end

		-- write everything else after group definitions
		missionFile:write("\n\t}" .. string.sub(mission, gr_end))
		missionFile:close()
		print("\n ..DONE..\n")
	end
end

io.write("\tmission.sqm reorder\n\t-------------------\n")
io.write("After choosing to output groups (Option 1), rearrange the element leaders in reorder_list.txt so that each has its own line. Save the file and then choose reorder groups (Option 2).")
io.write("\n\n 1. Ouput groups\n 2. Reorder groups\n 3. Quit\n\n")

while true do
	io.write(" >")
	local ch = io.read()
	if ch == "1" then
		processMission("output")
	elseif ch == "2" then
		-- check if group_order.txt exists
		local fl = io.open("reorder_list.txt","r")
		if fl ~= nil then
			io.close(fl)
			processMission("order")
		else print("No reorder_list.txt file. Choose option 1 first!") end
	elseif ch == "3" or ch == "q" then break end
end
If you want to test it, install a Lua 5.1 interpreter (will probably also work with 5.2). Save the code above as something like "reorder.lua" and put it in the folder of the mission you want to use it on. FOR THE LOVE OF GOD backup your mission.sqm file. Execute the script, and choosing the first option will spit out a text file containing the description entry of the most senior unit in each group. If there's no description it won't be listed. Reorder the names by hand so that each has its own line in the file. Then choose to reorder in the script and it should be done. The units from the text file are bumped up to Item0, Item1, etc.

I have no experience with sqm files so don't know whether I've just made a bunch of garbage that seems to work at the moment.

Post Reply