View Single Post
Old 09-12-2008, 07:35 PM   #5
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Ok, Thx guys for the help.
Now here is the simple spell, called SunRay you helped me creating.
Please enjoy and make constructive criticism.
Btw, You guys have credits, +rep.

Collapse JASS:
//===========================================================================
//The caster uses his light powers to summon Light Rays around him, damaging 
//enemy Undead units nearby, and healing allied units
//
//@author Flame_Phoenix 
//
//@credits
//- Modeler, he originally created the spell, I remade it into something different. 
//- the-thingy, by telling me where to use bj_DEGTORAD and why
//- Alexander244, for helping me fixing a bug with parenthesis ... lol
//- My first teacher of vJASS: Blue_Jeans
//- All other people I forgot or ignored
//
//@version 2.0
//===========================================================================
scope SunRay initializer Init
    
    //needed for spell's core, don't change
    private keyword tmpPlayer
//===========================================================================
//=============================SETUP START===================================
//===========================================================================
    globals
        private constant integer AID = 'A000'   //raecode of ability
        private constant real LIGHT_RADIUS = 100    //radius of each single light
        private constant string LIGHT_EFFECT = "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl" //the effect of the light
    endglobals

    private constant function Damage takes integer level returns real
        return level * 5.  //the damage the enemy undead units will take
    endfunction
    
    private constant function Heal takes integer level returns real
        return level * 10. //the heal your allied units will receive
    endfunction
    
    private constant function LightNumber takes integer level returns integer
    //each Sun Ray of (4 + level) lights
        return 4 + level
    endfunction
    
    private constant function RayNumber takes integer level returns integer
    //the number of Sun Rays of the spell
        return 5 + level
    endfunction
    
    private function AllyTargets takes nothing returns boolean
    //what allied units will be affected by the spell
        return IsUnitAlly(GetFilterUnit(), tmpPlayer) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL) == false) and (GetWidgetLife(GetFilterUnit()) > 0.405)
    endfunction
    
    private function EnemyTargets takes nothing returns boolean
    //what enemy units will be affected by the spell
        return IsUnitEnemy(GetFilterUnit(), tmpPlayer) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL) == false) and (GetUnitRace(GetFilterUnit()) == RACE_UNDEAD) and (GetWidgetLife(GetFilterUnit()) > 0.405)
    endfunction
//===========================================================================
//=============================SETUP END=====================================
//===========================================================================

    globals
        private player tmpPlayer
        private group g
        private boolexpr enemies
        private boolexpr allies
    endglobals
//===========================================================================
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == AID
    endfunction
//===========================================================================    
    private function Actions takes nothing returns nothing
        local unit caster = GetTriggerUnit()
        local real casterX = GetUnitX(caster)
        local real casterY = GetUnitY(caster)
        local integer level = GetUnitAbilityLevel(caster, AID)
        local unit f
        local real x 
        local real y
        local integer i
        local integer j
        local real distInc
        local real angle = 0
        
        //in this outer loop we create the Sun Rays
        set i = 0
        loop
            exitwhen(i == RayNumber(level))
            
            set distInc = 0
            //in this inner loop we create the lights of each SunRay
            set j = 0
            loop
                exitwhen(j == LightNumber(level))
            
                set x = casterX + distInc * Cos(angle)
                set y = casterY + distInc * Sin(angle)
            
                call DestroyEffect(AddSpecialEffect(LIGHT_EFFECT, x, y))
            
                //in this first double inner loop we select the enemy units and damage them
                set tmpPlayer = GetOwningPlayer(caster)
                call GroupEnumUnitsInRange(g, x, y, LIGHT_RADIUS, enemies)
                loop
                    set f = FirstOfGroup(g)
                    exitwhen(f == null)
                    call GroupRemoveUnit(g, f)
                    call UnitDamageTarget(caster, f, Damage(level), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null)
                endloop
            
                //in this second double inner loop we select the allied units and heal them
                set tmpPlayer = GetOwningPlayer(caster)
                call GroupEnumUnitsInRange(g, x, y, LIGHT_RADIUS, allies)
                loop
                    set f = FirstOfGroup(g)
                    exitwhen(f == null)
                    call GroupRemoveUnit(g, f)
                    call SetWidgetLife(f, GetWidgetLife(f) + Heal(level))
                endloop
            
                set distInc = distInc + LIGHT_RADIUS
                set j = j + 1
            endloop
            
            set angle = angle + (360 / RayNumber(level)) * bj_DEGTORAD
            set i = i + 1
        endloop
        
        set caster = null
    endfunction
//===========================================================================
    private function Init takes nothing returns nothing
        local trigger SunRayTrg = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( SunRayTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( SunRayTrg, Condition( function Conditions ) )
        call TriggerAddAction( SunRayTrg, function Actions )
        
        set SunRayTrg = null
        
        //setting globals
        set g = CreateGroup()
        set enemies = Condition(function EnemyTargets)
        set allies = Condition(function AllyTargets)
        
        //preloading effect
        call Preload(LIGHT_EFFECT)
    endfunction
endscope

I am now going to create another thread, asking for opinion. =)
PS: sorry Alexander, I can't +rep you, I have to spread reputation =(
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote