• 🏆 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] Need help with a code

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
okay, i've made a mpi code in jass, that is praticly like meat hook of pudge wars..
i was curious on how it worked, so i tried making it..
it works perfect for me, exept the repeat part..
if i use the spell once, and repeat it again after it comes back, the unit doesnt appear.. any help?

JASS:
library Hook

    globals
    
        private integer array Hook_Distance
        private integer array Hook_Count
        private location array Hook_RPoint
    
    endglobals
    
function Trig_Hook_Func001A takes nothing returns nothing

if Hook_Distance[GetPlayerId(GetOwningPlayer(GetEnumUnit()))] == 600 then

if Hook_Count[GetPlayerId(GetOwningPlayer(GetEnumUnit()))] >= 0 then

call SetUnitPositionLoc(GetEnumUnit(), Hook_RPoint[Hook_Count[GetPlayerId(GetOwningPlayer(GetEnumUnit()))]])
set Hook_RPoint[Hook_Count[GetPlayerId(GetOwningPlayer(GetEnumUnit()))]] = null
set Hook_Count[GetPlayerId(GetOwningPlayer(GetEnumUnit()))] = Hook_Count[GetPlayerId(GetOwningPlayer(GetEnumUnit()))]-1

else

call RemoveUnit(GetEnumUnit())
set Hook_Diaatance[GetPlayerId(GetOwningPlayer(GetEnumUnit()))] = Hook_Distance[GetPlayerId(GetOwningPlayer(GetEnumUnit()))]-30

endif

else

call SetUnitPositionLoc(GetEnumUnit(), PolarProjectionBJ(GetUnitLoc(GetEnumUnit()), 30, GetUnitFacing(GetEnumUnit())))
set Hook_RPoint[Hook_Count[GetPlayerId(GetOwningPlayer(GetEnumUnit()))]] = GetUnitLoc(GetEnumUnit())
set Hook_Count[GetPlayerId(GetOwningPlayer(GetEnumUnit()))] = Hook_Count[GetPlayerId(GetOwningPlayer(GetEnumUnit()))]+1
set Hook_Distance[GetPlayerId(GetOwningPlayer(GetEnumUnit()))] = Hook_Distance[GetPlayerId(GetOwningPlayer(GetEnumUnit()))]+30

endif

endfunction

function Trig_Hook_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsOfTypeIdAll('h000'), function Trig_Hook_Func001A )
endfunction
endlibrary

//===========================================================================
//===========================================================================
function InitTrig_Hook takes nothing returns nothing
    set gg_trg_Hook = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Hook, 0.05 )
    call TriggerAddAction( gg_trg_Hook, function Trig_Hook_Actions )
endfunction
 
You leak 3 locations per 'h000' unit every 0.5 seconds and a group every 0.05 seconds.

Setting a location 'null' does not clear the leak. You must still call RemoveLocation.

ForGroupBJ is pointless unless you are using set bj_wantDestroyGroup to true, which you are not doing.

You leak the three locations here:

JASS:
call SetUnitPositionLoc(GetEnumUnit(), PolarProjectionBJ(GetUnitLoc(GetEnumUnit()), 30, GetUnitFacing(GetEnumUnit())))
set Hook_RPoint[Hook_Count[GetPlayerId(GetOwningPlayer(GetEnumUnit()))]] = GetUnitLoc(GetEnumUnit())

You spam GetPlayerId(GetOwningPlayer(GetEnumUnit())). That should be a local variable set once at the top of the function, as well as GetEnumUnit(). If you use a local variable to store GetEnumUnit() instead of a global variable, be sure to set that local to null.

And, most importantly, indent your code.
 
Level 10
Joined
Jan 24, 2009
Messages
606
Whats the point of using a library when you don't even use any library needed prefixes (or Scope needed)
+ what's the point of putting the init trigger outside the library? put it inside and call it Init
then write:
JASS:
library Hook initializer Init
This will basically make the function Init the initializing function that creates the trigger.
Also, why not use private function instead of just function? unless you want to use it outside the library that is.
 
Status
Not open for further replies.
Top