Detecting unit comes in range

skyblader

You're living only because it's illegal killing.
Reaction score
159
For example, I use another trigger to add the event "Unit comes in range of" into this trigger.

So the event when added would be A comes in range of B. Triggering unit would be A, but is there a way to detect which unit is B? (Some way to use unit B, conditions or something.)
 

DioD

New Member
Reaction score
57
bound unit B to trigger Z with hashtables, this will force you to use trigger per unit.

OR detect possible units and sort for max range, unit with max range will likely to host event.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Could you explain slightly more detailed? I kinda lost you.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
The event is a periodic timer, which is added in from somewhere else.
Trigger:
  • Creating Fire
    • Events
    • Conditions
    • Actions
      • Unit Group - Pick every unit in SpitfireGroupSF and do (Actions)
        • Loop - Actions
          • Set AbilityLengthRemainingSF = (Load 0 of (Key (Picked unit)) from SpitfireHash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AbilityLengthRemainingSF Less than or equal to 0.00
            • Then - Actions
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in SpitfireHash
              • Unit Group - Remove (Picked unit) from SpitfireGroupSF
              • Unit - Set (Picked unit) movement speed to (Default movement speed of (Picked unit))
            • Else - Actions
              • Set FacingAngleOfFireSF = (Facing of (Picked unit))
              • Set DistanceOfFireSF = 800.00
              • Set SpeedOfFireSF = 24.00
              • Set TimeRequiredSF = (DistanceOfFireSF / SpeedOfFireSF)
              • Set TempPoint2 = (Position of (Picked unit))
              • Set TempPoint = (TempPoint2 offset by 30.00 towards FacingAngleOfFireSF degrees)
              • Unit - Create 1 Fire for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Hashtable - Save FacingAngleOfFireSF as 0 of (Key (Last created unit)) in FireHash
              • Hashtable - Save TimeRequiredSF as 1 of (Key (Last created unit)) in FireHash
              • Hashtable - Save SpeedOfFireSF as 2 of (Key (Last created unit)) in FireHash
              • Unit Group - Add (Last created unit) to FireGroupSF
              • Custom script: call RemoveLocation(udg_TempPoint)
              • Custom script: call RemoveLocation(udg_TempPoint2)
              • Hashtable - Save (AbilityLengthRemainingSF - IntervalSF) as 0 of (Key (Picked unit)) in SpitfireHash
              • Trigger - Add to In range of fire <gen> the event (Unit - A unit comes within RangeOfFire of (Last created unit))
              • Animation - Play (Picked unit)'s attack animation


Trigger:
  • In range of fire
    • Events
    • Conditions
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Special Effect - Create a special effect at TempPoint using Abilities\Spells\Other\Doom\DoomDeath.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: call RemoveLocation(udg_TempPoint)
 

luorax

Invasion in Duskwood
Reaction score
67
When the trigger fires, pick each unit in range, and if the distance betweeen the two units == the trigger distance, then the trigger unit is that unit. That's how I've done this event in my quest system, and it works.
 

Romek

Super Moderator
Reaction score
963
Moved to the WEHZ, from JASS Help.
 

DioD

New Member
Reaction score
57
Code:
CreateTrigger() > LCT()
TriggerAddAction(LCT(),function ABC)
TriggerRegisterUnitEvent(LCT(),EVENT_UNIT_IN_RANGE,400,_UNIT_A)
SaveUnitHandle(HASH,43534,GetHandleId(LCT()),_UNIT_A)

function ABC
_UNIT_A > LoadUnitHandle(HASH,43534,GetHandleId(GetTriggeringTrigger()))

Not possible from GUI, since there is no way to create triggers in runtime.

Its not possible to detect source unit if there is multiple units registered to same trigger.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Exactly why I posted in JASS section :p Actually I was aware you could just run a periodic timer to check if any unit is in range, but that'll be a hassle, just thought if there was a way to detect it in JASS, it'll be much better.

@DioD Won't that create many triggers? Is there a way to remove the triggers after the unit is removed?
 

DioD

New Member
Reaction score
57
Is there a way to remove the triggers after the unit is removed?
DestroyTrigger(_Trigger)

Won't that create many triggers?
one trigger per every unit with range detection

you dont care about event cleanup, soo dont ask about cleaning triggers, try to do it self first.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Okay how do I do it in JASS.. Now I'm able to get the unit, but how to do my next actions o.o

What I wanna do is clear up child hash of the detected unit, remove that unit, remove that unit from a unit group, create special effect and destroy it, and damage the unit in range.
 

Romek

Super Moderator
Reaction score
963
Moved back to JASS Help. :p
 

Ayanami

칼리
Reaction score
288
Okay how do I do it in JASS.. Now I'm able to get the unit, but how to do my next actions o.o

Possibly, something like this? I basically re-wrote your above triggers in vJASS.

JASS:
library Fire

globals
    private constant integer FIRE = 'h000'
    
    private hashtable Hash = InitHashtable()
    private trigger array Trig
    private integer TrigCount = -1
endglobals

private function InRangeOfFire takes nothing returns nothing
    local unit u = LoadUnitHandle(Hash, GetHandleId(GetTriggeringTrigger()), 0)
    local integer i = GetUnitUserData(u)
    local integer loopindex = i
    //Actions Here
    call FlsuhChildHashtable(Hash, GetHandleId(GetTriggeringTrigger()))
    set Trig<i> = null
    if i &lt; TrigCount then
        loop
            exitwhen loopindex &gt; TrigCount
            set Trig[loopindex] = Trig[loopindex + 1]
            set loopindex = loopindex + 1
        endloop
        set Trig[TrigCount] = null
    endif
    set TrigCount = TrigCount - 1
    set u = null
endfunction

private function GroupFunc takes nothing returns nothing
    local unit u = GetEnumUnit()
    local unit cre
    local integer id
    local real dur = LoadReal(udg_SpitfireHash, GetHandleId(u), 0)
    if dur &lt;= 0 then
        call FlushChildHashtable(udg_SpitfireHash, GetHandleId(u))
        call GroupRemoveUnit(udg_SpitfireGroupSF, u)
        call SetUnitMoveSpeed(u, GetUnitDefaultMoveSpeed(u))
    else
        set cre = CreateUnit(GetOwningPlayer(u), FIRE, GetUnitX(u), GetUnitY(u), 0)
        set id = GetHandleId(cre)
        call SaveReal(udg_FireHash, id, 0, GetUnitFacing(u))
        call SaveReal(udg_FireHash, id, 1, 800.0 / 24.0)
        call SaveReal(udg_FireHash, id, 2, 24.0)
        call GroupAddUnit(udg_FireGroupSF, cre)
        call SaveReal(udg_SpitfireHash, GetHandleId(u), 0, dur - udg_IntervalSF)
        call SetUnitAnimation(u, &quot;attack&quot;)
        set TrigCount = TrigCount + 1
        set Trig[TrigCount] = CreateTrigger()
        call TriggerRegisterUnitInRange(Trig[TrigCount], cre, udg_RangeOfFire, null)
        call TriggerAddAction(Trig[TrigCount], function InRangeOfFire)
        call SetUnitUserData(u, TrigCount)
        call SaveUnitHandle(Hash, GetHandleId(Trig[TrigCount]), 0, u)
    endif
    set u = null
    set cre = null
endfunction

public function CreatingFire takes nothing returns nothing
    call ForGroup(udg_SpitfireGroupSF, function GroupFunc)
endfunction

endlibrary
</i>


Not sure if that compiles, did not test. Simply, insert your desired actions in the comment "Action Here". Do note that the variable "FIRE" at the top of the code is the raw code of the created unit. Change it to your dummy. If you don't know how to include the actions, mind telling me what exactly you plan to do with what unit?

And since I changed the code from GUI to vJASS, you won't be able to add the periodic event to "Creating Fire" trigger. Create a new trigger named anything. Then instead of giving the periodic event to the "Creating Fire" trigger, give it to your newly created trigger. Your newly created trigger should simply be this:

Trigger:
  • NewTrigger
    • Events
    • Conditions
    • Actions
      • Custom script: call Fire_CreatingFire()


As for the "Trig" and "TrigCount" stuffs in the code, can someone clarify if nulling that is necessary? Not really 100% sure.

EDIT
Changed few stuffs in code.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Thanks for taking the time to do this... But is there a way to do it in JASS instead of vJASS? I can't use vJASS.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
My version of warcraft is pirated, can't get a legal one.

Edit: Okay, I'm somehow able to use it anyway... I changed the "flsuh" to "flush" I'm guessing it's a typo? And also replaced the rawcode for the unit.

But I have no idea to make use of the unit saved to the handle, could you do it for me and then I'll learn it from your codes? :)

Trigger:
  • In range of fire
    • Events
    • Conditions
    • Actions
      • Custom script: call Fire_CreatingFire( )
      • Set TempPoint = (Position of (Triggering unit))
      • Special Effect - Create a special effect at TempPoint using Abilities\Spells\Other\Doom\DoomDeath.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Unit - Cause (Picked unit) to damage (Triggering unit), dealing ((Real((Custom value of (Picked unit)))) x 50.00) damage of attack type Spells and damage type Normal
      • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in SpitfireHash
      • Unit Group - Remove (Picked unit) from SpitfireGroupSF
      • Unit - Remove (Picked unit) from the game


I need to replace all the picked units with the fire.

Also, in the creating fire trigger, where do I add the function to set custom value of fire to level of ability?
 

Ayanami

칼리
Reaction score
288
Edit: Okay, I'm somehow able to use it anyway... I changed the "flsuh" to "flush" I'm guessing it's a typo? And also replaced the rawcode for the unit.

Yep, was a typo.

Also, in the creating fire trigger, where do I add the function to set custom value of fire to level of ability?

Custom value of which unit? What do you need the Custom Value for? o.o
Just saw the damage part. Actually, couldn't you just load the level of ability in the damaging part, directly?

EDIT
In the above trigger, you're saying (Picked unit) is the Fire that's created in the Creating Fire trigger? But when you add the event "A unit comes within x range of ThisUnit", isn't the "Triggering unit" referred as the unit that's coming within range? So actually, "triggering unit" would be the created Fire.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top