Добавлен
Подскажите пожалуйста, не могу найти утечку в коде.
library UziLib


native UnitAlive takes unit id returns boolean

function GetLocZUzi takes real x, real y returns real
    call MoveLocation( LFZ, x, y )
    return GetLocationZ( LFZ )
endfunction

struct vectorUzi
    real x
    real y
    real z
    
    method normalize takes nothing returns nothing
        local real l = SquareRoot( x * x + y * y + z * z )
        
        if l == 0.00 then
            set l = 1.00
        endif
        
        set x = x * ( 1.00 / l )
        set y = y * ( 1.00 / l )
        set z = z * ( 1.00 / l )
    endmethod
    
    static method create takes real x, real y, real z returns thistype
        local thistype this = thistype.allocate( )
        
        set this.x = x
        set this.y = y
        set this.z = z
        
        call this.normalize( )
        
        return this
    endmethod
endstruct

struct bulletUzi
    unit caster
    unit dummy
    player p
    
    real x
    real y
    real z
    real s // speed
    real d // distance
    real r // radius
    
    vectorUzi v
endstruct

function MoveUzi takes nothing returns nothing
    local bullet A = LoadInteger( H, GetHandleId( GetExpiredTimer( ) ), 0 )
    local unit u
    local string BloodEffect = "Objects/Spawnmodels/Undead/UndeadBlood/UndeadBloodAcolyte.mdl"
    
    set A.x = A.x + A.s * A.v.x * Cos( A.v.z )
    set A.y = A.y + A.s * A.v.y * Cos( A.v.z )
    set A.z = A.z + A.s * A.v.z
    
    set A.d = A.d - A.s
    
    call SetUnitX( A.dummy, A.x )
    call SetUnitY( A.dummy, A.y )
    call SetUnitFlyHeight( A.dummy, A.z - GetLocZUzi( A.x, A.y ), 0.00 )
    
    call GroupEnumUnitsInRange( TempGroup, A.x, A.y, A.r, null )
    
    loop
        set u = FirstOfGroup( TempGroup )
        exitwhen u == null
        call GroupRemoveUnit( TempGroup, u )
        
        if UnitAlive( u ) and IsUnitEnemy( u, A.p ) and RAbsBJ( GetUnitFlyHeight( u ) - GetUnitFlyHeight( A.dummy ) ) <= 100.00 then
             
            
            call GroupClear( TempGroup )
            call UnitDamageTarget( A.caster, u, 15.00, false, false, null, null, null )
            call DestroyEffect( AddSpecialEffectTarget( BloodEffect, u, "origin" ) )
            call RemoveUnit( A.dummy )
            set BloodEffect = null
            call DestroyTimer( GetExpiredTimer( ) )
            call FlushChildHashtable( H, GetHandleId( GetExpiredTimer( ) ) )
            call DestroyTimer( GetExpiredTimer( ) )
            set A.dummy = null
            set A.caster = null
            call A.v.destroy( )
            call A.destroy( )
        endif
    endloop
    
    if A.d <= 0.00 or A.z - GetLocZUzi( A.x, A.y ) <= 20.00 then
        call DestroyTimer( GetExpiredTimer( ) )
        call FlushChildHashtable( H, GetHandleId( GetExpiredTimer( ) ) )
        call DestroyTimer( GetExpiredTimer( ) )
        
        call RemoveUnit( A.dummy )
        
        set A.dummy = null
        set A.caster = null
        call A.v.destroy( )
        call A.destroy( )
    endif
    
endfunction

function Trig_ShootUzi_Actions takes nothing returns nothing
    local timer t = CreateTimer( )
    local unit Target = udg_Camera[GetConvertedPlayerId(GetTriggerPlayer())]
    local bullet A = bullet.create( )
    local real x = GetUnitX(Target)
    local real y = GetUnitY(Target)
    local real z = GetLocZUzi( x, y ) + 50.00 
    local string WeaponEffect = "RifleImpact.mdx"
    local string WeaponEffect2 = "war3mapImported/RiflemanUZI.mdx"
    set A.caster = udg_MainHero_2[GetConvertedPlayerId(GetTriggerPlayer())]
    set A.p = GetOwningPlayer( A.caster )
    
    // for offset
    set A.x = GetUnitX( A.caster )
    set A.y = GetUnitY( A.caster )
    set A.z = GetUnitFlyHeight( A.caster ) + GetLocZUzi( A.x, A.y ) + 110.00 
    
    set A.v = vectorM16.create( x - A.x, y - A.y, z - A.z )
    
    set A.x = A.x + 90.00 * A.v.x * Cos( A.v.z )
    set A.y = A.y + 90.00 * A.v.y * Cos( A.v.z )
    set A.z = GetUnitFlyHeight( A.caster ) + GetLocZUzi( A.x, A.y ) + 110.00 
    
    // for move
        set A.v.x = x - A.x + GetRandomReal(-70.0, 70.0)
        set A.v.y = y - A.y + GetRandomReal(-70.0, 70.0)
        set A.v.z = z - A.z  

   
     call A.v.normalize( )
    
    set A.d = 4200.00
    set A.s = 1500.00 * 0.03125
    set A.r = 90.00
    

    set A.dummy = CreateUnit( A.p, 'u000', A.x, A.y, Atan2( A.v.y, A.v.x )  * bj_RADTODEG  )
    call SetUnitPathing( A.dummy, false )
    call UnitAddAbility( A.dummy, 'Arav' )
    call SetUnitX( A.dummy, A.x )
    call SetUnitY( A.dummy, A.y )
    call SetUnitFlyHeight( A.dummy, A.z - GetLocZUzi( A.x, A.y ), 0.00 )
    call BlzStartUnitAbilityCooldown( udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], 'A028', 0.02)
    call SaveInteger( H, GetHandleId( t ), 0, A )
    call TimerStart( t, 0.02, true, function MoveUzi )
    call DestroyEffect( AddSpecialEffectTarget( WeaponEffect, A.caster, "weapon" ) )
    call DestroyEffect( AddSpecialEffectTarget( WeaponEffect2, A.caster, "chest" ) )
    call SetItemCharges( GetItemOfTypeFromUnitBJ(udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], 'I00O'), ( GetItemCharges(GetItemOfTypeFromUnitBJ(udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], 'I00O')) - 1 ) )
    
    set t = null
    set Target = null
    
    set WeaponEffect = null
    set WeaponEffect2 = null
    call IssueImmediateOrderBJ( udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], "stop" )
    
endfunction

//===========================================================================
function ShootUzi_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A028' ) ) then
        return false
    endif
    if ( not ( GetItemCharges(GetItemOfTypeFromUnitBJ(udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], 'I00O')) != 0 ) ) then
        return false
    endif
    return true
endfunction

function InitTrig_ShootUzi takes nothing returns nothing
    local trigger t5 = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t5, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( t5, Condition( function ShootUzi_Conditions ) )
    call TriggerAddAction( t5, function Trig_ShootUzi_Actions )
    set t5 = null
endfunction
endlibrary

Принятый ответ

Если у тебя юнит использует этот предмет, то переделай событие триггера - юнит применяет способность, на юнит испоользует предмет. Можно сразу ссылаться на item being manipulated вместо GetItemOfTypeFromUnitBJ

Это бы упростило бы вам работу.
`
ОЖИДАНИЕ РЕКЛАМЫ...
0
27
5 месяцев назад
0
Раскрой GetItemOfTypeFromUnitBJ, тут 3 раза ты используешь. Там вроде не обнуленные локалки. Остальное не стал сильно просматривать, если ты все уничтожил: там даймики таймеры, и подчистил то норс


Вообще точно не уверен, утекает ли оно, ибо с собой под руки нет библиотеки. Раньше помню были с этим траблы
0
8
5 месяцев назад
0
МрачныйВорон, 2 раза в условии, в вычитании заряда,
0
27
5 месяцев назад
Отредактирован MpW
0
Если у тебя юнит использует этот предмет, то переделай событие триггера - юнит применяет способность, на юнит испоользует предмет. Можно сразу ссылаться на item being manipulated вместо GetItemOfTypeFromUnitBJ

Это бы упростило бы вам работу.
Принятый ответ
0
8
5 месяцев назад
0
МрачныйВорон, попробую
Чтобы оставить комментарий, пожалуйста, войдите на сайт.