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

[JASS] Specific Unit Event variable

Status
Not open for further replies.
Level 10
Joined
Aug 19, 2008
Messages
491
Hey dudes! :grin:
I'm making a spell in vJass (though GUI help is helpfull aswell) and I wanna make a Specific Unit Event, but it can be activated with a variable instead.
As far as I know, only pre-placed units can have this event "attached" to him, but I can be wrong, right?

(as and example I'll display my "problem" in gui form:)
  • TriggerOne
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Epic spell of Awesome Doom
    • Actions
      • Set MyUnit = (Triggering Unit)
  • TriggerTwo
    • Events
      • Unit - MyUnit Dies
    • Conditions
    • Actions
      • -------- some kind of actions --------
I already tried this way (in vJass ofc...) but it didn't activate at all



Solved! ok not really since this isn't help zone... :hohum:
by EpixBelongToMe and Reaper2008

Reapers answer:
Just use:
  • TriggerOne
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Epic spell of Awesome Doom
    • Actions
      • Trigger - Add to TriggerTwo the event ((Casting Unit) Dies)
  • TriggerTwo
    • Events
    • Conditions
    • Actions
      • -------- Your actions --------
 
Last edited:
Level 6
Joined
Aug 19, 2006
Messages
187
here is something from my td map which attaches a trigger to a spawning unit.
its a trigger which makes a unit move after rebirth.

JASS:
scope DFI
    globals
        private trigger array demonfire_array
    endglobals

public function SubCond takes nothing returns boolean
    return GetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE) - GetEventDamage() < 0.405 
endfunction

public function Conditions takes nothing returns boolean
    return GetUnitTypeId(GetEnteringUnit()) == 'n020' and GetOwningPlayer(GetEnteringUnit()) == Player(9)
endfunction

public function SubActions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call DisableTrigger(GetTriggeringTrigger())
    call DestroyTrigger(GetTriggeringTrigger())
    set demonfire_array[GetUnitIndex(u)] = null
    call PolledWait2(5.05)
    call SetUnitPathing(u, false)
    call UnitFollowNode(u, unitnextnode[GetUnitIndex(u)])
    set u = null
endfunction

public function Actions takes nothing returns nothing
        local unit u = GetEnteringUnit()
        local integer index = GetUnitIndex(u)
        set demonfire_array[index]  = CreateTrigger()
        call TriggerRegisterUnitEvent(demonfire_array[index], u, EVENT_UNIT_DAMAGED)
        call TriggerAddCondition(demonfire_array[index], Condition(function DFI_SubCond))
        call TriggerAddAction(demonfire_array[index], function DFI_SubActions)
endfunction

endscope

//===========================================================================
function InitTrig_Demon_Fire_Init takes nothing returns nothing
    local region map = CreateRegion()
    call RegionAddRect(map,GetWorldBounds())
    set gg_trg_Demon_Fire_Init = CreateTrigger(  )
    call TriggerRegisterEnterRegion( gg_trg_Demon_Fire_Init, map,null )
    call TriggerAddCondition( gg_trg_Demon_Fire_Init, Condition( function DFI_Conditions ) )
    call TriggerAddAction( gg_trg_Demon_Fire_Init, function DFI_Actions )
    set map = null
endfunction
 
Level 11
Joined
Feb 22, 2006
Messages
752
If you're going to use vJASS, it's simpler to make one trigger for all events instead of creating a new one for every unit, since lots of triggers = lag.

You just need an indexing system (Table is good enough...uses gamecache but since we're only doing one lookup every time the trigger fires it doesn't matter that gamecache is a little slow).

JASS:
library Trigger initializer init requres Table
interface Triggerable
    method conditions takes nothing returns boolean
    method actions takes nothing returns nothing
endinterface

struct UnitDeathTrigger extends Triggerable
    private static HandleTable table

    private unit triggerUnit

    static method create takes unit u returns UnitDeathTrigger
        local UnitDeathTrigger this = UnitDeathTrigger.allocate()
        set this.triggerUnit = u
        if (UnitDeathTrigger.table.exists(u)) then
            call UnitDeathTrigger(UnitDeathTrigger.table[u]).destroy()
        endif
        set UnitDeathTrigger.table[u] = this
        return this
    endmethod

    method operator .u takes nothing returns unit
        return .triggerUnit
    endmethod

    method conditions takes nothing returns boolean
        return false
    endmethod

    method actions takes nothing returns nothing
    endmethod

    static method onDeath takes nothing returns nothing
        local UnitDeathTrigger this = UnitDeathTrigger.table[GetTriggerUnit()]
        if (this != 0) then
            if (this.conditions()) then
                call this.actions()
            endif
        endif
    endmethod
    
    static method initialize takes nothing returns nothing
         local trigger t = CreateTrigger()
         set UnitDeathTrigger.table = HandleTable.create()
         call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
         call TriggerAddAction(t, UnitDeathTrigger.onDeath)
    endmethod
endstruct

private function init takes nothing returns nothing
    call UnitDeathTrigger.initialize()
endfunction

endlibrary

Just extend UnitDeathTrigger with another struct and override conditions() and actions() with the appropriate code. Then whenever you need to create a new trigger, just call .create() on the struct and pass it the appropriate unit argument. You can also do this with function interfaces if you don't care that you won't be able to use GetTriggeringTrigger().
 
Level 10
Joined
Aug 19, 2008
Messages
491
EpixBelongToMe
Firstly I'd like to ask why every function is public? (Ok you state in your name that you're GUI user so I won't go any further in the code)
Secondly, I think the idea of it could work, though I have to modify it alot.
If it helps I'm gonna give you +rep (hope I remember it though :xxd: )

aznricepuff
Actually I havn't got that far i vJass :sad: I barley just started with TimerUtils, and I still don't understand what structs are and their purpose.
Thanks for the epic trigger, but it's of no use to me (since I refuse to add something I don't understand)
 
Level 12
Joined
Jul 27, 2008
Messages
1,181
Just use:
  • TriggerOne
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Epic spell of Awesome Doom
  • Actions
    • Trigger - Add to TriggerTwo the event ((Casting Unit) Dies)
  • TriggerTwo
  • Events
  • Conditions
  • Actions
    • ...actions...
 
Level 9
Joined
Apr 25, 2009
Messages
468
Do as reaper said, or you simple Set the unit in a Variable, Event: Unit - A Unit Dies
If - Then - Else Actions
If (Dyring Unit) Equal to (Your Unit) do actions:
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Can you stop posting that lame-bugged solution?

What didn't you get when I posted on the other thread "when a unit gets attacked he is registered again and thus the actions run multiple times".

Add all the units on the map to that trigger. Even better if there are units that don't need to get added.
Whenever a unit enters the map - add it to the trigger as well.
 
Level 10
Joined
Aug 19, 2008
Messages
491
Can you stop posting that lame-bugged solution?

What didn't you get when I posted on the other thread "when a unit gets attacked he is registered again and thus the actions run multiple times".

Add all the units on the map to that trigger. Even better if there are units that don't need to get added.
Whenever a unit enters the map - add it to the trigger as well.

Epic rant... :xxd:
Was that directed to me or?
 
Status
Not open for further replies.
Top