Spell - Flaming Arrow - Having Trouble

Fulla

Evil Overlord
Reaction score
31
The spell is meant to be a pretty straight forward projectile spell. It launches an arrow in an arc towards a destination & upon impact explodes dealing AoE damage.

Anitarf helped me alot with this script, but he had to go, so seeking further help. I'm currently having 2 major problems:
  • The Z for the projectile seems to not working at all, i.e. the projectile remains at ground height through out.
  • The Speed seems to vary depending on which angle I cast at, i.e. sideways (roughly 0 or 180) it works fine, but other than that it gets completely screwed up

I'm also learning how to use scopes during this, so bare with me :)

JASS:
scope FlamingArrow

globals
    flamingarrowdata array FlamingArrowArray
    integer FlamingArrowTotal = 0
    
    private constant integer ABILITY_RAWCODE    = 'A002'
    private constant real TIMER_INTERVAL        = 0.03
    
    private constant real MISSILE_SPEED         = 900
    private constant real MISSILE_GRAVITY       = 300
    private constant real MISSILE_MINDIST       = 400
    
    private constant real MISSILE_DAMAGE        = 100
endglobals

struct flamingarrowdata
    unit missile = null
    effect sfx = null
    integer level = 0
    real sx = 0
    real sy = 0
    real sz = 0
    real vx = 0
    real vy = 0
    real vz = 0
    real time = 0
    real duration = 0
endstruct

function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILITY_RAWCODE
endfunction

function End takes unit u, integer level returns nothing
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl", x, y))
endfunction

function Timer takes nothing returns nothing
    local flamingarrowdata dat
    local integer i = 0
    local integer aoa = 0
    local real z = 0
    loop
        exitwhen i >= FlamingArrowTotal
        set dat = FlamingArrowArray<i>
        set dat.time = dat.time + (TIMER_INTERVAL / dat.duration)
        set z = GetZ(GetUnitX(dat.missile), GetUnitY(dat.missile))
        call SetUnitX(dat.missile, dat.sx + dat.vx * dat.time) 
        call SetUnitY(dat.missile, dat.sy + dat.vy * dat.time)
        call SetUnitFlyHeight(dat.missile, dat.sz + dat.vz * dat.time - MISSILE_GRAVITY * dat.time * dat .time / 2 - z, 0)
        set aoa = R2I(Atan2BJ(dat.vz -MISSILE_GRAVITY * dat.time, SquareRoot(dat.vx * dat.vx + dat.vy * dat.vy))) + 90 
        call SetUnitAnimationByIndex(dat.missile, aoa)
      //Missile has reached its destination  
        if dat.time &gt;= dat.duration then
          //Add an explosion
            call End(dat.missile, dat.level)
          //Destroy everything  
            call DestroyEffect(dat.sfx)
            call KillUnit(dat.missile)
            set FlamingArrowTotal = FlamingArrowTotal - 1
            set FlamingArrowArray<i> = FlamingArrowArray[FlamingArrowTotal]
            call dat.destroy()
            set i = i - 1
        endif
        set i = i + 1
    endloop
    if FlamingArrowTotal==0 then
        call ReleaseTimer(GetExpiredTimer())
    endif  
endfunction

function Actions takes nothing returns nothing
    local flamingarrowdata dat = flamingarrowdata.create()
    local unit u = GetTriggerUnit()
    local location l = GetSpellTargetLoc()
    local real dx = GetLocationX(l) - GetUnitX(u)
    local real dy = GetLocationY(l) - GetUnitY(u)
    local real dz = GetLocationZ(l) - (GetUnitZ(u) + 100)
    local real dist = SquareRoot(dx * dx + dy + dy)
  //Minimum distance  
    if dist &lt; MISSILE_MINDIST then
        set dx = dx * MISSILE_MINDIST / dist
        set dy = dy * MISSILE_MINDIST / dist
        set dist = MISSILE_MINDIST
    endif
    set dat.missile = CreateUnit(GetOwningPlayer(u), &#039;hmil&#039;, GetUnitX(u), GetUnitY(u), Atan2BJ(dy, dx))
    set dat.sfx = AddSpecialEffectTarget(GetAbilityEffectById(ABILITY_RAWCODE, EFFECT_TYPE_MISSILE, 1), dat.missile, &quot;origin&quot;)
    set dat.level = GetUnitAbilityLevel(u, ABILITY_RAWCODE)
    set dat.duration = dist / MISSILE_SPEED
    set dat.sx = GetUnitX(u)
    set dat.sy = GetUnitY(u)
    set dat.sz = GetUnitZ(u)
    set dat.vx = dx / dat.duration  
    set dat.vy = dy / dat.duration  
    set dat.vz = dz / dat.duration + MISSILE_GRAVITY * dat.duration / 2 
  //The Missile is shot/launched from 100 above the caster  
    call SetUnitFlyHeight(dat.missile, 100, 0)
    if FlamingArrowTotal == 0 then
        call TimerStart(NewTimer(), TIMER_INTERVAL, true, function Timer)
    endif
    set FlamingArrowArray[FlamingArrowTotal] = dat
    set FlamingArrowTotal = FlamingArrowTotal + 1
    call RemoveLocation(l)
    set u = null
endfunction

//===========================================================================
function InitTrig_Flaming_Arrow takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Condition(function Conditions))
    call TriggerAddAction(t, function Actions)
endfunction

endscope</i></i>


thx for any help.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
1)
JASS:
    flamingarrowdata array FlamingArrowArray


Does it work with creating the struct array variable before the acual struct?

2)

JASS:
function End takes unit u, integer level returns nothing
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    call DestroyEffect(AddSpecialEffect(&quot;Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl&quot;, x, y))
endfunction


Where do you use that level argument?
 

Trollvottel

never aging title
Reaction score
262
1)what is the units movement-type? if it isnt flying you have to add Crow Form to the dummy.

2) dont you use cos and sin? without them polar projection is almost impossible
 

Fulla

Evil Overlord
Reaction score
31
Does it work with creating the struct array variable before the acual struct?

I'm not sure what you mean?
Basically when I;ve finished intilializing/preparing a struct's data in the actions, I add it into the array for looping later in the timer.

Where do you use that level argument?

I don't yet, I haven't completed the explosion, because the spell is very buggy atm :p

what is the units movement-type? if it isnt flying you have to add Crow Form to the dummy.

Yup its flying & added crow form ability

dont you use cos and sin? without them polar projection is almost impossible

I did originally & simply used polar projection + a parabula for the arc.
But Anit insisted I ditch that & do it this way :p

===

Anyways I guess its best if I attach the testmap, just click on the Ranger & try casting spell a few times u'll see how 'dodgy' it is.
 

Attachments

  • Spell 1.w3x
    53.7 KB · Views: 112

Cohadar

master of fugue
Reaction score
209
I don't think it is ok for you to ask help on a spell for contest.
It could be considered cheating.
After all it is a contest of personal skills.
 

Flare

Stops copies me!
Reaction score
662
I don't think it is ok for you to ask help on a spell for contest.
It could be considered cheating.
After all it is a contest of personal skills.

A number of others are doing it over at WC3C :p (not sure if they are looking for bug-fixes, or just opinion on code, but it's still similar)

I'm not sure what you mean?
He means that the flamingarrowdata array was created above the struct declaration so, as far as the compiler is concerned, there is no type going by the name flamingarrowdata - you can use a keyword to solve it i.e.
JASS:
private keyword flamingarrowdata

globals
  private flamingarrowdata array Data
endglobals

struct flamingarrowdata
...
endstruct


Or declare the global flamingarrowdata array below the struct declaration
 

Fulla

Evil Overlord
Reaction score
31
Well consdering alot of ppl are doing it already on wc3camp, with mods/admins helping them can't see a problem.
It's all a contest to promote & encourage ppl to get out there code a few spells, get involved with the community & generally learn more.

Or declare the global flamingarrowdata array below the struct declaration

Oh ok, I've always done it this way thou & never had any problems.
 

Sevion

The DIY Ninja
Reaction score
413
Well consdering alot of ppl are doing it already on wc3camp, with mods/admins helping them can't see a problem.

WC3C != TH

JASS:
call SetUnitFlyHeight(dat.missile, dat.sz + dat.vz * dat.time - MISSILE_GRAVITY * dat.time * dat .time / 2 - z, 0)


On the last dat.time, you have a space between dat and .time.

That's all I can see from here. I'm not too familiar with structs.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top