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

[JASS] UnitAddAbility in Jass

Status
Not open for further replies.
Level 4
Joined
Aug 18, 2013
Messages
71
I've had this problem before, UnitAddAbility doesn't work. I don't know why but it doesn't work.

The unit never gets the ability, the IDs are always correct. I have no clue why it doesn't work. Can heroes/units not be given abilities after they are created? Is there a special step I always miss? Anyone know?

Here's my code
JASS:
//function Trig_GameDrawCardRed_OrCondition takes nothing returns boolean
//    if((GetTriggerUnit() == gg_unit_n00C_0053)or(GetTriggerUnit() == gg_unit_n00C_0020)) then
//        return true 
//    //else
//    //   if(GetTriggerUnit() == gg_unit_n00C_0020) then
//    //        return true
//    //   endif
//    else
//        return false
//    endif
//endfunction

function Trig_GameDrawCardRed_Conditions2 takes nothing returns boolean
    //return( ((GetTriggerUnit() == gg_unit_n00C_0053)or(GetTriggerUnit() == gg_unit_n00C_0020)) and ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 ))
  local unit a = GetTriggerUnit()
  if (((GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0) and ((GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_FOOD_USED) < GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_FOOD_CAP)))) and ((a == gg_unit_n00V_0069)or(a == gg_unit_n00V_0066))) then 
      set a = null
      //call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"true")
      return true
  else
      set a = null
      //call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"false")
      return false
  endif
endfunction

function Trig_GameDrawCardRed_Actions2 takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u 
    local integer max = 35
    local integer rand = GetRandomInt(0,max)
    //
    local integer array spellCards
    
    if(p == Player(0)) then
        set u = udg_HeroBot
        //call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"bot")
    else
        set u = udg_HeroTop
        //call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"top")
    endif
    
    set spellCards[0] = 'A00K'
    set spellCards[1] = 'A000'
    set spellCards[2] = 'A00L'
    set spellCards[3] = 'A00M'
    set spellCards[4] = 'A01F'
    set spellCards[5] = 'A00N'
    set spellCards[6] = 'A00O'
    set spellCards[7] = 'A00P'
    set spellCards[8] = 'A00Q'
    set spellCards[9] = 'A00R'
    set spellCards[10] = 'A00S'
    set spellCards[11] = 'A00T'
    set spellCards[12] = 'A00U'
    set spellCards[13] = 'A00W'
    set spellCards[14] = 'A00V'
    set spellCards[15] = 'A00X'
    set spellCards[16] = 'A00Y'
    set spellCards[17] = 'A00Z'
    set spellCards[18] = 'A010'
    set spellCards[19] = 'A011'
    set spellCards[20] = 'A012'
    set spellCards[21] = 'A013'
    set spellCards[22] = 'A014'
    set spellCards[23] = 'A015'
    set spellCards[24] = 'A017'
    set spellCards[25] = 'A018'
    set spellCards[26] = 'A01A'
    set spellCards[27] = 'A01B'
    set spellCards[28] = 'A01C'
    set spellCards[29] = 'A01D'
    set spellCards[30] = 'A01E'
    set spellCards[31] = 'A01G'
    set spellCards[32] = 'A01H'
    set spellCards[33] = 'A01J'
    set spellCards[34] = 'A01I'
    set spellCards[35] = 'A01K'
    //spellcards end
    
    
    call DisplayTextToPlayer(p,0,0,"Debug: "+AbilityId2String(spellCards[rand]))
    call UnitAddAbility(u,spellCards[rand])
    call SetUnitAbilityLevel(u,spellCards[rand],1)
    
    set p = null
    set u = null
    //call DisplayTextToPlayer( p,0,0,"You've drawn a : " + I2S(rand) + " : " + GetUnitName(GetLastCreatedUnit()) )
endfunction

//===========================================================================
function InitTrig_GameDrawCardspell takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(0), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(1), true )
    call TriggerAddCondition( t, Condition( function Trig_GameDrawCardRed_Conditions2 ) )
    call TriggerAddAction( t, function Trig_GameDrawCardRed_Actions2 )  
    set t = null
endfunction

For the debug. it shows up but the ability name or id does not display.
 
Level 4
Joined
Aug 18, 2013
Messages
71
that should work.
maybe its an hero ability that you try to add to a normal unit?

Nope. I also debugged and checked to see if 'u' was set to the right unit and it was.

I've never mentioned this before but I may as well, when i select the syntax check option in newgen an error appears : PJass not found, make sure it's in the same directory as TESH.dll and try again. I've never had a problem with any other trigger native so i've never mentioned that the syntax check doesn't work properly. could it possibly be that? (I doubt it but thought I'd mention it.)

EDIT: I'll just attach it. If anyone solves it please tell me what you did.
 

Attachments

  • WOC V4.w3x
    74.4 KB · Views: 74
Level 4
Joined
Aug 18, 2013
Messages
71
I knew what you meant, I know the object editor like the back of my hand. It's sad when I can recall almost any ability/unit/model from the game and what it does and what fields it has. haha

Playing with it, Even normal GUI doesn't work
  • Untitled Trigger 001
    • Events
      • Unit - Select to Draw Card (Spell) 0066 <gen> Is selected
    • Conditions
    • Actions
      • Unit - Add Chain Lightning to HeroBot
 
Level 4
Joined
Aug 18, 2013
Messages
71
Important update: When I add the ability to a unit not contained by a variable but initially on the map, it will add. But I know the Variable points to the hero. is it perhaps because the hero does not exist when the game begins? I can't imagine why that would cause a problem because the Variable 'u' does point to the correct unit when the original trigger is run. This is frustrating.
Must i preload the ability first? Do i have to do something to initialize the hero pointed to by 'u'?
 
Status
Not open for further replies.
Top