Setting a hero's attributes

BRUTAL

I'm working
Reaction score
118
I'm working on a trigger, that when a spell is cast, create a unit of the targeted unit type, and make this the casting players new hero for 30 seconds. The original is removed after setting its attributes, experience, level, max life and max mana etc. Then after removing the original hero and setting the new heroes attributes to the stored values, the attributes of the new hero aren't what they are supposed to be.
Is there some kind of bug with setting attributes? How am i supposed to properly achieve what I'm trying to do.
I don't think you'd need to see the trigger, but here anyways.
JASS:
scope shangm initializer qwe

globals
    private constant integer ID='A020' // ID of the spell.
    private constant real PERIOD=.02 // Period of KT2.
endglobals

private struct Data
    unit caster
    unit target
    unit replacement
    integer array level[5]
    integer array abil[5]
    integer ticks=1498
    
    static method create takes unit u, real x, real y, unit t returns Data
        local Data d=Data.allocate()
        local player p=GetOwningPlayer(u)
        local unit temp=CreateUnit(Passive,'Hamg',0,-4416,0)
        local real face=GetUnitFacing(u)
        local integer team=0 // Used to see what team the hero is in.
        local integer duelist=0 // Used to see if the hero is a duelist.
        local integer array stats // Stores various stats of the hero.
        set stats[0]=GetHeroAgi(u,true) // Set Shang Tsung stats, level etc.
        set stats[1]=GetHeroInt(u,true)
        set stats[2]=GetHeroStr(u,true)
        set stats[3]=GetHeroLevel(u)
        set stats[4]=GetHeroXP(u)
        set stats[5]=R2I(GetUnitState(u,Life))
        set stats[6]=R2I(GetUnitState(u,Mana))
        set stats[7]=R2I(GetUnitState(u,MaxLife))
        set stats[8]=R2I(GetUnitState(u,MaxMana))
        set d.level[1]=GetUnitAbilityLevel(u,'A00L')
            set d.abil[1]='A00L'
        set d.level[2]=GetUnitAbilityLevel(u,'A01V')
            set d.abil[2]='A01V'
        set d.level[3]=GetUnitAbilityLevel(u,'A01W')
            set d.abil[3]='A01W'
        set d.level[4]=GetUnitAbilityLevel(u,'A01X')
            set d.abil[4]='A01W' 
        if IsUnitInGroup(u,TeamWestHeroes) then // Checks if Shang Tsung is a duelist,
            set team=0                    // and what groups he's currently in.
            if u==DuelistWest then
                set duelist=1
            endif
            call GroupRemoveUnit(TeamWestHeroes,u)
        elseif IsUnitInGroup(u,TeamEastHeroes) then
            set team=1
            if u==DuelistEast then
                set duelist=2
            endif
            call GroupRemoveUnit(TeamEastHeroes,u)
        elseif IsUnitInGroup(u,TeamSoloHeroes) then
            set team=2
            call GroupRemoveUnit(TeamSoloHeroes,u)
        endif
        call RemoveUnit(u)
        call SetPlayerAllianceStateBJ(Aggressive,Passive,bj_ALLIANCE_UNALLIED)
        call SetUnitVertexColor(temp,255,255,255,0)
        set d.target=temp
        set d.caster=CreateUnit(Aggressive,IDshangtsung,0,-4416,face)
        call SelectHeroSkill(d.caster,ID)
        call SetUnitVertexColor(d.caster,255,255,255,0)
        call IssueTargetOrder(d.caster,"thunderbolt",temp)
        
        set d.replacement=CreateUnit(p,GetUnitTypeId(t),x,y,face)
        call UnitApplyTimedLife(d.replacement,'BHwe',30) // Apply the timed like.
        set PlayerHero[GetPlayerId(p)]=d.replacement // Make new hero the actual 
        if team==0 then                               // player's hero.
            call GroupAddUnit(TeamWestHeroes,d.replacement)
            if duelist==1 then
                set DuelistWest=d.replacement
            endif
        elseif team==1 then
            call GroupAddUnit(TeamEastHeroes,d.replacement)
            if duelist==2 then
                set DuelistEast=d.replacement
            endif
        elseif team==2 then
            call GroupAddUnit(TeamSoloHeroes,d.replacement)
        endif
        call SetUnitMaxState(d.replacement,MaxLife,stats[7])
        call BJDebugMsg(I2S(stats[7]))
        call SetUnitMaxState(d.replacement,MaxMana,stats[8])
        call BJDebugMsg(I2S(stats[8]))
        call SetHeroAgi(d.replacement,stats[0],false)
        call SetHeroInt(d.replacement,stats[1],false)
        call SetHeroStr(d.replacement,stats[2],false)
        if stats[3]!=1 then
            call SetHeroLevel(d.replacement,stats[3],false)
        endif
        call SetHeroXP(d.replacement,stats[4],false)
        call SetUnitState(d.replacement,Life,stats[5])
        call SetUnitState(d.replacement,Mana,stats[6])
        if GetLocalPlayer()==p then
            call SelectUnit(d.replacement,true)
        endif
        set temp=null
        return d
    endmethod
    
    method onDestroy takes nothing returns nothing
        local integer i=1
        local integer i2=1
        local unit u=.replacement
        local real x=GetUnitX(u)
        local real y=GetUnitY(u)
        local player p=GetOwningPlayer(u)
        local real face=GetUnitFacing(u)
        local integer team=0 // Used to see what team the hero is in.
        local integer duelist=0 // Used to see if the hero is a duelist.
        local integer array stats // Stores various stats of the hero.
        set stats[0]=GetHeroAgi(u,true) // Get the morphed heroes stats, level etc.
        set stats[1]=GetHeroInt(u,true)
        set stats[2]=GetHeroStr(u,true)
        set stats[3]=GetHeroLevel(u)
        set stats[4]=GetHeroXP(u)
        set stats[5]=R2I(GetUnitState(u,Life))
        set stats[6]=R2I(GetUnitState(u,Mana))
        set stats[7]=R2I(GetUnitState(u,MaxLife))
        set stats[8]=R2I(GetUnitState(u,MaxMana))
        if IsUnitInGroup(u,TeamWestHeroes) then // Checks if morphed hero is a duelist,
            set team=0                    // and what groups it's currently in.
            if u==DuelistWest then
                set duelist=1
            endif
        elseif IsUnitInGroup(u,TeamEastHeroes) then
            set team=1
            if u==DuelistEast then
                set duelist=2
            endif
        elseif IsUnitInGroup(u,TeamSoloHeroes) then
            set team=2
        endif
        call RemoveUnit(u)
        call SetUnitOwner(.caster,p,true) // Change ownership back to the player.        
        call SetUnitX(.caster,x) // The x of Game start point.
        call SetUnitY(.caster,y) // The y of Game start point.
        call IssueImmediateOrder(.caster,"stop")
        call SetUnitVertexColor(.caster,255,255,255,255)
        call RemoveUnit(SESDummy[GetPlayerId(p)])
        set PlayerHero[GetPlayerId(p)]=.caster // Make new hero the actual 
        if team==0 then                               // player's hero.
            call GroupAddUnit(TeamWestHeroes,.caster)
            if duelist==1 then
                set DuelistWest=.caster
            endif
        elseif team==1 then
            call GroupAddUnit(TeamEastHeroes,.caster)
            if duelist==2 then
                set DuelistEast=.caster
            endif
        elseif team==2 then
            call GroupAddUnit(TeamSoloHeroes,.caster)
        endif
        call SetUnitMaxState(.caster, UNIT_STATE_MAX_LIFE, stats[7])
        call SetUnitMaxState(.caster, UNIT_STATE_MAX_MANA, stats[8])
        call SetHeroAgi(.caster,stats[0],true)
        call SetHeroInt(.caster,stats[1],true)
        call SetHeroStr(.caster,stats[2],true)
        if stats[3]!=1 then
            call SetHeroLevel(.caster,stats[3],false)
        endif
        call SetHeroXP(.caster,stats[4],false)
        call SetUnitState(.caster,UNIT_STATE_LIFE,stats[5])
        call SetUnitState(.caster,UNIT_STATE_MANA,stats[6])
        
        loop
        exitwhen i>4
            loop
            exitwhen i2&gt;.level<i>
                call SelectHeroSkill(.caster,.abil<i>)
                set i2=i2+1
            endloop
            set i2=0
            set i=i+1
        endloop
        
        if GetLocalPlayer()==p then
            call SelectUnit(.caster,true)
        endif
    endmethod
endstruct

private function PeriodicFunc takes nothing returns boolean
    local Data d=KT_GetData()
    call SetUnitFacing(d.caster,GetUnitFacing(d.replacement))
    if not IsUnitPaused(d.replacement) then
        set d.ticks=d.ticks-1
    endif
    if d.ticks==1400 then
        call RemoveUnit(d.target)
        call SetPlayerAllianceStateBJ(Aggressive,Passive,bj_ALLIANCE_NEUTRAL)
    endif
    if d.ticks&lt;=0 then  
        call d.destroy()
        return true
    else
        return false
    endif  
endfunction 

private function a takes nothing returns boolean
    local unit u=GetTriggerUnit()
    if GetOwningPlayer(u)!=Aggressive then
        call KT_Add(function PeriodicFunc,Data.create(u,GetUnitX(u),GetUnitY(u),GetSpellTargetUnit()),PERIOD)
    endif
    set u=null
    return false
endfunction

private function qwe takes nothing returns nothing
    call TriggerAddCondition(GT_RegisterStartsEffectEvent(CreateTrigger(),ID),Condition(function a)) 
endfunction

endscope</i></i>
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top