• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Radiant Lightningz time! ups.

Status
Not open for further replies.
Level 6
Joined
Jan 7, 2007
Messages
247
Here comes my problem. Im new to jass (rly new). This is first thing with loops im trying to make.
So, its supporsed to make simple circle of lightnings like that:

lightningnormglukpk1.jpg


So, i tried to make something like that:
JASS:
    local lightning s
    local lightning p
    local real a
    local real b
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 8
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call AddLightningLoc( "CLPB", GetUnitLoc(GetSpellAbilityUnit()), PolarProjectionBJ(GetUnitLoc(GetSpellAbilityUnit()), ( 200.00 + ( I2R(GetHeroStatBJ(bj_HEROSTAT_INT, udg_Hero, true)) * 5.00 ) ), udg_int[GetForLoopIndexA()]) )
        set udg_int[( GetForLoopIndexA() + 1 )] = ( udg_int[GetForLoopIndexA()] + 45.00 )
        set udg_spark[GetForLoopIndexA()] = GetLastCreatedLightningBJ()
        set s = udg_spark[GetForLoopIndexA()]
        set a = udg_int[GetForLoopIndexA()]
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 9
    set bj_forLoopAIndexEnd = 17
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call AddLightningLoc( "CLPB", PolarProjectionBJ(GetUnitLoc(GetSpellAbilityUnit()), ( 200.00 + ( I2R(GetHeroStatBJ(bj_HEROSTAT_INT, udg_Hero, true)) * 5.00 ) ), udg_int[GetForLoopIndexA()]), PolarProjectionBJ(GetUnitLoc(GetSpellAbilityUnit()), ( 200.00 + ( I2R(GetHeroStatBJ(bj_HEROSTAT_INT, udg_Hero, true)) * 5.00 ) ), udg_int[( GetForLoopIndexA() + 1 )]) )
        set udg_int[( GetForLoopIndexA() + 1 )] = ( udg_int[GetForLoopIndexA()] + 45.00 )
        set udg_spark[GetForLoopIndexA()] = GetLastCreatedLightningBJ()
        set p = udg_spark[GetForLoopIndexA()]
        set b = udg_int[GetForLoopIndexA()]
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop

But theres some strange bug there :eekani: On first use of the spell it looks like..:
lightningglykdb8.jpg


I dont understand why =\ On second, third, etc uses it looks right how i need.
And if i try to make it localz, so it can be used by many units at one time, addin:

JASS:
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 17
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_int[GetForLoopIndexA()] = b
        set udg_spark[GetForLoopIndexA()] = s
        set udg_int[GetForLoopIndexA()] = a
        set udg_spark[GetForLoopIndexA()] = p
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop

to code, lightnings do not even appear!
Please, i need some help with that =\

P.S. Dont u think there are 2 lightnings on one at red spot on first screenie? O_O
P.P.S. As always i apologize for sucky english
 
Level 7
Joined
Jun 10, 2007
Messages
225
Ok, this wont help fix your problem, but one thing you should REALLY change. take out every bj_ForLoopIndexA, and instead, do this: at the start of your function declare a local variable i. Then, change your loops to look like the following, it will make your code alot cleaner and more effecient.
JASS:
function loops takes nothing returns nothing
    local integer i = 0
        loop
            set i = i + 1
            //actions here
            exitwhen i >=3
        endloop
endfunction
This loops 3 times.

Also, whenever you see something with bj in it, instead, use what is in that function (use JASSCraft to see what bj's actually do). PolarProjectionBJ is leaky and you can do it alot faster by using X/Y Coordinates.
JASS:
    local real x = source + distance * Cos(angle * bj_DEGTORAD)
    local real y = source + distance * Sin(angle * bj_DEGTORAD)
Basically, to do a polar projection with 90 degrees and 300 distance, you would do something like this.
JASS:
function Polar takes nothing returns nothing
    local real x = 0 //X coordinate of the source
    local real y = 0 //Y coordinate of the source
    local real x2 = x + 300 * Cos(90 * bj_DEGTORAD)
    local real y2 = y + 300 * Sin(90 * bj_DEGTORAD)
    //now x2 and y2 are the coordinates of the point, do your actions here
endfunction


EDIT: This code should work completely, however, I have not tested it. It doesnt use points (which makes it faster) and few bjs, so its more effecient.
JASS:
function lightningwheel takes nothing returns nothing
    local integer i = 0
    local integer i2 = 0 //this is so we can correctly give lightnings their arrays
    local lightning array l //this is being used so we can call upon these lightnings later
    local real x = 0
    local real y = 0  //the center of the circle will be at the area of the map which is 0 x and y
    local real x2
    local real y2
    local real x3
    local real y3
    local real angle
    local real distance = 300 //how far from the center the lightning will be created
    local integer segments = 8 //how many points will have lightning going to them, currently yours is 8
        loop
            set i = i + 1
            set i2 = i2 + 1
            set angle = (360/segments) * i
            set x2 = x + distance * Cos(angle * bj_DEGTORAD)
            set y2 = y + distance * Sin(angle * bj_DEGTORAD)
            set l[i2] = (AddLightning("CLPB",false,x,y,x2,y2))
            set i2 = i2 + 1
            set angle = (360/segments) * (i + 1)
            set x3 = x + distance * Cos(angle * bj_DEGTORAD)
            set y3 = y + distance * Sin(angle * bj_DEGTORAD)
            set l[l2] = (AddLightning("CLPB",false,x2,y2,x3,y3))
        exitwhen i >= segments
        endloop
endfunction
 
Last edited:
Level 6
Joined
Jan 7, 2007
Messages
247
oh one question please..
what does it mean:
JASS:
set l[l2] = (AddLightning("CLPB",false,x2,y2,x3,y3))

It causes some errors -.-
edit: oh i already found

Oh here goes another question:

JASS:
local real y = 0 //the center of the circle will be at the area of the map which is 0 x and y  local real x2

How can i convert it to position of casting unit? ^^
 
Last edited:
Level 3
Joined
May 28, 2007
Messages
57
JASS:
   local location <Whateva the name you want> = GetUnitLoc(<Whateva the unit is>)
JASS:
   set <Whateva the name you want> = null
But position of unit does leak and to use the X,Y coordernates is much faster, null the position at the end of the trigger.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
The Casting Unit, also known as the Triggering Unit, can be accessed through GetTriggerUnit() or GetSpellAbilityUnit(), though the former is preferrable in almost every way.

Since the functions GetUnitX and GetUnitY return the x and y positions of a specified unit respectively, then you input that unit and end up with

JASS:
local real x = GetUnitX( GetTriggerUnit() )
local real y = GetUnitY( GetTriggerUnit() )

//or

local unit u = GetTriggerUnit()
local real x = GetUnitX( u )
local real y = GetUnitY( u )
 
Level 6
Joined
Jan 7, 2007
Messages
247
Awww thanks everyone!
here goes what i got in the finish:

JASS:
function Trig_Heartbreaking_Field_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00U' ) ) then
        return false
    endif
    return true
endfunction
function Trig_Heartbreaking_Field_Func001 takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) != Player(3) )
endfunction

function Trig_Heartbreaking_Field_Func002 takes nothing returns nothing
    call SetUnitLifePercentBJ( GetEnumUnit(), ( GetUnitLifePercent(GetEnumUnit()) - ( GetUnitLifePercent(GetEnumUnit()) * 0.25 ) ) ) 
endfunction

function Trig_Heartbreaking_Field_Actions takes nothing returns nothing
    local integer i = 0
    local integer i2 = 0
    local lightning array l
    local real x = GetUnitX( GetTriggerUnit() ) 
    local real y = GetUnitY( GetTriggerUnit() )
    local real x2
    local real y2
    local real x3
    local real y3
    local real angle
    local real distance = ( 200.00 + ( I2R(GetHeroStatBJ(bj_HEROSTAT_INT, udg_Hero, true)) * 5.00 ) )
    local integer segments = 8
        loop
            set i = i + 1
            set i2 = i2 + 1
            set angle = (360/segments) * i
            set x2 = x + distance * Cos(angle * bj_DEGTORAD)
            set y2 = y + distance * Sin(angle * bj_DEGTORAD)
            set l[i2] = (AddLightning("CLPB",false,x,y,x2,y2))
            set i2 = i2 + 1
            set angle = (360/segments) * (i + 1)
            set x3 = x + distance * Cos(angle * bj_DEGTORAD)
            set y3 = y + distance * Sin(angle * bj_DEGTORAD)
            set l[i2] = (AddLightning("CLPB",false,x2,y2,x3,y3))
        exitwhen i >= segments
        endloop
        call ForGroupBJ( GetUnitsInRangeOfLocMatching(( 200.00 + ( I2R(GetHeroStatBJ(bj_HEROSTAT_INT, udg_Hero, true)) * 5.00 ) ), GetUnitLoc(GetSpellAbilityUnit()), Condition(function Trig_Heartbreaking_Field_Func001)), function Trig_Heartbreaking_Field_Func002 )
        endfunction


//===========================================================================
function InitTrig_Heartbreaking_Field takes nothing returns nothing
    set gg_trg_Heartbreaking_Field = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Heartbreaking_Field, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Heartbreaking_Field, Condition( function Trig_Heartbreaking_Field_Conditions ) )
    call TriggerAddAction( gg_trg_Heartbreaking_Field, function Trig_Heartbreaking_Field_Actions )
endfunction

Well..
There goes next question - how to remove these lightnings? ^^

P.S. Ugh, i know there is some leak with unit group, isnt it..
 
Last edited:
Level 3
Joined
May 28, 2007
Messages
57
Fisrt Change
JASS:
       function Trig_Heartbreaking_Field_Conditions takes nothing returns boolean
         if ( not ( GetSpellAbilityId() == 'A00U' ) ) then
          return false
         endif
        return true
      endfunction
to
JASS:
        function Trig_Heartbreaking_Field_Conditions takes nothing returns boolean 
          return GetSpellAbilityId() == 'A00U'
        endfunction
Second yes your group does leak a location, to solve it create a local variable and than null it after use.
and as for the lightning i think i'm not sure use
JASS:
native DestroyLightning             takes lightning whichBolt returns boolean
please someone correct me if i am wrong :)
 
Level 7
Joined
Jun 10, 2007
Messages
225
I made a mistake. Theres 2 identical lines, Set l[i2] = blabla bla. The second one says L2 instead of i2. Change that.
This is how you remove the lightnings (must be in the same function as you create them)
JASS:
loop
    set i3 = i3 + 1 //you need to declare i3 as a local variable now
    call DestroyLightning l[i3]
exitwhen i3 >= (segments * 2)
endloop
 
Level 6
Joined
Jan 7, 2007
Messages
247
Thanks you much :)
Here goes last question - i need to create(and remove after 0.4sec) Thunder Clap caster effect at the end of each basic lightning. Basic i mean first ones, who comes radiant from spellcaster. I know how to make em with polar offsets, but u say they cause lags so..
Please tell me how to make em with using coordinates
 
Status
Not open for further replies.
Top