Detecting unit comes in range

Ayanami

칼리
Reaction score
288
Done. Not sure if this is what you want.

JASS:

library Fire

globals
    private constant integer FIRE = 'h000' // raw code of unit "Fire"
    private constant integer ABILID = 'A000' // raw code of ability
    
    private hashtable Hash = InitHashtable()
    private trigger array Trig
    private integer TrigCount = -1
endglobals

private function InRangeOfFire takes nothing returns nothing
    local unit cre = LoadUnitHandle(Hash, GetHandleId(GetTriggeringTrigger()), 0)// load the value of cre
    local unit u = LoadUnitHandle(Hash, GetHandleId(GetTriggeringTrigger()), 1) // load the value of u
    local unit trigu = GetTriggerUnit() // setting the entering unit as trigu
    local effect e = AddSpecialEffect("Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl", GetUnitX(trigu), GetUnitY(trigu)) // creating effect of position of trigu
    local integer i = GetUnitUserData(u) // loading triggering trigger array value from cre's custom value
    local integer loopindex = i
    call UnitDamageTarget(u, trigu, GetUnitAbilityLevel(u, ABILID) * 50.0, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS) // dealing damage equal to level of ABILID * 50.0
    call GroupRemoveUnit(udg_FireGroupSF, cre) // removing cre from FireGroupSF
    call RemoveUnit(cre) // removing cre from game
    call FlushChildHashtable(Hash, GetHandleId(GetTriggeringTrigger())) // flush Hash with parent handle id of triggering trigger
    call DestroyEffect(e) // destroying created effect
    set Trig<i> = null // nulling the current trigger
    if i &lt; TrigCount then // checking if the current trigger is less than the highest array value
        loop // if it is, set all higher array values to one lower
            exitwhen loopindex &gt; TrigCount
            set Trig[loopindex] = Trig[loopindex + 1]
            set loopindex = loopindex + 1
        endloop
        set Trig[TrigCount] = null
    endif
    set TrigCount = TrigCount - 1 // decreasing the array value count
    set u = null     // nulling
    set cre = null   // local
    set trigu = null // vars
    set e = null     //
    call DestroyTrigger(GetTriggeringTrigger()) // destroying the current trigger
endfunction

private function GroupFunc takes nothing returns nothing
    local unit u = GetEnumUnit() // setting the picked unit to &quot;u&quot;
    local unit cre
    local integer id
    local real dur = LoadReal(udg_SpitfireHash, GetHandleId(u), 0)
    if dur &lt;= 0 then // checking if dur is less than or equal to 0
        call FlushChildHashtable(udg_SpitfireHash, GetHandleId(u)) // flush SpitfireHash with parent handle id of u
        call GroupRemoveUnit(udg_SpitfireGroupSF, u) // removing u from SpitfireGroupSF
        call SetUnitMoveSpeed(u, GetUnitDefaultMoveSpeed(u)) // setting movement speed of u to default movespeed
    else
        set cre = CreateUnit(GetOwningPlayer(u), FIRE, GetUnitX(u), GetUnitY(u), 0) // creating the unit &quot;Fire&quot; and setting it to &quot;cre&quot;
        set id = GetHandleId(cre) // saving the handle id of cre to &quot;id&quot;
        call SaveReal(udg_FireHash, id, 0, GetUnitFacing(u)) // saving facing of cre as 0 of id in FireHash
        call SaveReal(udg_FireHash, id, 1, 800.0 / 24.0) // saving value 800.0 / 24.0 as 1 of id in FireHash
        call SaveReal(udg_FireHash, id, 2, 24.0) // saving value 24.0 as 2 of id in FireHash
        call GroupAddUnit(udg_FireGroupSF, cre) // adding cre to FireGroupSF
        call SaveReal(udg_SpitfireHash, GetHandleId(u), 0, dur - udg_IntervalSF) // updating dur and saving it in SpitfireHash
        call SetUnitAnimation(u, &quot;attack&quot;) // playing u&#039;s attack animation
        set TrigCount = TrigCount + 1 // increasing the array value of Trig
        set Trig[TrigCount] = CreateTrigger() // creating a new trigger
        call TriggerRegisterUnitInRange(Trig[TrigCount], cre, udg_RangeOfFire, null) // adding the event &quot;A unit comes within RangeOfFire of cre&quot; to the created trigger
        call TriggerAddAction(Trig[TrigCount], function InRangeOfFire) // adding the action to created trigger, which is the function &quot;InRangeOfFire&quot; (above function)
        call SetUnitUserData(cre, TrigCount) // saving created trigger array value as cre&#039;s custom value
        call SaveUnitHandle(Hash, GetHandleId(Trig[TrigCount]), 0, cre) // saving cre as 0 of handle id of the triggering trigger in Hash
        call SaveUnitHandle(Hash, GetHandleId(Trig[TrigCount]), 1, u) // saving u as 1 of handle id of the triggering trigger in Hash
    endif
    set u = null  // nulling 
    set cre = null// local vars
endfunction

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

endlibrary
</i>
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Hmm.... Thanks for taking the time to write all the comments down :thup: But if I insert that, what would it do? Like what the codes actually do in simple terms. E.g. Destroys fire upon contact and deal damage.
 

Ayanami

칼리
Reaction score
288
Hmm.... Thanks for taking the time to write all the comments down :thup: But if I insert that, what would it do? Like what the codes actually do in simple terms. E.g. Destroys fire upon contact and deal damage.

If you insert the comments, it won't mess with the codes. It's just comment for the code, does not affect triggers.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Nono I meant insert your codes into my map, what does it do?
 

Ayanami

칼리
Reaction score
288
Nono I meant insert your codes into my map, what does it do?

Oh! Okay, well you'd probably have something like this.

Trigger:
  • Casts Ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to MyAbility
    • Actions
      • &lt;Actions&gt;
      • Trigger - Add to Periodic Trig &lt;gen&gt; the event (Time - Every x seconds of game time)


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


Basically, the one line of custom script replaces your previous unit group actions where you loaded the duration, create the fire, etc. Then, for every fire created, a new trigger is created which adds the event "A unit comes within RangeOfFire of Fire". Then, if a unit comes near the fire, the fire dies, dealing damage to the entering unit. Then, the special effect is created on the position of the fire. Basically, that's it.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Okay, it should be working now... Only problem is, how do I insert a condition for the unit that comes in range of the fire? I believe the fire is coming in range of the caster and being destroyed upon creation constantly... So I need to insert a condition checking whether the unit is an enemy of player 1.
 

Ayanami

칼리
Reaction score
288
Okay, it should be working now... Only problem is, how do I insert a condition for the unit that comes in range of the fire? I believe the fire is coming in range of the caster and being destroyed upon creation constantly... So I need to insert a condition checking whether the unit is an enemy of player 1.

Ah, yes. Just change your "InRangeOfFire" function to this:

JASS:

private function InRangeOfFire takes nothing returns nothing
    local unit cre = LoadUnitHandle(Hash, GetHandleId(GetTriggeringTrigger()), 0)// load the value of cre
    local unit u = LoadUnitHandle(Hash, GetHandleId(GetTriggeringTrigger()), 1) // load the value of u
    local unit trigu = GetTriggerUnit() // setting the entering unit as trigu
    local effect
    local integer i = GetUnitUserData(u) // loading triggering trigger array value from cre&#039;s custom value
    local integer loopindex = i
    if IsUnitEnemy(trigu, GetOwningPlayer(u)) then
        set e = AddSpecialEffect(&quot;Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl&quot;, GetUnitX(trigu), GetUnitY(trigu)) // creating effect of position of trigu
        call UnitDamageTarget(u, trigu, GetUnitAbilityLevel(u, ABILID) * 50.0, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS) // dealing damage equal to level of ABILID * 50.0
        call GroupRemoveUnit(udg_FireGroupSF, cre) // removing cre from FireGroupSF
        call RemoveUnit(cre) // removing cre from game
        call FlushChildHashtable(Hash, GetHandleId(GetTriggeringTrigger())) // flush Hash with parent handle id of triggering trigger
        call DestroyEffect(e) // destroying created effect
        set Trig<i> = null // nulling the current trigger
        if i &lt; TrigCount then // checking if the current trigger is less than the highest array value
            loop // if it is, set all higher array values to one lower
                exitwhen loopindex &gt; TrigCount
                set Trig[loopindex] = Trig[loopindex + 1]
                set loopindex = loopindex + 1
            endloop
            set Trig[TrigCount] = null
        endif
        set TrigCount = TrigCount - 1 // decreasing the array value count
        call DestroyTrigger(GetTriggeringTrigger()) // destroying the current trigger
    endif
    set u = null     // nulling
    set cre = null   // local
    set trigu = null // vars
    set e = null     //
endfunction
</i>


This basically makes it so that the fire only hits enemy units.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
It's not working... Hmm, now all that happens is, the unit is being stopped the effects come out but I don't see any fireballs.

Trigger:
  • Setup Spitfire
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set SpitfireHash = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set FireHash = (Last created hashtable)
      • Set AbilityLengthSF = 20.00
      • Set RangeOfFire = 30.00
      • Set IntervalSF = 0.40
      • Trigger - Add to Creating fire jass &lt;gen&gt; the event (Time - Every IntervalSF seconds of game time)


Trigger:
  • Casted
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Spitfire
    • Actions
      • Unit - Set (Triggering unit) movement speed to 0.00
      • Unit Group - Add (Triggering unit) to SpitfireGroupSF
      • Hashtable - Save AbilityLengthSF as 0 of (Key (Triggering unit)) in SpitfireHash
      • Set TempPoint = (Position of (Triggering unit))
      • Special Effect - Create a special effect at TempPoint using Abilities\Spells\Human\MarkOfChaos\MarkOfChaosTarget.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: call RemoveLocation(udg_TempPoint)


Trigger:
  • Move fire
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in FireGroupSF and do (Actions)
        • Loop - Actions
          • Set FacingAngleOfFireSF = (Load 0 of (Key (Picked unit)) from FireHash)
          • Set TimeRequiredSF = (Load 1 of (Key (Picked unit)) from FireHash)
          • Set SpeedOfFireSF = (Load 2 of (Key (Picked unit)) from FireHash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TimeRequiredSF 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 FireGroupSF
              • Unit - Remove (Picked unit) from the game
            • Else - Actions
              • Set TempPoint = (Position of (Picked unit))
              • Set TempPoint2 = (TempPoint offset by SpeedOfFireSF towards FacingAngleOfFireSF degrees)
              • Unit - Move (Picked unit) instantly to TempPoint2
              • Custom script: call RemoveLocation(udg_TempPoint)
              • Custom script: call RemoveLocation(udg_TempPoint2)
              • Hashtable - Save (TimeRequiredSF - 1.00) as 1 of (Key (Picked unit)) in FireHash


JASS:
library Fire

globals
    private constant integer FIRE = &#039;h003&#039; // raw code of unit &quot;Fire&quot;
    private constant integer ABILID = &#039;A001&#039; // raw code of ability
    
    private hashtable Hash = InitHashtable()
    private trigger array Trig
    private integer TrigCount = -1
endglobals

private function InRangeOfFire takes nothing returns nothing
    local unit cre = LoadUnitHandle(Hash, GetHandleId(GetTriggeringTrigger()), 0)// load the value of cre
    local unit u = LoadUnitHandle(Hash, GetHandleId(GetTriggeringTrigger()), 1) // load the value of u
    local unit trigu = GetTriggerUnit() // setting the entering unit as trigu
    local effect e = AddSpecialEffect(&quot;Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl&quot;, GetUnitX(trigu), GetUnitY(trigu)) // creating effect of position of trigu
    local integer i = GetUnitUserData(u) // loading triggering trigger array value from cre&#039;s custom value
    local integer loopindex = i
    if IsUnitEnemy(trigu, GetOwningPlayer(u)) then
        set e = AddSpecialEffect(&quot;Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl&quot;, GetUnitX(trigu), GetUnitY(trigu)) // creating effect of position of trigu
        call UnitDamageTarget(u, trigu, GetUnitAbilityLevel(u, ABILID) * 50.0, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS) // dealing damage equal to level of ABILID * 50.0
        call GroupRemoveUnit(udg_FireGroupSF, cre) // removing cre from FireGroupSF
        call RemoveUnit(cre) // removing cre from game
        call FlushChildHashtable(Hash, GetHandleId(GetTriggeringTrigger())) // flush Hash with parent handle id of triggering trigger
        call DestroyEffect(e) // destroying created effect
        set Trig<i> = null // nulling the current trigger
        if i &lt; TrigCount then // checking if the current trigger is less than the highest array value
            loop // if it is, set all higher array values to one lower
                exitwhen loopindex &gt; TrigCount
                set Trig[loopindex] = Trig[loopindex + 1]
                set loopindex = loopindex + 1
            endloop
            set Trig[TrigCount] = null
        endif
        set TrigCount = TrigCount - 1 // decreasing the array value count
        call DestroyTrigger(GetTriggeringTrigger()) // destroying the current trigger
    endif
    set u = null     // nulling
    set cre = null   // local
    set trigu = null // vars
    set e = null     //
endfunction

private function GroupFunc takes nothing returns nothing
    local unit u = GetEnumUnit() // setting the picked unit to &quot;u&quot;
    local unit cre
    local integer id
    local real dur = LoadReal(udg_SpitfireHash, GetHandleId(u), 0)
    if dur &lt;= 0 then // checking if dur is less than or equal to 0
        call FlushChildHashtable(udg_SpitfireHash, GetHandleId(u)) // flush SpitfireHash with parent handle id of u
        call GroupRemoveUnit(udg_SpitfireGroupSF, u) // removing u from SpitfireGroupSF
        call SetUnitMoveSpeed(u, GetUnitDefaultMoveSpeed(u)) // setting movement speed of u to default movespeed
    else
        set cre = CreateUnit(GetOwningPlayer(u), FIRE, GetUnitX(u), GetUnitY(u), 0) // creating the unit &quot;Fire&quot; and setting it to &quot;cre&quot;
        set id = GetHandleId(cre) // saving the handle id of cre to &quot;id&quot;
        call SaveReal(udg_FireHash, id, 0, GetUnitFacing(u)) // saving facing of cre as 0 of id in FireHash
        call SaveReal(udg_FireHash, id, 1, 800.0 / 24.0) // saving value 800.0 / 24.0 as 1 of id in FireHash
        call SaveReal(udg_FireHash, id, 2, 24.0) // saving value 24.0 as 2 of id in FireHash
        call GroupAddUnit(udg_FireGroupSF, cre) // adding cre to FireGroupSF
        call SaveReal(udg_SpitfireHash, GetHandleId(u), 0, dur - udg_IntervalSF) // updating dur and saving it in SpitfireHash
        call SetUnitAnimation(u, &quot;attack&quot;) // playing u&#039;s attack animation
        set TrigCount = TrigCount + 1 // increasing the array value of Trig
        set Trig[TrigCount] = CreateTrigger() // creating a new trigger
        call TriggerRegisterUnitInRange(Trig[TrigCount], cre, udg_RangeOfFire, null) // adding the event &quot;A unit comes within RangeOfFire of cre&quot; to the created trigger
        call TriggerAddAction(Trig[TrigCount], function InRangeOfFire) // adding the action to created trigger, which is the function &quot;InRangeOfFire&quot; (above function)
        call SetUnitUserData(cre, TrigCount) // saving created trigger array value as cre&#039;s custom value
        call SaveUnitHandle(Hash, GetHandleId(Trig[TrigCount]), 0, cre) // saving cre as 0 of handle id of the triggering trigger in Hash
        call SaveUnitHandle(Hash, GetHandleId(Trig[TrigCount]), 1, u) // saving u as 1 of handle id of the triggering trigger in Hash
    endif
    set u = null  // nulling 
    set cre = null// local vars
endfunction

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

endlibrary</i>


I''ve posted all my codes :p
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
True. Do tell me what changes you have made :p The triggers are in the category "Spitfire" and 1 more trigger "Setup Spitfire" in the "Setup" category.
 

Attachments

  • Mass Spells Map.w3x
    68.7 KB · Views: 215

Ayanami

칼리
Reaction score
288
Works. Just that you didn't do the triggers correctly :p

What you need to do is to make a new trigger, in the map, it's called "Untitled Trigger 001".

The trigger should consist of:

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


Then, at your "Setup Spitfire" Add the event to "Untitled Trigger 001", not "Creating fire jass".
 

Attachments

  • Mass Spells Map.w3x
    68.8 KB · Views: 244

skyblader

You're living only because it's illegal killing.
Reaction score
159
Nevermind the error. Tested it now, but it still doesn't work. o.o
 
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