• 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] Help with a spell.

Status
Not open for further replies.
Level 6
Joined
Mar 15, 2005
Messages
112
Yo I'm practicing with local variables but having trouble with em. Could someone tell me what is wrong with this?
  • Casted
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • Death Spiral Equal to (==) (Ability being cast)
    • Actions
      • Custom script: local point p0
      • Custom script: local point p1
      • Custom script: local integer i1
      • Custom script: local integer i2
      • Custom script: local effect e1
      • Custom script: set p0 = GetSpellTargetLoc()
      • Custom script: set i1 = 0
      • Custom script: set i2 = 90
      • Custom script: set p1 = PolarProjectionBj(p0, i1, i2)
      • Custom script: loop
      • Custom script: exitwhen i2 == 360
      • Wait 0.10 seconds
      • Special Effect - Create a special effect at (p1) using Units\Human\HeroBloodElf\BloodElfBall.mdl
      • Custom script: set e1 = GetLastCreatedEffectBJ()
      • Custom script: set i1 = i1 + 10
      • Custom script: set i2 = i2 + 30
      • Custom script: set p1 = PolarProjectionBj(p0, i1, i2)
      • Custom script: call DestroyEffect (e1)
      • Custom script: call removelocation (p1)
      • Custom script: endloop
I know location p0 still leaks don't worry about that. I like to keep the trigger in GUI and use custom script instead of converting to JASS format. Makes things easier for me to read.
 
Level 14
Joined
Jan 15, 2007
Messages
349
You have made several things wrong. For example you wrote the function RemoveLocation wrong. Also there is no handletype point there's just the handletype location.

  • Casted
  • Events
  • Unit - A unit Starts the effect of an ability
  • Conditions
  • Death Spiral Equal to (==) (Ability being cast)
  • Actions
  • Custom script: local location p0=GetSpellTargetLoc()
  • Custom script: local location p1
  • Custom script: local integer i1 =0
  • Custom script: local integer i2 =90
  • Custom script: local effect e1
  • Custom script: set p1 = PolarProjectionBJ(p0, i1, i2)
  • Custom script: loop
  • Custom script: exitwhen i2 == 360
  • Wait 0.10 seconds
  • Custom script: set e1= AddSpecialEffectLoc("Units\\Human\\HeroBloodElf\\BloodElfBall.mdl",p1)
  • Custom script: set i1 = i1 + 10
  • Custom script: set i2 = i2 + 30
  • Custom script: set p1 = PolarProjectionBJ(p0, i1, i2)
  • Custom script: call DestroyEffect (e1)
  • Custom script: call RemoveLocation (p1)
  • Custom script: endloop
  • Custom script: call RemoveLocation(p0)
  • Custom script: set e1=null
  • Custom script: set p0=null
  • Custom script: set p1=null
But just for remembering the location p1 have to be removed before the loop starts. But else this should work. Hope this helped you.
 
Level 6
Joined
Mar 15, 2005
Messages
112
Thanks, I'll give this a try. LoL I forgot point = location in JASS. I'm about a week into this stuff so bare with me =P.
  • Custom script: set p1 = PolarProjectionBJ(p0, i1, i2)
This is right? Wasn't sure if i wrote that correctly. Does p1 have to be removed if I don't set it until the loop starts? Like only set p1 during the loop. The reason my call removeloaction was wrong was due to its case sensitive? Must be Call RemoveLocation (p1) not removelocation (p1) ? or spacing? RemoveLocation(p1) not RemoveLocation (p1) Anyways +rep you've already been a big help.
 
Level 6
Joined
Mar 15, 2005
Messages
112
Hmm now the game will start but no effect is created. I put a debug message inside the loop and it only displays it once. So the loop doesn't loop =/. Heres the trigger.
JASS:
function Trig_Casted_Conditions takes nothing returns boolean
    if ( not ( 'A000' == GetSpellAbilityId() ) ) then
        return false
    endif
    return true
endfunction

function Trig_Casted_Actions takes nothing returns nothing
    local location p0 = GetSpellTargetLoc()
    local location p1
    local integer i1 = 0
    local integer i2 = 90
    local effect e1
    loop
    exitwhen i2 == 360
    call TriggerSleepAction( 0.10 )
    call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_008" )
    set e1 = AddSpecialEffectLocBJ( (p1), "Units\\Human\\HeroBloodElf\\BloodElfBall.mdl" )
    set i1 = i1 + 10
    set i2 = i2 + 30
    set p1 = PolarProjectionBJ(p0, I2R(i1), I2R(i2))
    call DestroyEffect(e1)
    call RemoveLocation(p1)
    endloop
    call RemoveLocation(p0)
    set p0 = null
    set p1 = null
    set e1 = null
endfunction

//===========================================================================
function InitTrig_Casted takes nothing returns nothing
    set gg_trg_Casted = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Casted, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Casted, Condition( function Trig_Casted_Conditions ) )
    call TriggerAddAction( gg_trg_Casted, function Trig_Casted_Actions )
endfunction

By the way thx element of water your suggestion helped get the game running at least =D.
 
For some reason a trigger in Jass format is mush easier for me to read than GUI... thanks for converting it :grin:
Anyway, the problem:
You try to add a special effect at a non-existent location first - p1 hasn't been set yet! This makes the thread crash and the rest of the loop not be executed. To solve this, either initialize p1 at declaration, or put the AddSpecialEffectLocBJ after the PolarProjection thing.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
i1 and i2 are integers, but PolarProjectionBJ takes real values. Therefore you need to convert them to reals with I2R so PolarProjectionBJ can take them. Like this...

C++ (and therefore Jass) automatically casts integers to floats when a function takes a float and you give it an integer, and therefore - you are wrong.

As to IncubiProtocoL, why the hell are you trying to make codes with Jass when you don't use a function list? Even though most of the functions have pretty reasonable names, you don't need to guess them, for god's sake.

Either use JassCraft, or JNGP, or just open common.j and blizzard.j.
 
Level 6
Joined
Mar 15, 2005
Messages
112
JASS:
function Trig_Casted_Conditions takes nothing returns boolean
    if ( not ( 'A000' == GetSpellAbilityId() ) ) then
        return false
    endif
    return true
endfunction

function Trig_Casted_Actions takes nothing returns nothing
    local location p0 = GetSpellTargetLoc()
    local location p1
    local integer i1 = 0
    local integer i2 = 90
    local effect e1
    set p1 = PolarProjectionBJ(p0, I2R(i1), I2R(i2))
    loop
    exitwhen i2 == 360
    call TriggerSleepAction( 0.10 )
    set i1 = i1 + 25
    set i2 = i2 + 30
    set p1 = PolarProjectionBJ(p0, I2R(i1), I2R(i2))
    call AddSpecialEffectLocBJ( (p1), "Objects\\Spawnmodels\\Undead\\UndeadDissipate\\UndeadDissipate.mdl" )
    set e1 = GetLastCreatedEffectBJ ()
    call RemoveLocation(p1)
    call DestroyEffect(e1)
    endloop
    call RemoveLocation(p0)
    set p0 = null
    set p1 = null
    set e1 = null
endfunction

//===========================================================================
function InitTrig_Casted takes nothing returns nothing
    set gg_trg_Casted = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Casted, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Casted, Condition( function Trig_Casted_Conditions ) )
    call TriggerAddAction( gg_trg_Casted, function Trig_Casted_Actions )
endfunction

This works perfectly =D. Ghostwolf I'm a noob with JASS so I don't know. I've read some of a JASS tutorial. Practicing with locals here. Wasn't playing on writing this in JASS originally, only using custom script. I use NGJP but I guess I'm not utilizing some of its features? I dunno what you mean by guessing of function names. This trigger was built in GUI at first if that explains.
 
Level 14
Joined
Jan 15, 2007
Messages
349
Well your script is kinda ineffective. Here you got a optimized one:

JASS:
function Trig_Casted_Conditions takes nothing returns boolean
    return 'A000' == GetSpellAbilityId()
endfunction

function Trig_Casted_Actions takes nothing returns nothing
    local location p0 = GetSpellTargetLoc()
    local location p1
    local real i1 = 0
    local real i2 = 90
    loop
    exitwhen i2 == 360.
    call TriggerSleepAction( 0.10 )
    set i1 = i1 + 25.
    set i2 = i2 + 30.
    set p1 = PolarProjectionBJ(p0, i1, i2)
    call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\Undead\\UndeadDissipate\\UndeadDissipate.mdl",p1))
    call RemoveLocation(p1)
    endloop
    call RemoveLocation(p0)
    set p0 = null
    set p1 = null
endfunction

Well I think this would be alot more effective but the best would be if you just work with x and y, like this:

JASS:
function Trig_Casted_Conditions takes nothing returns boolean
    return 'A000' == GetSpellAbilityId()
endfunction

function Trig_Casted_Actions takes nothing returns nothing
    local location p0 = GetSpellTargetLoc()
    local real i1 = 0.
    local real i2 = 90.
    local real x  =GetLocationX(p0)
    local real y  =GetLocationY(p0)
    local real mx
    local real my
    loop
    exitwhen i2 == 360.
    call TriggerSleepAction( 0.10 )
    set i1 = i1 + 25.
    set i2 = i2 + 30.
    set mx= y + i1*Cos(i2*0.01745327)
    set my= x + i1*Sin(i2*0.01745327)
    call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Undead\\UndeadDissipate\\UndeadDissipate.mdl",mx,my))
    endloop
    call RemoveLocation(p0)
    set p0 = null
endfunction

But well it's up to you if you use locations or not. But I would try to use so less locations as possible.
 
Last edited:
Level 6
Joined
Mar 15, 2005
Messages
112
I dunno what cos and sin mean. I've read about them but it makes no sense to me. Don't bother explaining I won't get it.
JASS:
call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Undead\\UndeadDissipate\\UndeadDissipate.mdl",x,y))
hmm you can create and destroy that at the same time? The point of using coordinates is so you don't have a location you have to destroy? Isn't that point at which the coordinates find become a location when something is created there? Thanks for the suggestions.
 
Level 14
Joined
Jan 15, 2007
Messages
349
If I understood your question right maybe the following will make you understand. Well, destroying the effect instantly after creating is possible and is clean. Because the function AddSpecialEffectLoc (or AddSpecialEffect, AddSpecialEffectLocBJ). AddSpecialEffectLocBJ just set the global bj_lastCreatedEffect to the handle which is created. Which means you can enter:
JASS:
call AddSpecialEffectLocBJ(somelocation,"someeffect")
call DestroyEffect(bj_lastCreatedEffect)
it's basicly the same as:
JASS:
call DestroyEffect(AddSpecialEffect("someeffect",0.,0.))
you also can enter:
JASS:
call DestroyEffect(AddSpecialEffectLocBJ(somelocation,"someeffect"))
And before you ask me what the hell is bj_lastCreatedEffect it's the global which is returned by the function GetLastCreatedEffectBJ(). Because the function GetLastCreatedEffectBJ is nothing more then:
JASS:
function GetLastCreatedEffectBJ takes nothing returns effect
  return bj_lastCreatedEffect
endfunction
and this is because the function AddSpecialEffectLocBJ is nothing else then:
JASS:
function AddSpecialEffectLocBJ takes location loc, string e returns nothing
    set bj_lastCreatedEffect = AddSpecialEffectLoc(e, loc)
    return bj_lastCreatedEffect
endfunction
That with the location is another story. If you just enter a location like:
JASS:
call DestroyEffect(AddSpecialEffectLoc("someeffect",PolarProjection(p0,i1,i2)))
It would still leak. Because you just destroy the effect but you dont destroy at the same time the location. That means that this would leak. So you have to make a variable like you did with p1 and make it like this:
JASS:
set p1=PolarProjection(p0,i1,i2)
call DestroyEffect(AddSpecialEffectLoc("someeffect",p1))
call RemoveLocation(p1)
Then this will be clean and don't leak. I hope that answered your question.
 
Status
Not open for further replies.
Top