• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

syntax error

Level 2
Joined
Apr 29, 2024
Messages
8
Hello, this ability is supposed to make the unit teleport to the enemy, but only if the distance is is 1000 or less. I want to compare udg_unit29 location, to the target unit location. The map works fine and loads without the if statement. Can someone help me with the if statement? I want it to work for the movement and damage The ability also leaks twice.. theres a lot of redunant code. Any help is appreciated

JASS:
function Trig_Super_Punch_Conditions takes nothing returns boolean
if(not(GetSpellAbilityId()=='A064'))then
return false
endif
return true
endfunction
function Trig_Super_Punch_Func023001003 takes nothing returns boolean
return(IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()),GetOwningPlayer(udg_unit29))==true)
endfunction
function Trig_Super_Punch_Func023A takes nothing returns nothing
call UnitDamageTargetBJ(udg_unit29,GetEnumUnit(),(I2R(GetHeroStatBJ(bj_HEROSTAT_STR,udg_unit29,false))*3.50),ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL)
endfunction
function Trig_Super_Punch_Actions takes nothing returns nothing
set udg_Loc=GetUnitLoc(udg_unit29)
set udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]=GetSpellTargetUnit()
call CreateNUnitsAtLoc(1,'h02H',Player(5),udg_Loc,GetUnitFacing(udg_unit29))
set udg_FTDummy=GetLastCreatedUnit()
call EnableTrigger(gg_trg_Image_Fade)
call UnitApplyTimedLifeBJ(0.20,'BTLF',GetLastCreatedUnit())
call RemoveLocation(udg_Loc)
call ShowUnitHide(udg_unit29)
call TriggerSleepAction(0.20)
call ShowUnitShow(udg_unit29)
call SelectUnitForPlayerSingle(udg_unit29,Player(5))
set udg_Loc=PolarProjectionBJ(GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]),50.00,(GetUnitFacing(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())])+180.00))
if DistanceBetweenPoints(udg_unit29,udg_Loc)<=1000 then
call SetUnitPositionLoc(udg_unit29,udg_Loc)
call SetUnitFacingToFaceUnitTimed(udg_unit29,udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())],0.00)
call IssueTargetOrder(udg_unit29,"attack",GetSpellTargetUnit())
call RemoveLocation(udg_Loc)
call DisableTrigger(gg_trg_Image_Fade)
set udg_Loc=GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())])
call AddSpecialEffectLocBJ(udg_Loc,"war3mapImported\\NewDirtEXNofire.mdx")
call DestroyEffect(GetLastCreatedEffectBJ())
call UnitDamageTargetBJ(udg_unit29,udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())],(I2R(GetHeroStatBJ(bj_HEROSTAT_STR,udg_unit29,false))*7.00),ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL)
call ForGroupBJ(GetUnitsInRangeOfLocMatching(200.00,udg_Loc,Condition(function Trig_Super_Punch_Func023001003)),function Trig_Super_Punch_Func023A)
endif
call RemoveLocation(udg_Loc)
set udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]=null
set udg_FTDummy=null
set udg_Transparency=0.00
endfunction
function InitTrig_Super_Punch takes nothing returns nothing
set gg_trg_Super_Punch=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Super_Punch,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_Super_Punch,Condition(function Trig_Super_Punch_Conditions))
call TriggerAddAction(gg_trg_Super_Punch,function Trig_Super_Punch_Actions)
endfunction
function Trig_Image_Fade_Actions takes nothing returns nothing
set udg_Transparency=(udg_Transparency+5.00)
call SetUnitVertexColorBJ(udg_FTDummy,100,100,100,udg_Transparency)
endfunction
function InitTrig_Image_Fade takes nothing returns nothing
set gg_trg_Image_Fade=CreateTrigger()
call DisableTrigger(gg_trg_Image_Fade)
call TriggerRegisterTimerEventPeriodic(gg_trg_Image_Fade,0.01)
call TriggerAddAction(gg_trg_Image_Fade,function Trig_Image_Fade_Actions)
endfunction
 
Last edited:
I formatted your code a bit so that it's easier to read:

JASS:
function Trig_Super_Punch_Conditions takes nothing returns boolean
    if(not(GetSpellAbilityId()=='A064'))then
        return false
    endif
    return true
endfunction

function Trig_Super_Punch_Func023001003 takes nothing returns boolean
    return(IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()),GetOwningPlayer(udg_unit29))==true)
endfunction

function Trig_Super_Punch_Func023A takes nothing returns nothing
    call UnitDamageTargetBJ(udg_unit29,GetEnumUnit(),(I2R(GetHeroStatBJ(bj_HEROSTAT_STR,udg_unit29,false))*3.50),ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL)
endfunction

function Trig_Super_Punch_Actions takes nothing returns nothing
    set udg_Loc=GetUnitLoc(udg_unit29)
    set udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]=GetSpellTargetUnit()
    call CreateNUnitsAtLoc(1,'h02H',Player(5),udg_Loc,GetUnitFacing(udg_unit29))
    set udg_FTDummy=GetLastCreatedUnit()
    call EnableTrigger(gg_trg_Image_Fade)
    call UnitApplyTimedLifeBJ(0.20,'BTLF',GetLastCreatedUnit())
    call RemoveLocation(udg_Loc)
    call ShowUnitHide(udg_unit29)
    call TriggerSleepAction(0.20)
    call ShowUnitShow(udg_unit29)
    call SelectUnitForPlayerSingle(udg_unit29,Player(5))
    set udg_Loc=PolarProjectionBJ(GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]),50.00,(GetUnitFacing(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())])+180.00))
    if DistanceBetweenPoints(udg_unit29,udg_Loc)<=1000 then
        call SetUnitPositionLoc(udg_unit29,udg_Loc)
        call SetUnitFacingToFaceUnitTimed(udg_unit29,udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())],0.00)
        call IssueTargetOrder(udg_unit29,"attack",GetSpellTargetUnit())
        call RemoveLocation(udg_Loc)
        call DisableTrigger(gg_trg_Image_Fade)
        set udg_Loc=GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())])
        call AddSpecialEffectLocBJ(udg_Loc,"war3mapImported\\NewDirtEXNofire.mdx")
        call DestroyEffect(GetLastCreatedEffectBJ())
        call UnitDamageTargetBJ(udg_unit29,udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())],(I2R(GetHeroStatBJ(bj_HEROSTAT_STR,udg_unit29,false))*7.00),ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL)
        call ForGroupBJ(GetUnitsInRangeOfLocMatching(200.00,udg_Loc,Condition(function Trig_Super_Punch_Func023001003)),function Trig_Super_Punch_Func023A)
    endif
    call RemoveLocation(udg_Loc)
    set udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]=null
    set udg_FTDummy=null
    set udg_Transparency=0.00
endfunction

function InitTrig_Super_Punch takes nothing returns nothing
    set gg_trg_Super_Punch=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Super_Punch,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Super_Punch,Condition(function Trig_Super_Punch_Conditions))
    call TriggerAddAction(gg_trg_Super_Punch,function Trig_Super_Punch_Actions)
endfunction

function Trig_Image_Fade_Actions takes nothing returns nothing
    set udg_Transparency=(udg_Transparency+5.00)
    call SetUnitVertexColorBJ(udg_FTDummy,100,100,100,udg_Transparency)
endfunction

function InitTrig_Image_Fade takes nothing returns nothing
    set gg_trg_Image_Fade=CreateTrigger()
    call DisableTrigger(gg_trg_Image_Fade)
    call TriggerRegisterTimerEventPeriodic(gg_trg_Image_Fade,0.01)
    call TriggerAddAction(gg_trg_Image_Fade,function Trig_Image_Fade_Actions)
endfunction

The issue is that the DistanceBetweenPoints function expects two locations ans input arguments, but you're passing udg_unit29 as the first argument, which is a unit. To fix this you have to do:
JASS:
DistanceBetweenPoints(GetUnitLoc(udg_unit29),udg_Loc)
Of course, this will leak a location. You've mentioned you're aware of the memory leaks, so I don't know if you need help fixing those.
 
Level 2
Joined
Apr 29, 2024
Messages
8
Thank you for ur help. Yeah I am aware of the memory leaks, but tbh I dont know how to fix it. Would appreciate it if u could help fix it
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,647
Thank you for ur help. Yeah I am aware of the memory leaks, but tbh I dont know how to fix it. Would appreciate it if u could help fix it
You don't NEED to fix memory leaks, it's just something to help keep your game performing smooth. That being said, there are rare cases where it could be very bad to not fix them so you might as well do it. Here's a tutorial:
Just 2 days ago a user was asking about memory leaks, you can find a million threads like this:
When coding in JASS or Lua you also have to worry about another memory leak which might not get mentioned in the above tutorial-> nulling local variables. It's quite simple though and I'm sure you can find some tons of information on it.
 
Last edited:
Level 2
Joined
Apr 29, 2024
Messages
8
Okay I read the memory leak one you sent. Would typing this right before at the end function be correct?
JASS:
call UnitRemoveTimedLifeBJ(udg_FTDummy)
call RemoveUnit(udg_FTDummy)
 
Level 39
Joined
Feb 27, 2007
Messages
5,058
Units are one of the only data types that have automatic garbage collection. If a unit dies and is allowed to decay it will be automatically removed. All you have to do for units is give them a timed life. You should be concerned about/weary of:

locations/points
(unit) groups
(player) forces
(special) effects

Any type that extends agent/handle/widget needs to be properly cleaned up.
 
Level 2
Joined
Apr 29, 2024
Messages
8
when I look at the code udg_loc is removed twice and the special effect is also destroyed. And there is already a timed life for the FTDummy if im seeing it correctly. Only other thing I can spot is the unit groups thats not being destroyed after being used
JASS:
call ForGroupBJ(GetUnitsInRangeOfLocMatching(200.00,udg_Loc,Condition(function Trig_Super_Punch_Func023001003)),function Trig_Super_Punch_Func023A)
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,647
when I look at the code udg_loc is removed twice and the special effect is also destroyed. And there is already a timed life for the FTDummy if im seeing it correctly. Only other thing I can spot is the unit groups thats not being destroyed after being used
JASS:
call ForGroupBJ(GetUnitsInRangeOfLocMatching(200.00,udg_Loc,Condition(function Trig_Super_Punch_Func023001003)),function Trig_Super_Punch_Func023A)
Antares pointed at a leak that HE created in his solution to your issue and was suggesting that you fix it:
vJASS:
DistanceBetweenPoints(GetUnitLoc(udg_unit29),udg_Loc)
There was no implication that any of the code was leaking aside from this NEW addition.
 
There is one leak in the line
JASS:
set udg_Loc=PolarProjectionBJ(GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]),50.00,(GetUnitFacing(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())])+180.00))
//GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())] leaks a location!
To remove it, save the location to a variable first, like you did in other parts of your trigger, then remove it afterwards.
 
Level 2
Joined
Apr 29, 2024
Messages
8
There is one leak in the line
JASS:
set udg_Loc=PolarProjectionBJ(GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]),50.00,(GetUnitFacing(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())])+180.00))
//GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())] leaks a location!
To remove it, save the location to a variable first, like you did in other parts of your trigger, then remove it afterwards.
Like this? Or how should I do it

JASS:
local location udg_TargetLoc
set udg_Loc=GetUnitLoc(udg_unit29)
set udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]=GetSpellTargetUnit()
call CreateNUnitsAtLoc(1,'h02H',Player(5),udg_Loc,GetUnitFacing(udg_unit29))
set udg_FTDummy=GetLastCreatedUnit()
call EnableTrigger(gg_trg_Image_Fade)
call UnitApplyTimedLifeBJ(0.20,'BTLF',GetLastCreatedUnit())
call RemoveLocation(udg_Loc)
call ShowUnitHide(udg_unit29)
call TriggerSleepAction(0.20)
call ShowUnitShow(udg_unit29)
call SelectUnitForPlayerSingle(udg_unit29,Player(5)
set udg_TargetLoc = GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())])
set udg_Loc = PolarProjectionBJ(udg_TargetLoc, 50.00, (GetUnitFacing(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]) + 180.00))
if DistanceBetweenPoints(GetUnitLoc(udg_unit29), udg_Loc) <= 1000 then
call SetUnitPositionLoc(udg_unit29,udg_Loc)
call SetUnitFacingToFaceUnitTimed(udg_unit29,udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())],0.00)
call IssueTargetOrder(udg_unit29,"attack",GetSpellTargetUnit())
call RemoveLocation(udg_Loc)
call DisableTrigger(gg_trg_Image_Fade)
set udg_Loc=GetUnitLoc(udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())])
call AddSpecialEffectLocBJ(udg_Loc,"war3mapImported\\NewDirtEXNofire.mdx")
call DestroyEffect(GetLastCreatedEffectBJ())
call UnitDamageTargetBJ(udg_unit29,udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())],(I2R(GetHeroStatBJ(bj_HEROSTAT_STR,udg_unit29,false))*7.00),ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL)
call ForGroupBJ(GetUnitsInRangeOfLocMatching(200.00,udg_Loc,Condition(function Trig_Super_Punch_Func023001003)),function Trig_Super_Punch_Func023A)
call RemoveLocation(udg_Loc)
call RemoveLocation(udg_TargetLoc)
set udg_SpellTarget[GetConvertedPlayerId(GetTriggerPlayer())]=null
set udg_FTDummy=null
set udg_Transparency=0.00
endif
 
Top