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

Status
Not open for further replies.
Level 8
Joined
Feb 15, 2009
Messages
463
Hey Guys i just want to get this checked if there could be done any improvements for this spell and i have a simple question:


Q: what is the advantage of coding a spell out of a struct?



This spell works and doesn't has any flaws, I just want to know if coding could be improved.

Also GroupTypeUnitMatch() exists in my library MatchingUtils.

JASS:
//**************************************************************************************
//** Name:               MetallicArrow
//** Version:            1.0
//** by:                    Saia_Djinn plz give Credits when using
//** Requires:          xedamage >= 0.6  ,GroupUtils and MatchingUtils
//** Codecredits:    Vexorian for xedamage ,Rising_Dusk for GroupUtils, Saia_Djinn for MatchingUtils and the JNGP team
//**Modelcredits:    JetFangInferno for the FreezingRing
//**************************************************************************************
scope Syphonica initializer Init

globals
    private constant integer SPELL_ID = 'A003'
    //The Rawcode of the BaseAbility
    private constant integer RED = 150
    //How much red the texttag color should contain
    private constant integer GREEN = 150
    //How much green the texttag color should contain
    private constant integer BLUE = 225
    //How much blue the texttag color should contain
    private constant integer ALPHA = 170
    //How much alpha the texttag color should contain
    
    private constant real TEXTTAG_LIFESPAN = 2.4
    //How long the Tag should last
    private constant real AOE_RANGE = 250.
    //The radius of the Area of Effect
    private constant real DEADLY_DAMAGE_LEVEL = 160.
    //How much damage is dealt if the arrow hit a target in the Deadly Damage Range per level
    private constant real HEAVY_DAMAGE_LEVEL = 125.
    //How much damage is dealt if the arrow hit a target in the Heavy Damage Range per level
    private constant real DAMAGE_LEVEL = 80.
    //How much damage is dealt if the arrow hit a target in the Damage Range per level
    private constant real WEAK_DAMAGE_LEVEL = 40.
    //How much damage is dealt if the arrow hit a target in the Weak Damage Range per level
    
    private constant real KILL_RANGE = 1200.
    //The minimum range which must be reached to deal deadly damage
    private constant real HEAVY_DAMAGE_RANGE = 800.
    //The minimum range which must be reached to deal heavy damage
    private constant real DAMAGE_RANGE = 600.
    //The minimum range which must be reached to deal damage
    private constant real WEAK_DAMAGE_RANGE = 300.
    //The minimum range which must be reached to deal weak damage
    private constant real NO_DAMAGE_RANGE = 0.
    //The minimum range which must be reached to deal no damage
        
    private constant boolean WANT_IMPACT_FX = true
    //If a Effect should be shown on hit
    private constant boolean WANT_DAMAGE_FX = true
    //If a Effect on damaging should be shown
    private constant boolean WANT_TEXTTAG = true
    //If you want a texttag to be shown
    
    private constant boolean SELF = false
    //Want to damage yourself
    private constant boolean ALLY = false
    //Want to damage allies
    private constant boolean ENEMY = true
    //Want to damage enemies
    private constant boolean NEUTRAL = true
    //Want to damage neutrals
    private constant boolean TREES = false
    //Want to damage trees
    
    private constant string IMPACT_FX = "FreezingRing.mdx"
    //The Effect shown on hit
    private constant string DAMAGE_FX = "Abilities\\Spells\\Undead\\ReplenishMana\\SpiritTouchTarget.mdl"
    //The Damage Effect
    private constant string DAMAGE_FX_ATTACH = "chest"
    //Where The Damage FX should be attached to
    private constant string TEXTTAG_TEXT_DEADLY = "A deadly damaging Syphon"
    //which text the texttag if wanted shall display if the target was in Kill Range
    private constant string TEXTTAG_TEXT_HEAVY = "A heavy damaging Syphon"
    //which text the texttag if wanted shall display if the target was in Heavy Damage Range
    private constant string TEXTTAG_TEXT = "A damaging Syphon"
    //which text the texttag if wanted shall display if the target was in Damage Range
    private constant string TEXTTAG_TEXT_WEAK = "A weak damaging Syphon"
    //which text the texttag if wanted shall display if the target was in Weak Damage Range
    private constant string TEXTTAG_TEXT_NONE = "Oh no a lacking Syphon"
    //which text the texttag if wanted shall display if the target was in No Damage Range
    
    private constant attacktype ATTACKTYPE = ATTACK_TYPE_CHAOS
    //The Attack Type of the Damage
    private constant damagetype DAMAGETYPE = DAMAGE_TYPE_UNIVERSAL 
    //The Damage Type of the Damage
    private constant weapontype WEAPONTYPE = WEAPON_TYPE_WHOKNOWS
    //The Weapon Type of the Damage
    
//Don't touch these vaiables
    private boolexpr bo
    private unit temp
    private xedamage damage
endglobals

private function Texttag takes unit attach , string text , real length returns nothing
    local texttag t = CreateTextTag()
  
    call SetTextTagText( t , text , 0.025 )
    call SetTextTagLifespan( t, length)
    call SetTextTagFadepoint( t , 0.0 )
    call SetTextTagPermanent( t ,false)
    call SetTextTagPosUnit( t, attach , 0.2)
    call SetTextTagVelocity( t ,0.0 ,0.03)
    call SetTextTagColor( t , 150 , 150 , 225 , 170 )
    call SetTextTagVisibility( t ,true)
    
    set t = null
endfunction

private function Match takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit() , GetOwningPlayer(temp)) and GroupTypeUnitMatch()
endfunction

private function SetUp takes nothing returns nothing
    set bo = Condition(function Match)
    
    if WANT_DAMAGE_FX then
        call damage.useSpecialEffect(DAMAGE_FX , DAMAGE_FX_ATTACH)
    endif
    
    set damage.atype = ATTACKTYPE
    set damage.dtype = DAMAGETYPE
    set damage.wtype = WEAPONTYPE
    set damage.damageSelf = SELF
    set damage.damageAllies = ALLY
    set damage.damageEnemies = ENEMY
    set damage.damageNeutral = NEUTRAL
    set damage.damageTrees = TREES
endfunction

private function Conditions takes nothing returns boolean
    local unit u
    local real ux
    local real uy
    local unit t
    local real tx
    local real ty
    local real r
    local integer l
    
    if GetSpellAbilityId() == SPELL_ID then
        set u = GetSpellAbilityUnit()
        set t = GetSpellTargetUnit()
        set ux = GetUnitX(u)
        set uy = GetUnitY(u)
        set tx = GetUnitX(t)
        set ty = GetUnitY(t)
        set r = SquareRoot((tx - ux) * (tx - ux) + (ty - uy) * (ty - uy))
        
//No
        if r < WEAK_DAMAGE_RANGE then
        
            if WANT_IMPACT_FX then
                call DestroyEffect(AddSpecialEffect(IMPACT_FX , tx , ty ))
            endif
            if WANT_TEXTTAG then
                call Texttag(t , TEXTTAG_TEXT_NONE , TEXTTAG_LIFESPAN)
            endif
//Weak
        elseif r < DAMAGE_RANGE then
        set l = GetUnitAbilityLevel( u , SPELL_ID)
        set temp = u
        call GroupRefresh(ENUM_GROUP)
        call GroupEnumUnitsInRange(ENUM_GROUP , tx , ty, AOE_RANGE , bo)
        call damage.damageGroup(u , ENUM_GROUP , WEAK_DAMAGE_LEVEL * l)
        
            if WANT_IMPACT_FX then
                call DestroyEffect(AddSpecialEffect(IMPACT_FX , tx , ty ))
            endif
            if WANT_TEXTTAG then
                call Texttag(t , TEXTTAG_TEXT_WEAK , TEXTTAG_LIFESPAN)
            endif
//Normal
        elseif r < HEAVY_DAMAGE_RANGE then
        set l = GetUnitAbilityLevel( u , SPELL_ID)
        set temp = u
        call GroupRefresh(ENUM_GROUP)
        call GroupEnumUnitsInRange(ENUM_GROUP , tx , ty, AOE_RANGE , bo)
        call damage.damageGroup(u , ENUM_GROUP , DAMAGE_LEVEL * l)
        
            if WANT_IMPACT_FX then
                call DestroyEffect(AddSpecialEffect(IMPACT_FX , tx , ty ))
            endif
            if WANT_TEXTTAG then
                call Texttag(t , TEXTTAG_TEXT , TEXTTAG_LIFESPAN)
            endif
//Heavy
        elseif r < KILL_RANGE then
        set l = GetUnitAbilityLevel( u , SPELL_ID)
        set temp = u
        call GroupRefresh(ENUM_GROUP)
        call GroupEnumUnitsInRange(ENUM_GROUP , tx , ty, AOE_RANGE , bo)
        call damage.damageGroup(u , ENUM_GROUP , HEAVY_DAMAGE_LEVEL * l)
        
            if WANT_IMPACT_FX then
                call DestroyEffect(AddSpecialEffect(IMPACT_FX , tx , ty ))
            endif
            if WANT_TEXTTAG then
                call Texttag(t , TEXTTAG_TEXT_HEAVY , TEXTTAG_LIFESPAN)
            endif
//Deadly
        else
        set l = GetUnitAbilityLevel( u , SPELL_ID)
        set temp = u
        call GroupRefresh(ENUM_GROUP)
        call GroupEnumUnitsInRange(ENUM_GROUP , tx , ty, AOE_RANGE , bo)
        call damage.damageGroup(u , ENUM_GROUP , DEADLY_DAMAGE_LEVEL * l)
        
            if WANT_IMPACT_FX then
                call DestroyEffect(AddSpecialEffect(IMPACT_FX , tx , ty ))
            endif
            if WANT_TEXTTAG then
                call Texttag(t , TEXTTAG_TEXT_DEADLY , TEXTTAG_LIFESPAN)
            endif
            
        endif
        
    endif
    
    set u = null
    set t = null
    return false
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t , EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t , Condition( function Conditions ))
    set damage = xedamage.create()
    call SetUp()
endfunction

endscope

As always help is rewarded
 
Status
Not open for further replies.
Top