• 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] Coded Metamorphisis Help

Status
Not open for further replies.
Level 4
Joined
Aug 18, 2013
Messages
71
Hi Guys, I'm currently working on a metamorphosis ability in jass. The issue I'm having is with ability ID's and getting their current level.

The alternate hero my caster transforms into is a completley different hero (Different Main Stat/ abilities)


Here's my current code
JASS:
function Trig_Alternate_Personality_Coded_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A03E' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Alternate_Personality_Coded_Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetSpellAbilityUnit()) == 'H00I' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Alternate_Personality_Coded_Actions takes nothing returns nothing
    //vars init
    local integer level = GetHeroLevel(GetSpellAbilityUnit())
    local integer experienceTotal = GetHeroXP(GetSpellAbilityUnit())
    local integer abil_Q_level 
    local integer abil_W_level
    local integer abil_E_level
    local integer abil_R_level
    local integer abil_Stat_level
    local integer skillPoints = GetHeroSkillPoints(GetSpellAbilityUnit())
    local item array items
    local unit unit_New
    local integer i = 0
    //vars setup
    set items[1] = UnitItemInSlot(GetSpellAbilityUnit(),0)
    set items[2] = UnitItemInSlot(GetSpellAbilityUnit(),1)
    set items[3] = UnitItemInSlot(GetSpellAbilityUnit(),2)
    set items[4] = UnitItemInSlot(GetSpellAbilityUnit(),3)
    set items[5] = UnitItemInSlot(GetSpellAbilityUnit(),4)
    set items[6] = UnitItemInSlot(GetSpellAbilityUnit(),5)
    
    //set abil_Q_level = GetUnitAbilityLevel( who, abilityCode)
    //set abil_W_level = GetUnitAbilityLevel( who, abilityCode)
    //set abil_E_level = GetUnitAbilityLevel( who, abilityCode)
    set abil_R_level = GetUnitAbilityLevel(  GetSpellAbilityUnit(), 'A03E')
    set abil_Stat_level = GetUnitAbilityLevel( GetSpellAbilityUnit(), 'A005')
    if ( Trig_Alternate_Personality_Coded_Func001C() ) then
        call CreateNUnitsAtLoc( 1, 'H00J', GetOwningPlayer(GetSpellAbilityUnit()), GetUnitLoc(GetSpellAbilityUnit()), GetUnitFacing(GetSpellAbilityUnit()) )
        set unit_New = GetLastCreatedUnit()
        call RemoveUnit( GetSpellAbilityUnit() )
    else
        call CreateNUnitsAtLoc( 1, 'H00I', GetOwningPlayer(GetSpellAbilityUnit()), GetUnitLoc(GetSpellAbilityUnit()), GetUnitFacing(GetSpellAbilityUnit()) )
        set unit_New = GetLastCreatedUnit()
        call RemoveUnit( GetSpellAbilityUnit() )
    endif
    call AddHeroXP(unit_New, experienceTotal, false)
    call SetHeroLevel(unit_New, level, false)
    
    //set Abilities
    call SetUnitAbilityLevel(unit_New,'A03E', abil_R_level)
    call SetUnitAbilityLevel(unit_New,'A005', abil_Stat_level)
                      
    set i = 0 //saftey set 
    loop
        exitwhen i == 6 //all inventory
        //---
        call UnitAddItemToSlotById(unit_New,GetItemTypeId(items[i]), i)
        //---
        set  i = i+1  //iterator
    endloop
    
        
    //Clean Vars
    set level = 0
    set experienceTotal = 0
    set abil_Q_level = 0 
    set abil_W_level = 0
    set abil_E_level = 0
    set abil_R_level = 0
    set abil_Stat_level = 0
    set skillPoints  = 0
    set i = 0 //saftey set 
    loop
        exitwhen i == 6 //all inventory
        //---
        set items[i] = null
        //---
        set  i = i+1  //iterator
    endloop
    set unit_New = null
    set i = 0
endfunction

//===========================================================================
function InitTrig_Alternate_Personality_Coded takes nothing returns nothing
    set gg_trg_Alternate_Personality_Coded = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Alternate_Personality_Coded, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Alternate_Personality_Coded, Condition( function Trig_Alternate_Personality_Coded_Conditions ) )
    call TriggerAddAction( gg_trg_Alternate_Personality_Coded, function Trig_Alternate_Personality_Coded_Actions )
endfunction
Specifically what isn't working is this bit of code
JASS:
    //set Abilities
    call SetUnitAbilityLevel(unit_New,'A03E', abil_R_level)
    call SetUnitAbilityLevel(unit_New,'A005', abil_Stat_level)
Any ideas?
 
Level 4
Joined
Aug 18, 2013
Messages
71
I haven't the slightest clue why your code is more efficient. And Yes they have the abilities

The Ability Id system is what Is bugging me.
 
Added these debug messages and let us know what the output is:
JASS:
//set Abilities
    call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E')))
    call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005')))
    call BJDebugMsg("---- BEFORE SET ----")
    call SetUnitAbilityLevel(unit_New,'A03E', abil_R_level)
    call SetUnitAbilityLevel(unit_New,'A005', abil_Stat_level)
    call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E')))
    call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005')))
    call BJDebugMsg("---- AFTER SET ----")
The first two levels (before set) should be numbers greater than 0. If that is true, then the "after set" values should also be greater than 0 (which means that code worked).
 
I haven't the slightest clue why your code is more efficient. And Yes they have the abilities

I meant do what purge said.
Why whose code ?
If you are talking about in my tutorial then look at inlining a lot more.
The code you use is locations.
In my tutorial i show how to use coordinates which are much faster.
The red text are BJs. Almost all of them are inefficient except for a few.
 
Level 4
Joined
Aug 18, 2013
Messages
71
Added these debug messages and let us know what the output is:
JASS:
//set Abilities
    call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E')))
    call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005')))
    call BJDebugMsg("---- BEFORE SET ----")
    call SetUnitAbilityLevel(unit_New,'A03E', abil_R_level)
    call SetUnitAbilityLevel(unit_New,'A005', abil_Stat_level)
    call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E')))
    call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005')))
    call BJDebugMsg("---- AFTER SET ----")
The first two levels (before set) should be numbers greater than 0. If that is true, then the "after set" values should also be greater than 0 (which means that code worked).
call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E'))) - 0
call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005'))) - 0
call BJDebugMsg("---- BEFORE SET ----")
call SetUnitAbilityLevel(unit_New,'A03E', abil_R_level)
call SetUnitAbilityLevel(unit_New,'A005', abil_Stat_level)
call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E'))) - 0
call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005'))) - 0
call BJDebugMsg("---- AFTER SET ----")

so 0 was returned every time
in game my hero should have had
A03E - 3
A005 - 15

and DeathIsMyFriend, i changed the code just for you ;D
JASS:
function Trig_Alternate_Personality_Coded_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A03E' 
endfunction

function Trig_Alternate_Personality_Coded_Func001C takes nothing returns boolean
    return GetUnitTypeId(GetSpellAbilityUnit()) == 'H00I'
endfunction

function Trig_Alternate_Personality_Coded_Actions takes nothing returns nothing
    //vars init
    local unit u = GetSpellAbilityUnit() 
    local integer level = GetHeroLevel(u)
    local integer experienceTotal = GetHeroXP(u)
    local integer abil_Q_level 
    local integer abil_W_level
    local integer abil_E_level
    local integer abil_R_level
    local integer abil_Stat_level
    local integer skillPoints = GetHeroSkillPoints(u)
    local item array items
    local unit unit_New
    local integer i = 0
    local real x = GetLocationX(GetUnitLoc(u))
    local real y = GetLocationY(GetUnitLoc(u))
    local real f = GetUnitFacing(u)
    local player p = GetOwningPlayer(u)
    //vars setup
    set items[1] = UnitItemInSlot(u,0)
    set items[2] = UnitItemInSlot(u,1)
    set items[3] = UnitItemInSlot(u,2)
    set items[4] = UnitItemInSlot(u,3)
    set items[5] = UnitItemInSlot(u,4)
    set items[6] = UnitItemInSlot(u,5)
    
    //set abil_Q_level = GetUnitAbilityLevel( who, abilityCode)
    //set abil_W_level = GetUnitAbilityLevel( who, abilityCode)
    //set abil_E_level = GetUnitAbilityLevel( who, abilityCode)
    set abil_R_level = GetUnitAbilityLevel(  u, 'A03E')
    set abil_Stat_level = GetUnitAbilityLevel( u, 'A005')
    if ( Trig_Alternate_Personality_Coded_Func001C() ) then
        call RemoveUnit( u )
        set u = null
        call CreateUnit( p, 'H00J', x , y , f )
        set unit_New = GetLastCreatedUnit()
    else
        call RemoveUnit( u )
        set u = null
        call CreateUnit( p, 'H00I', x , y , f )
        set unit_New = GetLastCreatedUnit()
    endif
    call AddHeroXP(unit_New, experienceTotal, false)
    call SetHeroLevel(unit_New, level, false)
    call SelectUnitForPlayerSingle(unit_New,GetOwningPlayer(unit_New))
    
    //set Abilities
    call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E')))
    call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005')))
    call BJDebugMsg("---- BEFORE SET ----")
    call SetUnitAbilityLevel(unit_New,'A03E', abil_R_level)
    call SetUnitAbilityLevel(unit_New,'A005', abil_Stat_level)
    call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E')))
    call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005')))
    call BJDebugMsg("---- AFTER SET ----")
                      
    set i = 0 //saftey set 
    loop
        exitwhen i == 6 //all inventory
        //---
        call UnitAddItemToSlotById(unit_New,GetItemTypeId(items[i]), i)
        //---
        set  i = i+1  //iterator
    endloop
        
    //Clean Vars
    set level = 0
    set experienceTotal = 0
    set abil_Q_level = 0 
    set abil_W_level = 0
    set abil_E_level = 0
    set abil_R_level = 0
    set abil_Stat_level = 0
    set skillPoints  = 0
    set i = 0 //saftey set 
    loop
        exitwhen i == 6 //all inventory
        //---
        set items[i] = null
        //---
        set  i = i+1  //iterator
    endloop
    set unit_New = null
    set i = 0
    set x = 0
    set y = 0
    set f = 0
    set p = null
endfunction

//===========================================================================
function InitTrig_Alternate_Personality_Coded takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_Alternate_Personality_Coded_Conditions ) )
    call TriggerAddAction( t, function Trig_Alternate_Personality_Coded_Actions )
    set t = null
endfunction
 
Last edited:
change this
JASS:
call CreateUnit( p, 'H00I', x , y , f )
        set unit_New = GetLastCreatedUnit()
to this
JASS:
set unit_New =  CreateUnit( p, 'H00I', x , y , f )

remove this
JASS:
function Trig_Alternate_Personality_Coded_Func001C takes nothing returns boolean
    return GetUnitTypeId(GetSpellAbilityUnit()) == 'H00I'
endfunction

change the ITE from this.
JASS:
if ( Trig_Alternate_Personality_Coded_Func001C() ) then
to this
JASS:
GetUnitTypeId(GetSpellAbilityUnit()) == 'H00I'

You also need to inline this.
JASS:
call SelectUnitForPlayerSingle(unit_New,GetOwningPlayer(unit_New))

As for your main problem. If everything returns 0 that means the spells were never added to that unit. Check to see if the abilities raw codes are correct.
 
Level 4
Joined
Aug 18, 2013
Messages
71
The Heroes have the abilities, the Raw Codes are right.
Am I supposed to convert it to an integer or is 'A005' in this case already considered an int?
'
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Am I supposed to convert it to an integer or is 'A005' in this case already considered an int?

It is considered as an integer.

Both the forms should have those A03E and A005 abilities, right? Use UnitMakeAbilityPermanent(unit, true, abilityId) to make the unit not lose the ability when transforming. You only need to use it once.
 
Level 4
Joined
Aug 18, 2013
Messages
71
It is considered as an integer.

Both the forms should have those A03E and A005 abilities, right? Use UnitMakeAbilityPermanent(unit, true, abilityId) to make the unit not lose the ability when transforming. You only need to use it once.

This only issue i see with this is, both forms only share these two abilities. They both have 3 seperate abilities. which leads to my problem again, It won't record the level of the ability.
 
Level 4
Joined
Aug 18, 2013
Messages
71
This is the only trigger used with this ability.
The abilities are added in the Abilities - Heroes list
Should I Add them in the code at map init?
 
Level 4
Joined
Aug 18, 2013
Messages
71
I added them in code, but it will not set them to level 1. These abilities are learnable hero abilities. I may have failed to explain that earlier.

In the Object Editor (Raw Code)
H00I:HBLM (The Split One Intel Version)
heroAbilList - A005, A03E
H00J:HBLM (The Split One Agil Version)
heroAbilList - A005, A03E

Jass Function - Under the Event that a character casts the Ability "Alternate Personality"

JASS:
//TESH.scrollpos=3
//TESH.alwaysfold=0
function Trig_Alternate_Personality_Coded_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A03E' //is the casted spell "Alternate Personality"
endfunction

function Trig_Alternate_Personality_Coded_Actions takes nothing returns nothing
    //vars init
    local unit u = GetSpellAbilityUnit() //set u = caster
    local integer level = GetHeroLevel(u) //level of caster
    local integer experienceTotal = GetHeroXP(u) // exp of caster
    local integer abil_Q_level = 0 //GetUnitAbilityLevel(  u, abil)//this should find the casters current level of "Abil"
    local integer abil_W_level = 0 //GetUnitAbilityLevel(  u, abil)//this should ... level of "Abil"
    local integer abil_E_level = 0 //GetUnitAbilityLevel(  u, abil)//this should ... level of "Abil"
    local integer abil_R_level = GetUnitAbilityLevel(  u, 'A03E')//this should ... level of "Alternate Personality"
    local integer abil_Stat_level = GetUnitAbilityLevel( u, 'A005')//this should ... level of "Attribute Bonus"
    local integer skillPoints = GetHeroSkillPoints(u)// - (abil_Q_level+abil_W_level+abil_E_level+abil_R_level+abil_Stat_level)
    local item array items //array of caster items, so can be added to new alternate
    local unit unit_New //unit var = alternate unit
    local integer i = 0 //generic iterator
    local real x = GetLocationX(GetUnitLoc(u)) //x coord of u
    local real y = GetLocationY(GetUnitLoc(u)) //y coord of u
    local real f = GetUnitFacing(u) //facing angle of u
    local player p = GetOwningPlayer(u) //owner of u
    //vars setup
    set items[1] = UnitItemInSlot(u,0) //item in slot 1
    set items[2] = UnitItemInSlot(u,1) //item in slot 2
    set items[3] = UnitItemInSlot(u,2) //item in slot 3
    set items[4] = UnitItemInSlot(u,3) //item in slot 4
    set items[5] = UnitItemInSlot(u,4) //item in slot 5
    set items[6] = UnitItemInSlot(u,5) //item in slot 6
    
    //set abil_Q_level = GetUnitAbilityLevel( who, abilityCode)
    //set abil_W_level = GetUnitAbilityLevel( who, abilityCode)
    //set abil_E_level = GetUnitAbilityLevel( who, abilityCode)
    //set abil_R_level = GetUnitAbilityLevel(  u, 'A03E')
    //set abil_Stat_level = GetUnitAbilityLevel( u, 'A005')
    if ( GetUnitTypeId(u) == 'H00I' )then
            call RemoveUnit( u )
            set u = null
            set unit_New =  CreateUnit( p, 'H00J', x , y , f ) 
            //if caster is Intel Version, remove and create Agil Version at position
        else
            call RemoveUnit( u )
            set u = null
            set unit_New =  CreateUnit( p, 'H00I', x , y , f )
            //if caster is Agil Version, remove and create Intel Version at position
    endif
    call AddHeroXP(unit_New, experienceTotal, false)//level alternate
    //call SetHeroLevel(unit_New, level, false)
    //call SelectUnitForPlayerSingle(unit_New,GetOwningPlayer(unit_New))
    if (GetLocalPlayer() == GetOwningPlayer(unit_New)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(unit_New, true)
    endif //selects the new unit for the owner of caster
    //set Abilities
    call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E')))
    call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005')))
    call BJDebugMsg("---- BEFORE SET ----")
    call SetUnitAbilityLevel(unit_New,'A03E', abil_R_level)
    call SetUnitAbilityLevel(unit_New,'A005', abil_Stat_level)
    call BJDebugMsg("Level 'A03E': " + I2S(GetUnitAbilityLevel(unit_New,'A03E')))
    call BJDebugMsg("Level 'A005': " + I2S(GetUnitAbilityLevel(unit_New,'A005')))
    call BJDebugMsg("---- AFTER SET ----")
    
    //Debug Report
    //These values return 0 before and After
    //this means that the function "GetUnitAbilityLevel(whichUnit,abilcode )" is returning 0
    //this means that the ability is = to level 0 (Which it is not) or the abil code and/or unit_New is incorrect
    
    //Add items to Alternate Unit
    set i = 0 //saftey set
    loop
        exitwhen i == 6 //all inventory
        //---
        call UnitAddItemToSlotById(unit_New,GetItemTypeId(items[i]), i)
        //---
        set  i = i+1  //iterator
    endloop
    
    //Clean Vars
    set level = 0
    set experienceTotal = 0
    set abil_Q_level = 0
    set abil_W_level = 0
    set abil_E_level = 0
    set abil_R_level = 0
    set abil_Stat_level = 0
    set skillPoints  = 0
    set i = 0 //saftey set
    loop
        exitwhen i == 6 //all inventory
        //---
        set items[i] = null
        //---
        set  i = i+1  //iterator
    endloop
    set unit_New = null
    set i = 0
    set x = 0
    set y = 0
    set f = 0
    set p = null
endfunction

//===========================================================================
function InitTrig_Alternate_Personality_Coded takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_Alternate_Personality_Coded_Conditions ) )
    call TriggerAddAction( t, function Trig_Alternate_Personality_Coded_Actions )
    set t = null
endfunction


*Game Starts*
Hero (Unit Code = 'H00I') learns "Attribute Bonus" (Abil Code = 'A005') to max level of 15
Hero learns "Alternate Personality" (Abil Code = 'A03E') up to 1,2,3 (all 3 tested)
Hero casts "Alternate Personality"
Hero is Removed
New Hero (Unit Code = 'H00J') is created and selected at that position
New Hero has no abilities learned but can learn both "Alternate Personality" and "Attribute Bonus". New Hero also has the correct number of spendable skill points.

New Hero (Unit Code = 'H00J') learns "Attribute Bonus" (Abil Code = 'A005') to max level of 15
New Hero learns "Alternate Personality" (Abil Code = 'A03E') up to 1,2,3 (all 3 tested)
New Hero casts "Alternate Personality"
New Hero is Removed

New Hero2 (Unit Code = 'H00I') is created at position of New Hero
... Same as Prev


I'm pretty stuck. I've added comments to explain what the code is supposed to be doing. If anyone wants a copy of the map to see if they can fix it, send me a mesage.
 
Status
Not open for further replies.
Top