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: 309

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 The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1

      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