Page 1 of 2
Find commander unit independent of mod
Posted: 11 Sep 2013, 17:12
by qray
Hi,
I'm trying to find a way to find the commander unit that is independent of the mod (or at least works for mods with commander as starting unit).
Would UnitDefs[ud].isCommander work? Or is there a better way to find out?
Thanks for your help, qray.
Re: Find commander unit independent of mod
Posted: 11 Sep 2013, 17:21
by Silentwings
Afaik it's not possible to do it absolutely independently of the mod since, in theory, mods can spawn any starting unit they like and may have no units tagged as (or even similar to) commanders.
I think the traditional solution for this has been to include a unit list for each mod and use the appropriate one. Within BA you can use uDef.customParams.iscommander, but you might need to wait for our next release before it works. I think with 94.0 and before you are safe with uDef.isCommander but with 95.0 I think maybe that's deprecated.
Re: Find commander unit independent of mod
Posted: 11 Sep 2013, 18:56
by FLOZi
Catch first unitID of a unit created for this team?
Re: Find commander unit independent of mod
Posted: 11 Sep 2013, 22:03
by qray
I kinda hoped I would get around the catching of the first spawned unit per team (if there is more than once race, there could be more than a single com id)... but it seems that this will be the only reliable way to find com in mods that use com.
Thanks for the answers

Re: Find commander unit independent of mod
Posted: 11 Sep 2013, 22:05
by SinbadEV
Silly Idea... ask the user... have your gui ask the user to confirm a unit is their com or click on the one they want to be treated as their com.
Re: Find commander unit independent of mod
Posted: 11 Sep 2013, 22:47
by qray
The com finding is to make a king of hill script work with more mods than just BA.
Asking the user would be a sure invitation to cheat

Re: Find commander unit independent of mod
Posted: 11 Sep 2013, 23:08
by gajop
include a unit list for each mod
Best option atm. I'm skeptic of any standardization in regards to that.
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 00:19
by smoth
not
every
spring
game
has
a
commander
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 00:25
by gajop
He knows that, see first post.
Still many have a commander-like unit and he wants his thing (map I think?) to work in a specific way for those mods that do, for whatever reason.
It's not a bad thing.
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 00:43
by CarRepairer
Why do you need a commander for koth?
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 01:17
by SinbadEV
CarRepairer wrote:Why do you need a commander for koth?
Maybe that's the unit that needs to be in the scoring zone to earn points?
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 02:02
by smoth
what if not every game has that setup for KOTH.
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 02:25
by Funkencool
Then this map isn't for those games, if it's what you assume it is. Can't you just let him do his thing? Or at least make suggestions/advice if thats what you're getting at.
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 02:49
by smoth
Point is much of the thread ends at that point.
"I'm trying to find a way to find the commander unit that is independent of the mod"
most of the rest of the thread is discussion about how to find said unit. In many cases said unit doesn't exist.
Many things, KOTH included are project specific. Sinbad posted a point. I posted a counter point.
There is no sort of generic way to assume this sort of thing. Best bet is to ask the *A(because in these cases that is who it is) guys what their KOTH setup is and then go to them about it.
When we get into MODES of gameplay we are talking specific to certain projects. Not everything is going to work for all projects.
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 13:09
by Funkencool
smoth wrote:not
every
spring
game
has
a
commander
smoth wrote:
most of the rest of the thread is discussion about how to find said unit. In many cases said unit doesn't exist.
smoth wrote:what if not every game has that setup for KOTH.
He already mentions not every game has a commander. Why repeat it in a long dramatic fashion, then again multiple times?
qray wrote:
(or at least works for mods with commander as starting unit).
From that I can only assume he isn't worried about the games that don't have commanders, or at least knows of them. Why bring them up and use them in counter arguments?
smoth wrote:
Many things, KOTH included are project specific. Sinbad posted a point. I posted a counter point.
There is no sort of generic way to assume this sort of thing. Best bet is to ask the *A(because in these cases that is who it is) guys what their KOTH setup is and then go to them about it.
When we get into MODES of gameplay we are talking specific to certain projects. Not everything is going to work for all projects.
This is his project, and yes it is specific to the way he wants it. Which probably includes a commander (*when there is one).
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 13:16
by Funkencool
gajop wrote:include a unit list for each mod
Best option atm. I'm skeptic of any standardization in regards to that.
I think this would be the most reliable, for sure.
As far as unit spawning goes..
I've noticed many games have a widget that auto-selects their commander units at gamestart and that could be useful in some way.
Here's the widget that does it in BA/BAR, it could probably be recycled in some fashion.
Code: Select all
function widget:GetInfo()
return {
name = "Select n Center!",
desc = "Selects and centers the Commander at the start of the game.",
author = "quantum and Evil4Zerggin and zwzsg",
date = "19 April 2008",
license = "GNU GPL, v2 or later",
layer = 5,
enabled = true -- loaded by default?
}
end
--bug with usage of "Spring.GetPlayerInfo" fixed by [teh]decay 27 may 2012
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:Update()
local t = Spring.GetGameSeconds()
_, _, spectator = Spring.GetPlayerInfo(Spring.GetMyPlayerID())
if (spectator or t > 10) then
widgetHandler:RemoveWidget()
return
end
if (t > 0) then
local x, y, z = Spring.GetTeamStartPosition(Spring.GetMyTeamID())
local unitArray = Spring.GetTeamUnits(Spring.GetMyTeamID())
if (unitArray and #unitArray==1) then
Spring.SelectUnitArray{unitArray[1]}
x, y, z = Spring.GetUnitPosition(unitArray[1])
end
if x and y and z then
Spring.SetCameraTarget(x, y, z)
end
widgetHandler:RemoveWidget()
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 13:33
by knorke
agree that including list of all known commanders is probally best.
For XTA a list is here:
http://code.google.com/p/xta-springrts/ ... ion.lua#43
For zK the com unitdefs are generated based on what modules players put on their commanders, might have to look at it to see what names it uses.
BA only has 2 coms I think?
Imo do not save com names "by mod", might just bring more problems than it solves. Just a list.
That way forks of mods that keep comnames will work, too.Think unlikely that a unit "arm_com" will be something totally game breaking different in another mod.
"First spawned unit" maybe not so good, because during game commander might become a different unit. By rezzing, capture (also of different faction) sharing, morphing,...
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 13:36
by KingRaptor
For ZK look for customParam "commtype" or "level"
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 15:54
by Jools
qray wrote:Hi,
I'm trying to find a way to find the commander unit that is independent of the mod (or at least works for mods with commander as starting unit).
Would UnitDefs[ud].isCommander work? Or is there a better way to find out?
For XTA, you can also use unitDef.customparams.iscommander, but that will also return the decoy commanders. Which may or may not be what you want to do.
Catching the first unit created for a team may not be fool proof. At least XTA has a mod option to begin with decoys (then that is your commander in every meaningful way), and there is a mission where you begin with a decoy and the real commander gets teleported to you later.
I think there is a loose consensus nowadays to put the iscommander field in customparams and in that way standardise the field between games.
Re: Find commander unit independent of mod
Posted: 12 Sep 2013, 16:34
by Jools
FLOZi wrote:Catch first unitID of a unit created for this team?
In that case it's even better to use:
Code: Select all
local startunit = Spring.GetTeamRulesParam(teamID, 'startUnit')