GoGo-Boy
You can change this now in User CP
- Reaction score
- 40
Here's my script for a trigger based projectile system. However I hope that you guys may find s.th. to improve the performance.
For example I dunno how to do that in a whole struct without any non-struct function. Or maybe another system than KT?
For example I dunno how to do that in a whole struct without any non-struct function. Or maybe another system than KT?
JASS:
scope Projectiles
globals
private constant real FREQUENZY=0.025
private unit VIC
endglobals
private struct Projectile
unit attacker
unit proj
effect model
real damage
real x
real y
real x_vel
real y_vel
real z
real time=0
real max_time
boolean aoe
real radius
real height
endstruct
private function Callback takes nothing returns boolean
local Projectile p=KT_GetData()
set p.time=p.time+FREQUENZY
set p.x=p.x+p.x_vel
set p.y=p.y+p.y_vel
call SetUnitX(p.proj,p.x)
call SetUnitY(p.proj,p.y)
call MoveLocation(LOC,p.x,p.y)
call SetUnitFlyHeight(p.proj,p.height+p.z-GetLocationZ(LOC),0)
call GroupEnumUnitsInRange(GROUP,p.x,p.y,p.radius,Filter(function HeroForce))
set VIC=FirstOfGroup(GROUP)
if not(VIC==null) then
call Damage_Physical(p.attacker,VIC,p.damage,ATTACK_TYPE_NORMAL,true,true)
call UnitApplyTimedLife(p.proj,TIMED_LIFE,2)
call DestroyEffect(p.model)
call p.destroy()
return true
endif
if p.time<=p.max_time then
return false
endif
call UnitApplyTimedLife(p.proj,TIMED_LIFE,2)
call DestroyEffect(p.model)
call p.destroy()
return true
endfunction
function Attack takes unit attacker,unit target,real damage,boolean aoe,real radius,real speed,real distance,real scale, string effect_model,real height returns nothing
local Projectile p=Projectile.create()
local real x=GetUnitX(attacker)
local real y=GetUnitY(attacker)
local real targ_x=GetUnitX(target)
local real targ_y=GetUnitY(target)
local real face=Atan2(targ_y-y,targ_x-x)
set p.attacker=attacker
set p.x=x
set p.y=y
set p.max_time=distance/speed
set p.x_vel=speed*FREQUENZY*Cos(face)
set p.y_vel=speed*FREQUENZY*Sin(face)
set p.aoe=aoe
set p.radius=radius
set p.damage=damage
set p.height=height
set p.proj=CreateUnit(Player(12),DUMMY2_ID,x,y,Rad2Deg(face))
call MoveLocation(LOC,x,y)
set p.z=GetLocationZ(LOC)
call UnitAddAbility(p.proj,CROW_ABILITY)
call SetUnitFlyHeight(p.proj,height,0)
call SetUnitScale(p.proj,scale,scale,scale)
set p.model=AddSpecialEffectTarget(effect_model,p.proj,"origin")
call KT_Add(function Callback,p,FREQUENZY)
endfunction
endscope