• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Spell:Leak/Native Check

Status
Not open for further replies.
Level 4
Joined
Dec 30, 2009
Messages
60
I have been working on a spell that would imitate a blink/attack effect and I would like to submit it but I need to check for leaks first, This is only my second JASS script and I would like some help finding leaks and replacing BJ's with natives.

There are some locals that I wish to keep constant.

Here it is:
JASS:
//=====================================================
//============== Blinky Spell(Custom) =================
//================ By: Drenferalis ====================
//=====================================================
//=====================================================
//==== This spell is used for Imitating multiple =====
//== attacks within few seconds. It requires the use ==
//== of a dummy unit to imitate an  attack sequence ==
//== and uses a damage target function to define how ==
//== much damage is dealt. The damage can be defined ==
//=== by changing  the appropriate variables in the ===
//============= function Spell_Actions. ===============
//=====================================================
//===WARNING: DO NOT CHANGE ANYTHING EXCEPT WHAT IS====
//====LABELED WITH CHANGE OR DEFINE SUCH AS BELOW!=====
//=====================================================
//=====================================================


//=====================================================
//CHANGE 'h000' TO YOUR DUMMY UNITS RAW ID==============
//=====================================================
function DC_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'h000' ) ) then
        return false
    endif
    return true
endfunction

//=======================================================
//========================================================
//=======================================================


function DC_Actions takes nothing returns nothing
    local location crater
    local unit target =  GetOrderTargetUnit()
    local integer DMG1
//=======================================================
//Define this for terrain changes=========================
//=======================================================
    local boolean TC = true
//=======================================================
//========================================================
//=======================================================
    loop
        exitwhen ( GetUnitCurrentOrder(GetTriggerUnit()) != String2OrderIdBJ("attackonce") )
        call TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 0.10))
        if (TC == true)then
        set crater = GetUnitLoc(GetTriggerUnit())
        call SetTerrainTypeBJ( crater, 'Nice', -1, 1, 0 )
        endif
    endloop
    set DMG1 = GetUnitUserData(GetTriggerUnit())
    call UnitDamageTargetBJ( GetTriggerUnit(), target, I2R(DMG1), ATTACK_TYPE_PIERCE, DAMAGE_TYPE_NORMAL )
    set target = null
    call RemoveUnit( GetTriggerUnit() )
endfunction

function Loc_trg takes nothing returns nothing
    local trigger DC = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( DC, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER  )
    call TriggerAddCondition( DC, Condition( function DC_Conditions ) )
    call TriggerAddAction( DC, function DC_Actions  )
endfunction







//Checks if the ability being cast is "Blinky"
//==========================================================
//REPLACE 'A000' WITH YOUR CUSTOM SPELL RAW ID!=============
//==========================================================
function Trig_Blinky_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction
//==========================================================
//END REPLACE===============================================
//==========================================================




//The main spell is here.
function Spell_Actions takes nothing returns nothing
    //Sets locals for MUI and leak removal.
    local unit Blinky = GetSpellTargetUnit()
    local unit Blink_E = GetSpellAbilityUnit()
    local unit B_Dummy
    local integer LI
    local location TR
    local location BlinkLoc
    local location BlinkELoc
    local real Stat
    local integer AL
    local real BD
    local real DMG
    local integer Dmmy
    local fogmodifier Fog
//==================================================================
//Definable Variables Below==========================================
//==================================================================
    //Change to STR for Strength, AGI for Agility, and INT for intelligence.
    local string Attribute = "AGI"
    //Multiplier Percentage of the spell (Will be multiplied by Spell Level [eg. Mult=.1) and Spell level is 3 the final Mult will be .3])
    local real Mult = 0
    //Wait between movement/attacks. 
    local real MWait = .01
    //Number of attacks
    local integer NumA = 500
    //Square Range of "Blink"
    local integer Bx = 5000
    //Dummy Unit RAW ID
    set Dmmy = 'h000'
    //Base Spell Damage
    set BD = 5
    //End of Definable Variables
//==================================================================
//===================================================================
//==================================================================

    if ( Attribute == "STR")then
    set Stat = I2R(GetHeroStatBJ(bj_HEROSTAT_STR, Blink_E, true))
    elseif (Attribute == "AGI")then
    set Stat = I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, Blink_E, true))
    elseif (Attribute == "INT")then
    set Stat = I2R(GetHeroStatBJ(bj_HEROSTAT_INT, Blink_E, true))
    endif
    set AL = GetUnitAbilityLevelSwapped(GetSpellAbilityId(), Blink_E)
    set DMG = ((Stat * (Mult * (I2R(AL)))) + BD)
    call Loc_trg()
    call PauseUnitBJ( true, Blinky )
    call PauseUnitBJ( true, Blink_E )
    call SetUnitInvulnerable( Blink_E, true )
    set BlinkLoc = GetUnitLoc(Blinky)
    call CreateFogModifierRadiusLocBJ( true, GetOwningPlayer(Blink_E), FOG_OF_WAR_VISIBLE, BlinkLoc, 512 )
    set Fog = GetLastCreatedFogModifier()
    set LI = 1
    
    loop
        exitwhen LI > NumA
        if ( IsUnitAliveBJ(Blinky) == true) then
            set BlinkLoc = GetUnitLoc(Blinky)
             
            set TR = GetRandomLocInRect(RectFromCenterSizeBJ(BlinkLoc, Bx, Bx))
            call SetUnitPositionLocFacingLocBJ( Blink_E, TR, BlinkLoc )
            call CreateNUnitsAtLocFacingLocBJ( 1, Dmmy, GetOwningPlayer(Blink_E), GetUnitLoc(Blink_E), BlinkLoc )
            set B_Dummy = GetLastCreatedUnit()
            call IssueTargetOrderBJ( B_Dummy, "attackonce", Blinky )
            call TriggerSleepAction( MWait)
            call SetUnitUserData( B_Dummy, R2I(DMG) )
            set TR = null
            set BlinkLoc = null
        else
            call PauseUnitBJ( false, Blink_E )
            call SetUnitInvulnerable( Blink_E, false )
            
            set B_Dummy = null
            call DestroyFogModifier( Fog )
            return
        endif
        
        set B_Dummy = null
        set LI = LI + 1
    endloop
    call PauseUnitBJ( false, Blink_E )
    call DestroyFogModifier( Fog )
    call SetUnitInvulnerable( Blink_E, false )
    call PauseUnitBJ( false, Blinky )
 set Blinky = null
 set Blink_E = null
 set LI = 0
endfunction

//===========================================================================
function InitTrig_Blinky takes nothing returns nothing
    set gg_trg_Blinky = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Blinky, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Blinky, Condition( function Trig_Blinky_Conditions ) )
    call TriggerAddAction( gg_trg_Blinky, function Spell_Actions )
endfunction

+Rep will be given for even just 1 leak or native replacement.
Thanks!

Edit: GetTriggeringUnit() is used in Loc_Trig's conditions and actions because its MUI and assigning a local unit variable was not working. Also Updated code comments a tiny bit.
 
I tried to fix a lot, but my eyes are tired so I must've overlooked some things. Try this out and see if it works, at least maybe it will make it easier for other people to optimize it further =P :
JASS:
//=====================================================
//============== Blinky Spell(Custom) =================
//================ By: Drenferalis ====================
//=====================================================
//=====================================================
//==== This spell is used for Imitating multiple =====
//== attacks within few seconds. It requires the use ==
//== of a dummy unit to imitate an  attack sequence ==
//== and uses a damage target function to define how ==
//== much damage is dealt. The damage can be defined ==
//=== by changing  the appropriate variables in the ===
//============= function Spell_Actions. ===============
//=====================================================
//===WARNING: DO NOT CHANGE ANYTHING EXCEPT WHAT IS====
//====LABELED WITH CHANGE OR DEFINE SUCH AS BELOW!=====
//=====================================================
//=====================================================


//=====================================================
//CHANGE 'h000' TO YOUR DUMMY UNITS RAW ID==============
//=====================================================
function DC_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'h000'
endfunction

//=======================================================
//========================================================
//=======================================================


function DC_Actions takes nothing returns nothing
    local real craterx = GetUnitX(GetTriggerUnit())
    local real cratery = GetUnitY(GetTriggerUnit())
    local unit target =  GetOrderTargetUnit()
    local integer DMG1
//=======================================================
//Define this for terrain changes=========================
//=======================================================
    local boolean TC = true
//=======================================================
//========================================================
//=======================================================
    loop
        exitwhen GetUnitCurrentOrder(GetTriggerUnit()) != OrderId("attackonce")
        call TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 0.10))
        if (TC == true)then
            call SetTerrainType(craterx,cratery,'Nice',-1,1,0)
        endif
    endloop
    set DMG1 = GetUnitUserData(GetTriggerUnit())
    call UnitDamageTarget(GetTriggerUnit(),target,I2R(DMG1),true,false,ATTACK_TYPE_PIERCE,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    set target = null
    call RemoveUnit(GetTriggerUnit())
endfunction

function Loc_trg takes nothing returns nothing
    local trigger DC = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(DC,EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
    call TriggerAddCondition(DC,Condition(function DC_Conditions))
    call TriggerAddAction(DC,function DC_Actions)
    set DC = null
endfunction







//Checks if the ability being cast is "Blinky"
//==========================================================
//REPLACE 'A000' WITH YOUR CUSTOM SPELL RAW ID!=============
//==========================================================
function Trig_Blinky_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction
//==========================================================
//END REPLACE===============================================
//==========================================================




//The main spell is here.
function Spell_Actions takes nothing returns nothing
    //Sets locals for MUI and leak removal.
    local unit Blinky = GetSpellTargetUnit()
    local unit Blink_E = GetSpellAbilityUnit()
    local unit B_Dummy
    local integer LI = 1
    local location TR
    local real BlinkX = GetUnitX(Blinky)
    local real BlinkY = GetUnitY(Blinky)
    local rect BlinkRect
    local location BlinkELoc
    local real Stat
    local integer AL
    local real BD = 5
    local real DMG
    local integer Dmmy = 'h000'
    local fogmodifier Fog
//==================================================================
//Definable Variables Below==========================================
//==================================================================
    //Change to STR for Strength, AGI for Agility, and INT for intelligence.
    local string Attribute = "AGI"
    //Multiplier Percentage of the spell (Will be multiplied by Spell Level [eg. Mult=.1) and Spell level is 3 the final Mult will be .3])
    local real Mult = 0
    //Wait between movement/attacks.
    local real MWait = .01
    //Number of attacks
    local integer NumA = 500
    //Square Range of "Blink"
    local integer Bx = 5000
    //Dummy Unit RAW ID
    //Base Spell Damage
    //End of Definable Variables
//==================================================================
//===================================================================
//==================================================================

    if ( Attribute == "STR")then
        set Stat = I2R(GetHeroStr(Blink_E,true))
    elseif (Attribute == "AGI")then
        set Stat = I2R(GetHeroAgi(Blink_E,true))
    elseif (Attribute == "INT")then
        set Stat = I2R(GetHeroInt(Blink_E,true))
    endif
    set AL = GetUnitAbilityLevel(Blink_E,GetSpellAbilityId())
    set DMG =((Stat*(Mult*(I2R(AL))))+BD)
    call Loc_trg()
    call PauseUnit(Blinky,true)
    call PauseUnit(Blink_E,true)
    call SetUnitInvulnerable(Blink_E,true)
    set Fog = CreateFogModifierRadius(GetOwningPlayer(Blink_E),FOG_OF_WAR_VISIBLE,BlinkX,BlinkY,512,true,false)
    call FogModifierStart(Fog)  
    loop
        exitwhen LI > NumA
        if GetUnitState(Blinky,UNIT_STATE_LIFE) >= 0.45 then
            set BlinkX = GetUnitX(Blinky)
            set BlinkY = GetUnitY(Blinky)
            set BlinkRect = Rect(BlinkX-Bx*0.5,BlinkY-Bx*0.5,BlinkX+Bx*0.5,BlinkY+Bx*0.5) 
            set TR = Location(GetRandomReal(GetRectMinX(BlinkRect), GetRectMaxX(BlinkRect)), GetRandomReal(GetRectMinY(BlinkRect), GetRectMaxY(BlinkRect)))
            call SetUnitPositionLoc(Blink_E,TR)
            call SetUnitFacing(Blink_E,bj_RADTODEG*Atan2(BlinkY-GetLocationY(TR),BlinkX-GetLocationX(TR)))
            set B_Dummy = CreateUnit(GetOwningPlayer(Blink_E),Dmmy,GetUnitX(Blink_E),GetUnitY(Blink_E),bj_RADTODEG*Atan2(GetUnitY(Blink_E)-BlinkY,GetUnitX(Blink_E)-BlinkX))
            call IssueTargetOrder(B_Dummy,"attackonce",Blinky)
            call TriggerSleepAction(MWait)
            call SetUnitUserData(B_Dummy,R2I(DMG))
            call RemoveLocation(TR)
        else
            call PauseUnit(Blink_E,false)
            call SetUnitInvulnerable(Blink_E,false)            
            call DestroyFogModifier(Fog)
            return
        endif        
        set LI = LI + 1
    endloop
    call PauseUnit(Blink_E,false)
    call DestroyFogModifier(Fog)
    call SetUnitInvulnerable(Blink_E,false)
    call PauseUnit(Blinky,false)
    call RemoveRect(BlinkRect)
    call RemoveLocation(BlinkELoc)
    set Fog = null
    set BlinkRect = null
    set Blinky = null
    set Blink_E = null
    set B_Dummy = null
    set BlinkELoc = null
    set TR = null
    set LI = 0
endfunction

//===========================================================================
function InitTrig_Blinky takes nothing returns nothing
    set gg_trg_Blinky = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Blinky, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Blinky, Condition( function Trig_Blinky_Conditions ) )
    call TriggerAddAction( gg_trg_Blinky, function Spell_Actions )
endfunction

Basically, I replaced a lot of BJ's. Removed some locations for coordinates. (I didn't remove like 2 of them or something out of laziness, that can be further optimized =P)

Anyway, just make sure you keep your original code just in case since my code has a tendency to not work. I mostly just did replacing but I might've gotten either confused or I just couldn't think straight. :bored:
 
Level 4
Joined
Dec 30, 2009
Messages
60
I tried to fix a lot, but my eyes are tired so I must've overlooked some things. Try this out and see if it works, at least maybe it will make it easier for other people to optimize it further =P :


Basically, I replaced a lot of BJ's. Removed some locations for coordinates. (I didn't remove like 2 of them or something out of laziness, that can be further optimized =P)

Anyway, just make sure you keep your original code just in case since my code has a tendency to not work. I mostly just did replacing but I might've gotten either confused or I just couldn't think straight. :bored:

This code ALMOST worked fine. You had set the craterx and cratery variables outside of the loop, The loop is what makes a "line" and also i believe the arrows dont spawn facing the enemy unit anymore but thats an easy fix as well.

+Rep I wish I could give you more.
 
Status
Not open for further replies.
Top