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
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.
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 = 039;A000039; //ID of the ability
private constant integer DUMM_CODE = 039;hfoo039; //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