Find commander unit independent of mod

Find commander unit independent of mod

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
qray
Posts: 377
Joined: 02 Feb 2009, 18:49

Find commander unit independent of mod

Post by qray » 11 Sep 2013, 17:12

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.
0 x

User avatar
Silentwings
Moderator
Posts: 3597
Joined: 25 Oct 2008, 00:23

Re: Find commander unit independent of mod

Post by Silentwings » 11 Sep 2013, 17:21

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.
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6109
Joined: 29 Apr 2005, 01:14

Re: Find commander unit independent of mod

Post by FLOZi » 11 Sep 2013, 18:56

Catch first unitID of a unit created for this team?
0 x

User avatar
qray
Posts: 377
Joined: 02 Feb 2009, 18:49

Re: Find commander unit independent of mod

Post by qray » 11 Sep 2013, 22:03

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 :-)
0 x

User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Re: Find commander unit independent of mod

Post by SinbadEV » 11 Sep 2013, 22:05

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.
0 x

User avatar
qray
Posts: 377
Joined: 02 Feb 2009, 18:49

Re: Find commander unit independent of mod

Post by qray » 11 Sep 2013, 22:47

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 :mrgreen:
0 x

gajop
Moderator
Posts: 3023
Joined: 05 Aug 2009, 20:42

Re: Find commander unit independent of mod

Post by gajop » 11 Sep 2013, 23:08

include a unit list for each mod
Best option atm. I'm skeptic of any standardization in regards to that.
0 x

User avatar
smoth
Posts: 22300
Joined: 13 Jan 2005, 00:46

Re: Find commander unit independent of mod

Post by smoth » 12 Sep 2013, 00:19

not

every

spring

game

has

a

commander
0 x

gajop
Moderator
Posts: 3023
Joined: 05 Aug 2009, 20:42

Re: Find commander unit independent of mod

Post by gajop » 12 Sep 2013, 00:25

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.
0 x

User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Find commander unit independent of mod

Post by CarRepairer » 12 Sep 2013, 00:43

Why do you need a commander for koth?
0 x

User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Re: Find commander unit independent of mod

Post by SinbadEV » 12 Sep 2013, 01:17

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?
0 x

User avatar
smoth
Posts: 22300
Joined: 13 Jan 2005, 00:46

Re: Find commander unit independent of mod

Post by smoth » 12 Sep 2013, 02:02

what if not every game has that setup for KOTH.
0 x

User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Find commander unit independent of mod

Post by Funkencool » 12 Sep 2013, 02:25

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.
0 x

User avatar
smoth
Posts: 22300
Joined: 13 Jan 2005, 00:46

Re: Find commander unit independent of mod

Post by smoth » 12 Sep 2013, 02:49

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.
0 x

User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Find commander unit independent of mod

Post by Funkencool » 12 Sep 2013, 13:09

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).
0 x

User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Find commander unit independent of mod

Post by Funkencool » 12 Sep 2013, 13:16

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


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
0 x

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Find commander unit independent of mod

Post by knorke » 12 Sep 2013, 13:33

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,...
0 x

User avatar
KingRaptor
Zero-K Developer
Posts: 838
Joined: 14 Mar 2007, 03:44

Re: Find commander unit independent of mod

Post by KingRaptor » 12 Sep 2013, 13:36

For ZK look for customParam "commtype" or "level"
0 x

User avatar
Jools
XTA Developer
Posts: 2804
Joined: 23 Feb 2009, 16:29

Re: Find commander unit independent of mod

Post by Jools » 12 Sep 2013, 15:54

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.
0 x

User avatar
Jools
XTA Developer
Posts: 2804
Joined: 23 Feb 2009, 16:29

Re: Find commander unit independent of mod

Post by Jools » 12 Sep 2013, 16:34

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')
0 x

Post Reply

Return to “Lua Scripts”