HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Light Simple Star

09-12-2008, 03:51 PM#1
Flame_Phoenix
Hi guys, I am trying to make a simple star effect for one of my spells, but I have problems =(

I want something like this


|||
|
...\|/...
|| /|\

I hope some of you can understand. However I can't do that, my maths are not correct. Can some one help me ?

Collapse JASS:
local real x 
        local real y
        local integer i
        local integer j
        local real distInc
        local real angle = 0
        
        set i = 0
        loop
            exitwhen(i == 8)
            
            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))
            
                set distInc = distInc + 100
                set j = j + 1
            endloop
            
            set angle = angle + 45
            set i = i + 1
        endloop

To start, the image should be centered on the caster, and it is not ... than everything messes up basically ... =S
09-12-2008, 04:59 PM#2
the-thingy
Your angle increment should be 45 * bj_DEGTORAD or bj_PI/4 (or (2*bj_PI)/8 if you want to keep the excess stuff)since Cos/Sin use radians instead of degrees
09-12-2008, 05:23 PM#3
Flame_Phoenix
Thx, but it still doesn't work .. what else do I have to change ?
09-12-2008, 05:53 PM#4
Alexander244
(casterX + distInc) * Cos(angle) should be casterX + distInc * Cos(angle), same with the y calculation.
09-12-2008, 06:35 PM#5
Flame_Phoenix
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 =(