Spell Electric Shield

Blackrage

Ultra Cool Member
Reaction score
25
Electric Shield

I made a spell about three years ago called Shock Shield, which was coded in GUI. This is an attempt to replace it. (Plus it's my first spell submission thats in vJASS)

The caster concentrates his energy into the form of orbs that circle around him for a duration. If an orb goes near an enemy unit, the unit will be damaged and the orb will not be able to damage any enemies for 2 seconds.


Information:
-Coding Style: vJASS
-MUI/MPI: Should be MUI.


Requires:
-Jass NewGen
-GTrigger
-Timer32
-BoolexprUtils

ElectricShieldDamage.png


Can't really see the action going on in this screenshot


Code:
JASS:
scope ElectricShield initializer Init 
    //CONFIGURABLES BELOW HERE.
    //CONFIGURABLES BELOW HERE.
    //CONFIGURABLES BELOW HERE.
    globals
        //The Ability Rawcode.
        private constant integer ABIL_ID = 'A000'
        
        //The Dummy Unit's Rawcode
        private constant integer DUMMY_ID = 'n000'
        
        //The Chain Lightning Rawcode. Only needed if you set the SPELL_CAST variable to true.
        private constant integer DUMMY_SPELL_ID = 'A001'
        
        
        
        //Enable if you want the orbs to cast something instead of dealing damage via script
        private constant boolean SPELL_CAST = false
        
        
        
        
        //The height of the orbs
        private constant real ORB_HEIGHT = 50
        
        //How far away the orbs circle from the caster
        private constant real ORBIT_RADIUS = 125
        
        //How fast the orbs orbit the caster.
        private constant real ORBIT_SPEED = 10
        
        //How close a unit needs to be to the orb to get damaged
        private constant real DAMAGE_RADIUS = 125
        
        //You need to adjust this if you adjust the GetOrbAmount() function.
        private constant integer MAX_ORBS = 5
        
        
        
        //The special effect used when the orbs are ready.
        private constant string READY_SFX = "Abilities\\Spells\\Orc\\LightningBolt\\LightningBoltMissile.mdl"
        
        //The special effect used while the orbs are recharging.
        private constant string COOLDOWN_SFX = "Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl"
        
        //The special effect used when the orbs damage a unit.
        private constant string DAMAGE_SFX = "Abilities\\Weapons\\Bolt\\BoltImpact.mdl"
        
        
        
        //The attack type
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_MAGIC
        
        //The damage type
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_LIGHTNING
        
        //The weapon type
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
    endglobals
    
    private function GetDamage takes integer level returns real
        return level*20.
    endfunction
    
    private function GetOrbAmount takes integer level returns integer
        return 1+level
    endfunction
    
    private function GetDuration takes integer level returns real
        return 11.+level
    endfunction
    
    private function GetCooldown takes integer level returns real
        return 2.
    endfunction
    //CONFIGURABLES ABOVE HERE
    //CONFIGURABLES ABOVE HERE
    //CONFIGURABLES ABOVE HERE
    
    //DO NOT TOUCH PAST THIS UNLESS YOU KNOW WHAT YOU ARE DOING
    //DO NOT TOUCH PAST THIS UNLESS YOU KNOW WHAT YOU ARE DOING
    //DO NOT TOUCH PAST THIS UNLESS YOU KNOW WHAT YOU ARE DOING
    
    globals
        private group g = CreateGroup()
    endglobals
    
    private struct Shield
        unit c
        unit array d[MAX_ORBS]
        effect array e[MAX_ORBS]
        real array cooldown[MAX_ORBS]
        boolean array onCooldown[MAX_ORBS]
        integer level
        
        real durationcounter
        real rotatecounter
        
        method periodic takes nothing returns nothing
            local real x
            local real y
            local integer i = 0
            local unit u = null
            local unit d = null
            
            set .rotatecounter = .rotatecounter + ORBIT_SPEED
            
            loop
                set i = i + 1
                set x = GetUnitX(.c) + ORBIT_RADIUS * Cos((360/GetOrbAmount(.level)*i+.rotatecounter) * bj_DEGTORAD)
                set y = GetUnitY(.c) + ORBIT_RADIUS * Sin((360/GetOrbAmount(.level)*i+.rotatecounter) * bj_DEGTORAD)
                
                
                call SetUnitX(.d<i>, x)
                call SetUnitY(.d<i>, y)
                
                
                if onCooldown<i> == true then
                    set cooldown<i> = cooldown<i> - T32_PERIOD
                    if cooldown<i> &lt;= 0 then
                        set onCooldown<i> = false
                        call DestroyEffect(.e<i>)
                        set .e<i> = AddSpecialEffectTarget(READY_SFX, .d<i>, &quot;origin&quot;)
                    endif
                endif
                
                call GroupEnumUnitsInRange(g, x, y, DAMAGE_RADIUS, BOOLEXPR_TRUE)
                loop
                    set u = FirstOfGroup(g)
                    exitwhen u == null
                    call GroupRemoveUnit(g, u)
                    if IsUnitEnemy(u, GetOwningPlayer(.c)) == true and .onCooldown<i> == false and GetWidgetLife(u) &gt; 0.405 then
                        if SPELL_CAST == false then
                            call UnitDamageTarget(.c, u, GetDamage(.level), false, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
                        else
                            set d = CreateUnit(GetOwningPlayer(.c), DUMMY_ID, x, y, 0.)
                            call UnitAddAbility(d, DUMMY_SPELL_ID)
                            call SetUnitAbilityLevel(d, DUMMY_SPELL_ID, .level)
                            call IssueTargetOrder(d, &quot;chainlightning&quot;, u)
                            call UnitApplyTimedLife(d, &#039;BTLF&#039;, 1.)
                        endif
                        call DestroyEffect(AddSpecialEffect(DAMAGE_SFX, x, y))
                        call DestroyEffect(.e<i>)
                        set .e<i> = AddSpecialEffectTarget(COOLDOWN_SFX, .d<i>, &quot;origin&quot;)
                        set .cooldown<i> = GetCooldown(.level)
                        set .onCooldown<i> = true
                    endif
                endloop
                exitwhen i == MAX_ORBS
            endloop
            
            set d = null
            
            if .rotatecounter &gt;= 360 then
                set .rotatecounter = 0
            endif
            
            set .durationcounter = .durationcounter + T32_PERIOD
            if .durationcounter &gt;= GetDuration(.level) then
                call .destroy()
                call .stopPeriodic()
            endif
        endmethod
        implement T32xs
        
        method onDestroy takes nothing returns nothing
            local integer i = 0
            loop
                set i = i + 1
                call KillUnit(.d<i>)
                set .d<i> = null
                call DestroyEffect(.e<i>)
                set .e<i> = null
                exitwhen i == MAX_ORBS
            endloop
            set .c = null
        endmethod
    endstruct
    
    private function Action takes nothing returns nothing
        local Shield d = Shield.create()
        local integer i = 0
        local real x
        local real y
        set d.c = GetTriggerUnit()
        set d.level = GetUnitAbilityLevel(d.c, ABIL_ID)
        set d.rotatecounter = 0
        set d.durationcounter = 0
        loop
            set i = i + 1
            set x = GetUnitX(d.c) + ORBIT_RADIUS * Cos(360/GetOrbAmount(d.level)*i * bj_DEGTORAD)
            set y = GetUnitY(d.c) + ORBIT_RADIUS * Sin(360/GetOrbAmount(d.level)*i * bj_DEGTORAD)
            set d.d<i> = CreateUnit(GetOwningPlayer(d.c), DUMMY_ID, x, y, 0.)
            set d.e<i> = AddSpecialEffectTarget(READY_SFX, d.d<i>, &quot;origin&quot;)
            set d.cooldown<i> = 0
            set d.onCooldown<i> = false
            exitwhen i == MAX_ORBS
        endloop
        call d.startPeriodic()
    endfunction
    
    private function Init takes nothing returns nothing
        call GT_AddStartsEffectAction(function Action, ABIL_ID)
    endfunction
endscope</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>


Known Bugs:
-None


How to Implement:
-Make sure you have the 'dummy.mdl' model in your map.

-Copy the Ability and the Dummy Unit (that looks like a chicken) into your map.

-If you want the spell to cast a spell instead of damaging, add the dummy chain lightning spell OR make a different dummy spell and set the DUMMY_SPELL_ID variable to the rawcode of the spell (found using ctrl+D when in the object editor)

-Make sure that you have all the requirements met.

-Copy the spell code into your map.

Credits not necessary, but please do not act like the author of this spell.

Feedback is appreciated.
 

Attachments

  • [Spell] Electric Shield.w3x
    72.3 KB · Views: 304

Laiev

Hey Listen!!
Reaction score
188
I think you forget something

Jass/Gui = ?
MUI/MPI = ?


and yes, i know it's jass, but people don't need to open spoiler trigger to see it.
 

Laiev

Hey Listen!!
Reaction score
188
I'll confess to you, I really liked his previous spell in gui, when I needed a skill to one of my items, I found that spell, but I don't get it because it was not MUI and there were some against, for example GUI.

I tested this version and sound very good... but i found some problem or my warcraft is a bit crazy..

sometimes when the orbs die (just when you spam the spell) the damage still happen.

I see too if you cast the spell some times, the lasts created orbs have the time of the first cast... probably not a bug
 

Blackrage

Ultra Cool Member
Reaction score
25
The bug happens when you cast it multiple times with the same unit. Apparently the first cast kills the dummy units on the next casts when it ends. I don't know the cause of this bug right now though.


EDIT: Fixed. In the loop where I destroy the orbs I forgot to end the loop. Uploading the new map right now.

EDIT2: Updated.
 

HydraRancher

Truth begins in lies
Reaction score
197
>-MUI/MPI: Should be MUI. There is currently a bug though (read the known bugs list).

I scrolled down and there were "None" buggs, I dont think "None" is a bugg :p.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
And that makes a difference, how ?!

That's just more ugly, and loses readability...
 

Joker(Div)

Always Here..
Reaction score
86
There's zero difference, but Vex did say he was going to deprecate this. eventually so its not a bad idea.
 

Azlier

Old World Ghost
Reaction score
461
You can even scrap 'this.' completely and use the variable's name directly these days.
 

Blackrage

Ultra Cool Member
Reaction score
25
>-MUI/MPI: Should be MUI. There is currently a bug though (read the known bugs list).

I scrolled down and there were "None" buggs, I dont think "None" is a bugg :p.

Ah, forgot to update that. There WAS a known bug, but it was fixed.

I'll update this soon and remove all the "this.variable" stuff.


EDIT: Updated. All the "this." were removed and I also added a configuration option where you could not do the damage by trigger, but instead have a dummy cast a spell. It is off by default, but if you want to test it you can set it on.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
                call GroupEnumUnitsInRange(g, x, y, DAMAGE_RADIUS, BOOLEXPR_TRUE)
                loop
                    set u = FirstOfGroup(g)
                    exitwhen u == null
                    call GroupRemoveUnit(g, u)
                    if IsUnitEnemy(u, GetOwningPlayer(.c)) == true and .onCooldown<i> == false and GetWidgetLife(u) &gt; 0.405 then
                        if SPELL_CAST == false then
                            call UnitDamageTarget(.c, u, GetDamage(.level), false, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
                        else
                            set d = CreateUnit(GetOwningPlayer(.c), DUMMY_ID, x, y, 0.)
                            call UnitAddAbility(d, DUMMY_SPELL_ID)
                            call SetUnitAbilityLevel(d, DUMMY_SPELL_ID, .level)
                            call IssueTargetOrder(d, &quot;chainlightning&quot;, u)
                            call UnitApplyTimedLife(d, &#039;BTLF&#039;, 1.)
                        endif
                        call DestroyEffect(AddSpecialEffect(DAMAGE_SFX, x, y))
                        call DestroyEffect(.e<i>)
                        set .e<i> = AddSpecialEffectTarget(COOLDOWN_SFX, .d<i>, &quot;origin&quot;)
                        set .cooldown<i> = GetCooldown(.level)
                        set .onCooldown<i> = true
                    endif
                endloop
                exitwhen i == MAX_ORBS
            endloop
</i></i></i></i></i></i>


->

JASS:
private function PickUnitCond takes nothing returns boolean
    //stuffs here.
    return false
endfunction


2) Use a global dummy instead of creating.

JASS:
if SPELL_CAST == false then

->
JASS:
static if not SPELL_CAST then
 

Blackrage

Ultra Cool Member
Reaction score
25
I don't really get what you mean by the first part of your post. Move everything that you quoted from my code into the '//stuffs here' comment and call the function in the periodic trigger or do you mean something else?
 

scorpion182

New Member
Reaction score
5
I don't really get what you mean by the first part of your post. Move everything that you quoted from my code into the '//stuffs here' comment and call the function in the periodic trigger or do you mean something else?

he mean, you should use GroupEnum iteration function instead FirstofGroup loop.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top