1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

RegisterPlayerUnitEvent problems.

Discussion in 'Triggers & Scripts' started by chopinski, Sep 8, 2019.

  1. chopinski

    chopinski

    Joined:
    May 16, 2012
    Messages:
    148
    Resources:
    0
    Resources:
    0
    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?

    Code (vJASS):
    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
     
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,905
    Resources:
    1
    Spells:
    1
    Resources:
    1
    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:

    Code (vJASS):
    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
     
  3. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,179
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    As the function runs, it probably means that it isn't a
    RegisterPlayerUnitEvent
    problem.
     
  4. chopinski

    chopinski

    Joined:
    May 16, 2012
    Messages:
    148
    Resources:
    0
    Resources:
    0
    Ofc, the udg_Sylvanas was not set properly ahhaha, thx guys.