Hi smoth,
You could start with the IdleBuilders widget by Ray.
Add the following into to the Initialize call-in function (perhaps at line 25):
Code: Select all
local unitDefId
for unitDefId = 1, table.getn(UnitDefs) do
if UnitDefs[unitDefId].name == "armsolar" then
lookingForUnitId = unitDefId
break
end
end
The above searches through the UnitDefs table to find the unitDefID that is your unit type and then sets the "lookingForUnitId" global variable to this value. You'll want to replace "armsolar" with the name of the unit you're looking for.
Next, at at line 87 is:
If you changed IsIdleBuilder to a new function, say, IsMyUnit():
and then create this new function like:
Code: Select all
function IsMyUnit(unitId)
local unitDefId = Spring.GetUnitDefId(unitId)
return unitDefId == lookingForUnitId
end
In theory the above should give you basically what you want, but I have not tested it. You'll also want to change the functions; LeftMouseButton, RightMouseButton and MiddleMouseButton to do the functions you want.
This will unfortunately be in-compatible with IdleBuilders as they'd operate in the same screen space, but you can fix this up after you've got it working.
You could also change the call to "GetTeamUnits()" to "GetTeamUnitsSorted()" along with the associated code, as this would be a lot more efficient for your purposes, but then again the difference may not be noticeable.
Cheers.