• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Rescueable Units - May need to trigger this

Status
Not open for further replies.
Level 7
Joined
Sep 9, 2007
Messages
253
There are Neutral towers scattered across my map and I want to allow the 2 forces to claim them. The teams are set up the same as your average AoS:

force 1
player 1 - computer
player 2,3,4 - user controlled

force 2
player 4 - computer
player 5,6,7 user controlled

I want allow a user's hero to claim a neutral tower for his team by walking next to it (like a normal rescue except he is not rescuing for himself he is rescuing for his computer-controlled ally). This shouldn't be a problem using the following trigger:

  • Hero Claimes a Tower
    • Events
      • Unit - A unit Is rescued
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Unit - Change ownership of (Attacking unit) to (Owner of (Triggering unit)) and Change color
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Triggering unit)) Equal to Player 2 (Blue)
          • (Owner of (Triggering unit)) Equal to Player 3 (Teal)
          • (Owner of (Triggering unit)) Equal to Player 4 (Purple)
        • Then - Actions
          • Unit - Change ownership of (Triggering unit) to Player 1 (Red) and Change color
        • Else - Actions
          • Unit - Change ownership of (Triggering unit) to Player 5 (Yellow) and Change color
However I also want to allow the computer controlled creeps (which are randomly pathing around the map) to claim the towers from range, Say 500 range. I'm not sure how to accomplish this but I need something like this:

Event - A unit comes within 500 range of a neutral tower.
Condition - unit type of unit(unit coming within range of the tower) = creep.
Action - change ownership of neutral tower to player(owner of unit(creep unit))
I was initially letting the neutral towers attack and changing owndership when they attack a unit. I had to give them no projectile and 0 damage because I didn't want it to be noticable.... This method kind of worked but I felt it was clunky and I didn't like it.
 
Level 7
Joined
Sep 9, 2007
Messages
253
Regions give a rectengular area, i need a circular area around the tower. I did answer my own question except that the event i used does not exist... Im hoping someone could suggest a method that.could be used.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
JASS:
function Trig_Capture_Actions takes nothing returns nothing
    local unit tower = LoadUnitHandle(udg_rescueHash, GetHandleId(GetTriggeringTrigger()), 0)
    
    if GetPlayerId(GetOwningPlayer(GetTriggerUnit())) < 5 then
        call SetUnitOwner(tower, Player(0), true)
    else
        call SetUnitOwner(tower, Player(3), true)
    endif 
    call FlushChildHashtable(udg_rescueHash, GetHandleId(GetTriggeringTrigger()))
    call DisableTrigger(GetTriggeringTrigger())
    call DestroyTrigger(GetTriggeringTrigger())
    set tower = null
endfunction

//===========================================================================
function InitTrig_Capture takes nothing returns nothing
    local trigger t
    local group g = CreateGroup()
    local unit u
    set udg_rescueHash = InitHashtable()
    
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        if GetUnitTypeId(u) == 'hwtw' then // Picks all scout tower
            set t = CreateTrigger()
            call TriggerRegisterUnitInRange(t, u, 500, null) // 500 is the range to enter
            call TriggerAddAction(t, function Trig_Capture_Actions)
            call SaveUnitHandle(udg_rescueHash, GetHandleId(t), 0, u)
        endif
        call GroupRemoveUnit(g, u)
    endloop
    call DestroyGroup(g)
    set g = null
endfunction

You can't lose the ownerhip of a tower with this, as you dodn't mention about it.
 

Attachments

  • Capture.w3x
    13.3 KB · Views: 75
Level 4
Joined
Apr 7, 2012
Messages
63
In the scenario properties set the player who owns the tower you want to capture to rescuable and not computer, this seemed to work for me if you target the object.
 
Level 7
Joined
Sep 9, 2007
Messages
253
You can't lose the ownerhip of a tower with this, as you dodn't mention about it.

Yes that is correct Maker. If a tower is destroyed it will respawn after 45 seconds as a neutral passive claimable tower.

Question: the function "InitTrig_Capture" is adding all of my towers to a unit group. When and how often does it do this? When a tower respawns during the map play I am able to claim it again so this is working well for my intentions but I'm curious how the function knows when to add a unit.


I only want specific unit-types to be able to claim Towers.... Would the following change be the appropriate way to achieve this?

JASS:
function Trig_Capture_Actions takes nothing returns nothing
    local unit tower = LoadUnitHandle(udg_rescueHash, GetHandleId(GetTriggeringTrigger()), 0)
    
    if GetPlayerId(GetOwningPlayer(GetTriggerUnit())) < 5 then
        if GetUnitTypeId(GetTriggerUnit()) == 'ohun' then
            call SetUnitOwner(tower, Player(0), true)
        else
        endif
    else
        if GetUnitTypeId(GetTriggerUnit()) == 'ogru' then
            call SetUnitOwner(tower, Player(3), true)
        else
        endif
    endif 
    call FlushChildHashtable(udg_rescueHash, GetHandleId(GetTriggeringTrigger()))
    call DisableTrigger(GetTriggeringTrigger())
    call DestroyTrigger(GetTriggeringTrigger())
    set tower = null
endfunction

//===========================================================================
function InitTrig_Capture takes nothing returns nothing
    local trigger t
    local group g = CreateGroup()
    local unit u
    set udg_rescueHash = InitHashtable()
    
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        if GetUnitTypeId(u) == 'o007' then // Picks all scout tower
            set t = CreateTrigger()
            call TriggerRegisterUnitInRange(t, u, 500, null) // 500 is the range to enter
            call TriggerAddAction(t, function Trig_Capture_Actions)
            call SaveUnitHandle(udg_rescueHash, GetHandleId(t), 0, u)
        endif
        call GroupRemoveUnit(g, u)
    endloop
    call DestroyGroup(g)
    set g = null
endfunction
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
JASS:
function Trig_Capture_Actions takes nothing returns nothing
    local unit tower
    if GetUnitTypeId(GetEnteringUnit()) == 'Hblm' then
        set tower  = LoadUnitHandle(udg_rescueHash, GetHandleId(GetTriggeringTrigger()), 0)
        if GetPlayerId(GetOwningPlayer(GetEnteringUnit())) < 5 then
            call SetUnitOwner(tower, Player(0), true)
        else
            call SetUnitOwner(tower, Player(3), true)
        endif 
        call FlushChildHashtable(udg_rescueHash, GetHandleId(GetTriggeringTrigger()))
        call DisableTrigger(GetTriggeringTrigger())
        call DestroyTrigger(GetTriggeringTrigger())
        set tower = null
    endif
endfunction

function RegisterTower takes unit u returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterUnitInRange(t, u, 500, null) // 500 is the range to enter
    call TriggerAddAction(t, function Trig_Capture_Actions)
    call SaveUnitHandle(udg_rescueHash, GetHandleId(t), 0, u)
    set t = null
endfunction

function TowerFilter takes nothing returns boolean
    if GetUnitTypeId(GetFilterUnit()) == 'hwtw' then
        call RegisterTower(GetFilterUnit())
    endif
    return false
endfunction

//===========================================================================
function InitTrig_Capture takes nothing returns nothing
    local region r = CreateRegion()
    local trigger t = CreateTrigger()
    local group g = CreateGroup()
    local unit u
    set udg_rescueHash = InitHashtable()
    
    call RegionAddRect(r, bj_mapInitialPlayableArea)
    call TriggerRegisterEnterRegion(t, r, function TowerFilter)
    
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        if GetUnitTypeId(u) == 'hwtw' then // Picks all scout tower
            call RegisterTower(u)
        endif
        call GroupRemoveUnit(g, u)
    endloop
    call DestroyGroup(g)
    set g = null
    set r = null
endfunction
 
Level 7
Joined
Sep 9, 2007
Messages
253
Wow that seems much more complicated. That code looks like it only allows for the blood mage. What if the two forces had 2 different types of creeps (different unit-types). The code I put in works for the 2 forces having different capturing units but I'm worried it may leak.
 
Status
Not open for further replies.
Top