- Joined
- Apr 16, 2011
- Messages
- 158
I will leave my doubt of the day here:
something that I still did not understand and how to move a unit on the map
What I want to do:
-create a unit in front of the "caster" order to move up to a point X with a speed Y,this movement should be done Z number of times
I'll leave my code here,he is creating units,i will still set the cordeadas,but what I need to know is how to move the unit.
something that I still did not understand and how to move a unit on the map
What I want to do:
-create a unit in front of the "caster" order to move up to a point X with a speed Y,this movement should be done Z number of times
I'll leave my code here,he is creating units,i will still set the cordeadas,but what I need to know is how to move the unit.
JASS:
library Code initializer onInit requires Tt,SpellEffectEvent
//==================================================================================//
globals
// Id of ability
private constant integer ID_ABILITY = 'A000'
// Id of dummy
private constant integer ID_DUMMY = 'u000'
// Model of dummy
private constant string MODEL_MISSILE = "Effect_StarfallMissle.mdx"
// Attack and damage type
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
// Speed of dummy
private constant real SPEED = 1600.
// AOE of damage
private constant real AREA_OF_EFFECT = 110.
endglobals
// Number of missiles
private function Missiles takes integer level returns integer
return 4*level
endfunction
// Damage
private function GetDamage takes integer heroInt,integer level returns real
return (heroInt/10.)+(level*15.)
endfunction
//interval dummys
private function GetTimeout takes integer level returns real
return .18
endfunction
//Target filter
private function TargetFilter takes unit caster, player owner, unit target returns boolean
return not IsUnitType(target, UNIT_TYPE_STRUCTURE) and not IsUnitType(target, UNIT_TYPE_DEAD) and IsUnitEnemy(target, owner)
endfunction
//==================================================================================//
private struct Spell extends array
private static unit array caster
private static unit array dummy
private static player array owner
private static integer array waves
private static real array damage
private static real array angle
private static real array distance
private static real array x
private static real array y
private static real array xx
private static real array yy
private static real array dx
private static real array dy
implement CTM
local unit t
local unit d
implement CTMExpire
set dummy[this] = CreateUnit(owner[this], ID_DUMMY, x[this], y[this], angle[this] * bj_RADTODEG)
call UnitApplyTimedLife(dummy[this], 'BTLF', 1.)
call SetUnitPosition(dummy[this], GetUnitX(dummy[this]) + 30. * Cos(angle[this]), GetUnitY(dummy[this]) + 30. * Sin(angle[this]))
call GroupEnumUnitsInRange(bj_lastCreatedGroup, GetUnitX(dummy[this]), GetUnitY(dummy[this]), AREA_OF_EFFECT, null)
loop
set t = FirstOfGroup(bj_lastCreatedGroup)
exitwhen t == null
call GroupRemoveUnit(bj_lastCreatedGroup, t)
// How i move?
if TargetFilter(caster[this], owner[this], t) then
call UnitDamageTarget(caster[this], t, damage[this], false, false, ATTACK_TYPE, DAMAGE_TYPE, null)
endif
endloop
set waves[this] = waves[this] - 1
if waves[this] == 0 then
call this.destroy()
set dummy[this] = null
set caster[this] = null
set owner[this] = null
endif
implement CTMEnd
private static method run takes nothing returns nothing
local integer level = GetUnitAbilityLevel(GetTriggerUnit(), ID_ABILITY)
local thistype this = create(GetTimeout(level))
local integer heroInt
// caster and owner
set caster[this] = GetTriggerUnit()
set owner[this] = GetOwningPlayer(caster[this])
// hero Int
set heroInt = GetHeroInt(caster[this], true)
// Get x,y and xx,yy
set x[this] = GetUnitX(caster[this])
set y[this] = GetUnitY(caster[this])
set xx[this] = GetSpellTargetX()
set yy[this] = GetSpellTargetY()
// dx dy
set dx[this] = x[this] - xx[this]
set dy[this] = y[this] - yy[this]
// angle and distance
set angle[this] = Atan2(dy[this],dx[this])
set distance[this] = SquareRoot(dx[this] * dx[this] + dy[this] * dy[this])
// damage and number of waves
set damage[this] = GetDamage(heroInt,level)
set waves[this] = Missiles(level)
endmethod
private static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(ID_ABILITY, function thistype.run)
endmethod
endstruct
endlibrary