• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Shockwave

Status
Not open for further replies.
Level 6
Joined
Aug 4, 2012
Messages
193
I want to make a shockwave ability based on hero stats. Can I know why this code is not working? Thanks for the help.

JASS:
function Trig_Shockwave_Conditions takes nothing returns boolean
    return(GetSpellAbilityId()=='A001')
endfunction

function Shockwave_IsEnemy takes nothing returns boolean
    return(IsUnitEnemy(GetEnumUnit(),GetOwningPlayer(ShockwaveCaster)))
endfunction

function Shockwave_Damage takes nothing returns nothing
    call UnitDamageTarget(ShockwaveCaster,GetEnumUnit(),GetHeroStr(ShockwaveCaster,true)*3,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endfunction

function Trig_Shockwave_Actions takes nothing returns nothing
    local location CasterLoc
    local real TravelledDistance
    local unit Dummy
    local location DummyLoc
    local group EnemyGroup=CreateGroup()
    set ShockwaveCaster=GetSpellAbilityUnit()
    set CasterLoc=GetUnitLoc(ShockwaveCaster)
    set Dummy=CreateUnitAtLoc(GetOwningPlayer(ShockwaveCaster),'h000',CasterLoc,AngleBetweenPoints(CasterLoc,GetSpellTargetLoc()))
    loop
        exitwhen TravelledDistance>=1200
        set TravelledDistance=TravelledDistance+63
        call TriggerSleepAction(0.06)
        set DummyLoc=GetUnitLoc(Dummy)
        call SetUnitPositionLoc(Dummy,PolarProjectionBJ(DummyLoc,63,GetUnitFacing(Dummy)))
        call GroupEnumUnitsInRangeOfLoc(EnemyGroup,DummyLoc,200,Condition(function Shockwave_IsEnemy))
        call ForGroup(EnemyGroup,function Shockwave_Damage)
    endloop
    call RemoveLocation(DummyLoc)
    call RemoveUnit(Dummy)
    call RemoveLocation(CasterLoc)
    call DestroyGroup(EnemyGroup)
endfunction
//===========================================================================
function InitTrig_Shockwave takes nothing returns nothing
    set gg_trg_Shockwave=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Shockwave,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Shockwave,Condition(function Trig_Shockwave_Conditions))
    call TriggerAddAction(gg_trg_Shockwave,function Trig_Shockwave_Actions)
endfunction
 
Last edited:
Level 6
Joined
Aug 4, 2012
Messages
193
The trigger isn't registered to an event. But yes, better always explain what's not working.
Thanks for pointing that out but that's not the problem. I fixed it before posting. The problem is with the dummy is not moving. Sorry for not making it clear.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
At least I think one error is that "TravelledDistance" is not initialisized before it's read in "exitwhen TravelledDistance>=1200". Set it to "0" when you declare it.
The reason this is a problem is because reading a non-array variable which is not initialized to a value causes a thread crash. The code stops executing at that line.
 
Level 6
Joined
Aug 4, 2012
Messages
193
There is no "GetEnumUnit()" context in the filter. The native GetEnumUnit() only works for ForGroup and not in Enum filter functions. Filter functions have to use GetFilterUnit().
JASS:
constant native GetFilterUnit takes nothing returns unit
Thanks for pointing that out.

I also wonder how you can use ShockwaveCaster without error, since it should be unknown in other functions.
No worry, that's a global variable.

By the way, can I pass local variable to another function?
 
Ah.
By the way, can I pass local variable to another function?
You can pass variables to a function yes, but not simply accessing locals from an foreign function.

How to pass:

JASS:
function print takes string whichString returns nothing
   
// use the parameter which is given
    call BJDebugMsg(whichString)
endfunction

function test takes nothing returns nothing

//  run print() function and give a string as parameter
    call print("Apple juice!!")
endfunction
 
An functions uses arguments, if they are mentioned after the "takes".

JASS:
function f takes integer i returns nothing
 call BJDebugMsg(I2S(i))
endfunction

function start takes nothing returns nothing
   local integer number = 10
   call f(number)
endfunction

But functions beeing an arument can not take arguments -> anytime your write something like "call y(... , function x)".
this function x can not take any argument.
Appears for example in:
  • Groups
  • Timers
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
You can pass variables to a function yes, but not simply accessing locals from an foreign function.

How to pass:
To clarify, that is actually making a new local variable within another function as a function parameter and copying a value to it.

But functions beeing an arument can not take arguments -> anytime your write something like "call y(... , function x)".
this function x can not take any argument.
That is because you are not calling the function but rather referencing a function using a code statement. "function x" is a code statemet where as x(...) is a function call taking "..." arguments as its parameters. The physical difference is a code is a function pointer, an address pointing to a start of a function, where as a call includes passing arguments as parameters then directly calling the function with a call instruction.

The dummy moves very slowly, even though the wait time is 0.01 second. Any better idea to do this?
The TriggerSleepAction is 0.1 + network latency in real time. It is not "0.01 seconds" in game time. For more accurate timing in game time use either periodic events or timers. Be warned that periodic timers do not survive save/load cycles well.
 
Status
Not open for further replies.
Top