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

[JASS] [SPELL HELP] ChainStormBolt

Status
Not open for further replies.
Level 2
Joined
Nov 7, 2007
Messages
8
Ok, I need some help with this spell bcoz I want to replace the "ChainTarget" global variable with a local variable n then work with tables, etc. Here's the code:
JASS:
scope ChainStormBolt //I want to make this spell MUI
globals                             
unit ChainTarget
endglobals
private function Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'Aisb' )
endfunction

private function Target_Conditions takes nothing returns boolean
    return GetIssuedOrderId() == String2OrderIdBJ("sleep")
endfunction

private function Target_Actions takes nothing returns nothing
    set ChainTarget = GetOrderTargetUnit()
endfunction

private function Chain_Group takes nothing returns boolean
    local timer tr = GetExpiredTimer()
    local string s = GetAttachmentTable(tr)
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTableUnit(s, "u")))== true and GetFilterUnit() != ChainTarget and IsUnitAliveBJ(GetFilterUnit()) == true and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) == false
endfunction

private function Timer_Actions takes nothing returns nothing
    local timer tr = GetExpiredTimer()
    local string s = GetAttachmentTable(tr)
    local unit u = GetTableUnit(s, "u")
    local unit a = GetTableUnit(s, "a")
    local real height = GetTableReal(s, "height")
    local real time = GetTableReal(s, "time")
    local real raisetime = GetTableReal(s, "raisetime")
    local integer counter = GetTableInt(s, "counter")
    local integer lvl = GetTableInt(s, "level")
    local unit temp
    call UnitAddAbility(a,'Acsb')
    call SetUnitPositionLoc( a, PolarProjectionBJ(GetUnitLoc(a), 7.00, AngleBetweenPoints(GetUnitLoc(a), GetUnitLoc(ChainTarget))) )
    if ( DistanceBetweenPoints(GetUnitLoc(a), GetUnitLoc(ChainTarget)) <= 50.00 ) then
        call SetTableInt(s, "counter", counter+1)
        if ( IsUnitIdType(GetUnitTypeId(ChainTarget), UNIT_TYPE_FLYING) == true ) then
            call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Orc\\LightningBolt\\LightningBoltMissile.mdl",ChainTarget,"origin" ))
        else
            call DestroyEffect(AddSpecialEffectTarget( "Abilities\\Spells\\Orc\\LightningBolt\\LightningBoltMissile.mdl",ChainTarget,"origin"))
    
        endif
        set temp= CreateUnitAtLoc( GetOwningPlayer(u), 'e004', PolarProjectionBJ(GetUnitLoc(ChainTarget), 100.00, 0.00), AngleBetweenPoints(PolarProjectionBJ(GetUnitLoc(ChainTarget), 100.00, 0.00), GetUnitLoc(ChainTarget)) )
        call SetUnitInvulnerable( temp, true )
        call UnitAddAbility(temp,'Acss')
        call SetUnitAbilityLevel(temp,'Acss',lvl)
        call IssueTargetOrder( temp, "thunderbolt", ChainTarget )
        //call BJDebugMsg("CHAINIMPACT")
        call RemoveUnitTimed(temp,1.5)
        set ChainTarget = GroupPickRandomUnit(GetUnitsInRangeOfLocMatching(800, GetUnitLoc(ChainTarget), Condition(function Chain_Group)))
        set height = GetUnitDefaultFlyHeight(ChainTarget)
        if (height < 40) then
            set height = 40
        endif
        if (ChainTarget == null) then
            set counter = 2 + (lvl * 3)
        endif
        set time = DistanceBetweenPoints(GetUnitLoc(a), GetUnitLoc(ChainTarget)) / 2000
        set raisetime = (RAbsBJ(height - GetUnitFlyHeight(a))) / time
        call SetUnitFlyHeightBJ( a, height, raisetime )
        if (counter == 2 + (lvl * 3) ) then
            //call BJDebugMsg("CHAINEND")
            call PauseTimer(tr)
            call DestroyTimer(tr)
            call ClearTable(s)
            call UnitRemoveAbility( a, 'Aloc' )
            call RemoveUnit(a)
        endif
    endif
set tr=null
endfunction
private function Actions takes nothing returns nothing
    local timer tr=CreateTimer()
    local string s = GetAttachmentTable(tr)
    local unit u=GetSpellAbilityUnit()
    local real height=GetUnitDefaultFlyHeight(ChainTarget)
    local real time
    local real raisetime
    local integer lvl = GetUnitAbilityLevel(u,'Aisb')
    local unit a
    set a= CreateUnit(GetOwningPlayer(u), 'e004', GetUnitX(u),GetUnitY(u), GetUnitFacing(u) )
    set time=DistanceBetweenPoints(GetUnitLoc(a), GetUnitLoc(ChainTarget)) / 2000
    set raisetime=(RAbsBJ(height - GetUnitFlyHeight(a))) / time
    call SetTableObject(s, "u", u)
    call SetTableObject(s, "a", a)
    call SetTableReal(s, "height",height )
    call SetTableReal(s, "time", time)
    call SetTableReal(s, "raisetime", raisetime)
    call SetTableInt(s, "counter", 0)
    call SetTableInt(s, "level", lvl)
    call SetUnitInvulnerable( a, true )
    call SetUnitPathing( a, false )
    call UnitAddAbility( a,'Aloc')    
    call TimerStart(tr, 0.01,true, function Timer_Actions)
    if (height < 40) then
        set height = 40
    endif
    call SetUnitFlyHeightBJ( a, height, raisetime )
endfunction
//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trg=CreateTrigger(  )
    local trigger issued = CreateTrigger(  )
    set gg_trg_ChainStormBolt = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trg, Condition( function Conditions ) )
    call TriggerAddAction( trg, function Actions )
    call TriggerRegisterAnyUnitEventBJ( issued, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddCondition( issued, Condition( function Target_Conditions ) )
    call TriggerAddAction( issued, function Target_Actions )
set trg=null
set issued=null
endfunction
endscope
*Thanks
 
Last edited:
Status
Not open for further replies.
Top