function InitStatic takes real x, real y returns texttag
local texttag t = CreateTextTag()
call SetTextTagText(t, I2S(0), 0.023)
call SetTextTagColor(t, 0, 140, 255, 255)
call SetTextTagPos(t, x, y, 50)
//set t = null
return t
endfunction
function CheckLoc takes real x, real y returns nothing
call DestroyEffect(AddSpecialEffect( "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", x, y))
endfunction
function SetText takes texttag text, integer newValue returns nothing
call SetTextTagText(text, I2S(newValue), .023 + .0046 * newValue)
call SetTextTagColor(text, 0, IMaxBJ(0,140 - (20 * newValue)), 255, 255)
endfunction
function CasterGroup takes nothing returns group
local group g = CreateGroup()
local integer count = 0
loop
exitwhen count == 12
if IsPlayerInForce(Player(count), udg_players) then
call GroupAddUnit(g, udg_casters[count])
endif
set count = count + 1
endloop
return g
endfunction
function ClearOrb takes unit tempOrb returns nothing
call FlushChildHashtable( udg_data, GetHandleId(tempOrb))
call DestroyTextTag(LoadTextTagHandle(udg_data, 3, GetHandleId(tempOrb)))
call GroupRemoveUnit(udg_orbs, tempOrb )
call RemoveUnit(tempOrb)
call DestroyEffect(AddSpecialEffect( "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", GetUnitX(tempOrb), GetUnitY(tempOrb)))
endfunction
function ClearLightning takes unit lightningHold returns nothing
call FlushChildHashtable( udg_data, GetHandleId(lightningHold))
call DestroyLightning(LoadLightningHandle(udg_data, 0, GetHandleId(lightningHold)))
call GroupRemoveUnit(udg_lightning, lightningHold)
call RemoveUnit(lightningHold)
endfunction
function Fibonacci takes integer index returns integer
local integer a = 1
local integer b = 0
local integer c = 0
local integer count = 0
loop
set count = count + 1
exitwhen count == index
set c = b
set b = a
set a = b + c
endloop
return a
endfunction
function Damage takes unit attacker, unit attacked, integer power returns nothing
call UnitDamageTarget(attacker, attacked, Pow(2, power), true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
endfunction
Name | Type | is_array | initial_value |
board | leaderboard | No | |
casters | unit | Yes | |
data | hashtable | No | |
effect | effect | Yes | |
gameArea | rect | No | RectNull |
isProjectile | boolean | Yes | |
killLimit | integer | No | |
lightning | group | No | |
orbs | group | No | |
players | force | No | |
score | integer | Yes | |
speed | real | Yes | |
staticControl | integer | Yes | |
staticText | texttag | Yes | |
xVelocity | real | Yes | |
yVelocity | real | Yes |
function Trig_Initialization_Func004A takes nothing returns nothing
if GetPlayerController(GetEnumPlayer()) == MAP_CONTROL_USER then
set udg_casters[GetPlayerId(GetEnumPlayer())] = CreateUnit(GetEnumPlayer(), 'H000', 500 * Cos(30 * GetPlayerId(GetEnumPlayer()) * bj_DEGTORAD),500 * Sin(30 * GetPlayerId(GetEnumPlayer()) * bj_DEGTORAD), 0)
set udg_staticText[GetPlayerId(GetEnumPlayer())] = InitStatic(0,0)
call CreateTextTagLocBJ( "TRIGSTR_040", GetRectCenter(GetPlayableMapRect()), 0, 10, 100, 100, 100, 0 )
call CreateFogModifierRectBJ( true, GetEnumPlayer(), FOG_OF_WAR_VISIBLE, udg_gameArea )
endif
endfunction
function Trig_Initialization_Actions takes nothing returns nothing
set udg_data = InitHashtable()
set udg_gameArea = Rect(-1060.00, -1060.00, 1060.00, 1060.00)
set udg_players = GetPlayersByMapControl(MAP_CONTROL_USER)
call ForForce( udg_players, function Trig_Initialization_Func004A )
endfunction
//===========================================================================
function InitTrig_Initialization takes nothing returns nothing
set gg_trg_Initialization = CreateTrigger( )
call TriggerAddAction( gg_trg_Initialization, function Trig_Initialization_Actions )
endfunction
function Trig_Explanation_Actions takes nothing returns nothing
call DisplayTimedTextToPlayer(GetTriggerPlayer(),0, 0,30, "TRIGSTR_085" )
endfunction
//===========================================================================
function InitTrig_Explanation takes nothing returns nothing
set gg_trg_Explanation = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(0), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(1), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(2), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(3), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(4), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(5), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(6), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(7), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(8), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(9), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(10), "-game", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation, Player(11), "-game", true )
call TriggerAddAction( gg_trg_Explanation, function Trig_Explanation_Actions )
endfunction
function Trig_Explanation2_Actions takes nothing returns nothing
call ClearTextMessages()
call DisplayTimedTextToPlayer( GetTriggerPlayer(),0,40,30, "Lightning:
|CFF005B7Faaaa|CFFFFF200/|CFF00AEEFb|CFFFFF200/|CFF005952cccc|CFFFFF200/|CFF00A99Dd|CFFFFF200/|CFF7ACCC8eee
a = The range of the spell.
b = The cooldown.
c = The speed at which the lightning will fire any target.
d = The StaticCharges the lightning will add to its target.
e = The width of the space that will be checked for units.
Thunder:
|CFF005B7Faaa|CFFFFF200/|CFF00AEEFbb|CFFFFF200/|CFF005952cc|CFFFFF200/|CFF00A99D1ddd
a = The range.
B = The cooldown.
C = The lifespan of Thunder.
D = The width of the bolt.
Orb:
|CFF005B7Faaa|CFFFFF200/|CFF00AEEFb|CFFFFF200/|CFF005952c
a = The speed of the orb.
B = The cooldown.
C = The initial static charge of the orb.
" )
endfunction
//===========================================================================
function InitTrig_Explanation2 takes nothing returns nothing
set gg_trg_Explanation2 = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(0), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(1), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(2), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(3), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(4), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(5), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(6), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(7), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(8), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(9), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(10), "-abilities", true )
call TriggerRegisterPlayerChatEvent( gg_trg_Explanation2, Player(11), "-abilities", true )
call TriggerAddAction( gg_trg_Explanation2, function Trig_Explanation2_Actions )
endfunction
function Trig_Lightning_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
function Trig_Lightning_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local integer level = GetUnitAbilityLevel(caster, 'A000')
local unit temp
local real tempPoint
local unit currentLightning
local unit currentTarget
local integer tempId
local real x = GetUnitX(caster)
local real y = GetUnitY(caster)
local real x2 = GetSpellTargetX()
local real y2 = GetSpellTargetY()
local real x3
local real y3
local real x4
local real y4
local real angle = bj_RADTODEG * Atan2(y2 - y, x2 - x)
local real tx
local real ty
local real bx
local real by
local real tx2
local real ty2
local real bx2
local real by2
local real lx
local real ly
local real tAngle
local real bAngle
local real slope
local real tIntercept
local real bIntercept
local real mIntercept
local real offset = 0
local real distance = SquareRoot((x2-x)*(x2-x)+(y2-y)*(y2-y))
local real targetDistance
local real currentDistance = distance
local real orbX
local real orbY
local real orbSpeed
local integer tempId
local boolean isAbove
local boolean wasAbove
local real offset = 0
local real lowXLimit
local real highXLimit
local real yIntercept
local group units = CreateGroup()
local group lightnings = CreateGroup()
local lightning lEffect
//Spell Level Variables
local real width = (180 + 20 * level) /2
local real speed = 1400 + 200 * level
local integer staticCharge = Fibonacci(level)
set bj_wantDestroyGroup = true
call GroupAddGroup( CasterGroup(), units)
call GroupAddGroup( udg_orbs, units)
call GroupRemoveUnit( units, caster)
if RAbsBJ(angle) < 90 then
set tAngle = angle + 90
set bAngle = angle - 90
else
set tAngle = angle - 90
set bAngle = angle + 90
endif
set tx = x + width * Cos(tAngle * bj_DEGTORAD)
set ty = y + width * Sin(tAngle * bj_DEGTORAD)
set bx = x + width * Cos(bAngle * bj_DEGTORAD)
set by = y + width * Sin(bAngle * bj_DEGTORAD)
set tx2 = x2 + width * Cos(tAngle * bj_DEGTORAD)
set ty2 = y2 + width * Sin(tAngle * bj_DEGTORAD)
set bx2 = x2 + width * Cos(bAngle * bj_DEGTORAD)
set by2 = y2 + width * Sin(bAngle * bj_DEGTORAD)
//call CheckLoc(tx, ty)
//call CheckLoc(tx2, ty2)
//call CheckLoc(bx, by)
//call CheckLoc(bx2, by2)
set slope = (y2-y)/(x2-x)
set tIntercept = ty - slope * tx
set bIntercept = by - slope * bx
set mIntercept = x - slope * y
loop
set temp = FirstOfGroup(units)
exitwhen temp == null
set x3 = GetUnitX(temp)
set y3 = GetUnitY(temp)
set targetDistance = SquareRoot((x3-x)*(x3-x)+(y3-y)*(y3-y))
if y3 < slope * x3 + tIntercept and y3 > slope * x3 + bIntercept and targetDistance < currentDistance then
set currentDistance = targetDistance
set currentTarget = temp
endif
call GroupRemoveUnit(units, temp)
endloop
//The end of Orb/Caster determinant actions. Beginning of Lightning intersection determinant actions.
//It is assumed that most variables can be reused at this point.
set x2 = Cos(angle * bj_DEGTORAD)
set y2 = Sin(angle * bj_DEGTORAD)
set x3 = x2
set y3 = y2
call BJDebugMsg(R2S(distance))
loop
set offset = offset + 10
exitwhen offset > distance
set x4 = x + x2 * offset
set y4 = y + y2 * offset
//call CheckLoc(x4,y4)
call GroupAddGroup(udg_lightning, lightnings)
loop
set temp = FirstOfGroup(lightnings)
exitwhen temp == null
set slope = LoadReal(udg_data, 1, GetHandleId(temp))
set yIntercept = LoadReal(udg_data, 2, GetHandleId(temp))
set lowXLimit = LoadReal(udg_data, 4, GetHandleId(temp))
set highXLimit = LoadReal(udg_data, 5, GetHandleId(temp))
set wasAbove = y3 > x3 * slope + yIntercept
set isAbove = y4 > x4 * slope + yIntercept
set targetDistance = SquareRoot((x4-x)*(x4-x)+(y4-y)*(y4-y))
if wasAbove != isAbove and x4 > lowXLimit and x4 < highXLimit and targetDistance < currentDistance then
set currentTarget = temp
set currentDistance = targetDistance
set lx = x4
set ly = y4
//call CheckLoc(x4, y4)
endif
call GroupRemoveUnit(lightnings, temp)
endloop
set x3 = x4
set y3 = y4
endloop
if GetUnitTypeId(currentTarget) == 'h002' then//THUNDER - DONE
set tempId = GetPlayerId(GetOwningPlayer(caster))
set udg_isProjectile[tempId] = true
set udg_xVelocity[tempId] = -x2
set udg_yVelocity[tempId] = -y2
set udg_speed[tempId] = speed
set udg_effect[tempId] = AddSpecialEffectTarget("Abilities\\Spells\\Orc\\LightningShield\\LightningShieldTarget.mdl", udg_casters[tempId], "chest")
call ClearLightning(currentTarget)
elseif GetUnitTypeId(currentTarget) == 'h001' then//ORB
set tempId = GetHandleId(currentTarget)
set lx = GetUnitX(currentTarget)
set ly = GetUnitY(currentTarget)
call SaveReal(udg_data, 0, tempId, Cos(angle * bj_DEGTORAD))
call SaveReal(udg_data, 1, tempId, Sin(angle * bj_DEGTORAD))
call SaveReal(udg_data, 2, tempId, speed)
call SetUnitUserData(currentTarget, GetUnitUserData(currentTarget) + staticCharge)
call SetText(LoadTextTagHandle(udg_data, 3, tempId), GetUnitUserData(currentTarget))
//call BJDebugMsg("Orb.")
elseif GetUnitTypeId(currentTarget) == 'H000' then
set tempId = GetPlayerId(GetOwningPlayer(currentTarget))
set udg_isProjectile[tempId] = true
set udg_xVelocity[tempId] = x2
set udg_yVelocity[tempId] = y2
set udg_speed[tempId] = speed
set udg_staticControl[tempId] = GetPlayerId(GetOwningPlayer(caster))
//call BJDebugMsg("Shocker.")
endif
set lEffect = AddLightning("CLPB", false, x,y, lx, ly)
call TriggerSleepAction(.2)
call DestroyLightning(lEffect)
set caster = null
set temp = null
set currentLightning = null
set currentTarget = null
call DestroyGroup(units)
call DestroyGroup(lightnings)
set units = null
set lightnings = null
set lEffect = null
endfunction
//===========================================================================
function InitTrig_Lightning takes nothing returns nothing
set gg_trg_Lightning = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Lightning, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Lightning, Condition( function Trig_Lightning_Conditions ) )
call TriggerAddAction( gg_trg_Lightning, function Trig_Lightning_Actions )
endfunction
function Trig_Orb_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A002'
endfunction
function Trig_Orb_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local integer level = GetUnitAbilityLevel(caster, 'A002')
local player owner = GetOwningPlayer(caster)
local real x = GetUnitX(caster)
local real y = GetUnitY(caster)
local real x2 = GetLocationX(GetSpellTargetLoc())
local real y2 = GetLocationY(GetSpellTargetLoc())
local unit orb = CreateUnit(owner, 'h001', x, y, GetUnitFacing(caster))
local real angle = bj_RADTODEG * Atan2(y2-y , x2-x)
local real orbX = Cos(angle*bj_DEGTORAD)
local real orbY = Sin(angle*bj_DEGTORAD)
//Level Variables
local integer staticCharge = Fibonacci(level)
local real speed = 600 + level * 200
local texttag text = InitStatic(x,y)
call SetUnitUserData(orb, staticCharge)
call SetText(text, staticCharge)
call SaveReal(udg_data, 0, GetHandleId(orb), orbX)
call SaveReal(udg_data, 1, GetHandleId(orb), orbY)
call SaveReal(udg_data, 2, GetHandleId(orb), speed)
call SaveTextTagHandle(udg_data, 3, GetHandleId(orb), text)
call GroupAddUnit(udg_orbs, orb)
//call UnitApplyTimedLife(orb, 'BTLF', 10.00)
set orb = null
set text = null
set owner = null
set caster = null
endfunction
//===========================================================================
function InitTrig_Orb takes nothing returns nothing
set gg_trg_Orb = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Orb, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Orb, Condition( function Trig_Orb_Conditions ) )
call TriggerAddAction( gg_trg_Orb, function Trig_Orb_Actions )
endfunction
constant function minLightningWidth takes nothing returns real
return 100.
endfunction
function Trig_Thunder_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A001'
endfunction
function Trig_Thunder_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local integer level = GetUnitAbilityLevel(caster, 'A001')
local player owner = GetOwningPlayer(caster)
local real x = GetUnitX(caster)
local real y = GetUnitY(caster)
local real x2 = GetLocationX(GetSpellTargetLoc())
local real y2 = GetLocationY(GetSpellTargetLoc())
local real lx
local real ly
local real lx2
local real ly2
local real facing = bj_RADTODEG * Atan2(y2 - y, x2 - x)
//Level Variables
local real length = 400 + level * 100
local real armLength = length/2
local real life = 9 + level // seconds
local real slope
local real angle
local lightning lightningEffect
local unit lightningHold = CreateUnit(owner, 'h002', 1500, 1500, GetUnitFacing(caster))
local integer lightningId = GetHandleId(lightningHold)
call GroupAddUnit(udg_lightning, lightningHold)
if y2 > y then
set lx = x2 + armLength * Cos((facing + 90) * bj_DEGTORAD)
set ly = y2 + armLength * Sin((facing + 90) * bj_DEGTORAD)
set lx2 = x2 + armLength * Cos((facing - 90) * bj_DEGTORAD)
set ly2 = y2 + armLength * Sin((facing - 90) * bj_DEGTORAD)
set angle = facing - 90
else
set lx = x2 + armLength * Cos((facing - 90) * bj_DEGTORAD)
set ly = y2 + armLength * Sin((facing - 90) * bj_DEGTORAD)
set lx2 = x2 + armLength * Cos((facing + 90) * bj_DEGTORAD)
set ly2 = y2 + armLength * Sin((facing + 90) * bj_DEGTORAD)
set angle = facing + 90
//set slope = (ly - ly2)/(lx - lx2)//length
endif
set slope = (ly2 - ly)/(lx2 - lx)//I'm not sure why this works for both above instances.
set lightningEffect = AddLightning("DRAM", false, lx,ly,lx2,ly2)
//call BJDebugMsg(R2S(slope))
if lx2 - lx < minLightningWidth() then
set lx2 = (minLightningWidth() - (lx2-lx))/2 + lx2
set lx = lx - (minLightningWidth() - (lx2-lx))/2
endif
call SaveLightningHandle(udg_data, 0, lightningId, lightningEffect)
call SaveReal (udg_data, 1, lightningId, slope)
call SaveReal (udg_data, 2, lightningId, ly - slope * lx)//Y-Intercept
call SaveReal (udg_data, 3, lightningId, angle)
call SaveReal (udg_data, 4, lightningId, lx)
call SaveReal (udg_data, 5, lightningId, lx2)
call SaveReal (udg_data, 6, lightningId, life * 50)
set caster = null
set owner = null
set lightningEffect = null
set lightningHold = null
endfunction
//===========================================================================
function InitTrig_Thunder takes nothing returns nothing
set gg_trg_Thunder = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Thunder, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Thunder, Condition( function Trig_Thunder_Conditions ) )
call TriggerAddAction( gg_trg_Thunder, function Trig_Thunder_Actions )
endfunction
constant function decelerationConstant takes nothing returns real
return 2.
endfunction
constant function decelerationAugment takes nothing returns real
return 5.
endfunction
constant function sideLength takes nothing returns real
return 1024.
endfunction
function Trig_Motion_Actions takes nothing returns nothing
local unit tempOrb
local unit tempCaster
local unit tempLightningPointer
local unit tempVictim
local integer count = 0
local real life
local real x
local real y
local real x2
local real y2
local real x3
local real y3
local real highXLimit
local real lowXLimit
local real slope
local real yIntercept
local real orbSpeed
local real lAngle
local real oAngle
local real linePoint
local integer handleId
local boolean isAbove
local boolean wasAbove
local lightning tempLightning
local texttag static
local group orbs = CreateGroup()
local group lightnings = CreateGroup()
local group victims = CreateGroup()
call GroupAddGroup(udg_orbs, orbs)
call GroupAddGroup(udg_lightning, lightnings)
//Processing the lifespan of the Thunders.
loop
set tempLightningPointer = FirstOfGroup(lightnings)
exitwhen tempLightningPointer == null
set life = LoadReal(udg_data, 6, GetHandleId(tempLightningPointer))
call SaveReal(udg_data, 6, GetHandleId(tempLightningPointer), life - 1)
if LoadReal(udg_data, 6, GetHandleId(tempLightningPointer)) <= 0 then
call ClearLightning(tempLightningPointer)
endif
call GroupRemoveUnit(lightnings, tempLightningPointer)
endloop
//Processing the flying dwarves.
loop
exitwhen count == 12
set x = GetUnitX(udg_casters[count])
set y = GetUnitY(udg_casters[count])
call SetTextTagPos(udg_staticText[count],x, y, 100)
if udg_isProjectile[count] then
set tempCaster = udg_casters[count]
if ModuloInteger(GetTriggerExecCount(GetTriggeringTrigger()), 5) == 0 then
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl", tempCaster, "feet"))
endif
call SetUnitPosition(tempCaster, x + udg_xVelocity[count] * (udg_speed[count]/50), y + udg_yVelocity[count] * (udg_speed[count]/50))
set udg_speed[count] = udg_speed[count] - decelerationConstant() * decelerationAugment()
set x = GetUnitX(tempCaster)
set y = GetUnitY(tempCaster)
call BJDebugMsg(R2S(x))
call GroupEnumUnitsInRange(victims, x,y, 100, null)
call GroupRemoveUnit(victims, tempCaster)
loop
set tempVictim = FirstOfGroup(victims)
exitwhen tempVictim == null
if IsUnitEnemy(tempVictim, GetOwningPlayer(tempCaster)) and GetUnitState(tempVictim, UNIT_STATE_LIFE) > 0 then
call Damage(udg_casters[udg_staticControl[count]], tempVictim, GetUnitUserData(tempCaster))
set udg_isProjectile[count] = false
call SetText(udg_staticText[count], 0)
endif
call GroupRemoveUnit(victims, tempVictim)
endloop
if y >= sideLength()-60 or y <= -sideLength()+60 then
set udg_yVelocity[count] = -udg_yVelocity[count]
endif
if x >= sideLength()-60 or x <= -sideLength()+60 then
set udg_xVelocity[count] = -udg_xVelocity[count]
endif
if udg_speed[count] < 0 then
set udg_isProjectile[count] = false
call DestroyEffect(udg_effect[count])
set udg_effect[count] = null
endif
endif
set count = count + 1
endloop
loop
exitwhen FirstOfGroup(orbs) == null
set tempOrb = FirstOfGroup(orbs)
call GroupRemoveUnit(orbs, tempOrb)
set handleId = GetHandleId(tempOrb)
set x = GetUnitX(tempOrb) //Original Position of Orb
set y = GetUnitY(tempOrb)
set x2 = LoadReal(udg_data, 0, handleId)//Placeholders
set y2 = LoadReal(udg_data, 1, handleId)
set orbSpeed = LoadReal(udg_data, 2, handleId)
set static = LoadTextTagHandle(udg_data, 3, handleId)
set x3 = orbSpeed/50 * x2 + x //Suggested Position of Orb
set y3 = orbSpeed/50 * y2 + y
set oAngle = Atan2(y2,x2) * bj_RADTODEG
call SetUnitPosition(tempOrb, x3, y3)
call GroupEnumUnitsInRange(victims, x3,y3, 100, null)
loop
set tempVictim = FirstOfGroup(victims)
exitwhen tempVictim == null
if IsUnitEnemy(tempVictim, GetOwningPlayer(tempOrb)) and GetUnitState(tempVictim, UNIT_STATE_LIFE) > 0 then
call Damage(tempOrb, tempVictim, GetUnitUserData(tempOrb))
call ClearOrb(tempOrb)
endif
call GroupRemoveUnit(victims, tempVictim)
endloop
if x3 >= sideLength() or x3 <= -sideLength() then
call SaveReal(udg_data, 0, GetHandleId(tempOrb), -x2)
endif
if y3 >= sideLength() or y3 <= -sideLength() then
call SaveReal(udg_data, 1, GetHandleId(tempOrb), -y2)
endif
call GroupAddGroup(udg_lightning, lightnings)
loop
exitwhen FirstOfGroup(lightnings) == null
//call CheckLoc(x3, y3)
set tempLightningPointer = FirstOfGroup(lightnings)
call GroupRemoveUnit(lightnings, tempLightningPointer)
set slope = LoadReal(udg_data, 1, GetHandleId(tempLightningPointer))
set yIntercept = LoadReal(udg_data, 2, GetHandleId(tempLightningPointer))
set lAngle = LoadReal(udg_data, 3, GetHandleId(tempLightningPointer))
set lowXLimit = LoadReal(udg_data, 4, GetHandleId(tempLightningPointer))
set highXLimit = LoadReal(udg_data, 5, GetHandleId(tempLightningPointer))
if x3 > lowXLimit and x3 < highXLimit then
set linePoint = x * slope + yIntercept
set isAbove = (linePoint < y)
set linePoint = x3 * slope + yIntercept
set wasAbove = (linePoint < y3)
if isAbove != wasAbove then
call DisplayTimedTextFromPlayer(Player(0),0,0,1, "xxx")
set oAngle = -oAngle + 2 * lAngle //A formula I came up with that miraculously works :D
call SaveReal(udg_data, 0, GetHandleId(tempOrb), Cos(oAngle * bj_DEGTORAD)) //Resetting the coordinates.
call SaveReal(udg_data, 1, GetHandleId(tempOrb), Sin(oAngle * bj_DEGTORAD))
call SetUnitPosition(tempOrb, x,y) //Backtracking so as not to get stuck in the lightning.
call SetUnitUserData(tempOrb, 1 + GetUnitUserData(tempOrb))
call SetText(static, GetUnitUserData(tempOrb))
endif
endif
endloop
call SetTextTagPos(static,GetUnitX(tempOrb), GetUnitY(tempOrb), 100)
if orbSpeed <= 0 then
call ClearOrb(tempOrb)
else
call SaveReal(udg_data, 2, handleId, orbSpeed - decelerationConstant())
endif
endloop
call DestroyGroup(victims)
call DestroyGroup(orbs)
call DestroyGroup(lightnings)
set orbs = null
set victims = null
set tempLightning = null
set static = null
set lightnings = null
set tempOrb = null
set tempLightningPointer = null
set tempLightning = null
set tempVictim = null
endfunction
//===========================================================================
function InitTrig_Motion takes nothing returns nothing
set gg_trg_Motion = CreateTrigger( )
call TriggerRegisterTimerEvent( gg_trg_Motion, 0.02, true )
call TriggerAddAction( gg_trg_Motion, function Trig_Motion_Actions )
endfunction