| 09-14-2006, 02:47 AM | #1 |
This may sound noobish but I just can't figure out how to do this. How can I can to see if player X owns a unit of unit-type X? for example: JASS:if player owns unit-type Archer then //Do something endif |
| 09-14-2006, 03:00 AM | #2 |
JASS:if GetOwningPlayer(GetTriggerUnit())==Player(0) then call Your Actions endif or maybe to find the player owning the unit JASS:function OwningPlayer takes nothing returns integer local unit u // set to the unit you are checking local integer i=0 loop exitwhen i>15 if GetOwningPlayer(u)==Player(i) then exitwhen true endif set i=i+1 endloop return i endfunction edit -- I just re-read the question and see now what you are asking for. JASS:function OwningPlayer takes nothing returns boolean local group g = CreateGroup() local player p //depending on how you're using it to setup the player local integer unitId = 'earc' //unit id for archer local unit u local boolean b = false call GroupEnumUnitsOfPlayer(g,p,null) loop set u=FirstOfGroup(g) exitwhen u==null if GetUnitTypeId(u)==unitId then set b = true exitwhen true endif call GroupRemoveUnit(g,u) endloop call DestroyGroup(g) set g=null set u=null set p=null return b endfunction JASS:function OwningPlayerBool takes nothing returns boolean return GetUnitTypeId(GetFilterUnit())=='earc' endfunction function OwningPlayer takes nothing returns boolean local group g = CreateGroup() local player p = GetTriggerPlayer() //depending on how you're using it to setup the player, this will change local boolexpr bx = Condition(function OwningPlayerBool) local boolean b = false call GroupEnumUnitsOfPlayer(g,p,bx) if FirstOfGroup(g)!=null then set b=true endif call DestroyGroup(g) call DestroyBoolExpr(bx) set p=null set g=null set bx=null return b endfunction Of course there are other methods depending on how you are using it. |
| 09-14-2006, 03:01 AM | #3 |
I want to just see if player x has at least 1 unit of unit-type not find owner of a unit. |
| 09-14-2006, 03:31 AM | #4 |
The last 2 scripts I gave to you would do that. Put this in the trigger or in your custom script and call it. JASS:function PlayerOwnsUnit takes player whichPlayer, integer unitId returns boolean local group g = CreateGroup() local unit u local boolean b = false call GroupEnumUnitsOfPlayer(g,whichPlayer,null) loop set u=FirstOfGroup(g) exitwhen u==null if GetUnitTypeId(u)==unitId then set b = true exitwhen true endif call GroupRemoveUnit(g,u) endloop call DestroyGroup(g) set g=null set u=null return b endfunction Then you would in your trigger use something like: JASS:local player p = Set to your player if PlayerOwnsUnit(p,'earc') then Your actions endif |
| 09-14-2006, 03:58 AM | #5 |
thanks, works great. |
