Check if unit is mine

Check if unit is mine

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

Moderator: Moderators

Post Reply
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Check if unit is mine

Post by Pithikos »

How do I check if a unit is mine?

I have this so far to get my ID:

Code: Select all

myPlayerID=Spring.GetMyPlayerID()
Then what can I use to check if a unit belongs to me? Searched a bit and didn't find anything.
Is there some function I can call to give me the unit's owner?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Check if unit is mine

Post by knorke »

There are playerIDs, teamIDs and allyteamIDs.
Lets say there is a 2v2 game and one team has 3 players but to make it fair 2 players controll one team together.

playerIDs - every player one has, even specs.
ie
Bob = 0
mastakilla = 1
powernoob = 2
[LOL]superrusher = 3
panzermann = 4

teamIDs - each team ("color") has one, ie two players can controll one team together
bob & mastakilla = 0
powernoob = 1
[LOL]superrusher = 2
panzermann = 2

AllyIDs - the allied teams.
bob & mastakilla & powernoob = 0
[LOL]superrusher & panzermann = 1


http://springrts.com/wiki/Lua_UnsyncedR ... eam.2CAlly


You want to compare: Spring.GetLocalTeamID (playerID)
and
Spring.GetUnitTeam (unitID)
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Check if unit is mine

Post by aegis »

if you're co-oping with someone, every unit on your team is yours (you can control it), there's no very good way to differentiate...

sure, children of your commander, but there's no point in co-op if you're not going to share things.
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Check if unit is mine

Post by Pithikos »

Yes I just got everything messed up in my head for a moment.
I guess what I really was looking for was Spring.GetUnitTeam (unitID)

Else if I really want my widget to effect ONLY my own units then I suppose I have to record the whole tech tree beginning from my commander. But that's an overkill so I will stick with the TeamID :D
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Check if unit is mine

Post by aegis »

curious what kind of widget you're making ^_^
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Check if unit is mine

Post by Pithikos »

aegis wrote:curious what kind of widget you're making ^_^
Well I saw there are many "auto repair" gadgets but none "auto reclaim" so I thought of making one. Though in the end it became a hybrid.. I use the fight command for idle builders so builders both repair damaged units and reclaim metal if the metal is under the limitbar 8)
Post Reply

Return to “Lua Scripts”