• 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! My spell compiles fine, but does nothing!

Status
Not open for further replies.
Level 9
Joined
Aug 27, 2004
Messages
471
Ok, i just tested my first jass spell, but it doesnt work!
It should: Damage enemies, heal allies, create some special effects.

Heres the code, its sorta long:
JASS:
function HE_Var_Setup takes nothing returns nothing //                           ~|
local real array Damage //                                                       ~|
local real array Healing //                                                      ~|
local real array Range //                                                        ~|
local integer alvl //                                                            ~|
local unit castingunit //  

set Damage[1] = 100.00
set Damage[2] = 175.00
set Damage[3] = 250.00
set Healing[1] = 50.00
set Healing[2] = 90.00
set Healing[3] = 125.00
set Range[1] = 500.00
set Range[2] = 510.00
set Range[3] = 520.00

set alvl = GetHandleInt(GetTriggeringTrigger(), "alvl")
call SetHandleReal(GetTriggeringTrigger(), R2S(Damage[alvl]), Damage[alvl])
call SetHandleReal(GetTriggeringTrigger(), R2S(Healing[alvl]), Healing[alvl])
call SetHandleReal(GetTriggeringTrigger(), R2S(Range[alvl]), Range[alvl])
endfunction

function Holy_Explosion_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

//--------------------------Conditional functions---------------------------------

function HEA_BF takes nothing returns nothing
endfunction

function HEA_Cond1 takes nothing returns boolean
return IsUnitAliveBJ(GetFilterUnit()) == true
endfunction

function HEA_Cond2 takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetSpellAbilityUnit())) == true
endfunction

function HEA_CondSpec1 takes nothing returns boolean
return GetBooleanAnd(HEA_Cond1(), HEA_Cond2())
endfunction

function HEA_Cond3 takes nothing returns boolean
return IsUnitAlly(GetFilterUnit(), GetOwningPlayer(GetSpellAbilityUnit())) == true
endfunction

function HEA_CondSpec2 takes nothing returns boolean
return GetBooleanAnd(HEA_Cond1(), HEA_Cond3())
endfunction

//--------------------------------------------------------------------------------

//Damage function

function DealDamageL takes real Dam1, group Gro1 returns nothing
local unit FOG
if (CountUnitsInGroup(Gro1) > 0) then
 loop
  exitwhen(CountUnitsInGroup(Gro1) <= 0)
  set FOG = FirstOfGroup(Gro1)
  call SetUnitLifeBJ(FOG, (GetUnitStateSwap(UNIT_STATE_LIFE, FOG) - Dam1))
  call GroupRemoveUnit(Gro1, FOG)
  endloop
 set FOG = null
 set Gro1 = null
else
call DoNothing()
endif
endfunction

//Healing function

function DealHealingL takes real Hea1, group Gro1 returns nothing
local unit FOG
if (CountUnitsInGroup(Gro1) > 0) then
 loop
  exitwhen(CountUnitsInGroup(Gro1) <= 0)
  set FOG = FirstOfGroup(Gro1)
  call SetUnitLifeBJ(FOG, (GetUnitStateSwap(UNIT_STATE_LIFE, FOG) + Hea1))
  call GroupRemoveUnit(Gro1, FOG)
 endloop
 set FOG = null
 set Gro1 = null
else
call DoNothing()
endif
endfunction

//EyeCandy

function SpecialEffectsL takes real Radius, unit CSP returns nothing
local integer Counter = (R2I(Radius) / 50)
local real Momentum = 0
local real Facing = 0
if (Radius > 0) then
  loop
  exitwhen(Momentum > Counter)
  set Momentum = (Momentum + 1)
   loop
    exitwhen(Facing > 360)
    call AddSpecialEffectLocBJ(PolarProjectionBJ(GetUnitLoc(CSP), Momentum, Facing), "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl")
    set Facing = (Facing + 1.00)
   endloop
  endloop
 else
 call DoNothing()
endif
endfunction

//-----------------------------End of conditional functions-----------------------

//-~=-~=-~=-~=-~=-~=-~=-~=-~=-~=-~=Main Body-~=-~=-~=-~=-~=-~=-~=-~=-~=-~=-~=-~=-~
function Holy_Explosion_Actions takes nothing returns nothing
local integer alvl
local unit caster = GetSpellAbilityUnit()
local location casterpos = GetUnitLoc(GetSpellAbilityUnit())
local real FinDamage
local real FinHealing
local real FinRange
local group EnemyTargs
local group AllyTargs

set alvl = GetUnitAbilityLevel(GetSpellAbilityUnit(), 'A000')
call SetHandleInt(GetTriggeringTrigger(), "alvl", alvl)
call SetHandleHandle(GetTriggeringTrigger(), "caster", caster)
call HE_Var_Setup()

set FinDamage = (GetHandleReal(GetTriggeringTrigger(), ("Damage["+I2S(alvl)+"]")))
set FinHealing = (GetHandleReal(GetTriggeringTrigger(), ("Healing["+I2S(alvl)+"]")))
set FinRange = (GetHandleReal(GetTriggeringTrigger(), ("Range["+I2S(alvl)+"]")))
set EnemyTargs = GetUnitsInRangeOfLocMatching(FinRange, casterpos, Condition(function HEA_CondSpec1))
set AllyTargs = GetUnitsInRangeOfLocMatching(FinRange, casterpos, Condition(function HEA_CondSpec2))

call DealDamageL(FinDamage, EnemyTargs)
call DealHealingL(FinHealing, AllyTargs)
call SpecialEffectsL(FinRange, caster)
endfunction

//===========================================================================
function InitTrig_Holy_Explosion takes nothing returns nothing
    set gg_trg_Holy_Explosion = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Holy_Explosion, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Holy_Explosion, Condition( function Holy_Explosion_Conditions ) )
    call TriggerAddAction( gg_trg_Holy_Explosion, function Holy_Explosion_Actions )
endfunction

It compiles fine, but it does nothing... Even after i use it 10-20 times. Why doesnt this damn thing work?
 
Level 3
Joined
Mar 27, 2004
Messages
70
The problem is in the HE_Var_Setup function.
JASS:
// This is where you set the variables
set alvl = GetHandleInt(GetTriggeringTrigger(), "alvl")
call SetHandleReal(GetTriggeringTrigger(), R2S(Damage[alvl]), Damage[alvl])
call SetHandleReal(GetTriggeringTrigger(), R2S(Healing[alvl]), Healing[alvl])
call SetHandleReal(GetTriggeringTrigger(), R2S(Range[alvl]), Range[alvl]) 


// Try this instead:
set alvl = GetHandleInt(GetTriggeringTrigger(), "alvl")
call SetHandleReal(GetTriggeringTrigger(), "Damage["+I2S(alvl)+"]", Damage[alvl])
call SetHandleReal(GetTriggeringTrigger(), "Healing["+I2S(alvl)+"]", Healing[alvl])
call SetHandleReal(GetTriggeringTrigger(), "Range["+I2S(alvl)+"]", Range[alvl])

The reason why it didn't do anything is that GetHandleReal and GetHandleInt return 0 when the variable hasn't been set. And the variable was never set because you used another variable name in the setup function.

Actually, you would make things easier for yourself by simply using "damage", "healing" and "range" as variable names instead of including the ability level in it.
 
Level 9
Joined
Aug 27, 2004
Messages
471
Omg! TY!!!!

It actualy runs ^,^.

Im using arrays because im lazy, also, i want easy editability. (I also want it to be simple to add more levels.)

Jass is way more complicated then gui, but now, i cant use gui anymore >.>. Jass is to fun ^,^!
 
Level 2
Joined
Oct 19, 2005
Messages
23
Actually just using a non array variable is easier in my opinion. Example instead of
JASS:
set Damage[1] = 100.00
set Damage[2] = 175.00
set Damage[3] = 250.00
You could simply put
JASS:
set Damage = 25+75*GetUnitAbilityLevel(GetSpellAbilityUnit(),'A000')
 
Level 9
Joined
Aug 27, 2004
Messages
471
What if i want my damage to be:

Level 1 - 3
Level 2 - 7
Level 3 - 22
level 4 - 49
level 5 - 3081?

Its not only easier to edit in array form, but its alot more flexible. I can give it any real pausitive number, with no need for formulas. (Though if I didint plan on releasing the spell, i might use your method)


The downside to this is if i want 100's of levels, you have to make tons of array values, unlike a formula. In this case, 25 levels is 75 entries. 50 is 150, ect.

So, forulas are nice if you dont intend to release a spell publicly/have huge amounts of levels.

What was i talking about again? :p
 
Level 3
Joined
Mar 27, 2004
Messages
70
What I meant was that you don't need to include the spell level in the handle var label:

So you do like this:
JASS:
// Here you set it:
call SetHandleReal(GetTriggeringTrigger(), "Damage", Damage[alvl])
call SetHandleReal(GetTriggeringTrigger(), "Healing", Healing[alvl])
call SetHandleReal(GetTriggeringTrigger(), "Range", Range[alvl]) 

// Here you read it:
 set FinDamage = GetHandleReal(GetTriggeringTrigger(), "Damage")
set FinHealing = GetHandleReal(GetTriggeringTrigger(), "Healing")
set FinRange = GetHandleReal(GetTriggeringTrigger(), "Range")

Remember, you can choose whatever name you want for the handle var.
 
Status
Not open for further replies.
Top