• 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.

[System] How Can I Improve The Code?

Status
Not open for further replies.
Level 18
Joined
Oct 17, 2012
Messages
849
How can I improve the code for this spawn system? My goal is to reduce the amount of triggers. Here is the code:

I have two more triggers similar to this.
  • Spawn Next Creep Easy
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
      • SpawnCreepMiddle Equal to False
      • SpawnCreepHard Equal to False
    • Actions
      • Trigger - Run CreepSpawnTriggersEasy[(CreepSpawnNumberEasy mod 24)] (checking conditions)
      • Set CreepSpawnNumberEasy = (CreepSpawnNumberEasy + 1)
There is one more trigger similar to this one.
  • Change Spawn Middle
    • Events
      • Time - Elapsed game time is 900.00 seconds
    • Conditions
    • Actions
      • Game - Display to (All players) for 20.00 seconds the text: |cffffcc00Now the r...
      • Set SpawnCreepMiddle = True
      • Set SpawnCreepHard = False
      • Set CreepSpawnNumberMiddle = 0
      • Trigger - Run Setup Creep Spawn Triggers Middle <gen> (checking conditions)
System includes 2 more triggers similar to this for moderate and hard difficulty.
  • Setup Creep Spawn Triggers Easy
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set CreepSpawnTriggersEasy[0] = FurlborgOne <gen>
      • Set CreepSpawnTriggersEasy[1] = OwlbearOne <gen>
      • Set CreepSpawnTriggersEasy[2] = RockOne <gen>
      • Set CreepSpawnTriggersEasy[3] = ReverantOne <gen>
      • Set CreepSpawnTriggersEasy[4] = NerubianOne <gen>
      • Set CreepSpawnTriggersEasy[5] = RazormanOne <gen>
      • Set CreepSpawnTriggersEasy[6] = LizardOne <gen>
      • Set CreepSpawnTriggersEasy[7] = DragonOne <gen>
      • Set CreepSpawnTriggersEasy[8] = FurlborgTwo <gen>
      • Set CreepSpawnTriggersEasy[9] = OwlbearTwo <gen>
      • Set CreepSpawnTriggersEasy[10] = RockTwo <gen>
      • Set CreepSpawnTriggersEasy[11] = ReverantTwo <gen>
      • Set CreepSpawnTriggersEasy[12] = NerubianTwo <gen>
      • Set CreepSpawnTriggersEasy[13] = RazormanTwo <gen>
      • Set CreepSpawnTriggersEasy[14] = LizardTwo <gen>
      • Set CreepSpawnTriggersEasy[15] = DragonTwo <gen>
      • Set CreepSpawnTriggersEasy[16] = FurldorgThree <gen>
      • Set CreepSpawnTriggersEasy[17] = OwlbearThree <gen>
      • Set CreepSpawnTriggersEasy[18] = RockThree <gen>
      • Set CreepSpawnTriggersEasy[19] = ReverantThree <gen>
      • Set CreepSpawnTriggersEasy[20] = NerubianThree <gen>
      • Set CreepSpawnTriggersEasy[21] = RazormanThree <gen>
      • Set CreepSpawnTriggersEasy[22] = LizardThree <gen>
      • Set CreepSpawnTriggersEasy[23] = DragonThree <gen>
Now is the actual spawning of creeps and ordering of creeps to move.
  • FurlborgOne
    • Events
    • Conditions
    • Actions
      • Set CreepSpawn_SpawnPoint = (Center of FurbogSpawnPoint <gen>)
      • Unit - Create 1 Furbolg Pup for Neutral Hostile at CreepSpawn_SpawnPoint facing 270.00 degrees
      • Set TopLeftNewUnit = (Last created unit)
      • Trigger - Run Move Creep Top Left <gen> (ignoring conditions)
      • Custom script: call RemoveLocation(udg_CreepSpawn_SpawnPoint)
      • Custom script: set udg_TopLeftNewUnit = null
System includes 72 triggers similar to the one above for spawning each individual creep.
  • Move Creep Top Left
    • Events
    • Conditions
    • Actions
      • Set CreepSpawn_MovePoint = (Random point in FurbogMovePoint <gen>)
      • Unit - Wake up TopLeftNewUnit
      • Unit - Order TopLeftNewUnit to Attack-Move To CreepSpawn_MovePoint
      • Wait 10.00 seconds
      • Unit - Replace TopLeftNewUnit with a (Unit-type of TopLeftNewUnit) using The old unit's relative life and mana
      • Custom script: call RemoveLocation(udg_CreepSpawn_MovePoint)
      • Custom script: set udg_TopLeftNewUnit = null
Since there are 8 spawning locations, there are 8 of these triggers above.
 
Level 7
Joined
Nov 15, 2009
Messages
225
Hey,
first of all I would reduce the amount of move triggers

To a single one like this:
  • Event
    • Unit enters playable map area
  • Conditions
    • Owner of Unit equal Neutral Hostile
  • Actions
    • Order Unit to Attack-Move to CreepSpawn_MovePoint
And for spawnings I would use a loop
  • Event
    • Every 2 seconds of game time
  • Conditions
  • Actions
    • Comment: level is an integer which shows the current level
    • Comment: MaximumSpawn is an integer array variable to set the amount of spawned units
    • loop from 1 to MaximumSpawn[level]
      • Create 1 CreepSpawnTriggersEasy[level] for Neutral Hostile..
    • endloop
Remember to remove leaks and stuff.

And another trigger which turns off sleeping
Player - Disable sleeping for all creeps
 
Level 18
Joined
Oct 17, 2012
Messages
849
Thanks for the advice and +rep.

Edit: I have not succeeded because the idea of the spawn system is a bit more complicated. In addition, how you setup your triggers is not so clear to me. A loop would work if the creep that I am spawning at each location is constant.

Here is the idea for the spawn system:

1. Spawns 3 - 9 different creeps (NOT all creeps at a time but only one) at 8 different locations every 5 seconds
2. After every 900 seconds of game time, the 3 - 9 different creeps change for each location.

Basically, the system spawns a UNIQUE SET of 3 - 9 creeps for 900 seconds for each location. After 900 seconds, the creeps in the set change.
 
Last edited:
Level 7
Joined
Nov 15, 2009
Messages
225
Thanks for the advice and +rep.

Edit: I have not succeeded because the idea of the spawn system is a bit more complicated. In addition, how you setup your triggers is not so clear to me. A loop would work if the creep that I am spawning at each location is constant.

Here is the idea for the spawn system:

1. Spawns 3 - 9 different creeps (NOT all creeps at a time but only one) at 8 different locations every 5 seconds
2. After every 900 seconds of game time, the 3 - 9 different creeps change for each location.

Basically, the system spawns a UNIQUE SET of 3 - 9 creeps for 900 seconds for each location. After 900 seconds, the creeps in the set change.

In that case, I would try something like this:

  • Event
    • Every 5 seconds
  • Condition
  • Actions
    • if SpawnAmountUnitXY Lesser than 10 then
      • Spawn 1 UnitXY at SpawnPointXY
      • set SpawnAmountUnitXY = SpawnAmountUnitXY + 1
    • endif
    • // Add units for all spawn points here
Remember to remove leaks again :p

But I must admit, that your triggers confuse me a little bit either, because there's a missing spawn trigger at all.
CreepSpawnTriggersEasy[(CreepSpawnNumberEasy mod 24)]
 
Level 18
Joined
Oct 17, 2012
Messages
849
Okay, let me explain how I think your trigger works. Correct me if I made a mistake.

Every 5 seconds, the trigger checks if a integer called SpawnAmountUnitXY is less than 10. Then it spawns a unit and sets the integer to integer + 1 if the statement before is true. Afterwards, it setups the units to be spawned. Perhaps, I would understand better if I see a test map. The only problem that I have with your triggers is the setup creeps part.
 
Status
Not open for further replies.
Top