• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

MY buggy projectile sytem

Status
Not open for further replies.
Level 7
Joined
Apr 1, 2010
Messages
289
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

JASS:
function Trig_MS_Actions takes nothing returns nothing
   local integer i = 0
   local boolean e
   loop
      set i = i+1
      exitwhen i > udg_MS_Max        
      set e = false
      loop
         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])
         else
            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]
            
         endif
         exitwhen e == true or udg_MS_Max == 0
      endloop
   endloop
   if udg_MS_Max == 0 then
      call DisableTrigger(gg_trg_MS)
   endif
endfunction

//========================================================================
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 )
endfunction
JASS:
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")
endfunction
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.
JASS:
   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
 

Attachments

  • 2dProjectiles .04.w3x
    18.7 KB · Views: 34
Last edited:
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
Joined
Apr 1, 2010
Messages
289
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.
 
Status
Not open for further replies.
Top