HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS spell help ;/

08-17-2007, 04:32 AM#1
botanic
Im trying to modify the Dash_Strike_Image_Damage and the Dash_Strike_Target_Damage from Level * a number to using the AGI of the hero... I tried doing

Jass:

Collapse JASS:
constant function Dash_Strike_Target_Damage takes real Level returns real
    return Level * I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, udg_Shapeshifter_Hero, true)) //Damage done to the target
endfunction


however it gives me an error "expected expression" ?!?

I think it MIGHT be because the variable Shapeshifter_Hero is a global that I want to get the AGI from... (sometimes I get the constant being called from non-constant funcion error...)

I know the I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, udg_Shapeshifter_Hero, true)) is fine because i used it in a spell earlier however it seems that im missing something ~.~ Works great without trying to base the damage off the AGI...

IF you want the spell script it is:

Jass:

Collapse JASS:
constant function Dash_Strike_SpellId takes nothing returns integer
    return 'A01H' //Rawcode of the ability being cast
endfunction

function Dash_Strike_DummyID takes nothing returns integer
    return 'n00H' //Rawcode for the Dash Dummy unit
endfunction

function Dash_Strike_Distance takes nothing returns real
    return 1.3 //Distance out related to the total distance between the target and caster
endfunction

constant function Dash_Strike_Target_Damage takes real Level returns real
    return Level * 50 //Damage done to the target
endfunction

constant function Dash_Strike_Image_Damage takes real Level returns real
    return Level * 50 //Damage done by the image movement
endfunction

constant function Dash_Strike_Image_Damage_Area takes real Level returns real
    return 50 + Level * 0 //Area of damage done by the image movement
endfunction

function Dash_Strike_Attack_Effect takes nothing returns string
    return "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl" //Effect on the caster when they attack the target
endfunction

function Dash_Strike_Attack_Effect_Location takes nothing returns string
    return "weapon" //Location of effect on the caster when they attack the target
endfunction

function Dash_Strike_Slide_Effect takes nothing returns string
    return "Abilities\\Spells\\Human\\FlakCannons\\FlakTarget.mdl" //Effect at the feat of the dummys as the dash
endfunction

//***************************************************\\

function Dash_Strike_Bezier_Curve takes real a, real b, real A, real B, real C  returns real
    return A*a*a+2*B*a*b+C*b*b 
endfunction

function Dash_Strike_MoveUnitToPolarProjection takes unit tomove, real dist, real angle returns nothing
    call SetUnitPosition(tomove, GetUnitX(tomove) + dist * Cos(angle * bj_DEGTORAD) , GetUnitY(tomove) + dist * Sin(angle * bj_DEGTORAD))
endfunction

function Dash_Strike_Fade_In takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t,"u")
    local integer i = GetHandleInt(t,"i")
    
    if i < 255 then
        call SetUnitVertexColor(u,255,255,255,i)
        set i=i+6
        call SetHandleInt(t,"i",i)
    else
        call PauseTimer(t)
        call FlushHandleLocals(t)
        call DestroyTimer(t) 
    endif

    set t = null
    set u = null
endfunction

function Dash_Strike_Fade_Out takes nothing returns nothing
    local timer t4 = GetExpiredTimer()
    local timer t = CreateTimer()
    local unit u = GetHandleUnit(t4,"u")
    local integer i = GetHandleInt(t4,"i")
    
    if i>0 then
        call SetUnitVertexColor(u,255,255,255,i)
        set i=i-6
        call SetHandleInt(t4,"i",i)
    else
        call PauseTimer(t4)
        call FlushHandleLocals(t4)
        call DestroyTimer(t4)
        call SetHandleHandle(t,"u",u)
        call SetHandleInt(t,"i",i)   
        call TimerStart(t, 0.01, true, function Dash_Strike_Fade_In)
    endif
        
    set u = null 
    set t = null   
    set t4 = null
endfunction

function Dash_Strike_Group takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(),bj_groupEnumOwningPlayer) and IsUnitType(GetFilterUnit(),UNIT_TYPE_GROUND)==true
endfunction

function Dash_Strike_Damage takes unit u, real r, real x, real y, real r2, boolean attack, boolean ranged, attacktype at, damagetype dt, weapontype wt returns nothing
    local group g = CreateGroup()
    local boolexpr b = Condition(function Dash_Strike_Group)
    local unit v

    set bj_groupEnumOwningPlayer = GetOwningPlayer(u)
    call GroupEnumUnitsInRange(g, x, y, r, b)
    call DestroyBoolExpr(b)    
    loop
        set v = FirstOfGroup(g)
        exitwhen v == null
        call GroupRemoveUnit(g,v)
        call UnitDamageTarget(u,v,r2,attack,ranged,at,dt,wt)
    endloop    
    call DestroyGroup(g)

    set g = null
    set b = null
endfunction

function Dash_Strike_Move3 takes nothing returns nothing
    local timer t3 = GetExpiredTimer()
    local unit u = GetHandleUnit(t3,"u")
    local unit dum3 = GetHandleUnit(t3,"dum3")
    local real lvl = GetHandleReal(t3,"lvl")
    local real angle = GetHandleReal(t3,"angle")
    local real dist = GetHandleReal(t3,"dist")    
    local real x2 = GetHandleReal(t3,"x2")
    local real y2 = GetHandleReal(t3,"y2") 
     
    call Dash_Strike_MoveUnitToPolarProjection(dum3,dist,angle)    
    call SetUnitAnimation(dum3, "walk")
    call DestroyEffect( AddSpecialEffect(Dash_Strike_Slide_Effect(),GetUnitX(dum3),GetUnitY(dum3)))
    call Dash_Strike_Damage(u,Dash_Strike_Image_Damage_Area(lvl), GetUnitX(dum3), GetUnitY(dum3), Dash_Strike_Image_Damage(lvl), false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
    if IsUnitInRangeXY(dum3,x2,y2, 50) then 
        call KillUnit(dum3)
        call RemoveUnit(dum3)        
        call PauseTimer(t3)
        call FlushHandleLocals(t3)        
        call DestroyTimer(t3)
    endif

    set t3 = null
    set u = null
    set dum3 = null
endfunction

function Dash_Strike_Move2 takes nothing returns nothing
    local timer t2 = GetExpiredTimer()
    local unit u = GetHandleUnit(t2,"u")
    local unit dum2 = GetHandleUnit(t2,"dum2")
    local real lvl = GetHandleReal(t2,"lvl")        
    local real x1 = GetHandleReal(t2,"x1")
    local real y1 = GetHandleReal(t2,"y1")
    local real x2 = GetHandleReal(t2,"x2")
    local real y2 = GetHandleReal(t2,"y2")
    local real x4 = GetHandleReal(t2,"x4")
    local real y4 = GetHandleReal(t2,"y4")    
    local real a = GetHandleReal(t2,"a") 
    local real b = 1-a 
    local real dum2x = Dash_Strike_Bezier_Curve(a,b,x1,x4,x2) 
    local real dum2y = Dash_Strike_Bezier_Curve(a,b,y1,y4,y2)           
    
    call SetUnitPosition(dum2,dum2x,dum2y)    
    call SetUnitAnimation(dum2, "walk")
    call DestroyEffect( AddSpecialEffect(Dash_Strike_Slide_Effect(),dum2x,dum2y))
    call Dash_Strike_Damage(u,Dash_Strike_Image_Damage_Area(lvl), dum2x, dum2y, Dash_Strike_Image_Damage(lvl), false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
    if IsUnitInRangeXY(dum2,x2,y2, 50) then 
        call KillUnit(dum2)
        call RemoveUnit(dum2)        
        call PauseTimer(t2)
        call FlushHandleLocals(t2)        
        call DestroyTimer(t2)
    endif    
    call SetHandleReal(t2,"a",a - .04)    
                                      
    set u = null
    set dum2 = null       
    set t2 = null
endfunction

function Dash_Strike_Move1 takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t,"u")
    local unit dum1 = GetHandleUnit(t,"dum1") 
    local real lvl = GetHandleReal(t,"lvl")       
    local real x1 = GetHandleReal(t,"x1")
    local real y1 = GetHandleReal(t,"y1")
    local real x2 = GetHandleReal(t,"x2")
    local real y2 = GetHandleReal(t,"y2")
    local real x3 = GetHandleReal(t,"x3")
    local real y3 = GetHandleReal(t,"y3")    
    local real a = GetHandleReal(t,"a") 
    local real b = 1-a 
    local real dum1x = Dash_Strike_Bezier_Curve(a,b,x1,x3,x2) 
    local real dum1y = Dash_Strike_Bezier_Curve(a,b,y1,y3,y2)           
    
    call SetUnitPosition(dum1,dum1x,dum1y)    
    call SetUnitAnimation(dum1, "walk")
    call DestroyEffect( AddSpecialEffect(Dash_Strike_Slide_Effect(),dum1x,dum1y))
    call Dash_Strike_Damage(u,Dash_Strike_Image_Damage_Area(lvl), dum1x, dum1y, Dash_Strike_Image_Damage(lvl), false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
    if IsUnitInRangeXY(dum1,x2,y2, 50) then 
        call KillUnit(dum1)
        call RemoveUnit(dum1)        
        call PauseTimer(t)
        call FlushHandleLocals(t)        
        call DestroyTimer(t)
    endif    
    call SetHandleReal(t,"a",a - .04)    
                                      
    set u = null
    set dum1 = null       
    set t = null
endfunction

function Trig_Dash_Strike_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit u2 = GetSpellTargetUnit()
    local timer t = CreateTimer() 
    local timer t2 = CreateTimer() 
    local timer t3 = CreateTimer()
    local timer t4 = CreateTimer() 
    local real lvl = GetUnitAbilityLevel(u, Dash_Strike_SpellId())  
    local real x1 = GetUnitX(u) 
    local real y1 = GetUnitY(u)         
    local real x2 = GetUnitX(u2) 
    local real y2 = GetUnitY(u2)    
    local real a = bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
    local unit dum1 = CreateUnit(GetOwningPlayer(u), Dash_Strike_DummyID(), x1, y1, a)
    local unit dum2 = CreateUnit(GetOwningPlayer(u), Dash_Strike_DummyID(), x1, y1, a)
    local unit dum3 = CreateUnit(GetOwningPlayer(u), Dash_Strike_DummyID(), x1, y1, a)         
    local real length = SquareRoot((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/Dash_Strike_Distance()  
    local real dist = SquareRoot((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/2 
    local real dist2 = SquareRoot((dist*dist)+(length*length))   
    local real x3 = x1 + dist2 * Cos((a+45) * bj_DEGTORAD)  
    local real y3 = y1 + dist2 * Sin((a+45) * bj_DEGTORAD)
    local real x4 = x1 + dist2 * Cos((a+315) * bj_DEGTORAD) 
    local real y4 = y1 + dist2 * Sin((a+315) * bj_DEGTORAD)
    
    call SetHandleReal(t,"lvl",lvl)
    call SetHandleReal(t2,"lvl",lvl)
    call SetHandleReal(t3,"lvl",lvl)
    call SetHandleReal(t,"x1",x1) 
    call SetHandleReal(t,"y1",y1)
    call SetHandleReal(t,"x2",x2)
    call SetHandleReal(t,"y2",y2)
    call SetHandleReal(t2,"x1",x1) 
    call SetHandleReal(t2,"y1",y1)
    call SetHandleReal(t2,"x2",x2)
    call SetHandleReal(t2,"y2",y2)
    call SetHandleReal(t3,"x2",x2)
    call SetHandleReal(t3,"y2",y2)
    call SetHandleReal(t,"x3",x3) 
    call SetHandleReal(t,"y3",y3)
    call SetHandleReal(t2,"x4",x4) 
    call SetHandleReal(t2,"y4",y4)    
    call SetHandleReal(t,"a",1)
    call SetHandleReal(t2,"a",1)
    call SetHandleReal(t3,"angle",bj_RADTODEG * Atan2(y2 - y1, x2 - x1))
    call SetHandleReal(t3,"dist",SquareRoot((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/25)
    call SetHandleInt(t4,"i",255)      
    call SetHandleHandle(t,"dum1",dum1) 
    call SetHandleHandle(t2,"dum2",dum2)
    call SetHandleHandle(t3,"dum3",dum3)
    call SetHandleHandle(t,"u",u)
    call SetHandleHandle(t2,"u",u)
    call SetHandleHandle(t3,"u",u)
    call SetHandleHandle(t4,"u",u)        
   
    call SetUnitTimeScalePercent(dum1, 10000)
    call SetUnitAnimation(dum1, "walk")
    call SetUnitTimeScalePercent(dum2, 10000)
    call SetUnitAnimation(dum2, "walk")
    call SetUnitTimeScalePercent(dum3, 10000)
    call SetUnitAnimation(dum3, "walk")
    call ClearSelectionForPlayer(GetOwningPlayer(u))    
    call TimerStart(t, .025, true, function Dash_Strike_Move1) 
    call TimerStart(t2, .025, true, function Dash_Strike_Move2)
    call TimerStart(t3, .025, true, function Dash_Strike_Move3)
    call TimerStart(t4, .01, true, function Dash_Strike_Fade_Out)    
    call TriggerSleepAction(.4) 
    call SetUnitPosition(u,GetUnitX(u2),GetUnitY(u2))
    call SelectUnitAddForPlayer(u,GetOwningPlayer(u))
    if IsUnitAlly(u2,GetOwningPlayer(u))==false then   
        call IssueTargetOrder(u,"attack",u2)
        call UnitDamageTarget(u,u2,Dash_Strike_Target_Damage(lvl),false,false,ATTACK_TYPE_HERO,DAMAGE_TYPE_NORMAL,null)
        call DestroyEffect(AddSpecialEffectTarget( Dash_Strike_Attack_Effect(), u , Dash_Strike_Attack_Effect_Location()))
    endif
    call TriggerSleepAction(2)  
    
    set t = null
    set t2 = null
    set t3 = null
    set t4 = null
    set u = null
    set u2 = null
    set dum1 = null
    set dum2 = null
    set dum3 = null    
endfunction

//===========================================================================
function Trig_Dash_Strike_Conditions takes nothing returns boolean  
    return GetSpellAbilityId() == Dash_Strike_SpellId()
endfunction

function InitTrig_Dash_Strike takes nothing returns nothing
    set gg_trg_Dash_Strike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Dash_Strike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Dash_Strike, Condition( function Trig_Dash_Strike_Conditions ) )
    call TriggerAddAction( gg_trg_Dash_Strike, function Trig_Dash_Strike_Actions )
endfunction
08-17-2007, 04:17 PM#2
Silvenon
It gives you an error because you called a non-constant function (I2R) inside a constant function.
08-17-2007, 07:15 PM#3
botanic
any idea how i can fix that? I only know that method of getting a units AGI...
08-17-2007, 10:40 PM#4
Silvenon
Remove the 'constant' from the function. There is no big difference and it's easier to work with normal functions. Or if you really want it to be constant, then you have to change it into something like this:

Collapse JASS:
constant function Dash_Strike_Target_Damage takes real Level, real Str returns real
    return Level * Str
endfunction

Then, when calling that function, do this:

Collapse JASS:
local real str = I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, udg_Shapeshifter_Hero, true))
call Dash_Strike_Damage(u,Dash_Strike_Image_Damage_Area(lvl), GetUnitX(dum3), GetUnitY(dum3), Dash_Strike_Image_Damage(lvl, str), false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)

EDIT: I forgot to say that the error occurs because of GetHeroStatBJ also
08-18-2007, 08:10 AM#5
botanic
Hey thanks it works great now just a quick question tho what is the difference between a constant function and a non constant function?
08-18-2007, 08:56 AM#6
Silvenon
From constant functions you cannot call a non-constant function and constant functions are slightly faster.
08-18-2007, 10:18 AM#7
darkwulfv
Constant functions are also a lot easier and neater to use and read when making big spells/systems. They're usually only used in major spells or submitted JASS, and rarely have any major impact on regular use maps.
08-18-2007, 03:40 PM#8
Silvenon
Why are they easier to read and use? They just have more limitation than a normal function. I don't understand why is a function that has 'constant' in it easier to read.
08-18-2007, 04:12 PM#9
Fireeye
Because you can easily modify a Spell then without searching for every part where the constant is used.
This is why the JESP Standart requires all (or at least almost all) options in constant function, so the user can easily change it.
08-18-2007, 05:00 PM#10
Alexander244
Pipedream did some tests at some point, and I believe he found that function + constant function calls are the same speed. The reason people use constant functions is that they are inlined with Vexorians Map Optimizer. (Function calls are slow, so this is good)

With JassNewGenPack, you also have the option of using constant globals, which can also be inlined. Globals are, arguably, easier to read than constant functions, but they cannot takes values - which means anything with a calculation is hard to change.

Examples are always helpful:

Collapse Pre Optimization:
globals
  constant real spelldamage = 25.
endglobals

constant function Damage takes real lvl returns real
  return 10.+lvl*25.
endfunction

function SpellMain takes real lvl returns nothing
  local real r1 = Damage(lvl)

  local real r2 = 10.+spelldamage*lvl 
  //the +10. and *lvl are inside the code, and not in the config section, so you
  //have to go through the code to find and change them.
endfunction

Collapse Post Optimization:
function SpellMain takes real lvl returns nothing
  local real r1 = 10.+25.*lvl
  local real r2 = 10.+25.*lvl
endfunction
08-18-2007, 05:32 PM#11
botanic
so is there any real reason that i shouldn't make all the functions non-constants in my spells?
08-18-2007, 06:03 PM#12
Alexander244
If you are using vex's map optimizer, using constant funcs will be faster. If you are not, there is no point making them constant.
08-18-2007, 06:13 PM#13
botanic
Ok thanks just one more thing how much faster?
08-18-2007, 06:40 PM#14
darkwulfv
To be honest, unless you're running a very big spell very often, or a very large system, or something to that effect, the difference won't be noticable.
08-18-2007, 06:44 PM#15
PurgeandFire111
I believe it will be hardly noticable.

I've also heard that there is no difference. But that seems untrue.

True, constant functions allow you to obtain a JESP standard but since the effect is hardly noticable, it won't make much of a difference. If you are creating a spell for your map and your map only, then it won't matter as much.

All that now can easily be replaced with vJASS's globals.