• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Its leaking?

Status
Not open for further replies.
Level 17
Joined
Nov 13, 2006
Messages
1,814
this leaking or no coz enough the nulling location?
JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local integer a = 0
    local integer b = 0
    local integer c = 0
    local integer d = 0
    local integer e = 0
    local unit u = GetTriggerUnit()
    local unit u1 = null
    local unit u2 = null
    local location l1 =  GetUnitLoc(u)
    local location l2 =  GetSpellTargetLoc()
    local real x1 = GetLocationX(l1)
    local real y1 = GetLocationY(l1)
    local real x2 = GetLocationX(l2)
    local real y2 = GetLocationY(l2)
    local real x3 = 0
    local real y3 = 0
    local real x4 = 0
    local real y4 = 0
    local real g = 3.14159/180
    local real dmg = 10 + (GetUnitAbilityLevel(u, 'ANcl')) * 50
    local player p = GetOwningPlayer(u)
    local string s = "Abilities\\Spells\\Items\\VampiricPotion\\VampPotionCaster.mdl"
    local effect f =  AddSpecialEffectTarget(s, u, "origin")
    loop
        exitwhen a > 110
        loop
       exitwhen b > 10
            set x3 = GetLocationX(l1) + GetRandomReal(0, 200.00) * Cos(g * GetRandomReal(0, 359.0))         
            set y3 = GetLocationY(l1) + GetRandomReal(0, 200.00) * Cos(g * GetRandomReal(0, 359.0))
            set u1 = CreateUnit (p, 'h000', x3 , y3, 0)   
            call UnitAddAbility(u1, 'Amrf' )
            call UnitRemoveAbility(u1, 'Amrf' )
            call SetUnitFlyHeight( u1, 1500.00, GetRandomReal(800.00, 1000.00) )
            call UnitApplyTimedLife( u1,'BTLF', 3.00 )
            set u1 = null
            set b = b + 1
        endloop
        
        if (a > 5) then

        loop
            exitwhen c > 10
            set x4 = GetLocationX(l2) + GetRandomReal(0, 200.00) * Cos(g * GetRandomReal(0, 359.0))         
            set y4 = GetLocationY(l2) + GetRandomReal(0, 200.00) * Cos(g * GetRandomReal(0, 359.0))           
            set u2 = CreateUnit (p, 'h001', x4 , y4, 0)   
            call UnitAddAbility(u2, 'Amrf' )
            call UnitRemoveAbility(u2, 'Amrf' )
            call SetUnitFlyHeight( u2, GetRandomReal(5.00, 40.00), GetRandomReal(900.00, 1000.00) )
            call UnitApplyTimedLife( u2,'BTLF', 6.00 )
            set c = c + 1
        endloop
        set d = d + 1
            if ((a - I2R(R2I(a / 2)) * 2) == 0) then
            call UnitDamagePoint(u, 0, 200, x2, y2, dmg, true, false, ConvertAttackType(6), ConvertDamageType(4), ConvertWeaponType(0))
            call SetUnitState(u, ConvertUnitState(2), GetUnitState(u,ConvertUnitState(2)) - 5)
            endif
        endif
call TriggerSleepAction(0.1)

              if ((OrderId2StringBJ(GetUnitCurrentOrder(u)) != "channel") and (GetUnitState(u, ConvertUnitState(0)) > 0)) then
              set a = 10000
              elseif (GetUnitState(u, ConvertUnitState(2)) < 5.00) then
              set a = 10000
              call IssueImmediateOrder( GetTriggerUnit(), "stop" )
              endif
        set a = a + 1
        set e = e + 1
        set b = 0
        set c = 0
endloop
call DestroyEffect(f)
set d = e - d + 3
set a = 0

    loop
        exitwhen a > d
         loop
            exitwhen c > 10
            set x4 = GetLocationX(l2) + GetRandomReal(0, 200.00) * Cos(g * GetRandomReal(0, 359.0))         
            set y4 = GetLocationY(l2) + GetRandomReal(0, 200.00) * Cos(g * GetRandomReal(0, 359.0))           
            set u2 = CreateUnit (p, 'h001', x4 , y4, 0)   
            call UnitAddAbility(u2, 'Amrf' )
            call UnitRemoveAbility(u2, 'Amrf' )
            call SetUnitFlyHeight( u2, GetRandomReal(10.00, 30.00), GetRandomReal(900.00, 1000.00) )
            call UnitApplyTimedLife( u2,'BTLF', 6.00 )
            set c = c + 1
         endloop
        call TriggerSleepAction(0.1)
        if ((a - I2R(R2I(a / 2)) * 2) == 0) then
        call UnitDamagePoint(u, 0, 200, x2, y2, dmg, true, false, ConvertAttackType(6), ConvertDamageType(4), ConvertWeaponType(0))
        endif
        set a = a + 1
        set c = 0
    endloop


set u = null
set u1 = null
set u2 = null
set p = null
set s = null
set f = null
set l1 = null
set l2 = null
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Does a unit vanish when you null all variables pointing to it? You still need to remove the locations with RemoveLocation(<location>) or do not use GetUnitLoc(<unit>) and GetSpellTargetLoc() in the first place but GetUnitX/Y(<unit>) or GetWidgetX/Y(<widget>) and GetSpellTargetX/Y().
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
thanks very much
if i use Location(x,y) when i create a item, its same like location variable?

what is widget?
example if i want a random cordinate in a region then how its work?

GetWidgetX(GetRandomLocInRect(GetPlayableMapRect()))
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Location(<x>, <y>) also creates a location that you should destroy. widget is the parent type of destructable, item and unit. So you can use GetWidgetX/Y(<widget>) to get any destructable's, item's or unit's x/y coordinate.

You mean a random x/y pair in a rect is what you want. You do not need GetRandomLocInRect(<rect>) at all, which is a BJ by the way. Just take a look at how it does things:

JASS:
function GetRandomLocInRect takes rect whichRect returns location
    return Location(GetRandomReal(GetRectMinX(whichRect), GetRectMaxX(whichRect)), GetRandomReal(GetRectMinY(whichRect), GetRectMaxY(whichRect)))
endfunction

So just random a x/y between min x/y and max x/y of the rect.

I see btw that you try to roll any angle above with GetRandomReal(0, 359.0). But that does not include 359 til 360/0, the angle is a real after all. Simply take between 0 and 360. And for converting in radian declare a public constant variable please, not a local that is created and calculated everytime the function is called. Better yet, do not work in degree/radian at all, I count in full angles (or a multiple of it for precision). At least have a GetRandomAngle() function.
 
Status
Not open for further replies.
Top