kallieblakie
New Member
- Reaction score
- 5
why would it be a bad idea?/> Does BoolExpr leak if not destroyed
No, they never leak.
And because of this destroying is a bad idea.
why would it be a bad idea?/> Does BoolExpr leak if not destroyed
No, they never leak.
And because of this destroying is a bad idea.
function KillSelected takes nothing returns boolean
call KillUnit(GetFilterUnit())
return false
endfunction
function OnEsc takes nothing returns boolean
local group g = CreateGroup()
local boolexpr f = Condition(function KillSelected)
call GroupEnumUnitsSelected(g, GetTriggerPlayer(), f)
call DestroyBoolExpr(f)
call DestroyGroup(g)
set f = null
set g = null
return false
endfunction
//===========================================================================
function InitTrig_SelectedOnEsc takes nothing returns nothing
local trigger trigEsc = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerEvent(trigEsc, Player(i), EVENT_PLAYER_END_CINEMATIC)
set i = i + 1
exitwhen(i == 12)
endloop
call TriggerAddCondition(trigEsc, Condition(function OnEsc))
set trigEsc = null
endfunction
function Arrow_Filter takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) != true and GetWidgetLife(GetFilterUnit()) > 0.405
endfunction
function Trig_Arrow_Elunes_Arrow_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 039;AOsh039;
endfunction
function DPP takes location locA, location locB returns real
local real dx = GetLocationX(locB) - GetLocationX(locA)
local real dy = GetLocationY(locB) - GetLocationY(locA)
return SquareRoot(dx * dx + dy * dy)
endfunction
function Arrow_Move takes nothing returns nothing
local timer Loop = GetExpiredTimer()
local unit arrow = GetHandleUnit(Loop, "arrow")
local unit caster = GetHandleUnit(Loop, "caster")
local real angle = GetHandleReal(Loop, "angle")
local integer Range = GetHandleInt(Loop, "Range")
local integer Radius = GetHandleInt(Loop, "Radius")
local real Speed = GetHandleReal(Loop, "Speed")
local integer PlayerNo = GetHandleInt(Loop, "PlayerNo")
local real distanceCurrent = GetHandleReal(Loop, "distanceCurrent")
local location C
local location Next
local boolexpr b
local real x
local real y
local group g
local unit p
local unit dummy
local integer Number
local location locA
local location locB
if (R2I(distanceCurrent) <= Range) then
set distanceCurrent = distanceCurrent + Speed
call SetHandleReal (Loop, "distanceCurrent", distanceCurrent)
set x = GetUnitX(arrow) + Speed * Cos(angle * bj_DEGTORAD)
set y = GetUnitY(arrow) + Speed * Sin(angle * bj_DEGTORAD)
call SetUnitPosition(arrow, x, y)
set g = CreateGroup()
set b = Condition(function Arrow_Filter)
call GroupEnumUnitsInRangeCounted(g, x, y, I2R(Radius), b, 1)
call DestroyBoolExpr(b)
set b = null
set p = FirstOfGroup(g)
call DestroyGroup(g)
set g = null
if p != null then
if ( ( UnitHasBuffBJ(p, 039;BPSE039;) == true ) ) then
call UnitDamageTarget(caster, p, 100000, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
call RemoveUnit(arrow)
//---I think you should flush and destroy the timer here as well
call FlushHandleLocals(Loop)
call PauseTimer(Loop)
call DestroyTimer(Loop)
elseif ( (IsUnitEnemy(p, GetOwningPlayer(caster)) == true)) then
call UnitDamageTarget(caster, p, udg_Damage[PlayerNo], false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
set dummy = CreateUnitAtLoc(GetOwningPlayer(caster), 039;hfoo039;, Next, 0.00)
call UnitAddAbility(dummy, 039;ANsb039;)
call SetUnitAbilityLevel(dummy, 039;ANsb039;, udg_Stun[PlayerNo])
call IssueTargetOrder(dummy, "thunderbolt", p)
call UnitApplyTimedLife(dummy, 039;BTLF039;, 2.00)
set locA = GetUnitLoc(caster)
set locB = GetUnitLoc(arrow)
call UnitDamageTarget(caster, p, (( I2R(udg_I_PrecisionLevel[PlayerNo]) * ( 0.06 * DPP(locA,locB)))+( ( 35000.00 * ( 0.40 * I2R(udg_I_bladeLevel[PlayerNo]) ) ) / DPP(locA,locB))),false,true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_METAL_HEAVY_BASH )
call RemoveLocation (locA)
call RemoveLocation (locB)
set locA = null
set locB = null
call RemoveUnit(arrow)
call FlushHandleLocals(Loop)
call PauseTimer(Loop)
call DestroyTimer(Loop)
endif
set p = null
endif
elseif (R2I(distanceCurrent) > Range) then
call KillUnit(arrow)
call RemoveUnit(arrow)
call FlushHandleLocals(Loop)
call PauseTimer(Loop)
call DestroyTimer(Loop)
endif
set arrow = null
set caster = null
set Loop = null
endfunction
function Trig_Arrow_Elunes_Arrow_Actions takes nothing returns nothing
local timer Loop = CreateTimer()
local unit caster = GetSpellAbilityUnit()
local location casterPosition = GetUnitLoc(caster)
local location targetPosition = GetSpellTargetLoc()
local integer PlayerNo = GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit())) //I won't start messing with playerIds, but I like Player() and GetPlayerId() functions better
local integer radius = udg_Radius[PlayerNo]
local real angle = AngleBetweenPoints(casterPosition, targetPosition)
local real x = GetLocationX(casterPosition) + (radius+2)*Cos(angle*bj_DEGTORAD)
local real y = GetLocationY(casterPosition) + (radius+2)*Sin(angle*bj_DEGTORAD)
local real Scale = ( 100.00 * ( I2R(radius) / 80.00 ) )
local integer Range = udg_Range[PlayerNo]
local real Speed = udg_Speed[PlayerNo]
local unit arrow = CreateUnit(ConvertedPlayer(PlayerNo), 039;hpea039;, x, y, angle)
call SetUnitScalePercent( arrow, Scale, Scale, Scale )
call SetUnitPathing( arrow, false )
call RemoveLocation(casterPosition)
call RemoveLocation(targetPosition)
call SetHandleHandle(Loop, "arrow", arrow)
call SetHandleHandle(Loop, "caster", caster)
call SetHandleReal(Loop,"angle",angle)
call SetHandleInt(Loop, "Range", Range)
call SetHandleReal(Loop, "Speed", Speed)
call SetHandleInt(Loop, "Radius", radius)
call SetHandleInt(Loop, "PlayerNo", PlayerNo)
call TimerStart(Loop, 0.03, true, function Arrow_Move)
set Loop = null
set caster = null
set casterPosition = null
set targetPosition = null
set arrow = null
endfunction
//===========================================================================
function InitTrig_Arrow_Elunes_Arrow takes nothing returns nothing
set gg_trg_Arrow_Elunes_Arrow = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_Arrow_Elunes_Arrow, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Arrow_Elunes_Arrow, Condition( function Trig_Arrow_Elunes_Arrow_Conditions ) )
call TriggerAddAction( gg_trg_Arrow_Elunes_Arrow, function Trig_Arrow_Elunes_Arrow_Actions )
endfunction
Anyway, the trigger doesn't work! it doesn't properly destroy the loop when it hits a unit. ARGGHS
function DebugUnitTag takes string s, unit u returns nothing
local texttag tag = CreateTextTag()
local integer width = StringLength(s)
call SetTextTagText(tag, s, 0.023)
call SetTextTagPos(tag, GetUnitX(u) - width * 10, GetUnitY(u), 0.)
call SetTextTagColor(tag, 255, 50, 50, 255)
call SetTextTagPermanent(tag, false)
call SetTextTagLifespan(tag, 3.)
call SetTextTagFadepoint(tag, 1.5)
call SetTextTagVelocity(tag, 0., .071)
set tag = null
endfunction
I've already corrected the mistake. The script you made allows the arrow to does extra few hits to the enemy before it disappears. say, supposingly it should deal 100 damage, your script allows the arrow to "poke" the enemy 4-5 times, dealing 500 damage instead.Hmm... that's weird. I must have done a mistake. Can you tell me more about what happens?
Does the arrow move as it should and as far as it should?
Do units get damaged when the arrow goes through them?
Does it hit some times but not always?
etc.
I need more info to correct the mistake without being able to test myself.
Here is how you can pinpoint the bug yourself:
Place small debug messages after every if, elseif and else so you know what code is being run and what's not.
Then find out why the if/elseif argument isn't returning true by checking what the varibales in that argument is all the way from the beginning of the trigger and up to the if/elseif in question. When you find out where the value is wrong, you can usually know why and correct it.
elseif ( (IsUnitEnemy(p, GetOwningPlayer(caster)) == true)) then
call UnitDamageTarget(caster, p, udg_Damage[PlayerNo], false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
set dummy = CreateUnitAtLoc(GetOwningPlayer(caster), 039;hfoo039;, Next, 0.00)
call UnitAddAbility(dummy, 039;ANsb039;)
call SetUnitAbilityLevel(dummy, 039;ANsb039;, udg_Stun[PlayerNo])
call IssueTargetOrder(dummy, "thunderbolt", p)
call UnitApplyTimedLife(dummy, 039;BTLF039;, 2.00)
set locA = GetUnitLoc(caster)
set locB = GetUnitLoc(arrow)
call UnitDamageTarget(caster, p, (( I2R(udg_I_PrecisionLevel[PlayerNo]) * ( 0.06 * DPP(locA,locB)))+( ( 35000.00 * ( 0.40 * I2R(udg_I_bladeLevel[PlayerNo]) ) ) / DPP(locA,locB))),false,true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_METAL_HEAVY_BASH )
call RemoveLocation (locA)
call RemoveLocation (locB)
set locA = null
set locB = null
call RemoveUnit(arrow)
call FlushHandleLocals(Loop)
call PauseTimer(Loop)
call DestroyTimer(Loop)
call RemoveUnit(arrow)