• 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.

How to choose the closest unit.

Status
Not open for further replies.
Level 6
Joined
Oct 4, 2011
Messages
226
  • Fiery Claws
    • Events
      • Time - Every 4.00 seconds of game time
    • Conditions
    • Actions
      • Set FieryClawsCaster_UGrp = (Units in (Entire map) matching (((Level of Fiery Claws (Neutral Hostile) for (Matching unit)) Greater than 0) and (((Matching unit) is alive) Equal to True)))
      • Unit Group - Pick every unit in FieryClawsCaster_UGrp and do (Actions)
        • Loop - Actions
          • Hashtable - Save Handle Of(Picked unit) as (Key caster) of (Key fireball) in BlazingFiend01_HashTable
          • Hashtable - Save Handle Of(Position of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable)) as (Key location1) of (Key caster) in BlazingFiend01_HashTable
          • Set FieryClawsTargets_UGrp = (Units within 400.00 of (Load (Key location1) of (Key caster) in BlazingFiend01_HashTable) matching ((((Matching unit) belongs to an enemy of (Owner of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable))) Equal to True) and ((((Matching unit) b
          • Unit Group - Pick every unit in FieryClawsTargets_UGrp and do (Actions)
            • Loop - Actions
              • Set FieryClawsDistance_Real = (Distance between (Load (Key location1) of (Key caster) in BlazingFiend01_HashTable) and (Position of (Picked unit)))
          • Special Effect - Create a special effect at (Load (Key location1) of (Key caster) in BlazingFiend01_HashTable) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
          • Special Effect - Destroy (Last created special effect)
          • -------- The Other location will have to be inserted before the unit is made and faces the direction --------
          • Unit - Create 1 Fireball for (Owner of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable)) at ((Load (Key location1) of (Key caster) in BlazingFiend01_HashTable) offset by 75.00 towards (Angle from (Position of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable)) to (Position of (Triggering unit))) degrees) facing Default building facing degrees
          • Unit Group - Add (Last created unit) to Fireballs_UGrp
      • Unit Group - Remove all units from FieryClawsCaster_UGrp
      • Hashtable - Clear all child hashtables of child (Key location1) in BlazingFiend01_HashTable
Now I just want to look over the section that involves the targets unit group. I don't know how to use the distance from here.
Edit: And ty!
 
Last edited by a moderator:
Level 6
Joined
Oct 4, 2011
Messages
226
  • Fiery Claws
    • Events
      • Time - Every 4.00 seconds of game time
    • Conditions
    • Actions
      • Set FieryClawsCaster_UGrp = (Units in (Entire map) matching (((Level of Fiery Claws (Neutral Hostile) for (Matching unit)) Greater than 0) and (((Matching unit) is alive) Equal to True)))
      • Set FieryClawsDistance2_Real = 400.00
      • Unit Group - Pick every unit in FieryClawsCaster_UGrp and do (Actions)
        • Loop - Actions
          • Hashtable - Save Handle Of(Picked unit) as (Key caster) of (Key fireball) in BlazingFiend01_HashTable
          • Hashtable - Save Handle Of(Position of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable)) as (Key location1) of (Key caster) in BlazingFiend01_HashTable
          • Set FieryClawsTargets_UGrp = (Units within 400.00 of (Load (Key location1) of (Key caster) in BlazingFiend01_HashTable) matching ((((Matching unit) belongs to an enemy of (Owner of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable))) Equal to True) and ((((Matching unit) b
          • Unit Group - Pick every unit in FieryClawsTargets_UGrp and do (Actions)
            • Loop - Actions
              • Hashtable - Save Handle Of(Position of (Picked unit)) as (Key location2) of (Key target) in BlazingFiend01_HashTable
              • Set FieryClawsDistance_Real = (Distance between (Load (Key location1) of (Key caster) in BlazingFiend01_HashTable) and (Load (Key location2) of (Key target) in BlazingFiend01_HashTable))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • FieryClawsDistance_Real Less than FieryClawsDistance2_Real
                  • (((Picked unit) is A structure) Equal to False) and ((((Picked unit) belongs to an enemy of (Owner of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable))) Equal to True) and (((Picked unit) belongs to an ally of (Owner of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable))) Equal
                • Then - Actions
                  • Set FieryClawsDistance2_Real = FieryClawsDistance_Real
                  • Hashtable - Save Handle Of(Picked unit) as (Key target) of (Key fireball) in BlazingFiend01_HashTable
                • Else - Actions
          • Special Effect - Create a special effect at (Load (Key location1) of (Key caster) in BlazingFiend01_HashTable) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
          • Special Effect - Destroy (Last created special effect)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in FieryClawsTargets_UGrp) Greater than 0
            • Then - Actions
              • Unit - Create 1 Fireball for (Owner of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable)) at ((Load (Key location1) of (Key caster) in BlazingFiend01_HashTable) offset by 75.00 towards (Angle from (Position of (Load (Key caster) of (Key fireball) in BlazingFiend01_HashTable)) to (Load (Key location2) of (Key target) in BlazingFiend01_HashTable)) degr facing (Angle from (Load (Key location1) of (Key caster) in BlazingFiend01_HashTable) to (Load (Key location2) of (Key target) in BlazingFiend01_HashTable)) degrees
              • Hashtable - Save Handle Of(Last created unit) as (Key unit) of (Key fireball) in BlazingFiend01_HashTable
              • Unit Group - Add (Last created unit) to Fireballs_UGrp
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Fiery Claws Mover <gen> is on) Equal to False
                • Then - Actions
                  • Trigger - Turn on Fiery Claws Mover <gen>
                • Else - Actions
            • Else - Actions
      • Unit Group - Remove all units from FieryClawsCaster_UGrp
      • Hashtable - Clear all child hashtables of child (Key location1) in BlazingFiend01_HashTable
Then, my mover.

  • Fiery Claws Mover
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Fireballs_UGrp) Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • Hashtable - Save Handle Of(Position of (Load (Key unit) of (Key fireball) in BlazingFiend01_HashTable)) as (Key location3) of (Key fireball) in BlazingFiend01_HashTable
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between (Load (Key location3) of (Key fireball) in BlazingFiend01_HashTable) and (Position of (Load (Key target) of (Key fireball) in BlazingFiend01_HashTable))) Less than 53.00
        • Then - Actions
          • Unit - Cause (Load (Key unit) of (Key fireball) in BlazingFiend01_HashTable) to damage (Load (Key target) of (Key fireball) in BlazingFiend01_HashTable), dealing 50.00 damage of attack type Spells and damage type Normal
          • Unit - Kill (Load (Key unit) of (Key fireball) in BlazingFiend01_HashTable)
        • Else - Actions
          • Unit - Move (Load (Key unit) of (Key fireball) in BlazingFiend01_HashTable) instantly to ((Position of (Load (Key unit) of (Key fireball) in BlazingFiend01_HashTable)) offset by 7.50 towards (Angle from (Position of (Load (Key unit) of (Key fireball) in BlazingFiend01_HashTable)) to (Position of (Load (Key target) of (Key fireball) in BlazingFien, facing (Angle from (Position of (Load (Key unit) of (Key fireball) in BlazingFiend01_HashTable)) to (Position of (Load (Key target) of (Key fireball) in BlazingFiend01_HashTable))) degrees
      • Hashtable - Clear all child hashtables of child (Key location3) in BlazingFiend01_HashTable

My ability isn't currently working but I'm seeing improvements. the damage done is usually more then 50 (bug), the spell doesnt have Multi instanceablity yet for some reason, is this becuase the targets unit group isnt put into a group handle in a hashtable instead of a unit group variable? anyways anything that is pointed out would help me alot.
 
Last edited by a moderator:
Level 17
Joined
Nov 13, 2006
Messages
1,814
Are the index and the unit 2 different variables? or does the unit variable have an index. (Array type)

convert trigger to custom text


UG=unit group variable
Target_Table=hashtable variable

JASS:
    local unit u = GetTriggerUnit()
    local unit pu
    local player p = GetTriggerPlayer()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local integer index = 0
    local integer cv = GetUnitUserData(u)
    call GroupEnumUnitsInRange(udg_UG, x, y, 600.00, null)
    loop
        set pu = FirstOfGroup(udg_UG)
        exitwhen (pu==null)
// if dont need if u dont want filter the unit
//        if IsUnitAlly(pu, p)  then 
                
             call SaveUnitHandle(udg_Target_Table, cv, index, pu)
             set index = index + 1
//        endif
        call GroupRemoveUnit(udg_UG, pu)
    endloop

    set u = null
    set p = null
    set pu = null

i have no ideea why u need hashtable when u can use unit variable

JASS:
    local unit u = GetTriggerUnit()
    local unit pu
    local player p = GetTriggerPlayer()
    local integer cv = GetUnitUserData(u)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    set udg_index = 0
  
    call GroupEnumUnitsInRange(udg_UG, x, y, 600.00, null)
    loop
        set pu = FirstOfGroup(udg_UG)
        exitwhen (pu==null)
                
//i removed the if but u can put back if u want

             set udg_Target[cv] = pu
             set udg_index[cv] = udg_index[cv] + 1

        call GroupRemoveUnit(udg_UG, pu)
    endloop

    set u = null
    set p = null
    set pu = null

index is integer variable array
Target is unit variable array
so then u can loop from 0 till index for get every target :p
 
Status
Not open for further replies.
Top