- Joined
- Mar 16, 2008
- Messages
- 941
Hey guys. Fixed!
I tried to recreate a spell of mine, however, it completly fails.
It's supposed to create two missles, one at the left side and one at the right side of the caster, both chasing towards the castpoint.
The problem is, that the missles don't move.
They start moving when the spell is used very often, although each of them uses a seperate timer!
There are some functions that are required for this.
The others are TimerUtils, GroupUtils and a custom trigger system,
but this works, the spell is started
Greets, Justify
I tried to recreate a spell of mine, however, it completly fails.
It's supposed to create two missles, one at the left side and one at the right side of the caster, both chasing towards the castpoint.
The problem is, that the missles don't move.
They start moving when the spell is used very often, although each of them uses a seperate timer!
JASS:
scope ChillingStreams initializer InitStreams
globals
private constant integer SPELL_ID = 'A000'
private constant real PERIOD = 0.04
private constant string SFX_PATH = "Abilities\\Weapons\\FrostWyrmMissile\\FrostWyrmMissile.mdl"
private constant string SFX_ATTACH = "chest"
private constant real SPEED = 400.
private constant real SIDEDIST = 100.
private constant integer MISSLE_COUNT = 2
private constant real STEP = SPEED*PERIOD
endglobals
private constant function GetMaxDist takes integer lvl returns real
return 500.+lvl*200.
endfunction
private constant function GetDamage takes integer lvl returns real
return lvl*70.
endfunction
private struct Streams
private unit caster
private player owner
private unit array missle[MISSLE_COUNT]
private effect array sfx[MISSLE_COUNT]
private real array vecx[MISSLE_COUNT]
private real array vecy[MISSLE_COUNT]
private group array hit[MISSLE_COUNT]
private real dist
private real maxdist
private timer movetim
method onDestroy takes nothing returns nothing
local integer i = 0
set .caster = null
loop
exitwhen i >= MISSLE_COUNT
call ReleaseDummyTimed(.missle[i])
call DestroyEffect(.sfx[i])
set .sfx[i] = null
call ReleaseGroup(.hit[i])
set .hit[i] = null
set i = i+1
endloop
call ReleaseTimer(movetim)
endmethod
static method movement takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
local integer i = 0
loop
exitwhen i >= MISSLE_COUNT
call SetUnitX(.missle[i], GetUnitX(.missle[i])+.vecx[i])
call SetUnitY(.missle[i], GetUnitY(.missle[i])+.vecy[i])
set i = i+1
endloop
set .dist = .dist+STEP
if .dist >= .maxdist then
call .destroy()
endif
endmethod
static method createStreams takes nothing returns nothing
local thistype this = thistype.allocate()
local real spellx = GetSpellTargetX()
local real spelly = GetSpellTargetY()
local real x
local real y
local real casterx
local real castery
local real angle
local real facing
local integer i = 0
set .caster = GetTriggerUnit()
set casterx = GetUnitX(.caster)
set castery = GetUnitY(.caster)
set facing = Atan2(spelly-castery, spellx-casterx) //Real angle between the caster and the spell
set .owner = GetOwningPlayer(.caster)
loop
exitwhen i >= MISSLE_COUNT
set facing = facing+(i+1)/2*bj_PI
set x = PolarX(casterx, facing, SIDEDIST) //Creating points right and left (one per loop)
set y = PolarY(castery, facing, SIDEDIST) //of the caster
set angle = Atan2(spelly-y, spellx-x)
set .missle[i] = NewDummy(x, y, angle)
call AddSpecialEffectTarget(SFX_PATH, .missle[i], SFX_ATTACH)
set .vecx[i] = PolarX(0, angle, STEP)
set .vecy[i] = PolarY(0, angle, STEP)
set .hit[i] = NewGroup()
set i = i+1
endloop
set .dist = 0.
set .maxdist = GetMaxDist(GetUnitAbilityLevel(.caster, SPELL_ID))
set .movetim = NewTimer()
call SetTimerData(.movetim, this)
call TimerStart(.movetim, PERIOD, true, function thistype.movement)
endmethod
endstruct
private function InitStreams takes nothing returns nothing
call AddSpellAction(SPELL_ID, Streams.createStreams)
endfunction
endscope
There are some functions that are required for this.
The others are TimerUtils, GroupUtils and a custom trigger system,
but this works, the spell is started
JASS:
function PolarX takes real x, real angle, real distance returns real
return x+distance*Cos(angle)
endfunction
function PolarY takes real y, real angle, real distance returns real
return y+distance*Sin(angle)
endfunction
Greets, Justify
Last edited: