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: 113

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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top