• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 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!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

MY buggy projectile sytem

Not open for further replies.
Level 7
Apr 1, 2010
well, here is my projectile system, it has a few bugs, and it doesn't recycle projectiles (yet) and it bugs up occasionally(my test map illustrates the bug, just test it and cast flame strike somewhere) some of the pigs stop moving while others keep moving, but it can have over 600 projectiles out at a time without lagging, except from creating 600 units. (to test simple remove the wait out of the cast trigger.)

please test.

currently my projectiles do nothing more then tell you that they hit something running they could easily do so.

could someone make projectile recycling system please?

edit: posting code

function Trig_MS_Actions takes nothing returns nothing
   local integer i = 0
   local boolean e
      set i = i+1
      exitwhen i > udg_MS_Max        
      set e = false
         set udg_MS_Life[i] = udg_MS_Life[i]-.03
         if udg_MS_Life[i] > 0 then
            set e = true
            call SetUnitX(udg_MS_U[i],GetUnitX(udg_MS_U[i])+udg_MS_X[i])
            call SetUnitY(udg_MS_U[i],GetUnitY(udg_MS_U[i])+udg_MS_Y[i])
            call SetUnitUserData(udg_MS_U[udg_MS_Max],i)
            call SetUnitUserData(udg_MS_U[i],0)
            call DisableTrigger(LoadTriggerHandle(udg_MS,0,GetHandleId(udg_MS_U[i])))
            set udg_MS_X[i] = udg_MS_X[udg_MS_Max]
            set udg_MS_Y[i] = udg_MS_Y[udg_MS_Max]
            set udg_MS_Life[i] = udg_MS_Life[udg_MS_Max]
            set udg_MS_Max = udg_MS_Max-1
            set udg_MS_U[i] = udg_MS_U[udg_MS_Max]
         exitwhen e == true or udg_MS_Max == 0
   if udg_MS_Max == 0 then
      call DisableTrigger(gg_trg_MS)

function InitTrig_MS takes nothing returns nothing
    set gg_trg_MS = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_MS, 0.03 )
    call TriggerAddAction( gg_trg_MS, function Trig_MS_Actions )
function Collision takes nothing returns nothing
   set udg_MS_Collision = 0
   set udg_MS_CollisionUnit = LoadUnitHandle(udg_MS,0,GetHandleId(GetTriggeringTrigger()))
   set udg_MS_CollidingU = GetTriggerUnit()
   set udg_MS_Collision = 1
    call DisplayTimedTextToForce( GetPlayersAll(), 1.00, "Colliding")
Basic creation(note, i am using a gui trigger for this with a wall of custom text and i thought this would be easier to read.
   local unit c = GetTriggerUnit()
   local real f = GetUnitFacing(c)
   local real s = 10
   local real x = GetUnitX(c)
   local real y = GetUnitY(c)
   set udg_MS_Max = udg_MS_Max+1
   set udg_T = CreateTrigger()
   set udg_MS_U[udg_MS_Max] = CreateUnit(GetTriggerPlayer(),'h000',x,y,f)
   call TriggerRegisterUnitInRangeSimple( udg_T,120, udg_MS_U[udg_MS_Max] )
   call TriggerAddAction(udg_T,function Collision)
   call SaveTriggerHandle(udg_MS,0,GetHandleId(udg_MS_U[udg_MS_Max]),udg_T)
   call SaveUnitHandle(udg_MS,0,GetHandleId(udg_T),udg_MS_U[udg_MS_Max])
   set udg_MS_Y[udg_MS_Max]=((Sin(f*3.141592/180))*s)
   set udg_MS_X[udg_MS_Max]=((Cos(f*3.141593/180))*s)
   set udg_MS_Life[udg_MS_Max] = 5
   call SetUnitUserData(udg_MS_U[udg_MS_Max],udg_MS_Max)
   set c = null


  • 2dProjectiles .04.w3x
    18.7 KB · Views: 33
Last edited:


Code Reviewer
Level 26
Mar 19, 2008
Why don't you use one of appoved systems in Spell section instead?

Your script requires to be actually rewritten. And I'd recommend to read to advanced jass/jass tips tutorials.

'Red' functions can be ofen replaced with natives, like TriggerRegisterTimerEventPeriodic with TriggerRegisterTimerEvent

Hahstable can be initialized in any 'InitTrig_' function; you do not need separate trigger for that. All triggers (since as I see you want to do that in jass) should be merged together.
600 loop instances per cast? With CreateUnit() + trigger declaration within each iteration? that hurts ;/
SavingTriggerHandle? You do not need that.

Unit Indexer can help you with proper index manipulation - and you don't have to recycle indexes after instance finishes;
With help of such system you can just call GetUnitUserData(someunit) to get index for global parameters.
Don't forget to null the handles. Instead of AddActions, run actions with AddConditions.
Level 7
Apr 1, 2010
Why don't you use one of appoved systems in Spell section instead?
1st there are no 2d projectile systems on the hive, secondly this supports more projectiles then any system involving unit groups will ever.

600 loop instances per cast? With CreateUnit() + trigger declaration within each iteration? that hurts ;/
which is why i want to do projectile recycling, + this is just an example of the system. the main point of this was that it can have 600 porjectiles flying detecting collisions at the same time with out lagging(I know that when you cast it lags a little, but after it is done making the projectiles it doesn't lag at all, with 600, 1200 or even 2400 projectiles.)

SavingTriggerHandle? You do not need that.
if i want to recall what unit was connected to that trigger i do.
i will modify the less efficient part. because this is a projectile, system i need to find out which projectile collided with something and that is the only way i could think of.
Not open for further replies.