• 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] Anyone know why this trigger loops?

Status
Not open for further replies.
Level 4
Joined
Aug 18, 2013
Messages
71
Anyone know why this trigger loops forever?

I'm looking at it but I'm starting to think i'm crazy.

JASS:
///* Werewolf Transformation
//   a unit casts 'A05U'
//   moves caster to remote location and disables them
//   werewolf unit is created in place with respective life and mana percentages, xp, and ability levels
//   45,60,or 75 seconds pass; caster returns to spot with werewolfs respective ^
//   werewolf removed
//*/
function Trig_WereWolfTransform_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A05U' )
endfunction

function Trig_WereWolfTransform_Actions takes nothing returns nothing
//'H00W' = Werewolf Normal Form
//'H00X' = Werewolf Alternate Form
local integer w1 = 'H00W' // normal
local integer w2 = 'H00X' // werwolf
local unit u1 = GetSpellAbilityUnit()// caster
local unit u2
local integer l = GetUnitAbilityLevel(u1,'A05U')
local item array items //array of caster items, so can be added to new alternate
local integer i = 0 //generic iterator
local real x = GetUnitX(u1) //x coord of u
local real y = GetUnitY(u1) //y coord of u
local real f = GetUnitFacing(u1) //facing angle of u
local player p = GetOwningPlayer(u1) //owner of u
local real life = GetUnitStatePercent(u1, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE)
local real m = GetUnitStatePercent(u1, UNIT_STATE_MANA, UNIT_STATE_MAX_MANA)
local integer xp = GetHeroXP(u1)
local integer lev = GetHeroLevel(u1)
local integer l1 = GetUnitAbilityLevel(u1,0)//q abil
local integer l2 = GetUnitAbilityLevel(u1,0)//w abil
local integer l3 = GetUnitAbilityLevel(u1,0)//e abil
local integer l4 = GetUnitAbilityLevel(u1,'A05T')//r abil
local integer l5 = GetUnitAbilityLevel(u1,'A005')//stat abil
local integer sp = GetHeroSkillPoints(u1)//stat points remaining
    //vars setup
    set items[1] = UnitItemInSlot(u1,0) //item in slot 1
    set items[2] = UnitItemInSlot(u1,1) //item in slot 2
    set items[3] = UnitItemInSlot(u1,2) //item in slot 3
    set items[4] = UnitItemInSlot(u1,3) //item in slot 4
    set items[5] = UnitItemInSlot(u1,4) //item in slot 5
    set items[6] = UnitItemInSlot(u1,5) //item in slot 6
    
    //Cast Start
    call SetUnitX(u1, 5910)
    call SetUnitY(u1, -5500)
    call ShowUnit(u1,false)//hide caster
    call PauseUnit(u1,true)//pause unit
    set u2 = CreateUnit(p,w2,x,y,f)//create werewolf
    call SetHeroXP(u2,xp,false)
    call SetUnitAbilityLevel(u2,0,l1)//set q abil level
    call SetUnitAbilityLevel(u2,0,l2)//set w abil level
    call SetUnitAbilityLevel(u2,0,l3)//set e abil level
    call SetUnitAbilityLevel(u2,'A05T',l4)//set r abil level
    call SetUnitAbilityLevel(u2,'A005',l4)//set stat abil level
    call SetUnitLifePercentBJ(u2,life)
    call SetUnitManaPercentBJ(u2,m)
    
    //inventory: this block adds all the items from caster to werewolf
    set i = 0 //saftey set
    loop
        exitwhen i == 6 //all inventory
        //---
        call UnitAddItem(u2,items[i])
        //---
        set  i = i+1  //iterator
    endloop
    
    //this block selects the newly created werewolf
    if (GetLocalPlayer() == GetOwningPlayer(u2)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(u2, true)
    endif //selects the new unit for the owner of caster
    
    //Caster should be gone safe and sound, werewolf unit in its place. 
    call PolledWait(30 + l4*15)//wait = 45,60,75 based on level 1,2,3
    //get hero level info
    set xp = GetHeroXP(u2)
    set l1 = GetUnitAbilityLevel(u2,0)//q abil
    set l2 = GetUnitAbilityLevel(u2,0)//w abil
    set l3 = GetUnitAbilityLevel(u2,0)//e abil
    set l4 = GetUnitAbilityLevel(u2,0)//r abil
    set l5 = GetUnitAbilityLevel(u2,'A005')//stat abil
    //set hero levels
    call SetHeroXP(u1,xp,false)//set original hero xp to werewolf
    call SetUnitAbilityLevel(u1,0,l1)//set q abil level
    call SetUnitAbilityLevel(u1,0,l2)//set w abil level
    call SetUnitAbilityLevel(u1,0,l3)//set e abil level
    call SetUnitAbilityLevel(u1,0,l4)//set r abil level 
    call SetUnitAbilityLevel(u1,'A005',l5)//set stat abil level
    
    //set location
    set x =  GetUnitX(u2)
    set y =  GetUnitY(u2)
    call SetUnitX(u1, x)//set original x to werewolf x
    call SetUnitY(u1, y)//set original y to werewolf y
    
    //enable unit
    call ShowUnit(u1,true)//show caster 
    call PauseUnit(u1,false)//unpause unit
    
    //set unit life and mana
    set life = GetUnitStatePercent(u2, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE)//get werewolf life percentage
    set m = GetUnitStatePercent(u2, UNIT_STATE_MANA, UNIT_STATE_MAX_MANA)//get werewolf mana percentage
    call SetUnitLifePercentBJ(u1,life)//set orig life
    call SetUnitManaPercentBJ(u1,m)//set orig mana 
    
    //inventory revert
    set i = 0 //saftey set
    loop
        exitwhen i == 6 //all inventory
        //---
        call UnitAddItem(u1,items[i])
        //---
        set  i = i+1  //iterator
    endloop
    
    if (GetLocalPlayer() == GetOwningPlayer(u1)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(u1, true)
    endif //selects the caster
    
    //cleanup
    call RemoveUnit(u2)
    set  u1 = null
    set  u2 = null
    set  l = 0
    set  i = 0 //generic iterator
    set  x = 0
    set  y = 0
    set  f = 0
    call DisplayTimedTextToPlayer(p,0,0,5,"Werewolf Transformation Complete")//debug message
    set  p = null
    set  l = 0
    set  m = 0
    set  xp = 0
    set  lev = 0
    set  l1 = 0//q abil
    set  l2 = 0//w abil
    set  l3 = 0//e abil
    set  l4 = 0//r abil
    set  l5 = 0//stat abil
    set  sp = 0//stat points remaining
    //vars setup
    set items[1] = null //item in slot 1
    set items[2] = null //item in slot 2
    set items[3] = null //item in slot 3
    set items[4] = null //item in slot 4
    set items[5] = null //item in slot 5
    set items[6] = null //item in slot 6
endfunction

//===========================================================================
function InitTrig_WereWolfTransform takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_WereWolfTransform_Conditions ) )
    call TriggerAddAction( t, function Trig_WereWolfTransform_Actions )
    set t = null
endfunction

JASS:
///* Werewolf Transformation
//   a unit casts 'A05U'
//   moves caster to remote location and disables them
//   werewolf unit is created in place with respective life and mana percentages, xp, and ability levels
//   45,60,or 75 seconds pass; caster returns to spot with werewolfs respective ^
//   werewolf removed
//*/
function Trig_WereWolfTransform_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A05U' )
endfunction

function Trig_WereWolfTransform_Actions takes nothing returns nothing
//'H00W' = Werewolf Normal Form
//'H00X' = Werewolf Alternate Form
//Spells Vars
local integer Q = 0
local integer W = 'A05V'
local integer E = 'A05S'
local integer R1 = 'A05T'
local integer R2 = 'A05U'
local integer T = 'A005'
//Unit Numbers
local integer w1 = 'H00W' // normal
local integer w2 = 'H00X' // werwolf
//Local Vars
local unit u1 = GetSpellAbilityUnit()// caster
local unit u2
local integer l = GetUnitAbilityLevel(u1,'A05U')
local item array items //array of caster items, so can be added to new alternate
local integer i = 0 //generic iterator
local real x = GetUnitX(u1) //x coord of u
local real y = GetUnitY(u1) //y coord of u
local real f = GetUnitFacing(u1) //facing angle of u
local player p = GetOwningPlayer(u1) //owner of u
local real life = GetUnitStatePercent(u1, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE)
local real m = GetUnitStatePercent(u1, UNIT_STATE_MANA, UNIT_STATE_MAX_MANA)
local integer xp = GetHeroXP(u1)
local integer lev = GetHeroLevel(u1)
local integer l1 = GetUnitAbilityLevel(u1,Q)//q abil
local integer l2 = GetUnitAbilityLevel(u1,W)//w abil
local integer l3 = GetUnitAbilityLevel(u1,E)//e abil
local integer l4 = GetUnitAbilityLevel(u1,R1)//r abil
local integer l5 = GetUnitAbilityLevel(u1,T)//stat abil
local integer sp = GetHeroSkillPoints(u1)//stat points remaining
    //debug level display
    call DisplayTextToPlayer(p,0,0,"Q : "+I2S(l1))
    call DisplayTextToPlayer(p,0,0,"W : "+I2S(l2))
    call DisplayTextToPlayer(p,0,0,"E : "+I2S(l3))
    call DisplayTextToPlayer(p,0,0,"R : "+I2S(l4))
    call DisplayTextToPlayer(p,0,0,"T : "+I2S(l5))
    //----------

    //vars setup
    set items[1] = UnitItemInSlot(u1,0) //item in slot 1
    set items[2] = UnitItemInSlot(u1,1) //item in slot 2
    set items[3] = UnitItemInSlot(u1,2) //item in slot 3
    set items[4] = UnitItemInSlot(u1,3) //item in slot 4
    set items[5] = UnitItemInSlot(u1,4) //item in slot 5
    set items[6] = UnitItemInSlot(u1,5) //item in slot 6
    
    //Cast Start
    call SetUnitX(u1, 5910)
    call SetUnitY(u1, -5500)
    set u2 = CreateUnit(p,w2,x,y,f)//create werewolf
    call SetUnitLifePercentBJ(u2,life)
    call SetUnitManaPercentBJ(u2,m)
    
    //Set Werewolf Levels etc
    call SetHeroXP(u2,xp,false)
    call ModifyHeroSkillPoints(u2,bj_MODIFYMETHOD_ADD,sp)
    call SetUnitAbilityLevel(u2,Q,l1)//set q abil level
    call SetUnitAbilityLevel(u2,W,l2)//set w abil level
    call SetUnitAbilityLevel(u2,E,l3)//set e abil level
    call SetUnitAbilityLevel(u2,R1,l4)//set r abil level 
    call SetUnitAbilityLevel(u2,T,l5)//set stat abil level
    
    //global set for etc. if werewolf dies saves him etc. idk
    set udg_WerewolfUnit[GetConvertedPlayerId(GetOwningPlayer(u1))] = u2 
    
    //inventory: this block adds all the items from caster to werewolf
    set i = 0 //saftey set
    loop
        exitwhen i == 7 //all inventory
        //---
        call UnitAddItem(u2,items[i])
        //---
        set  i = i+1  //iterator
    endloop
    
    //this block selects the newly created werewolf
    if (GetLocalPlayer() == GetOwningPlayer(u2)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(u2, true)
    endif //selects the new unit for the owner of caster
   
    // set ability levels try2
    call SetUnitAbilityLevel(u2,Q,l1)//set q abil level
    call SetUnitAbilityLevel(u2,W,l2)//set w abil level
    call SetUnitAbilityLevel(u2,E,l3)//set e abil level
    call SetUnitAbilityLevel(u2,R1,l4)//set r abil level 
    call SetUnitAbilityLevel(u2,T,l5)//set stat abil level
    
    //hide Hero
    call ShowUnit(u1,false)//hide caster
    
    //Caster should be gone safe and sound, werewolf unit in its place. 
    call PolledWait(31 + l4*15)//wait = 45,60,75 based on level 1,2,3; Actual Values: 46,61,76
    
    //enable unit
    call ShowUnit(u1,true)//show caster
    
    //remove TransformAbility
    call UnitRemoveAbility( u1,'A05U' )
    
    //get werewolf level info
    set xp = GetHeroXP(u2)
    set l1 = GetUnitAbilityLevel(u2,Q)//q abil
    set l2 = GetUnitAbilityLevel(u2,W)//w abil
    set l3 = GetUnitAbilityLevel(u2,E)//e abil
    set l4 = GetUnitAbilityLevel(u2,R1)//r abil
    set l5 = GetUnitAbilityLevel(u2,T)//stat abil
    //debug level display
    call DisplayTextToPlayer(p,0,0,"Q : "+I2S(l1))
    call DisplayTextToPlayer(p,0,0,"W : "+I2S(l2))
    call DisplayTextToPlayer(p,0,0,"E : "+I2S(l3))
    call DisplayTextToPlayer(p,0,0,"R : "+I2S(l4))
    call DisplayTextToPlayer(p,0,0,"T : "+I2S(l5))
    //----------
    
    //set hero levels
    call SetHeroXP(u1,xp,false)//set original hero xp to werewolf
    call SetUnitAbilityLevel(u1,Q,l1)//set q abil level
    call SetUnitAbilityLevel(u1,W,l2)//set w abil level
    call SetUnitAbilityLevel(u1,E,l3)//set e abil level
    call SetUnitAbilityLevel(u1,R1,l4)//set r abil level 
    call SetUnitAbilityLevel(u1,T,l5)//set stat abil level
    
    //set location
    set x =  GetUnitX(u2)
    set y =  GetUnitY(u2)
    call SetUnitX(u1, x)//set original x to werewolf x
    call SetUnitY(u1, y)//set original y to werewolf y
    
    //set unit life and mana
    set life = GetUnitStatePercent(u2, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE)//get werewolf life percentage
    set m = GetUnitStatePercent(u2, UNIT_STATE_MANA, UNIT_STATE_MAX_MANA)//get werewolf mana percentage
    call SetUnitLifePercentBJ(u1,life)//set orig life
    call SetUnitManaPercentBJ(u1,m)//set orig mana 
    
    //inventory revert
    set i = 0 //saftey set
    loop
        exitwhen i == 7 //all inventory
        //---
        set items[i+1] = UnitItemInSlot(u2,i) //item in slot i
        call UnitAddItem(u1,items[i])
        //---
        set  i = i+1  //iterator
    endloop
    
    //this block selects the hero
    if (GetLocalPlayer() == GetOwningPlayer(u1)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(u1, true)
    endif //selects the caster
    
    //cleanup
    call RemoveUnit(u2)
    set  u1 = null
    set  u2 = null
    set  l = 0
    set  i = 0 //generic iterator
    set  x = 0
    set  y = 0
    set  f = 0
    call DisplayTimedTextToPlayer(p,0,0,5,"Werewolf Transformation Complete")//debug message
    set  p = null
    set  l = 0
    set  m = 0
    set  xp = 0
    set  lev = 0
    set  l1 = 0//q abil
    set  l2 = 0//w abil
    set  l3 = 0//e abil
    set  l4 = 0//r abil
    set  l5 = 0//stat abil
    set  sp = 0//stat points remaining
    //vars setup
    set items[1] = null //item in slot 1
    set items[2] = null //item in slot 2
    set items[3] = null //item in slot 3
    set items[4] = null //item in slot 4
    set items[5] = null //item in slot 5
    set items[6] = null //item in slot 6
endfunction

//===========================================================================
function InitTrig_WereWolfTransform takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_WereWolfTransform_Conditions ) )
    call TriggerAddAction( t, function Trig_WereWolfTransform_Actions )
    set t = null
endfunction

Not sure why.
the ability 'A05U' is based after channel
its instant so this trigger shouldn't be looping indefinitley.
It also does not move the caster back, but it does create a new werewolf ever 45 seconds at the same position removing the previous one.
 
Last edited:
Level 4
Joined
Aug 18, 2013
Messages
71
Hey guys, I have to leave for a while; But upon examination

as u2 is removed and replaced by u1
u1 instantly casts 'A05U' restarting the chain
I do not know how to fix this asides removing 'A05U' from u1 right after the cast.
But this is a glitchy way to fix it and I can't test it now.

anyone know whats going on?
 
If I were you, I would save a boolean flag into a hashtable when the spell is cast, like so:
JASS:
call SaveBoolean(udg_SomeHashtableVariable, GetHandleId(u1), 0, true)
That would basically tell you: hey, this guy morphed already so don't repeat!

After the polled wait finishes, just add the line to set the flag to false:
JASS:
call SaveBoolean(udg_SomeHashtableVariable, GetHandleId(u1), 0, false)

In the conditions part, you would check:
JASS:
function Trig_WereWolfTransform_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A05U' ) and (not SaveBoolean(udg_SomeHashtableVariable, GetHandleId(u1), 0))
endfunction
Which would check to make sure it is false before executing the actions part.

However, you might want to increase your polled wait by a few milliseconds or so beyond the actual transformation duration, in case it sets the flag to false prematurely (I don't think it will considering the nature of the polled wait function, but still), which would lead to the repeat happening again.
 
Level 7
Joined
Mar 6, 2006
Messages
282
Comment out the call PauseUnit(u1,true)//pause unit and see if it still loops.

The initial cast of Werewolf might be getting interrupted by the pause, and then it fires the trigger again once it's un-paused.

Use call IssueImmediateOrder( u1, "stop" ) right after you call PauseUnit
 
Comment out the call PauseUnit(u1,true)//pause unit and see if it still loops.

The initial cast of Werewolf might be getting interrupted by the pause, and then it fires the trigger again once it's un-paused.

Missed that one.

@TO
You should never use pause unit for spells.
Take a look at my tutorial Converting GUI to Efficient JASS.
 
Level 7
Joined
Mar 6, 2006
Messages
282
Fixed it, Besides for setabilitylevel(params), The levels wont be set so.

I've had problems with this before.
but thanks everyone

Well unless you updated it, the code in your first post has no ability codes in those fields.

JASS:
    //set hero levels
    call SetHeroXP(u1,xp,false)//set original hero xp to werewolf
    call SetUnitAbilityLevel(u1,0,l1)//set q abil level
    call SetUnitAbilityLevel(u1,0,l2)//set w abil level
    call SetUnitAbilityLevel(u1,0,l3)//set e abil level
    call SetUnitAbilityLevel(u1,0,l4)//set r abil level 
    call SetUnitAbilityLevel(u1,'A005',l5)//set stat abil level

Same with the GetUnitAbilityLevel lines.
 
Level 4
Joined
Aug 18, 2013
Messages
71
Well unless you updated it, the code in your first post has no ability codes in those fields.

JASS:
    //set hero levels
    call SetHeroXP(u1,xp,false)//set original hero xp to werewolf
    call SetUnitAbilityLevel(u1,0,l1)//set q abil level
    call SetUnitAbilityLevel(u1,0,l2)//set w abil level
    call SetUnitAbilityLevel(u1,0,l3)//set e abil level
    call SetUnitAbilityLevel(u1,0,l4)//set r abil level 
    call SetUnitAbilityLevel(u1,'A005',l5)//set stat abil level

Same with the GetUnitAbilityLevel lines.

I fixed the code, but the ability still doesnt work
Here it is updated
JASS:
///* Werewolf Transformation
//   a unit casts 'A05U'
//   moves caster to remote location and disables them
//   werewolf unit is created in place with respective life and mana percentages, xp, and ability levels
//   45,60,or 75 seconds pass; caster returns to spot with werewolfs respective ^
//   werewolf removed
//*/
function Trig_WereWolfTransform_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A05U' )
endfunction

function Trig_WereWolfTransform_Actions takes nothing returns nothing
//'H00W' = Werewolf Normal Form
//'H00X' = Werewolf Alternate Form
//Spells Vars
local integer Q = 0
local integer W = 'A05V'
local integer E = 'A05S'
local integer R1 = 'A05T'
local integer R2 = 'A05U'
local integer T = 'A005'
//Unit Numbers
local integer w1 = 'H00W' // normal
local integer w2 = 'H00X' // werwolf
//Local Vars
local unit u1 = GetSpellAbilityUnit()// caster
local unit u2
local integer l = GetUnitAbilityLevel(u1,'A05U')
local item array items //array of caster items, so can be added to new alternate
local integer i = 0 //generic iterator
local real x = GetUnitX(u1) //x coord of u
local real y = GetUnitY(u1) //y coord of u
local real f = GetUnitFacing(u1) //facing angle of u
local player p = GetOwningPlayer(u1) //owner of u
local real life = GetUnitStatePercent(u1, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE)
local real m = GetUnitStatePercent(u1, UNIT_STATE_MANA, UNIT_STATE_MAX_MANA)
local integer xp = GetHeroXP(u1)
local integer lev = GetHeroLevel(u1)
local integer l1 = GetUnitAbilityLevel(u1,Q)//q abil
local integer l2 = GetUnitAbilityLevel(u1,W)//w abil
local integer l3 = GetUnitAbilityLevel(u1,E)//e abil
local integer l4 = GetUnitAbilityLevel(u1,R1)//r abil
local integer l5 = GetUnitAbilityLevel(u1,T)//stat abil
local integer sp = GetHeroSkillPoints(u1)//stat points remaining
    //debug level display
    call DisplayTextToPlayer(p,0,0,"Q : "+I2S(l1))
    call DisplayTextToPlayer(p,0,0,"W : "+I2S(l2))
    call DisplayTextToPlayer(p,0,0,"E : "+I2S(l3))
    call DisplayTextToPlayer(p,0,0,"R : "+I2S(l4))
    call DisplayTextToPlayer(p,0,0,"T : "+I2S(l5))
    //----------

    //vars setup
    set items[1] = UnitItemInSlot(u1,0) //item in slot 1
    set items[2] = UnitItemInSlot(u1,1) //item in slot 2
    set items[3] = UnitItemInSlot(u1,2) //item in slot 3
    set items[4] = UnitItemInSlot(u1,3) //item in slot 4
    set items[5] = UnitItemInSlot(u1,4) //item in slot 5
    set items[6] = UnitItemInSlot(u1,5) //item in slot 6
    
    //Cast Start
    call SetUnitX(u1, 5910)
    call SetUnitY(u1, -5500)
    set u2 = CreateUnit(p,w2,x,y,f)//create werewolf
    call SetUnitLifePercentBJ(u2,life)
    call SetUnitManaPercentBJ(u2,m)
    
    //Set Werewolf Levels etc
    call SetHeroXP(u2,xp,false)
    call ModifyHeroSkillPoints(u2,bj_MODIFYMETHOD_ADD,sp)
    call SetUnitAbilityLevel(u2,Q,l1)//set q abil level
    call SetUnitAbilityLevel(u2,W,l2)//set w abil level
    call SetUnitAbilityLevel(u2,E,l3)//set e abil level
    call SetUnitAbilityLevel(u2,R1,l4)//set r abil level 
    call SetUnitAbilityLevel(u2,T,l5)//set stat abil level
    
    //global set for etc. if werewolf dies saves him etc. idk
    set udg_WerewolfUnit[GetConvertedPlayerId(GetOwningPlayer(u1))] = u2 
    
    //inventory: this block adds all the items from caster to werewolf
    set i = 0 //saftey set
    loop
        exitwhen i == 7 //all inventory
        //---
        call UnitAddItem(u2,items[i])
        //---
        set  i = i+1  //iterator
    endloop
    
    //this block selects the newly created werewolf
    if (GetLocalPlayer() == GetOwningPlayer(u2)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(u2, true)
    endif //selects the new unit for the owner of caster
   
    // set ability levels try2
    call SetUnitAbilityLevel(u2,Q,l1)//set q abil level
    call SetUnitAbilityLevel(u2,W,l2)//set w abil level
    call SetUnitAbilityLevel(u2,E,l3)//set e abil level
    call SetUnitAbilityLevel(u2,R1,l4)//set r abil level 
    call SetUnitAbilityLevel(u2,T,l5)//set stat abil level
    
    //hide Hero
    call ShowUnit(u1,false)//hide caster
    
    //Caster should be gone safe and sound, werewolf unit in its place. 
    call PolledWait(31 + l4*15)//wait = 45,60,75 based on level 1,2,3; Actual Values: 46,61,76
    
    //enable unit
    call ShowUnit(u1,true)//show caster
    
    //remove TransformAbility
    call UnitRemoveAbility( u1,'A05U' )
    
    //get werewolf level info
    set xp = GetHeroXP(u2)
    set l1 = GetUnitAbilityLevel(u2,Q)//q abil
    set l2 = GetUnitAbilityLevel(u2,W)//w abil
    set l3 = GetUnitAbilityLevel(u2,E)//e abil
    set l4 = GetUnitAbilityLevel(u2,R1)//r abil
    set l5 = GetUnitAbilityLevel(u2,T)//stat abil
    //debug level display
    call DisplayTextToPlayer(p,0,0,"Q : "+I2S(l1))
    call DisplayTextToPlayer(p,0,0,"W : "+I2S(l2))
    call DisplayTextToPlayer(p,0,0,"E : "+I2S(l3))
    call DisplayTextToPlayer(p,0,0,"R : "+I2S(l4))
    call DisplayTextToPlayer(p,0,0,"T : "+I2S(l5))
    //----------
    
    //set hero levels
    call SetHeroXP(u1,xp,false)//set original hero xp to werewolf
    call SetUnitAbilityLevel(u1,Q,l1)//set q abil level
    call SetUnitAbilityLevel(u1,W,l2)//set w abil level
    call SetUnitAbilityLevel(u1,E,l3)//set e abil level
    call SetUnitAbilityLevel(u1,R1,l4)//set r abil level 
    call SetUnitAbilityLevel(u1,T,l5)//set stat abil level
    
    //set location
    set x =  GetUnitX(u2)
    set y =  GetUnitY(u2)
    call SetUnitX(u1, x)//set original x to werewolf x
    call SetUnitY(u1, y)//set original y to werewolf y
    
    //set unit life and mana
    set life = GetUnitStatePercent(u2, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE)//get werewolf life percentage
    set m = GetUnitStatePercent(u2, UNIT_STATE_MANA, UNIT_STATE_MAX_MANA)//get werewolf mana percentage
    call SetUnitLifePercentBJ(u1,life)//set orig life
    call SetUnitManaPercentBJ(u1,m)//set orig mana 
    
    //inventory revert
    set i = 0 //saftey set
    loop
        exitwhen i == 7 //all inventory
        //---
        set items[i+1] = UnitItemInSlot(u2,i) //item in slot i
        call UnitAddItem(u1,items[i])
        //---
        set  i = i+1  //iterator
    endloop
    
    //this block selects the hero
    if (GetLocalPlayer() == GetOwningPlayer(u1)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(u1, true)
    endif //selects the caster
    
    //cleanup
    call RemoveUnit(u2)
    set  u1 = null
    set  u2 = null
    set  l = 0
    set  i = 0 //generic iterator
    set  x = 0
    set  y = 0
    set  f = 0
    call DisplayTimedTextToPlayer(p,0,0,5,"Werewolf Transformation Complete")//debug message
    set  p = null
    set  l = 0
    set  m = 0
    set  xp = 0
    set  lev = 0
    set  l1 = 0//q abil
    set  l2 = 0//w abil
    set  l3 = 0//e abil
    set  l4 = 0//r abil
    set  l5 = 0//stat abil
    set  sp = 0//stat points remaining
    //vars setup
    set items[1] = null //item in slot 1
    set items[2] = null //item in slot 2
    set items[3] = null //item in slot 3
    set items[4] = null //item in slot 4
    set items[5] = null //item in slot 5
    set items[6] = null //item in slot 6
endfunction

//===========================================================================
function InitTrig_WereWolfTransform takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_WereWolfTransform_Conditions ) )
    call TriggerAddAction( t, function Trig_WereWolfTransform_Actions )
    set t = null
endfunction

But the new unit (u2) appears, has # skillpoints available, and no skills invested

Ingame Text Screenshot
VksqS5w.jpg


In the game, all these actions occur which result in ^ message log
1. Select u1
2. Learn W to lev 4, Learn E to lev 4, Learn R1 to lev 1, Learn T to lev 1.
3. Use R1, u2 is created, u1 is moved away
First Message Half is shown.
Q : 0
W : 4
E : 4
R : 1
T : 1
4. select u2
5. Learn W to lev 4, Learn E to lev 4, Learn R1 to lev 1, Learn T to lev 1.
6. wait time; u2 is removed, u1 returns
7. Second Message Half is shown. (These Values are Correct)
Q : 0
W : 4
E : 4
R : 1
T : 1
Werewolf Transformation Complete


I know the second part works because it correctly sets the skills from u2 back to u1
Scenario 2 actions are below
1. Select u1
2. Learn W to lev 4, Learn E to lev 4, Learn R1 to lev 1, Learn T to lev 1.
3. Use R1, u2 is created, u1 is moved away
First Message Half is shown.
Q : 0
W : 4
E : 4
R : 1
T : 1
4. select u2
5. Learn W to lev 4, Learn E to lev 2, Learn R1 to lev 1, Learn T to lev 3.
6. wait time; u2 is removed, u1 returns
7. Second Message Half is shown. (These Values are Correct)
Q : 0
W : 4
E : 2
R : 1
T : 3
Werewolf Transformation Complete
 
Last edited:
Level 19
Joined
Mar 18, 2012
Messages
1,716
JASS:
    //set unit life and mana
    set life = GetUnitStatePercent(u2, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE)//get werewolf life percentage
    set m = GetUnitStatePercent(u2, UNIT_STATE_MANA, UNIT_STATE_MAX_MANA)//get werewolf mana percentage
    call SetUnitLifePercentBJ(u1,life)//set orig life
    call SetUnitManaPercentBJ(u1,m)//set orig mana
--->
JASS:
        //set unit life and mana
    set life = GetWidgetLife(u2)/GetUnitState(u2, UNIT_STATE_MAX_LIFE)//get werewolf life percentage
    set m = GetUnitState(u2, UNIT_STATE_MANA)/GetUnitState(u2, UNIT_STATE_MAX_MANA)//get werewolf mana percentage
    call SetWidgetLife(u1,GetUnitState(u1, UNIT_STATE_MAX_LIFE)*life)//set orig life
    call SetUnitState(u1, UNIT_STATE_MANA, GetUnitState(u1, UNIT_STATE_MAX_MANA)*m)

for debugging you can tag the respective line with the keyword debug --> debug call ....
call PolledWait(31 + l4*15) Never ever use PolledWait, use a Timer instead. Search for a tutorial for how to attach data to a timer. Also I4 looks like 14, don't you think thats confusing? To avoid this, a local variable should start with lower case -> i4
set udg_WerewolfUnit[GetConvertedPlayerId(GetOwningPlayer(u1))] = u2 -->set udg_WerewolfUnit[GetPlayerId(p)] = u2
GetSpellAbilityUnit() --> GetTriggerUnit()
GetOwningPlayer(u1) --> GetTriggerPlayer()

call SetUnitX(u1, 5910) and call SetUnitY(u1, -5500) be carefull here, these coordinates have to be inside your map, otherwise the map carshes. If you want safety use SetUnitPosition(u1, x, y)

You don't have to set local real, integer, (string) variables to 0 (null)
[hidden="Redundant]
JASS:
    set  l = 0
    set  i = 0 //generic iterator
    set  x = 0
    set  y = 0
    set  f = 0
    set  l = 0
    set  m = 0
    set  xp = 0
    set  lev = 0
    set  l1 = 0//q abil
    set  l2 = 0//w abil
    set  l3 = 0//e abil
    set  l4 = 0//r abil
    set  l5 = 0//stat abil
    set  sp = 0//stat points remaining
[/hidden]
 
Last edited:
Level 7
Joined
Mar 6, 2006
Messages
282
How about UnitAddAbility? SetUnitAbilityLevel doesn't add the ability.

Oh yeah, he's right, the 2nd hero isn't learning the skills.

I think he means SelectHeroSkill() though, that will learn the skill for the new unit, and THEN you can set the ability level.

So you would make the new hero, and make sure the skills are learned:

JASS:
// learn abilities
call SelectHeroSkill(u2,Q,l1) // learn q abil level
call SelectHeroSkill(u2,W,l2) // learn w abil level
call SelectHeroSkill(u2,E,l3) // learn e abil level
call SelectHeroSkill(u2,R,l4) // learn r abil level
call SelectHeroSkill(u2,T,l5) // learn stat abil level

// set ability levels try2
call SetUnitAbilityLevel(u2,Q,l1)//set q abil level
call SetUnitAbilityLevel(u2,W,l2)//set w abil level
call SetUnitAbilityLevel(u2,E,l3)//set e abil level
call SetUnitAbilityLevel(u2,R1,l4)//set r abil level 
call SetUnitAbilityLevel(u2,T,l5)//set stat abil level


Also dude, your variable names are really short and hard to understand; it makes debugging your code really difficult. You can use whatever variable names you want, because you can optimize your map with a third party program and it will shorten all your variables to be as small as possible.
 
Level 4
Joined
Aug 18, 2013
Messages
71
I apologize if my var names are short. I do it because it's easier on me. Just a habit, but I understand it. Also BPower, Its not a "I", it is a lowercase "L". it stands for level. I understand coding style, my code is very simple for me to read. But I add comments so others get it.

On another note: Heroes who haven't learnt a skill yet technically don't have it? So I have to learn it first, then set the level? (I'm testing this so haha)
 
Status
Not open for further replies.
Top