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
964
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
964
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top