• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

RegisterPlayerUnitEvent problems.

Status
Not open for further replies.
Level 20
Joined
May 16, 2012
Messages
635
Hello Hivers,

Recently i've found out about a snippet system called RegisterPlayerUnitEvent created by Magtheridon96 and i'm converting a few of my triggers to use it, but i'm having a problem in triggres that have calls of the CreateUnit native function. I added i few debug messeges int he code to figure out what was the problem but nothing is really worng it seems, the messeges go out when they are supposed to do but still the units that should be created, are not. any ideas on why?

JASS:
scope BlackArrow initializer Init

private function OnDeath_Conditions takes nothing returns boolean
    local unit u
    local unit target = GetTriggerUnit()

    call DisplayTextToPlayer(Player(0), 0, 0, "BlackArrowDeath")

    if GetUnitAbilityLevel(target, 'A00O') == 1 then
        if IsUnitType(target, UNIT_TYPE_MELEE_ATTACKER) then
            set u = CreateUnit(GetOwningPlayer(udg_Sylvanas), 'u008', GetUnitX(target), GetUnitY(target), 0)
            call UnitApplyTimedLife(u, 'BTLF', 20)
            call DisplayTextToPlayer(Player(0), 0, 0, "CreateUnit")
        else
            set u = CreateUnit(GetOwningPlayer(udg_Sylvanas), 'n00P', GetUnitX(target), GetUnitY(target), 0)
            call UnitApplyTimedLife(u, 'BTLF', 20)
            call DisplayTextToPlayer(Player(0), 0, 0, "CreateUnit")
        endif
    elseif GetUnitAbilityLevel(target, 'A00O') == 2 then
        if IsUnitType(target, UNIT_TYPE_MELEE_ATTACKER) then
            set u = CreateUnit(GetOwningPlayer(udg_Sylvanas), 'u00A', GetUnitX(target), GetUnitY(target), 0)
            call UnitApplyTimedLife(u, 'BTLF', 20)
            call DisplayTextToPlayer(Player(0), 0, 0, "CreateUnit")
        else
            set u = CreateUnit(GetOwningPlayer(udg_Sylvanas), 'n00Q', GetUnitX(target), GetUnitY(target), 0)
            call UnitApplyTimedLife(u, 'BTLF', 20)
            call DisplayTextToPlayer(Player(0), 0, 0, "CreateUnit")
        endif
    elseif GetUnitAbilityLevel(target, 'A00O') == 3 then
        if IsUnitType(target, UNIT_TYPE_MELEE_ATTACKER) then
            set u = CreateUnit(GetOwningPlayer(udg_Sylvanas), 'u00B', GetUnitX(target), GetUnitY(target), 0)
            call UnitApplyTimedLife(u, 'BTLF', 20)
            call DisplayTextToPlayer(Player(0), 0, 0, "CreateUnit")
        else
            set u = CreateUnit(GetOwningPlayer(udg_Sylvanas), 'n00R', GetUnitX(target), GetUnitY(target), 0)
            call UnitApplyTimedLife(u, 'BTLF', 20)
            call DisplayTextToPlayer(Player(0), 0, 0, "CreateUnit")
        endif
    elseif GetUnitAbilityLevel(target, 'A00O') == 4 then
        if IsUnitType(target, UNIT_TYPE_MELEE_ATTACKER) then
            set u = CreateUnit(GetOwningPlayer(udg_Sylvanas), 'u00C', GetUnitX(target), GetUnitY(target), 0)
            call UnitApplyTimedLife(u, 'BTLF', 20)
            call DisplayTextToPlayer(Player(0), 0, 0, "CreateUnit")
        else
            set u = CreateUnit(GetOwningPlayer(udg_Sylvanas), 'n00S', GetUnitX(target), GetUnitY(target), 0)
            call UnitApplyTimedLife(u, 'BTLF', 20)
            call DisplayTextToPlayer(Player(0), 0, 0, "CreateUnit")
        endif
    endif

    set u = null
    set target = null
    return false
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    /*
    local trigger t = CreateTrigger()
    set gg_trg_BlackArrow = CreateTrigger()
    set udg_Sylvanas = gg_unit_Hvwd_0586
    call DisableTrigger(gg_trg_BlackArrow)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddCondition(t, Condition(function OnDeath_Conditions))
    call TriggerRegisterAnyUnitEventBJ(gg_trg_BlackArrow, EVENT_PLAYER_UNIT_DAMAGED)
    call TriggerAddCondition(gg_trg_BlackArrow, Condition(function Conditions))
    */
    call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function OnDeath_Conditions)
endfunction

endscope
 
Level 39
Joined
Feb 27, 2007
Messages
5,011
Don't use that snippet, as per this comment: [Snippet] RegisterPlayerUnitEvent. Use the resource Bo linked to there instead.

Are you certain udg_Sylvanas has been set properly? Do the created units have models that you should see if they were created? Have you printed the XY coordinates of their creation to see where they're being created? Are you certain some other trigger is not immediately removing them? Your code could also be massively simplified:

JASS:
private function OnDeath_Conditions takes nothing returns boolean
    local unit u
    local unit target = GetTriggerUnit()
    local integer ID = 0

    call DisplayTextToPlayer(Player(0), 0, 0, "BlackArrowDeath")

    if GetUnitAbilityLevel(target, 'A00O') == 1 then
        if IsUnitType(target, UNIT_TYPE_MELEE_ATTACKER) then
            set ID = 'u008'
        else
            set ID = 'n00P'
        endif
    elseif GetUnitAbilityLevel(target, 'A00O') == 2 then
        if IsUnitType(target, UNIT_TYPE_MELEE_ATTACKER) then
            set ID = 'u00A'
        else
            set ID = 'n00Q'
        endif
    elseif GetUnitAbilityLevel(target, 'A00O') == 3 then
        if IsUnitType(target, UNIT_TYPE_MELEE_ATTACKER) then
            set ID = 'u00B'
        else
            set ID = 'n00R'
        endif
    elseif GetUnitAbilityLevel(target, 'A00O') == 4 then
        if IsUnitType(target, UNIT_TYPE_MELEE_ATTACKER) then
            set ID = 'u00C'
        else
            set ID = 'n00S'
        endif
    endif

    if ID != 0 then
        set u = CreateUnit(GetOwningPlayer(udg_Sylvanas), ID, GetUnitX(target), GetUnitY(target), 0)
        call UnitApplyTimedLife(u, 'BTLF', 20)
        call DisplayTextToPlayer(Player(0), 0, 0, "CreateUnit")

        set u = null
    endif

    set target = null
    return false
endfunction
 
Status
Not open for further replies.
Top