Fireball issue

Tyman2007

Ya Rly >.
Reaction score
74
Well, I tried to make a fireball spell.
This is my first Trigger Enhanced Spell that uses structs and timers.

I tried and got most of it done, just the unit gets created, then just stays there..

I had a couple other functions (Such as pause casting unit and unpause) but I got rid of those to see if that would work.

What is wrong? I'm not that good at vJass and could use some advice on how to make this better and how to fix this problem

JASS:
scope Fireball initializer Init

globals
    private constant integer ABIL_CODE = 'A000'     //ID of the ability
    private constant integer DUMM_CODE = 'hfoo'     //ID of the dummy unit (Fireball)
    
    private constant real P_DIST = 150              //Distance from the dummy
//  private constant real S = 10                    //Initial scale of the dummy (in percent)
//  Commented for possible use in future versions
    private constant sound FIRE_SOUND = gg_snd_RainOfFireTarget1 //Sound of the initial cast
    private constant real M_DIST = 20               //How fast the fireball moves
endglobals

private struct DATA
    unit u
    unit u2
    player p
    
    location l1
    location l2
    location l3
    
    real r1
    real r2
    integer Ticks
    integer MTicks
endstruct

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

private function GoFireballGo takes nothing returns nothing
    local DATA d = GetTimerData(GetExpiredTimer())
    local location FBPosition = GetUnitLoc(d.u2)
    local location MoveToPoint
    local timer l = GetExpiredTimer()
    
    set d.MTicks = R2I(d.r2 / M_DIST)
    set d.Ticks = d.Ticks + 1
    set MoveToPoint = PolarProjectionBJ(FBPosition, M_DIST, d.r1)
    call SetUnitPositionLoc(d.u2, MoveToPoint)
        
    call RemoveLocation(MoveToPoint)
    call RemoveLocation(FBPosition)
    set d.u = null
    set d.u2 = null
    
    if d.Ticks >= d.MTicks then
        call PauseTimer(l)
        call ResetUnitAnimation(d.u)
        
        call RemoveLocation(MoveToPoint)
        call RemoveLocation(FBPosition)
        set d.u = null
        set d.u2 = null
        call ReleaseTimer(l)
        call d.destroy()
    endif
endfunction

private function Actions takes nothing returns nothing
    local DATA d = DATA.create()
    local timer l = NewTimer()
    
    set d.u = GetSpellAbilityUnit()
    set d.p = GetOwningPlayer(d.u)
    
    set d.l1 = GetUnitLoc(d.u)
    set d.l2 = GetSpellTargetLoc()
    
    set d.r1 = AngleBetweenPoints(d.l1, d.l2)
    set d.r2 = DistanceBetweenPoints(d.l1, d.l2)
    set d.l3 = PolarProjectionBJ(d.l1, P_DIST, d.r1)
    
    call CreateUnitAtLoc( d.p, DUMM_CODE, d.l3, 270 )
    set d.u2 = GetLastCreatedUnit()
    call SetUnitPathing( d.u2, false)
    call SetUnitAnimation(d.u, "spell channel")
//  call SetUnitScalePercent( d.u2, S, S, S )
//  Commented for possible use in future versions.
    
    call PlaySoundAtPointBJ( FIRE_SOUND, 100, d.l3, 0 )
    call TriggerSleepAction(2.5)
    
    call SetTimerData(l, d)
    call TimerStart(l, 0.03, true, function GoFireballGo)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


I should also add I'm using TimerUtils.

I tried making a trigger to test if everything is working right and it does, and I think it's because of the units and what not.. I followed a guide and I don't think it helped.

This is the trigger that is working fine.
JASS:
scope Tick initializer Init

private struct Data
    integer Ticks
    string Msg
endstruct

private function Callback takes nothing returns nothing
    local Data d = GetTimerData(GetExpiredTimer())
    local timer t = GetExpiredTimer()
    call DisplayTextToPlayer(Player(0), 0, 0, d.Msg)
    set d.Ticks = d.Ticks + 1
    if d.Ticks >= 1 then
        call PauseTimer(t)
        call ReleaseTimer(t)
        call d.destroy()
    endif
endfunction

private function Actions takes nothing returns nothing
    local timer t = NewTimer()
    local Data d = Data.create()
    
    set d.Msg = "Tick"
    call DisplayTextToPlayer(Player(0), 0, 0, d.Msg)
    
    call SetTimerData(t, d)
    call TimerStart(t, 1, true, function Callback)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( t, function Actions )
endfunction

endscope
 

Rllulium

New Member
Reaction score
10
Try to avoid the use of Locations... use real values to store X and Y coordinates instead.
 

Tyman2007

Ya Rly >.
Reaction score
74
I use locations for their compatability with PolarProjectionBJ
I can't use x and y with that since it requires a location and it just gets the x and y of the location and returns it anyway...

I'm not in trigonometry or calculus. I'm not that advanced to make it work.
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
I use locations for their compatability with PolarProjectionBJ
I'm not in trigonometry or calculus. I'm not that advanced to make it work.
make your own PolarProjectionBJ, it's not really hard
 

Tyman2007

Ya Rly >.
Reaction score
74
Thanks for the response.. but is that just something that can make this better or something that can resolve the issue.
 

Tyman2007

Ya Rly >.
Reaction score
74
Appearantly you didn't understand me... I was asking if it would fix the problem..

It shouldn't.. It doesn't.. Tried.. Nope..

JASS:
scope Fireball initializer Init

globals
    private constant integer ABIL_CODE = 'A000'     //ID of the ability
    private constant integer DUMM_CODE = 'hfoo'     //ID of the dummy unit (Fireball)
    
    private constant real P_DIST = 150              //Distance from the dummy
//  private constant real S = 10                    //Initial scale of the dummy (in percent)
//  Commented for possible use in future versions
    private constant sound FIRE_SOUND = gg_snd_RainOfFireTarget1 //Sound of the initial cast
    private constant real M_DIST = 20               //How fast the fireball moves
endglobals

private struct DATA
    unit u
    unit u2
    player p
    
    location l1
    location l2
    location l3
    
    real r1
    real r2
    integer Ticks
    integer MTicks
    
    real x
    real y
endstruct

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

private function GoFireballGo takes nothing returns nothing
    local DATA d = GetTimerData(GetExpiredTimer())
    local real x = d.x + M_DIST * Cos(d.r1 * bj_DEGTORAD)
    local real y = d.y + M_DIST * Sin(d.r1 * bj_DEGTORAD)
    local timer l = GetExpiredTimer()
    
    set d.MTicks = R2I(d.r2 / M_DIST)
    set d.Ticks = d.Ticks + 1
    call SetUnitPosition(d.u2, x, y)
    
    call DisplayTextToPlayer(Player(0), 0, 0, "Tock")
        
    set d.x = GetUnitX(d.u2)
    set d.y = GetUnitY(d.u2)
    set d.u = null
    set d.u2 = null
    
    if d.Ticks >= d.MTicks then
        call PauseTimer(l)
        call SetUnitAnimation(d.u, "stand")
        call ReleaseTimer(l)
        call d.destroy()
    endif
endfunction

private function Actions takes nothing returns nothing
    local DATA d = DATA.create()
    local timer l = NewTimer()
    
    set d.u = GetSpellAbilityUnit()
    set d.p = GetOwningPlayer(d.u)
    
    set d.l1 = GetUnitLoc(d.u)
    set d.l2 = GetSpellTargetLoc()
    
    set d.r1 = AngleBetweenPoints(d.l1, d.l2)
    set d.r2 = DistanceBetweenPoints(d.l1, d.l2)
    set d.l3 = PolarProjectionBJ(d.l1, P_DIST, d.r1)
    
    call CreateUnitAtLoc( d.p, DUMM_CODE, d.l3, 270 )
    set d.u2 = GetLastCreatedUnit()
    call SetUnitPathing( d.u2, false)
    call SetUnitAnimation(d.u, "spell channel")
//  call SetUnitScalePercent( d.u2, S, S, S )
//  Commented for possible use in future versions.

    set d.x = GetUnitX(d.u2)
    set d.y = GetUnitY(d.u2)
    
    call PlaySoundAtPointBJ( FIRE_SOUND, 100, d.l3, 0 )
    call TriggerSleepAction(2.5)
    
    call SetTimerData(l, d)
    call TimerStart(l, 0.03, true, function GoFireballGo)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


The trigger is running, just the unit is not getting moved.
 

_whelp

New Member
Reaction score
54
Simple. [ljass]CreateUnit...[/ljass] doesn't set [ljass]GetLastCreatedUnit()[/ljass].

JASS:

scope Fireball initializer Init

globals
    private constant integer ABIL_CODE = 'A000'     //ID of the ability
    private constant integer DUMM_CODE = 'hfoo'     //ID of the dummy unit (Fireball)
    
    private constant real P_DIST = 150              //Distance from the dummy
//  private constant real S = 10                    //Initial scale of the dummy (in percent)
//  Commented for possible use in future versions
    private constant sound FIRE_SOUND = gg_snd_RainOfFireTarget1 //Sound of the initial cast
    private constant real M_DIST = 20               //How fast the fireball moves
endglobals

private struct DATA
    unit u
    unit u2
    player p
    
    location l1
    location l2
    location l3
    
    real r1
    real r2
    integer Ticks
    integer MTicks
    
    real x
    real y
endstruct

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

private function GoFireballGo takes nothing returns nothing
    local DATA d = GetTimerData(GetExpiredTimer())
    local real x = d.x + M_DIST * Cos(d.r1 * bj_DEGTORAD)
    local real y = d.y + M_DIST * Sin(d.r1 * bj_DEGTORAD)
    local timer l = GetExpiredTimer()
    
    set d.MTicks = R2I(d.r2 / M_DIST)
    set d.Ticks = d.Ticks + 1
    call SetUnitPosition(d.u2, x, y)
    
    call DisplayTextToPlayer(Player(0), 0, 0, "Tock")
        
    set d.x = GetUnitX(d.u2)
    set d.y = GetUnitY(d.u2)
    set d.u = null
    set d.u2 = null
    
    if d.Ticks >= d.MTicks then
        call PauseTimer(l)
        call SetUnitAnimation(d.u, "stand")
        call ReleaseTimer(l)
        call d.destroy()
    endif
endfunction

private function Actions takes nothing returns nothing
    local DATA d = DATA.create()
    local timer l = NewTimer()
    
    set d.u = GetSpellAbilityUnit()
    set d.p = GetOwningPlayer(d.u)
    
    set d.l1 = GetUnitLoc(d.u)
    set d.l2 = GetSpellTargetLoc()
    
    set d.r1 = AngleBetweenPoints(d.l1, d.l2)
    set d.r2 = DistanceBetweenPoints(d.l1, d.l2)
    set d.l3 = PolarProjectionBJ(d.l1, P_DIST, d.r1)
    
    set d.u2 = CreateUnitAtLoc( d.p, DUMM_CODE, d.l3, 270 )
    call SetUnitPathing( d.u2, false)
    call SetUnitAnimation(d.u, "spell channel")
//  call SetUnitScalePercent( d.u2, S, S, S )
//  Commented for possible use in future versions.

    set d.x = GetUnitX(d.u2)
    set d.y = GetUnitY(d.u2)
    
    call PlaySoundAtPointBJ( FIRE_SOUND, 100, d.l3, 0 )
    call TriggerSleepAction(2.5)
    
    call SetTimerData(l, d)
    call TimerStart(l, 0.03, true, function GoFireballGo)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top