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

[vJASS] Hero to Unit Spell

Status
Not open for further replies.
I have been attempting to convert this spell to a unit spell instead of a hero spell that relies on the learn string.

JASS:
//*********************************************************************************************************
//*                                                                                                       *
//*                                      Wolf's Adaptation                                                *
//*                                        by Spinnaker                                                   *
//*                                                                                                       *
//********************************************************************************************************* 
    
    //* Trig                             Global trigger to manipulate damage dealing properly,
    //*                                  since it interferes with other triggers.
    //* AdaptationGroup                  Global group for heroes with learnt skill.
    //* EyeCandy                         Global group for summoned wolf shadows.
    //* CandyAlpha                       Stores current transparency for given shadow.
    //* AntiSpam                         Additional cariable for controlling amount of wofls spawned.
    //* MSInstance                       Current movement instance for hero.
    //* AdaptationTarget                 Stores current target for given hero.
    //* ASDur                            Stores duration for attack speed efect. Removes bonus if reaches 0.
    //* MSReset                          Stores duration for reseting movement bonus.
    //*                                  If reaches 0, all instances are reseted.
    //* ASAdd                            Stores duration after which bonus ms instancance will be added.
    //* ASRemove                         Stores duration after which one instance will be removed.
    
    globals
    
        trigger Trig                                    = CreateTrigger()
        group AdaptationGroup                           = CreateGroup()
        group EyeCandy                                  = CreateGroup()
        integer array CandyAlpha
        integer array AntiSpam
        integer array MSInstance
        unit array AdaptationTarget
        real array ASDur
        real array MSReset
        real array MSAdd
        real array MSRemove
        
    //* ANTI_SPAM_CONSTANT               Amount of loops required to run for each one wolf created.
    //* AS_MAX_INSTANCE                  Maximum amount of attack speed instances. Requires object editor work.
    //* MS_MAX_INSTANCE                  Maximum of movement speed instances.
    //* ADAPTATION_DUMMY_ID              Rawcode of dummy shadow.
    //* ADAPTATION_AS_ID                 Rawcode of attack speed dummy ability.
    //* ADAPTATION_LEARN_ID              Rawcode of main ability.
    //* ADAPTATION_INTERVAL              Interval of adaptation's function executing.
        
        constant integer ANTI_SPAM_CONSTANT             = 3
        constant integer AS_MAX_INSTANCE                = 10
        constant integer MS_MAX_INSTANCE                = 10
        constant integer ADAPTATION_DUMMY_ID            = 'h9WZ'
        constant integer ADAPTATION_AS_ID               = 'A9WZ'
        constant integer ADAPTATION_LEARN_ID            = 'A9ZF'
        constant real ADAPTATION_INTERVAL               = 0.03125
        
    endglobals

    
    
    //* Number of seconds without attacking needed to reset attack speed buff.
    function GetAsDuration takes nothing returns real
        return 5.
    endfunction

    //* bonus movement speed added per instance.
    function GetMsBonus takes nothing returns real
        return 12.
    endfunction

    //* Number of seconds without moving needed to reset movement speed buff.
    function GetMsDuration takes nothing returns real
        return 3.
    endfunction

    //* Number of seconds moving required to add single instance.
    function GetMsAddInterval takes nothing returns real
        return 1.
    endfunction

    //* Number of seconds moving required to remove single instance.
    function GetMsRemoveInterval takes nothing returns real
        return 0.5
    endfunction

    //* Fade time of each shadow.
    function GetEyeCandyFadeTime takes nothing returns real
        return 1.
    endfunction

    
    
//* Code itself. I recommend to not touch it.  
function EyeCandy_Group_Loop takes nothing returns nothing
    local unit u = GetEnumUnit()
    local integer key = GetUnitUserData(u)
    local real time = GetEyeCandyFadeTime()
    
    if CandyAlpha[key] > 0 then
        set CandyAlpha[key] = CandyAlpha[key] - (255 / R2I(time / ADAPTATION_INTERVAL))
        call SetUnitVertexColor(u, 125, 125, 125, CandyAlpha[key])
    else
        call GroupRemoveUnit(EyeCandy, u)
        call RemoveUnit(u)
    endif
    
    set u = null
endfunction

function Adaptation_Group_Loop takes nothing returns nothing
    local unit u = GetEnumUnit()
    local integer key = GetUnitUserData(u)
    local integer key2
    local integer levelas = GetUnitAbilityLevel(u, ADAPTATION_AS_ID)
    local real ms = GetUnitMoveSpeed(u)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    
    if ASDur[key] <= 0. then
        if levelas > 1 then
            call SetUnitAbilityLevel(u, ADAPTATION_AS_ID, 1)
            set AdaptationTarget[key] = null
        endif
    else
        set ASDur[key] = ASDur[key] - ADAPTATION_INTERVAL
    endif
    if udg_UnitMoving[key] then
        if AntiSpam[key] == ANTI_SPAM_CONSTANT then
            set bj_lastCreatedUnit = CreateUnit(GetOwningPlayer(u), ADAPTATION_DUMMY_ID, x, y, GetUnitFacing(u))
            call SetUnitAnimationByIndex(bj_lastCreatedUnit, 2)
            call SetUnitTimeScale(bj_lastCreatedUnit, 0.5)
            call GroupAddUnit(EyeCandy, bj_lastCreatedUnit)
            set key2 = GetUnitUserData(bj_lastCreatedUnit)
            set CandyAlpha[key2] = 255
            set AntiSpam[key] = 0
        else
            set AntiSpam[key] = AntiSpam[key] + 1
        endif
        if MSAdd[key] >= GetMsAddInterval() then
            if MSInstance[key] < MS_MAX_INSTANCE then
                call SetUnitMoveSpeed(u, ms + GetMsBonus())
                set MSInstance[key] = MSInstance[key] + 1
                set MSAdd[key] = 0.
                set MSRemove[key] = 0.
                set MSReset[key] = 0.
            endif
        else
            set MSAdd[key] = MSAdd[key] + ADAPTATION_INTERVAL
        endif
    else
        if MSReset[key] >= GetMsDuration() then
            call SetUnitMoveSpeed(u, ms - (MSInstance[key] * GetMsBonus()))
            set MSInstance[key] = 0
            set MSAdd[key] = 0.
            set MSRemove[key] = 0.
            set MSReset[key] = 0.
        elseif MSRemove[key] >= GetMsRemoveInterval() then
            if MSInstance[key] > 0 then
                call SetUnitMoveSpeed(u, ms - GetMsBonus())
                set MSInstance[key] = MSInstance[key] - 1
                set MSAdd[key] = 0.
                set MSRemove[key] = 0.
            endif
        else
            set MSRemove[key] = MSRemove[key] + ADAPTATION_INTERVAL
            set MSReset[key] = MSReset[key] + ADAPTATION_INTERVAL
        endif
    endif
    
    set u = null
endfunction

function For_Group takes nothing returns nothing
    call ForGroup(AdaptationGroup, function Adaptation_Group_Loop)
    call ForGroup(EyeCandy, function EyeCandy_Group_Loop)
endfunction

function GetWolf_Actions takes unit u returns nothing
    local integer key = GetUnitUserData(u)
    
    set AdaptationTarget[key] = null
    set ASDur[key] = 0.
    set MSReset[key] = 0.
    set MSAdd[key] = 0.
    set MSRemove[key] = 0.
    set MSInstance[key] = 0
    set AntiSpam[key] = 0
    call UnitAddAbility(u, ADAPTATION_AS_ID)
    call GroupAddUnit(AdaptationGroup, u)
endfunction

function WolfsAdaptation_Conditions takes nothing returns boolean
    return IsUnitInGroup(udg_GDD_DamageSource, AdaptationGroup)
endfunction

function WolfsAdaptation_Actions takes nothing returns nothing
    local integer key = GetUnitUserData(udg_GDD_DamageSource)
    local integer level = GetUnitAbilityLevel(udg_GDD_DamageSource, ADAPTATION_AS_ID)
    
    set ASDur[key] = GetAsDuration()
    if (not (AdaptationTarget[key] == null)) then
        if AdaptationTarget[key] == udg_GDD_DamagedUnit then
            if level < AS_MAX_INSTANCE + 1 then
                call IncUnitAbilityLevel(udg_GDD_DamageSource, ADAPTATION_AS_ID)
            endif
        else
            call SetUnitAbilityLevel(udg_GDD_DamageSource, ADAPTATION_AS_ID, level / 2)
            set AdaptationTarget[key] = udg_GDD_DamagedUnit
        endif
    else
        set AdaptationTarget[key] = udg_GDD_DamagedUnit
    endif
endfunction

//===========================================================================
function Wolfs_Adaptation_Actions takes nothing returns nothing
    local trigger t2 = CreateTrigger()
    
    call TriggerRegisterVariableEvent(Trig, "udg_GDD_Event", EQUAL, 0 )
    call TriggerAddCondition(Trig, Condition( function WolfsAdaptation_Conditions))
    call TriggerAddAction(Trig, function WolfsAdaptation_Actions )
    call TriggerRegisterTimerEvent(t2, ADAPTATION_INTERVAL, true)
    call TriggerAddAction(t2, function For_Group)
    
    set t2 = null
endfunction

function InitTrig_Wolfs_Adaptation takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, 0.00, false)
    call TriggerAddAction(t, function Wolfs_Adaptation_Actions)
    set t = null
    call Preload("war3mapimported\\dummy.mdx")
endfunction

struct WolfsAdapation_EnterStruct extends array
    static method AIDS_filter takes unit u returns boolean
        if GetUnitTypeId(u)=='u3RA' then
            call GetWolf_Actions(u)
        endif
        return false
    endmethod
    //! runtextmacro AIDS()
endstruct
 
Status
Not open for further replies.
Top