• 🏆 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!

[Solved] IsUnitType won't recognize hero as a hero?

Status
Not open for further replies.
Level 2
Joined
Jun 18, 2017
Messages
6
Hello, it's me getting stuck again. :/
"Action" won't show up after training a hero, unless i type "not" before the condition, but that just means my heroes aren't seen as heroes for some odd reason. Any ideas why could that be?
JASS:
globals
    integer array heroLevel
endglobals
function Trig_Level_1_Conditions takes nothing returns boolean
    local integer heroIndex =  GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
    call BJDebugMsg("Condition")
    call BJDebugMsg(I2S(heroIndex))
    if IsUnitType(GetTriggerUnit(),UNIT_TYPE_HERO) then
        call BJDebugMsg("Action")
        set heroLevel[heroIndex] = 1
        call MultiboardSetItemValueBJ( GetLastCreatedMultiboard(), 3, ( heroIndex + 4 ), I2S(heroLevel[heroIndex]) )
    endif
    return true
endfunction
//===========================================================================
function InitTrig_Level_1 takes nothing returns nothing
    set gg_trg_Level_1 = CreateTrigger(  ) 
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Level_1, EVENT_PLAYER_UNIT_TRAIN_FINISH)
    call TriggerAddCondition(gg_trg_Level_1, Condition( function Trig_Level_1_Conditions ) )
endfunction
 
Hi, the GetTriggerUnit() in your case refers to the building, and not to the trained unit, because of event fires when a unit finishes training something (events for buildings).
You could refer to one of these instead:
  • constant native GetTrainedUnit takes nothing returns unit
  • constant native GetTrainedUnitType takes nothing returns integer
 
Level 2
Joined
Jun 18, 2017
Messages
6
Oh, I see, it works now. Can I somehow get to know for a future reference which events are fired by which type of unit? I wouldn't even think that a building fires this event.
Thank you again. :D
 
Last edited:
I often looked up how I would have maked it in GUI, to see correct events/responses, but with time it will get easier.

call TriggerRegisterAnyUnitEventBJ(gg_trg_Level_1, EVENT_PLAYER_UNIT_TRAIN_FINISH) is called.
In GUI the event is called "A Unit finishes training a unit". This implies that "TriggeringUnit", which is always the actor who let the trigger run, is not the trained unit, but the building.

There are also TrainStart and TrainCancel events, and there, TriggeringUnit() exists, too, and it's the building. At these events though, "TrainedUnit()" does not exist/not work, because at this point no trained unit object exists yet, that we could reference.

Not sure what helps most, with time you'll for sure get it. In TriggerRegisterAnyUnitEventBJ event it will call internaly the TriggerRegisterPlayerUnitEvent native always, and there we can remember, that we always may use TriggeringPlayer(), and also TrigeringUnit() as valid responses, because it's a PlayerUnitEvent. There are also only UnitEvents, where we then can not call TriggeringPlayer() properly, but have to use OwnerOfUnit(GetTriggerUnit()) instead.
 
Status
Not open for further replies.
Top