• 🏆 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] Problem with a Spell

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,852
I made this spell based on Steal Spell:
JASS:
scope SpellSteal initializer Init

globals
    private integer array Spell_Stealed
    private integer array Base_Spell_NH
    private integer array Base_Spell_H
    private integer array What_Spell
    private integer array Counter
    private integer array Last_Spell
endglobals

private function Remove takes nothing returns nothing
    local integer i=GetTimerData(GetExpiredTimer())
    local RageAttack t
    set Counter[i]=Counter[i]-1
    if Counter[i]==0 then
        call UnitRemoveAbility(udg_UDexUnits[i],What_Spell[i])
        if What_Spell[i]=='A08T' then
            set t=RA_Instance[i]
            call t.destroy()
        endif
        call ReleaseTimer(GetExpiredTimer())
    endif
endfunction

struct SpellSteal
 
    unit caster
    unit target
    player owner
    boolean llego
    integer steal
    integer lvl
    integer duration
    integer counter
    unit head
    unit tail
    real prevdistance
    real prevangle
    effect myeffect1
    unit myeffect2
    lightning l1
    lightning l2
    lightning l3
    timer t
 
    static method create takes unit caster, unit target returns thistype
        local thistype this=thistype.allocate()
        local real x=GetUnitX(target)
        local real y=GetUnitY(target)
        local player p=GetOwningPlayer(caster)
        set this.caster=caster
        set this.target=target
        set this.owner=GetOwningPlayer(this.target)
        set this.llego=false
        set this.steal=Last_Spell[GetUnitUserData(target)]
        set this.lvl=GetUnitAbilityLevel(target,this.steal)
        set this.duration=60*(GetUnitAbilityLevel(caster,Spell)+2)
        set this.counter=0
        set this.head=CreateUnit(p,'h00V',x,y,bj_UNIT_FACING)
        set this.tail=CreateUnit(p,'h00V',x,y,bj_UNIT_FACING)
        call SetUnitMoveSpeed(this.head,900)
        call SetUnitMoveSpeed(this.tail,900)
        set this.prevdistance=0.00
        set this.prevangle=0.00
        set this.myeffect2=CreateUnit(p,'h00U',x,y,bj_UNIT_FACING)
        call SetUnitVertexColor(this.myeffect2,216,0,255,255)
        set this.l1=AddLightningEx("DRAM",true,x,y,0,x,y,0)
        call SetLightningColor(this.l1,0.84,0.00,1.00,1.00)
        set this.l2=AddLightningEx("HWPB",true,x,y,0,x,y,0)
        call SetLightningColor(this.l2,0.84,0.00,1.00,1.00)
        set this.l3=AddLightningEx("DRAM",true,x,y,0,x,y,0)
        call SetLightningColor(this.l3,0.84,0.00,1.00,1.00)
        set this.t=NewTimerEx(this)
        call TimerStart(this.t,0.01,true,function thistype.callperiodic)
        return this
    endmethod
 
    method period takes nothing returns nothing
        local location l1
        local location l2
        local location l3
        local real x1
        local real y1
        local real z1
        local real x2
        local real y2
        local real z2
        call SetUnitPosition(this.myeffect2,GetUnitX(this.target),GetUnitY(this.target))
        if counter==150 then
            call RemoveUnit(this.myeffect2)
        endif
        set l1=GetUnitLoc(this.head)
        set l2=GetUnitLoc(this.caster)
        if this.llego==false then
            if DistanceBetweenPoints(l1,l2)<200 then
                set this.myeffect1=AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DeathPact\\DeathPactCaster.mdl",caster,"origin")
                set this.llego=true
            endif
        else
            if DistanceBetweenPoints(l1,l2)>200 then
                call SetUnitPositionLoc(this.head,l2)
                call RemoveLocation(l1)
                set l1=GetUnitLoc(this.tail)
                set l3=PolarProjectionBJ(l2,this.prevdistance,this.prevangle)
                call SetUnitPositionLoc(this.tail,l3)
                call RemoveLocation(l3)
            endif
        endif
        call RemoveLocation(l1)
        set l1=GetUnitLoc(this.tail)
        set this.prevdistance=DistanceBetweenPoints(l1,l2)
        set this.prevangle=AngleBetweenPoints(l2,l1)
        call RemoveLocation(l1)
        call IssuePointOrder(this.head,"move",GetUnitX(this.caster),GetUnitY(this.caster))
        set x1=GetUnitX(this.tail)
        set y1=GetUnitY(this.tail)
        set z1=GetUnitZ(this.tail)
        set x2=GetUnitX(this.head)
        set y2=GetUnitY(this.head)
        set z2=GetUnitZ(this.head)
        call MoveLightningEx(this.l1,true,x1,y1,z1+50,x2,y2,z2+50)
        call MoveLightningEx(this.l2,true,x1,y1,z1+70,x2,y2,z2+70)
        call MoveLightningEx(this.l3,true,x1,y1,z1+90,x2,y2,z2+90)
        set l1=GetUnitLoc(this.tail)
        if DistanceBetweenPoints(l1,l2)<200 then
            call this.destroy()
        endif
        call RemoveLocation(l2)
        set l1=null
        set l2=null
        set l3=null
    endmethod
 
    static method callperiodic takes nothing returns nothing
        local thistype this=GetTimerData(GetExpiredTimer())
        if this.counter<150 then
            call SetUnitPosition(this.myeffect2,GetUnitX(this.target),GetUnitY(this.target))
            set this.counter=this.counter+1
        else
            call IssuePointOrder(this.tail,"move",GetUnitX(this.head),GetUnitY(this.head))
        endif
        call this.period()
    endmethod
 
    method destroy takes nothing returns nothing
        local boolean b=false
        local integer u=0
        local integer j=GetUnitUserData(this.caster)
        local RageAttack t
        local integer lvl
        //Select the spell
        loop
            exitwhen u>77 or b
            if this.steal==Base_Spell_NH[u] or this.steal==Base_Spell_H[u] then
                set b=true
                call UnitRemoveAbility(this.caster,What_Spell[j])
                if udg_Modo[5]!="Classic (Not leveling up)." then
                    if SubString(GetObjectName(Spell_Stealed[u]),0,3)=="Ult" then
                        set this.lvl=this.lvl+1
                        if u==44 then
                            set RA_Instance[j]=RageAttack.create(this.caster,'A04L')
                            set t=RA_Instance[j]
                            call t.update()
                        endif
                    else
                        set this.lvl=this.lvl+2
                    endif
                endif
                call UnitAddAbility(this.caster,Spell_Stealed[u])
                call SetUnitAbilityLevel(this.caster,Spell_Stealed[u],this.lvl)
                set What_Spell[j]=Spell_Stealed[u]
            endif
            set u=u+1
        endloop
        if Counter[j]==0 then
            call TimerStart(NewTimerEx(j),1.00,true,function Remove)
        endif
        set Counter[j]=this.duration
        //-- --
        call ReleaseTimer(this.t)
        call DestroyEffect(this.myeffect1)
        call RemoveUnit(this.myeffect2)
        call DestroyLightning(this.l1)
        call DestroyLightning(this.l2)
        call DestroyLightning(this.l3)
        call RemoveUnit(this.head)
        call RemoveUnit(this.tail)
        set this.caster=null
        set this.target=null
        set this.myeffect1=null
        set this.myeffect2=null
        set this.head=null
        set this.tail=null
        set this.l1=null
        set this.l2=null
        set this.l3=null
        call this.deallocate()
    endmethod
endstruct

//-- --

private function Conditions takes nothing returns boolean
    return Spell=='A08L' or Spell=='A08M'
endfunction

private function Actions takes nothing returns nothing
    call SpellSteal.create(Caster,GetSpellTargetUnit())
endfunction

//-- --

private function Is_Hero takes nothing returns boolean
    return IsUnitType(Caster,UNIT_TYPE_HERO)
endfunction

private function Register takes nothing returns nothing
    local boolean b=false
    local integer temp=Spell
    local integer i=0
    loop
        exitwhen i>77 or b
        if temp==Base_Spell_NH[i] or temp==Base_Spell_H[i] then
            set b=true
            set Last_Spell[GetUnitUserData(Caster)]=temp
        endif
        set i=i+1
    endloop
endfunction

//-- --

private function Conditions_What takes nothing returns boolean
    if Spell!='A08L' then
        return false
    elseif Spell!='A08M' then
        return false
    elseif GetUnitTypeId(GetSpellTargetUnit())!='H00X' then
        return false
    elseif GetUnitTypeId(GetSpellTargetUnit())!='H00W' then
        return false
    endif
    return true
endfunction

private function Actions_What takes nothing returns nothing
    call IssueTargetOrder(Caster,"attack",Caster)
    call ErrorMessage("Wait, Why?",GetOwningPlayer(Caster))
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t,Condition(function Conditions_What))
    call TriggerAddAction(t,function Actions_What)
    //dem
    set Spell_Stealed[0]='A09C'
    set Base_Spell_NH[0]='A011'
    set Base_Spell_H[0]='A03L'
    set Spell_Stealed[1]='A0A1'
    set Base_Spell_NH[1]='A04T'
    set Base_Spell_H[1]='A04P'
    //da
    set Spell_Stealed[2]='A098'
    set Base_Spell_NH[2]='A006'
    set Base_Spell_H[2]='A03I'
    set Spell_Stealed[3]='A026'
    set Base_Spell_NH[3]='A02S'
    set Base_Spell_H[3]='A03A'
    set Spell_Stealed[4]='A075'
    set Base_Spell_NH[4]='A075'
    set Base_Spell_H[4]='A075'
    set Spell_Stealed[5]='A09M'
    set Base_Spell_NH[5]='A02P'
    set Base_Spell_H[5]='A03X'
    //her
    set Spell_Stealed[6]='A05N'
    set Base_Spell_NH[6]='A00N'
    set Base_Spell_H[6]='A044'
    set Spell_Stealed[7]='A08R'
    set Base_Spell_NH[7]='A001'
    set Base_Spell_H[7]='A035'
    set Spell_Stealed[8]='A063'
    set Base_Spell_NH[8]='A05W'
    set Base_Spell_H[8]='A05X'
    set Spell_Stealed[9]='A027'
    set Base_Spell_NH[9]='A02Z'
    set Base_Spell_H[9]='A046'
    //dseer
    set Spell_Stealed[10]='A08S'
    set Base_Spell_NH[10]='A002'
    set Base_Spell_H[10]='A036'
    set Spell_Stealed[11]='A08Z'
    set Base_Spell_NH[11]='A007'
    set Base_Spell_H[11]='A03C'
    set Spell_Stealed[12]='A09B'
    set Base_Spell_NH[12]='A04V'
    set Base_Spell_H[12]='A04R'
    //dz
    set Spell_Stealed[13]='A09S'
    set Base_Spell_NH[13]='A07N'
    set Base_Spell_H[13]='A087'
    set Spell_Stealed[14]='A00J'
    set Base_Spell_NH[14]='A07O'
    set Base_Spell_H[14]='A085'
    set Spell_Stealed[15]='A00O'
    set Base_Spell_NH[15]='A07P'
    set Base_Spell_H[15]='A088'
    //ES
    set Spell_Stealed[16]='A05Y'
    set Base_Spell_NH[16]='A004'
    set Base_Spell_H[16]='A039'
    set Spell_Stealed[17]='A090'
    set Base_Spell_NH[17]='A00P'
    set Base_Spell_H[17]='A03D'
    //Sala
    set Spell_Stealed[18]='A09U'
    set Base_Spell_NH[18]='A00T'
    set Base_Spell_H[18]='A040'
    set Spell_Stealed[19]='A08X'
    set Base_Spell_NH[19]='A00S'
    set Base_Spell_H[19]='A03B'
    set Spell_Stealed[20]='A097'
    set Base_Spell_NH[20]='A072'
    set Base_Spell_H[20]='A073'
    //SW
    set Spell_Stealed[21]='A028'
    set Base_Spell_NH[21]='A01L'
    set Base_Spell_H[21]='A01K'
    set Spell_Stealed[22]='A08Y'
    set Base_Spell_NH[22]='A01M'
    set Base_Spell_H[22]='A01N'
    set Spell_Stealed[23]='A02R'
    set Base_Spell_NH[23]='A01Q'
    set Base_Spell_H[23]='A01S'
    //Pr
    set Spell_Stealed[24]='A09R'
    set Base_Spell_NH[24]='A07I'
    set Base_Spell_H[24]='A081'
    set Spell_Stealed[25]='A09G'
    set Base_Spell_NH[25]='A07F'
    set Base_Spell_H[25]='A082'
    set Spell_Stealed[26]='A09Q'
    set Base_Spell_NH[26]='A07E'
    set Base_Spell_H[26]='A083'
    set Spell_Stealed[27]='A09P'
    set Base_Spell_NH[27]='A07G'
    set Base_Spell_H[27]='A084'
    //Anch
    set Spell_Stealed[28]='A08W'
    set Base_Spell_NH[28]='A05T'
    set Base_Spell_H[28]='A05S'
    set Spell_Stealed[29]='A0A0'
    set Base_Spell_NH[29]='A05G'
    set Base_Spell_H[29]='A05J'
    set Spell_Stealed[30]='A05P'
    set Base_Spell_NH[30]='A05P'
    set Base_Spell_H[30]='A05P'
    set Spell_Stealed[31]='A09N'
    set Base_Spell_NH[31]='A05U'
    set Base_Spell_H[31]='A05V'
    //Blood
    set Spell_Stealed[32]='A08U'
    set Base_Spell_NH[32]='A07B'
    set Base_Spell_H[32]='A038'
    set Spell_Stealed[33]='A099'
    set Base_Spell_NH[33]='A005'
    set Base_Spell_H[33]='A03J'
    set Spell_Stealed[34]='A08P'
    set Base_Spell_NH[34]='A02Y'
    set Base_Spell_H[34]='A04K'
    //Caci
    set Spell_Stealed[35]='A09L'
    set Base_Spell_NH[35]='A00F'
    set Base_Spell_H[35]='A03W'
    set Spell_Stealed[36]='A08X'
    set Base_Spell_NH[36]='A014'
    set Base_Spell_H[36]='A049'
    set Spell_Stealed[37]='A091'
    set Base_Spell_NH[37]='A030'
    set Base_Spell_H[37]='A04N'
    set Spell_Stealed[38]='A0A5'
    set Base_Spell_NH[38]='A022'
    set Base_Spell_H[38]='A025'
    //Spec
    set Spell_Stealed[39]='A08Q'
    set Base_Spell_NH[39]='A01W'
    set Base_Spell_H[39]='A01X'
    set Spell_Stealed[40]='A09Y'
    set Base_Spell_NH[40]='A01Y'
    set Base_Spell_H[40]='A01Z'
    set Spell_Stealed[41]='A0A8'
    set Base_Spell_NH[41]='A01T'
    set Base_Spell_H[41]='A01O'
    set Spell_Stealed[42]='A069'
    set Base_Spell_NH[42]='A069'
    set Base_Spell_H[42]='A069'
    set Spell_Stealed[43]='A09T'
    set Base_Spell_NH[43]='A05K'
    set Base_Spell_H[43]='A068'
    //Doom
    set Spell_Stealed[44]='A08T'
    set Base_Spell_NH[44]='A02Q'
    set Base_Spell_H[44]='A04L'
    set Spell_Stealed[45]='A094'
    set Base_Spell_NH[45]='A00W'
    set Base_Spell_H[45]='A03F'
    set Spell_Stealed[46]='A09I'
    set Base_Spell_NH[46]='A00V'
    set Base_Spell_H[46]='A03T'
    //Sor
    set Spell_Stealed[47]='A09Z'
    set Base_Spell_NH[47]='A00K'
    set Base_Spell_H[47]='A047'
    set Spell_Stealed[48]='A09F'
    set Base_Spell_NH[48]='A009'
    set Base_Spell_H[48]='A03Q'
    set Spell_Stealed[49]='A09H'
    set Base_Spell_NH[49]='A00A'
    set Base_Spell_H[49]='A03R'
    set Spell_Stealed[50]='A077'
    set Base_Spell_NH[50]='A077'
    set Base_Spell_H[50]='A077'
    set Spell_Stealed[51]='A09J'
    set Base_Spell_NH[51]='A04S'
    set Base_Spell_H[51]='A04M'
    //Inf
    set Spell_Stealed[52]='A09U'
    set Base_Spell_NH[52]='A00T'
    set Base_Spell_H[52]='A040'
    set Spell_Stealed[53]='A0A3'
    set Base_Spell_NH[53]='A010'
    set Base_Spell_H[53]='A00D'
    set Spell_Stealed[54]='A092'
    set Base_Spell_NH[54]='A04W'
    set Base_Spell_H[54]='A048'
    //Maid
    set Spell_Stealed[55]='A09L'
    set Base_Spell_NH[55]='A00F'
    set Base_Spell_H[55]='A03W'
    set Spell_Stealed[56]='A09D'
    set Base_Spell_NH[56]='A013'
    set Base_Spell_H[56]='A03O'
    set Spell_Stealed[57]='A09K'
    set Base_Spell_NH[57]='A00H'
    set Base_Spell_H[57]='A03V'
    set Spell_Stealed[58]='A0A2'
    set Base_Spell_NH[58]='A04Y'
    set Base_Spell_H[58]='A04I'
    set Spell_Stealed[59]='A0A5'
    set Base_Spell_NH[59]='A022'
    set Base_Spell_H[59]='A025'
    //Malef
    set Spell_Stealed[60]='A09E'
    set Base_Spell_NH[60]='A00E'
    set Base_Spell_H[60]='A03P'
    set Spell_Stealed[61]='A00L'
    set Base_Spell_NH[61]='A02N'
    set Base_Spell_H[61]='A03S'
    set Spell_Stealed[62]='A096'
    set Base_Spell_NH[62]='A04X'
    set Base_Spell_H[62]='A04J'
    //Axe
    set Spell_Stealed[63]='A01V'
    set Base_Spell_NH[63]='A07S'
    set Base_Spell_H[63]='A04D'
    set Spell_Stealed[64]='A09A'
    set Base_Spell_NH[64]='A07T'
    set Base_Spell_H[64]='A08E'
    set Spell_Stealed[65]='A08N'
    set Base_Spell_NH[65]='A07U'
    set Base_Spell_H[65]='A08G'
    //DW
    set Spell_Stealed[66]='A08V'
    set Base_Spell_NH[66]='A05C'
    set Base_Spell_H[66]='A05D'
    set Spell_Stealed[67]='A09O'
    set Base_Spell_NH[67]='A055'
    set Base_Spell_H[67]='A054'
    set Spell_Stealed[68]='A0A4'
    set Base_Spell_NH[68]='A056'
    set Base_Spell_H[68]='A059'
    set Spell_Stealed[69]='A0A6'
    set Base_Spell_NH[69]='A058'
    set Base_Spell_H[69]='A05A'
    set Spell_Stealed[70]='A09X'
    set Base_Spell_NH[70]='A05E'
    set Base_Spell_H[70]='A05F'
    //Lava
    set Spell_Stealed[71]='A065'
    set Base_Spell_NH[71]='A07X'
    set Base_Spell_H[71]='A08H'
    set Spell_Stealed[72]='A08O'
    set Base_Spell_NH[72]='A07Y'
    set Base_Spell_H[72]='A08I'
    set Spell_Stealed[73]='A062'
    set Base_Spell_NH[73]='A080'
    set Base_Spell_H[73]='A064'
    //Pit
    set Spell_Stealed[74]='A09W'
    set Base_Spell_NH[74]='A00X'
    set Base_Spell_H[74]='A043'
    set Spell_Stealed[75]='A09V'
    set Base_Spell_NH[75]='A00Y'
    set Base_Spell_H[75]='A042'
    set Spell_Stealed[76]='A06A'
    set Base_Spell_NH[76]='A06A'
    set Base_Spell_H[76]='A06A'
    set Spell_Stealed[77]='A095'
    set Base_Spell_NH[77]='A02V'
    set Base_Spell_H[77]='A03G'
    //-- --
    set t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t,Condition(function Is_Hero))
    call TriggerAddAction(t,function Register)
    set t=null
    //-- --
    set gg_trg_Spell_Steal=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Spell_Steal,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Spell_Steal,Condition(function Conditions))
    call TriggerAddAction(gg_trg_Spell_Steal,function Actions)
endfunction
endscope
But my problems are:
  • I wanna make a "lightning snake" that looks like that absorbs the essence of the target, to do that I use two units to the position of the head and the tail, it worked but sometimes those unit get stucked and I don't know why.
  • I made an exeption to that spell to don't cast on a unit that is the same type of the caster, but I doesn't work too.
If you ask what is that of "Caster", "Level" and "Spell" I realize that doing this:
JASS:
library EasyVariables initializer Init

globals
    unit Caster
    integer Spell
    integer Level
endglobals

private function Conditions takes nothing returns boolean
    set Caster=GetSpellAbilityUnit()
    set Spell=GetSpellAbilityId()
    set Level=GetUnitAbilityLevel(Caster,Spell)
    return false
endfunction

private function I takes nothing returns nothing
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    set gg_trg_Easy_Variables=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Easy_Variables,EVENT_PLAYER_UNIT_SPELL_CHANNEL)
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Easy_Variables,EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Easy_Variables,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Easy_Variables,EVENT_PLAYER_UNIT_SPELL_ENDCAST)
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Easy_Variables,EVENT_PLAYER_UNIT_SPELL_FINISH)
    call TriggerAddCondition(gg_trg_Easy_Variables,Condition(function Conditions))
    call TriggerAddAction(gg_trg_Easy_Variables,function I)
endfunction
endlibrary
Replace that functions to every trigger that have that same events, and no, that wasn't the problem because it happened even with the normal functions.

By the way, thank you.
 
Last edited:
Status
Not open for further replies.
Top