• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Units in range owned by different players

Status
Not open for further replies.
1) Player Comparison: (Owner of (Picked unit)) Equal to (Owner of (your unit))
2) Well,
  • Set Point1 = (Position of (your unit))
  • Set Temp_group = (Units within 500.00 of (Point1))
  • If (All conditions are true) then do (Actions) else do (Actions)
    • If - Conditions
      • (Number of units in (Temp_group)) Equal to 0
    • Then - Actions
      • .. Your actions here ..
    • Else - Actions
  • Custom script: call RemoveLocation (udg_Point1)
  • Custom script: call DestroyGroup (udg_Temp_group)
 
I should clarify, the specific unit is neutrally owned so "(Owner of (Picked unit)) Equal to (Owner of (your unit))" won't work.

The idea here is that the neutral unit will have ownership transfered to which ever player is in range, and that can be the only player - if there are other players units nothing will happen.

The second script is fine, since what that is checking for is to set the unit back to neutral ownership if no player unit is in range.
 
I should clarify, the specific unit is neutrally owned so "(Owner of (Picked unit)) Equal to (Owner of (your unit))" won't work.
That's funny. So Neutral Passive is not considered as a player?

The idea here is that the neutral unit will have ownership transfered to which ever player is in range, and that can be the only player - if there are other players units nothing will happen.
You need a script here, that gets the closest unit, in order to change the ownership.
Here: http://www.hiveworkshop.com/forums/jass-functions-413/getclosestunit-s-59254/
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
  • Untitled Trigger 019
    • Events
    • Conditions
    • Actions
      • Set Temp_Unit_1 = Some unit
      • Set Temp_Integer_1 = 0
      • Set Temp_Loc_1 = (Position of Temp_Unit_1)
      • Set Temp_Group_1 = (Units within 512.00 of Temp_Loc_1 matching (((Matching unit) is alive) Equal to True)) // you may need to change how you pick this group, don't pick temp_unit_1 or something
      • Unit Group - Pick every unit in Temp_Group_1 and do (Actions)
        • Loop - Actions
          • Set Temp_Integer_Array_1[Temp_Integer_1] = (Player number of (Owner of (Picked unit)))
          • Set Temp_Integer_1 = (Temp_Integer_1 + 1)
      • Set Temp_Integer_1 = (Number of units in Temp_Group_1)
      • Custom script: call DestroyGroup(udg_Temp_Group_1)
      • Custom script: call RemoveLocation(udg_Temp_Loc_1)
      • For each (Integer A) from 0 to (Temp_Integer_1 - 1), do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Integer_Array_1[0] Equal to Temp_Integer_Array_1[(Integer A)]
            • Then - Actions
            • Else - Actions
              • Skip remaining actions
      • Do your thing, units of only one player are in range
 
For the first one, you can use this script I made real quick, I tested it and it works for all players including neutral passive and stuff. Tell me if it causes any error: (JNGP = JassNewGen Pack)

JASS:
//call OwnerOfGroup(group g) returns boolean         - Checks if every unit in the group is of the same
//call GetOwnerOfGroup(group g) returns player       - Retrieves the owner of the units in the specified group
// globals: udg_GroupPlayer (Player Variable) ; udg_GroupBool (Boolean Variable)

function OwnerOfGroupCallback takes nothing returns nothing
    local player p = GetOwningPlayer(GetEnumUnit())
    if udg_GroupPlayer == p then
        set udg_GroupBool = true
    else
        set udg_GroupBool = false
        return
    endif
endfunction
function OwnerOfGroup takes group g returns boolean
    set udg_GroupPlayer = GetOwningPlayer(FirstOfGroup(g))
    call ForGroup(g,function OwnerOfGroupCallback)
    return udg_GroupBool
endfunction
function GetOwnerOfGroup takes group g returns player
    if OwnerOfGroup(g) then
        return udg_GroupPlayer
    endif
    return null
endfunction
JASS:
//call OwnerOfGroup(group g) returns boolean         - Checks if every unit in the group is of the same
//call GetOwnerOfGroup(group g) returns player       - Retrieves the owner of the units in the specified group
// globals: udg_GroupPlayer (Player Variable) ; udg_GroupBool (Boolean Variable)

globals
    player GroupPlayer
    boolean GroupBool
endglobals

function OwnerOfGroupCallback takes nothing returns nothing
    local player p = GetOwningPlayer(GetEnumUnit())
    if GroupPlayer == p then
        set GroupBool = true
    else
        set GroupBool = false
        return
    endif
endfunction
function OwnerOfGroup takes group g returns boolean
    set GroupPlayer = GetOwningPlayer(FirstOfGroup(g))
    call ForGroup(g,function OwnerOfGroupCallback)
    return GroupBool
endfunction
function GetOwnerOfGroup takes group g returns player
    if OwnerOfGroup(g) then
        return GroupPlayer
    endif
    return null
endfunction

The first requires you to create two global variables.

Example of usage:
  • Blargh
    • Events
    • Conditions
    • Actions
      • Custom script: if OwnerOfGroup(udg_MyGroup) then
      • Game - Display to (All players) the text: Group g is owned by...
      • Custom script: endif
      • Custom script: set udg_MyBoolean = OwnerOfGroup(udg_MyGroup)
      • Custom script: set udg_MyPlayer = GetOwnerOfGroup(udg_MyGroup)
For those curious, this is the testing trig I used:
JASS:
scope Tests initializer Init
globals
endglobals
private function P2S takes player p returns string //I used only p1, p7, and np/nh in these tests...
// I also tried it with pink and gray and it worked, so it should probably work with everything else
    if p == Player(0) then
        return "Player 1 (Red)"
    elseif p == Player(7) then
        return "Player 7 (Green)"
    elseif p == Player(15) then
        return "Neutral Passive"
    endif
    return "Unknown Player"
endfunction
private function B2S takes boolean b returns string
    if b then
        return "true"
    endif
    return "false"
endfunction
private function Act takes nothing returns nothing
    local group g = CreateGroup()
    call GroupAddUnit(g,gg_unit_opeo_0002) //peon 1
    call GroupAddUnit(g,gg_unit_opeo_0003) //peon 2
    call GroupAddUnit(g,gg_unit_opeo_0004) //peon 3
    call BJDebugMsg("Final: "+B2S(OwnerOfGroup(g)))
    call BJDebugMsg("Final: "+P2S(GetOwnerOfGroup(g)))
endfunction
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t,2,false)
    call TriggerAddAction(t,function Act)
    set t = null
endfunction
endscope

Good luck if you end up using this. No need for credits or anything like that. =)
 
  • Capture
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Picked unit)) Equal to Circle of Power (large))) and do (Actions)
        • Loop - Actions
          • Set CapUnit = (Picked unit)
          • Set CapInt = 0
          • Set CapPoint = (Position of CapUnit)
          • Set CapGroup = (Units within 512.00 of CapPoint matching ((((Matching unit) is A structure) Equal to False) and (((Matching unit) is alive) Equal to True)))
          • Unit Group - Pick every unit in CapGroup and do (Actions)
            • Loop - Actions
              • Set CapIntArr[CapInt] = (Player number of (Owner of (Picked unit)))
              • Set CapInt = (CapInt + 1)
          • Set CapInt = (Number of units in CapGroup)
          • Custom script: call DestroyGroup(udg_CapGroup)
          • Custom script: call RemoveLocation(udg_CapPoint)
          • For each (Integer A) from 0 to (CapInt - 1), do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • CapIntArr[0] Equal to CapIntArr[(Integer A)]
                • Then - Actions
                • Else - Actions
                  • Skip remaining actions
          • Unit - Change ownership of CapUnit to Player 1 (Red) and Change color


It does not function correctly, what did I do wrong?

I used player 1 just for testing, it should be the owner of the units in range.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
  • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Picked unit))...
Picked unit -> matching unit.

You may also need to add ...matching unit not equal to CapUnit in the second unit group pick.

Skip remaining actions makes the trigger skip the first unit group pick also. So if some unit changes owner, then no other unit can change owner until the trigger runs again.
 
It's what I need, but it seems to bug sometimes.

I pretty much just randomly ran the two heroes around for a bit and eventually the bottom tower would only revet to that color even if it was out of range and the other hero was right next to it.

I don't know if that's just because of the test map and being able to control two players or something else.

I'm looking at the triggers now.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Updated version. I increases the range the unit pick towers when it gets close, because the range was too small so it didn't pick towers all the time, it didn't detect the tower the unit got close to.

I also change "player number of triggering player" to "player number of owner of (triggering unit) in the first trigger.
 

Attachments

  • Tower_Capture_System.w3x
    19.8 KB · Views: 70
  • Like
Reactions: Kam
Status
Not open for further replies.
Top