SineCosine
I'm still looking for my Tangent
- Reaction score
- 77
Be kind now..
I've been trying to get a spell to Damage nearby enemies and heal allies (and the caster) based on the formula:
(Damage * No. of enemies hit) / (No. of allies nearby + 1)
= Total damage dealt / (No. of allies nearby + 1)
The thing is, one value is stuck at 10.00
That is, the totaldmg value
I know there is a better way to do what I'm doing..
But I don't know what that other much better way is, so I'm asking for help here in hopes that someone will enlighten me.
I don't mind starting from scratch, it isn't exactly a lot of code, but I just need a little nudge in the right direction![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
method GroupReverse is where my problem is, about mid-way through the code
[EDIT]
I got the spell to work the way I wanted it to.
But I'd still like to know if there is a much better way to do things
All enemies are Orc race
I've been trying to get a spell to Damage nearby enemies and heal allies (and the caster) based on the formula:
(Damage * No. of enemies hit) / (No. of allies nearby + 1)
= Total damage dealt / (No. of allies nearby + 1)
The thing is, one value is stuck at 10.00
That is, the totaldmg value
I know there is a better way to do what I'm doing..
But I don't know what that other much better way is, so I'm asking for help here in hopes that someone will enlighten me.
I don't mind starting from scratch, it isn't exactly a lot of code, but I just need a little nudge in the right direction
method GroupReverse is where my problem is, about mid-way through the code
JASS:
scope ReversedA initializer RAInit
struct RA
private static RA data = 0
private static RA data2 = 0
unit caster
player playcast
group TBRA = CreateGroup()
integer ticks
integer AbilityLevel
real casterx
real castery
real damage
real heal
real totaldmg
integer allies
integer healself
static method GroupHeal takes nothing returns boolean
local RA r = RA.data2
local unit u = GetFilterUnit()
set r.heal = (r.totaldmg / r.allies)
if IsUnitEnemy(u, r.playcast) == false then
call SetWidgetLife(u, GetWidgetLife(u) + r.heal)
endif
if r.healself == 0 then
call SetWidgetLife(r.caster, GetWidgetLife(r.caster) + r.heal)
set r.healself = 1
endif
set u = null
return false
endmethod
static method GroupReverse takes nothing returns boolean
local RA r = RA.data
local unit u = GetFilterUnit()
set r.heal = 0
set r.totaldmg = 0
set r.allies = 1
set r.healself = 0
if IsUnitEnemy(u, r.playcast) == true then
call UnitDamageTarget(r.caster, u, r.damage, true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_DIVINE, null)
set r.totaldmg = r.totaldmg + r.damage
call BJDebugMsg(R2S(r.totaldmg)) //This value is eternally stuck at 10.00
endif
if IsUnitEnemy(u, r.playcast) == false then
set r.allies = r.allies + 1
endif
set RA.data2 = r
set u = null
return false
endmethod
private method periodic takes nothing returns nothing
local RA r = this
if r.ticks == 32 or r.ticks == 64 or r.ticks == 96 or r.ticks == 128 or r.ticks == 160 then
set r.casterx = GetUnitX(r.caster)
set r.castery = GetUnitY(r.caster)
set RA.data = r
call GroupEnumUnitsInRange(r.TBRA, r.casterx, r.castery, 500.00, function RA.GroupReverse)
call GroupEnumUnitsInRange(r.TBRA, r.casterx, r.castery, 500.00, function RA.GroupHeal)
endif
if r.ticks == 161 then
call r.stopPeriodic()
call r.destroy()
endif
set r.ticks = r.ticks + 1
endmethod
implement T32x
static method RAACT takes nothing returns nothing
local RA r = RA.allocate()
set r.caster = GetTriggerUnit()
set r.playcast = GetTriggerPlayer()
set r.ticks = 0
set r.AbilityLevel = GetUnitAbilityLevel(r.caster, 039;A004039;)
set r.casterx = GetUnitX(r.caster)
set r.castery = GetUnitY(r.caster)
set r.damage = (r.AbilityLevel * 5.00) + 5.00
call r.startPeriodic()
endmethod
endstruct
private function RACond takes nothing returns boolean
return GetSpellAbilityId() == 039;A004039;
endfunction
private function RAInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
exitwhen i == 4
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set i = i+1
endloop
call TriggerAddCondition(t, Condition(function RACond))
call TriggerAddAction(t, function RA.RAACT)
endfunction
endscope
[EDIT]
I got the spell to work the way I wanted it to.
But I'd still like to know if there is a much better way to do things
All enemies are Orc race
JASS:
scope ReversedA initializer RAInit
struct RA
private static RA data = 0
private static RA data2 = 0
unit caster
player playcast
group TBRA = CreateGroup()
integer ticks
integer AbilityLevel
real casterx
real castery
real damage
real heal
integer allies
integer healself
integer enemies
static method GroupHeal takes nothing returns boolean
local RA r = RA.data2
local unit u = GetFilterUnit()
set r.heal = ((r.damage * r.enemies) / r.allies)
if IsUnitEnemy(u, r.playcast) == false and IsUnitType(u, UNIT_TYPE_STRUCTURE) == false and IsUnitType(u, UNIT_TYPE_TOWNHALL) == false then
call SetWidgetLife(u, GetWidgetLife(u) + r.heal)
endif
if r.healself == 0 then
call SetWidgetLife(r.caster, GetWidgetLife(r.caster) + r.heal)
set r.healself = 1
endif
call BJDebugMsg(R2S(r.allies))
set u = null
return false
endmethod
static method GroupReverse takes nothing returns boolean
local RA r = RA.data
local unit u = GetFilterUnit()
set r.heal = 0
set r.healself = 0
if IsUnitEnemy(u, r.playcast) == true and IsUnitRace(u, RACE_ORC) == true then
call UnitDamageTarget(r.caster, u, r.damage, true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_DIVINE, null)
set r.enemies = r.enemies + 1
endif
if IsUnitEnemy(u, r.playcast) == false and IsUnitType(u, UNIT_TYPE_STRUCTURE) == false and IsUnitType(u, UNIT_TYPE_TOWNHALL) == false then
set r.allies = r.allies + 1
endif
set RA.data2 = r
set u = null
return false
endmethod
private method periodic takes nothing returns nothing
local RA r = this
if r.ticks == 32 or r.ticks == 64 or r.ticks == 96 or r.ticks == 128 or r.ticks == 160 then
set r.casterx = GetUnitX(r.caster)
set r.castery = GetUnitY(r.caster)
set r.enemies = 0
set r.allies= 0
set RA.data = r
call GroupEnumUnitsInRange(r.TBRA, r.casterx, r.castery, 500.00, function RA.GroupReverse)
call GroupEnumUnitsInRange(r.TBRA, r.casterx, r.castery, 500.00, function RA.GroupHeal)
endif
if r.ticks == 161 then
call r.stopPeriodic()
call r.destroy()
endif
set r.ticks = r.ticks + 1
endmethod
implement T32x
static method RAACT takes nothing returns nothing
local RA r = RA.allocate()
set r.caster = GetTriggerUnit()
set r.playcast = GetTriggerPlayer()
set r.ticks = 0
set r.AbilityLevel = GetUnitAbilityLevel(r.caster, 039;A004039;)
set r.casterx = GetUnitX(r.caster)
set r.castery = GetUnitY(r.caster)
set r.damage = (r.AbilityLevel * 5.00) + 5.00
call UnitAddAbility(r.caster, 039;A002039;)
call UnitAddAbility(r.caster, 039;A003039;)
call UnitAddAbility(r.caster, 039;A005039;)
call r.startPeriodic()
endmethod
method onDestroy takes nothing returns nothing
call UnitRemoveAbility(.caster, 039;A002039;)
call UnitRemoveAbility(.caster, 039;A003039;)
call UnitRemoveAbility(.caster, 039;A005039;)
set .caster = null
call GroupClear(.TBRA)
call DestroyGroup(.TBRA)
set .TBRA = null
endmethod
endstruct
private function RACond takes nothing returns boolean
return GetSpellAbilityId() == 039;A004039;
endfunction
private function RAInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
exitwhen i == 4
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set i = i+1
endloop
call TriggerAddCondition(t, Condition(function RACond))
call TriggerAddAction(t, function RA.RAACT)
endfunction
endscope