Page 1 of 1
how can I determine that the unit belongs to me?
Posted: 21 Aug 2012, 16:17
by Broker
may be like this?
uid = mouseSelection
myTeamID=Spring.GetMyTeamID()
if myTeamID==getUnitTeam(uid) then .......
Re: how can I determine that the unit belongs to me?
Posted: 22 Aug 2012, 20:10
by knorke
what unit do you mean with "the unit"?
Code: Select all
if Spring.GetMyTeamID () == Spring.GetUnitTeam (unitID) then
--unit belongs to me
end
Re: how can I determine that the unit belongs to me?
Posted: 23 Aug 2012, 16:46
by Broker
I'm trying to upgrade the widget Smart_select.
Code: Select all
local team = (playing and GetMyTeamID())
mouseSelection = GetUnitsInScreenRectangle(x, y, x1, y1, team)
local battle_unit = false
battle_unit variable is true if mouseSelection contains at least one combat unit.
Mylist includes all constructors, mylist_comm includes commanders.
Code: Select all
for i=1, #mouseSelection do
uid = mouseSelection[i]
udid = GetUnitDefID(uid)
if (mylist[udid]==false and mylist_comm[udid]==false )then
battle_unit = true
break
end
end
The code below leaves in mouseSelection only combat units.
Code: Select all
if (battle_unit) then
tmp = {}
for i=1, #mouseSelection do
uid = mouseSelection[i]
udid = GetUnitDefID(uid)
if (mylist[udid]== false and mylist_comm[udid]==false) then
tmp[#tmp+1] = uid
end
end
mouseSelection = tmp
end
The problem is that if my commander to be surrounded by other people's fighting units, the variable battle_unit is true, although in mouseSelection be only my commander.
So I added the code myTeamID == getUnitTeam (uid) in the condition.
Code: Select all
if (mylist[udid]==false and mylist_comm[udid]==false and myTeamID==getUnitTeam(uid) )then
result
[f=0002823] Error in Update(): [string "LuaUI\Widgets\unit_smart_select.lua"]:355: Bad unitID parameter in GetUnitTeam()
[f=0002823] Removed widget: SmartSelect
Re: how can I determine that the unit belongs to me?
Posted: 23 Aug 2012, 18:24
by zwzsg
If you do: mouseSelection = GetUnitsInScreenRectangle(x, y, x1, y1, team)
With a team argument, why do you need to test again for team later?
Can you pastebin the whole widget? I suspect something wrong outside of those particular bits.
Re: how can I determine that the unit belongs to me?
Posted: 24 Aug 2012, 11:40
by Broker
modified widget is very useful the widgets gui_idle_builders_new and unit_auto_group_com. control becomes like a supreme commander
if in mouseSelection are builders and military units the script selects only combat units.
Code: Select all
local battle_unit = false
for i=1, #mouseSelection do
uid = mouseSelection[i]
udid = GetUnitDefID(uid)
if (mylist[udid]==false and mylist_comm[udid]==false ) then
battle_unit = true
break
end
end
if (battle_unit) then
tmp = {}
for i=1, #mouseSelection do
uid = mouseSelection[i]
udid = GetUnitDefID(uid)
if (mylist[udid]== false and mylist_comm[udid]==false) then
tmp[#tmp+1] = uid
end
end
mouseSelection = tmp
Re: how can I determine that the unit belongs to me?
Posted: 24 Aug 2012, 19:16
by zwzsg
You store the unit selection in widget:MousePress
You use the unit selection in widget:Update
Inbetween, a few frames may have elapsed, unit IDs may have become invalid.
Either do everyting in widget:MousePress, or everything in widget:Update.
And bring back the Spring.GetMyTeamID from widget:Initialize as well, you wouldn't want your widget to break when a player change team ingame, would you?
Or... maybe the same selection is used in many calls to widget:Update, in which case you have to find a way to trim the dead units from it.
Re: how can I determine that the unit belongs to me?
Posted: 25 Aug 2012, 13:57
by Google_Frog
Why not use 'widget:SelectionChanged(selectedUnits)' ?
Re: how can I determine that the unit belongs to me?
Posted: 25 Aug 2012, 14:22
by gajop
Google_Frog wrote:Why not use 'widget:SelectionChanged(selectedUnits)' ?
iirc this isn't a default spring event and it may not exist depending on the widgethandler you're using
Re: how can I determine that the unit belongs to me?
Posted: 27 Aug 2012, 09:26
by Broker
I do not understand the difference.
works:
my commander
my commander and my constructor
my commander, my constructor and my combat unit
My commander and the commander of the enemy or the constructor or building.
but does not work
My commander and another combat unit.
what is the difference between.
Re: how can I determine that the unit belongs to me?
Posted: 27 Aug 2012, 14:21
by knorke
How/in which game is it even possible to select enemy units?
Or do you mean in replays or as spectator?
Re: how can I determine that the unit belongs to me?
Posted: 29 Aug 2012, 16:43
by Broker
All experiments were conducted in BA.
My attempt to change the logic of the widget is:
If builders and combat units get together in the selection rectangle, the final group will be involve only combat units. If there are not combat units, the final group will be involve only builders.
It can simply be explained by these screenshots:
This screenshot shows that the selected group involves only the Commander.
Then the builder adds to this group.
Now here comes the first combat unit and builders eliminates.
There is a problem in this screenshot.
Despite the fact that only my builder is in the framework of selection rectangle, he is not active. I understand this is due to the fact that my ally bot builds attack plane in the aircraft factory which refers to the fighting units.
It is impossible to choose my builder if there is ally combat unit.
The last screenshot shows that the allocation works only for my combat units despite that there are other enemy units are in the frame.
Re: how can I determine that the unit belongs to me?
Posted: 03 Sep 2012, 08:27
by Broker
HELP )))))
Re: how can I determine that the unit belongs to me?
Posted: 03 Sep 2012, 13:39
by knorke
hm, seems like something that can not be answered without looking at the widget in detail and understanding it..
That might be some work, not sure if somebody is in the mood for that.
Re: how can I determine that the unit belongs to me?
Posted: 11 Sep 2012, 10:12
by Broker
Maybe the problem is that GetTeamUnits (team) returns not only my units. units = GetTeamUnits (team). variable units contains my units and allied units as they have the same team.
Re: how can I determine that the unit belongs to me?
Posted: 11 Sep 2012, 14:32
by SirMaverick
Broker wrote:Maybe the problem is that GetTeamUnits (team) returns not only my units. units = GetTeamUnits (team). variable units contains my units and allied units as they have the same team.
Are you sure? The engine differs between teams and allies. One team is what one player "normally" controls. In a 2v2 there are 2 teams on each side (each team is controlled by one player) and each side has one alliance containing both teams.
Post your setup (script.txt) and the widget else it's very hard to help when we might talk about different things.
Re: how can I determine that the unit belongs to me?
Posted: 11 Sep 2012, 15:18
by Broker
why variable batle_unit is true when other player’s combat unit is in the selection area? Despite the fact that only my builder is in the selection area.
Code: Select all
local batle_unit = false
for i=1, #mouseSelection do
uid = mouseSelection[i]
udid = GetUnitDefID(uid)
if (mylist[udid]==false and mylist_comm[udid]==false) then
batle_unit = true
break
end
end
mouseSelection = GetUnitsInScreenRectangle(x, y, x1, y1, team)
Code: Select all
local function GetUnitsInScreenRectangle(x1, y1, x2, y2, team)
local units
if (team) then
units = GetTeamUnits(team)
else
units = GetAllUnits()
end
local left, right = sort(x1, x2)
local bottom, top = sort(y1, y2)
local result = {}
for i=1, #units do
local uid = units[i]
x, y, z = GetUnitPosition(uid)
x, y = WorldToScreenCoords(x, y, z)
if (left <= x and x <= right) and (top >= y and y >= bottom) then
result[#result+1] = uid
end
end
return result
end
Code: Select all
local playing = GetPlayerInfo(myPlayerID).spectating == false
local team = (playing and GetMyTeamID())
Re: how can I determine that the unit belongs to me?
Posted: 11 Sep 2012, 21:04
by SirMaverick
In Update():
Code: Select all
local playing = GetPlayerInfo(myPlayerID).spectating == false
That doesn't work. GetPlayerInfo(myPlayerID).spectating is always nil.
As a result:
=> playing is false
=> team is false
=> GetAllUnits() is called, instead of GetTeamUnits()
=> units not from your team are checked, too
=> combat units not from your team will trigger "batle_unit = true"
Change the line to:
Code: Select all
local playing = select(3,GetPlayerInfo(myPlayerID)) == false
Re: how can I determine that the unit belongs to me?
Posted: 13 Sep 2012, 08:26
by Broker
it is live ! thank you.