- Joined
- Dec 6, 2009
- Messages
- 173
Hello. I remade a gui trigger in vjass to get back into vjass again after some time away. The spell is a straight lined beam which is supposed to deal damage to everyone for 100 damage withing 500 range of the beam.
But my problem is that right now the damage event is running 25 times because the LOOP_NUMBER is 25 times. And it mesures a 500 radius from each dummy unit I spawn. So if a unit is withing range of 2 or more it takes damage for each dummy unit it is withing range of. So the spell deals more like 500-1000 damage. So my question is how do you guys fix it easily so that the unit only takes damage one time? Also I wonder why my damage function returns 1.00 when it's supposed to return 100? It doesn't matter if I write something like "return 200" or "return BASE_DAMAGE + 500" it still says 1.00.
Anyway here is the code for the spell:
But my problem is that right now the damage event is running 25 times because the LOOP_NUMBER is 25 times. And it mesures a 500 radius from each dummy unit I spawn. So if a unit is withing range of 2 or more it takes damage for each dummy unit it is withing range of. So the spell deals more like 500-1000 damage. So my question is how do you guys fix it easily so that the unit only takes damage one time? Also I wonder why my damage function returns 1.00 when it's supposed to return 100? It doesn't matter if I write something like "return 200" or "return BASE_DAMAGE + 500" it still says 1.00.
JASS:
private function damage takes nothing returns real
return BASE_DAMAGE
endfunction
Anyway here is the code for the spell:
JASS:
scope WaterBeam initializer init
native UnitAlive takes unit id returns boolean
globals
private constant integer AID = 'A001'
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_MAGIC
private constant real DISTANCE = 50.00
private constant integer LOOP_NUMBER = 25
private constant real BASE_DAMAGE = 100
private constant real AOE = 500.00
private constant integer DUMMY_UNIT = 'h000'
private group g = CreateGroup()
endglobals
private function TargetFilter takes unit target, player owner returns boolean
return UnitAlive(target) and IsUnitEnemy(target, owner) and not IsUnitType(target, UNIT_TYPE_STRUCTURE)
endfunction
private function damage takes nothing returns real
return BASE_DAMAGE
endfunction
private function applyDamage takes nothing returns nothing
local unit target = GetEnumUnit()
local player owner = GetTriggerPlayer()
if (TargetFilter(target, owner)) then
call UnitDamageTarget(GetTriggerUnit(), target, BASE_DAMAGE, false, false, ATTACK_TYPE, DAMAGE_TYPE, null)
call DisplayTextToForce( GetPlayersAll(), R2S(BASE_DAMAGE) + "BaseDamage" )
call DisplayTextToForce( GetPlayersAll(), R2S(damage) + "damage" )
call GroupRemoveUnitSimple( target, g)
endif
set target = null
set owner = null
endfunction
private function run takes nothing returns nothing
local unit dummy
local unit array dummy2
local unit caster = GetTriggerUnit()
local real x = GetSpellTargetX()
local real y = GetSpellTargetY()
local real facing = GetUnitFacing(caster)
local player owner = GetOwningPlayer(caster)
local integer i = 1
local location loc = PolarProjectionBJ(GetUnitLoc(caster), 100.00, facing)
local location loc_loop
set dummy = CreateUnitAtLoc(owner, DUMMY_UNIT, loc, facing)
call UnitApplyTimedLifeBJ( 1.00, 'BTLF', dummy )
loop
exitwhen i > LOOP_NUMBER
set loc_loop = PolarProjectionBJ( loc, DISTANCE * I2R(i), facing)
set dummy2[i] = CreateUnitAtLoc(owner, DUMMY_UNIT, loc_loop, facing)
call UnitApplyTimedLifeBJ( ( 0.85 - ( 0.01 * I2R(i) ) ), 'BTLF', dummy2[i] )
set g = GetUnitsInRangeOfLocAll(AOE, loc_loop)
call ForGroup( g, function applyDamage)
call RemoveLocation(loc_loop)
call DestroyGroup(g)
set i = i + 1
set dummy2[i] = null
endloop
set dummy = null
set g = null
set owner = null
call RemoveLocation(loc)
endfunction
private function init takes nothing returns nothing
call RegisterSpellEffectEvent(AID, function run)
endfunction
endscope