- 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:
+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.
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.