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

[Trigger] MUI about real-time counting

Status
Not open for further replies.
Level 5
Joined
Sep 22, 2012
Messages
90
I'm wondering about muis, I've tried to make my own custom buff and indexer in which stacks armor on my custom damage system (newbie system), damageapply=(damage - armor).

I've also tried to create my custom indexer and unit ID creator which uses an array of booleans and integers.

here are my trigger:
  • unitmaindies
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Dying unit)) Equal to Adept
          • (Unit-type of (Dying unit)) Equal to Enforcer
          • (Unit-type of (Dying unit)) Equal to Chemist
          • (Unit-type of (Dying unit)) Equal to Archer
    • Actions
      • Set A_ALLUNITS_tempunit = (Dying unit)
      • Set unit_has_main[(Player number of (Owner of A_ALLUNITS_tempunit))] = False
      • -------- find the data for the dying unit --------
      • For each (Integer A_recon_finder) from 1 to A_ALLUNITS_count, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • A_ALLUNITS_tempunit Equal to A_ALLUNITS_UNITS[A_recon_finder]
            • Then - Actions
              • Set A_recon_found_index = A_recon_finder
              • Set A_recon_finder = 101
            • Else - Actions
      • -------- > return back the id on the register --------
      • Set A_A_valid_IDS[A_ALLUNITS_ID[A_recon_found_index]] = False
      • -------- BRING / CARRY --------
      • Set A_ALLUNITS_UNITS[A_recon_found_index] = A_ALLUNITS_UNITS[A_ALLUNITS_count]
      • Set A_ALLUNITS_ARMOR[A_recon_found_index] = A_ALLUNITS_ARMOR[A_ALLUNITS_count]
      • Set A_ALLUNITS_SPEED[A_recon_found_index] = A_ALLUNITS_SPEED[A_ALLUNITS_count]
      • Set A_ALLUNITS_ID[A_recon_found_index] = A_ALLUNITS_ID[A_ALLUNITS_count]
      • Set A_ALLUNITS_count = (A_ALLUNITS_count - 1)
      • Set A_recon_found_index = 0
  • respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to |Cffff0000Defeated
    • Actions
      • Set AAA_player_temp = (Player number of (Owner of (Dying unit)))
      • Set res_loc = (Random point in sanctuary <gen>)
      • Unit - Create 1 db_unit_pool[unit_class[AAA_player_temp]] for (Player(AAA_player_temp)) at res_loc facing 270.00 degrees
      • Unit - Move vector_cam_unit[AAA_player_temp] instantly to res_loc
      • Selection - Select (Last created unit) for (Owner of (Dying unit))
      • Set unit_main[AAA_player_temp] = (Last created unit)
      • Set unit_has_main[AAA_player_temp] = True
      • -------- add data --------
      • Set A_ALLUNITS_count = (A_ALLUNITS_count + 1)
      • Set A_ALLUNITS_UNITS[A_ALLUNITS_count] = unit_main[AAA_player_temp]
      • Set A_ALLUNITS_ARMOR[A_ALLUNITS_count] = db_unit_armor[unit_class[AAA_player_temp]]
      • Set A_ALLUNITS_SPEED[A_ALLUNITS_count] = db_unit_speeds[unit_class[AAA_player_temp]]
      • -------- find and assign a valid id to created unit --------
      • For each (Integer A_A_ID_finder) from 1 to 100, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • A_A_valid_IDS[A_A_ID_finder] Equal to False
            • Then - Actions
              • Set A_A_found_ID = A_A_ID_finder
              • -------- give the id to someone --------
              • Set A_ALLUNITS_ID[A_ALLUNITS_count] = A_A_found_ID
              • -------- turn on the id on our tally --------
              • Set A_A_valid_IDS[A_A_found_ID] = True
              • -------- exitloop --------
              • Set A_A_ID_finder = 101
            • Else - Actions
      • -------- clear --------
      • Custom script: call RemoveLocation(udg_res_loc)
      • Set AAA_player_temp = 0
and here's my own custom buff :|
  • armorINIT
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to /req_armor
    • Actions
      • Set bad_armor_caster = (Casting unit)
      • Unit - Cause bad_armor_caster to damage bad_armor_caster, dealing 10.00 damage of attack type Normal and damage type Universal
      • Set bad_armor_caster_loc = (Position of bad_armor_caster)
      • -------- create new instance --------
      • Set bad_armor_counter = (bad_armor_counter + 1)
      • -------- find id of caster --------
      • For each (Integer bad_armor_init_cycle) from 1 to A_ALLUNITS_count, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • bad_armor_caster Equal to A_ALLUNITS_UNITS[bad_armor_init_cycle]
            • Then - Actions
              • Set bad_armor_found = bad_armor_init_cycle
              • -------- exit loop --------
              • Set bad_armor_init_cycle = (A_ALLUNITS_count + 1)
            • Else - Actions
      • -------- finally add the armor to our caster --------
      • Set bad_armor_target_id[bad_armor_counter] = A_ALLUNITS_ID[bad_armor_found]
      • Set bad_armor_each_duration[bad_armor_counter] = 0.00
      • Set bad_armor_each_flag[bad_armor_counter] = True
      • For each (Integer bad_armor_particle_cycle) from 0 to 2, do (Actions)
        • Loop - Actions
          • Set bad_armor_caster_TEMP_angle = ((Real(bad_armor_particle_cycle)) x 120.00)
          • Set bad_armor_caster_cycle_loc = (bad_armor_caster_loc offset by 80.00 towards bad_armor_caster_TEMP_angle degrees)
          • Unit - Create 1 _req_sheilds for (Owner of bad_armor_caster) at bad_armor_caster_cycle_loc facing bad_armor_caster_TEMP_angle degrees
          • Unit - Add Crow Form to (Last created unit)
          • Animation - Change (Last created unit) flying height to 20.00 at 1000000000.00
          • Unit - Turn collision for (Last created unit) Off
          • Set bad_armor_particles[((bad_armor_counter x 3) + bad_armor_particle_cycle)] = (Last created unit)
          • Custom script: call RemoveLocation(udg_bad_armor_caster_cycle_loc)
          • Set bad_armor_caster_TEMP_angle = 0.00
      • Set bad_armor_found = 0
      • Custom script: call RemoveLocation(udg_bad_armor_caster_loc)
      • Custom script: set udg_bad_armor_caster = null
      • Trigger - Turn on armorLOOP <gen>
      • Trigger - Run armorLOOP <gen> (ignoring conditions)
  • armorLOOP
    • Events
      • Time - bad_armor_TIMER expires
    • Conditions
    • Actions
      • Countdown Timer - Start bad_armor_TIMER as a Repeating timer that will expire in 0.03 seconds
      • -------- loop through instances --------
      • For each (Integer bad_armor_looper) from 1 to bad_armor_counter, do (Actions)
        • Loop - Actions
          • Set bad_armor_ALLOW = False
          • -------- find caster id --------
          • For each (Integer bad_armor_LOCAL_finder) from 1 to A_ALLUNITS_count, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • bad_armor_target_id[bad_armor_looper] Equal to A_ALLUNITS_ID[bad_armor_LOCAL_finder]
                • Then - Actions
                  • Set bad_armor_found = bad_armor_LOCAL_finder
                  • Set bad_armor_ALLOW = True
                  • Set bad_armor_LOCAL_finder = 101
                • Else - Actions
          • -------- if the id is not found then that unit is DEAD on our ALLUNITS_db --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • bad_armor_ALLOW Equal to True
              • bad_armor_each_duration[bad_armor_looper] Less than or equal to bad_armor_k_duration
            • Then - Actions
              • -------- update the duration of instance --------
              • Set bad_armor_each_duration[bad_armor_looper] = (bad_armor_each_duration[bad_armor_looper] + 0.03)
              • -------- flag the instance boolean AND change the armor to max!!! --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • bad_armor_each_flag[bad_armor_looper] Equal to True
                • Then - Actions
                  • Set A_ALLUNITS_ARMOR[bad_armor_found] = (A_ALLUNITS_ARMOR[bad_armor_found] + 3.00)
                  • Set bad_armor_each_flag[bad_armor_looper] = False
                • Else - Actions
              • -------- move/draw the particles --------
              • Set bad_armor_looper_from_loc = (Position of A_ALLUNITS_UNITS[bad_armor_found])
              • For each (Integer bad_armor_paticle_looper) from 0 to 2, do (Actions)
                • Loop - Actions
                  • Set bad_armor_LOCAL_particle = bad_armor_particles[((bad_armor_looper x 3) + bad_armor_paticle_looper)]
                  • Set bad_armor_LOCAL_angle = (Facing of bad_armor_LOCAL_particle)
                  • Set bad_armor_LOCAL_angle = (bad_armor_LOCAL_angle + 90.00)
                  • Set bad_armor_looper_to_loc = (bad_armor_looper_from_loc offset by 3.00 towards bad_armor_LOCAL_angle degrees)
                  • Unit - Move bad_armor_LOCAL_particle instantly to bad_armor_looper_to_loc, facing bad_armor_LOCAL_angle degrees
                  • Custom script: call RemoveLocation(udg_bad_armor_looper_to_loc)
                  • Set bad_armor_LOCAL_angle = 0.00
                  • Custom script: set udg_bad_armor_LOCAL_particle = null
              • Custom script: call RemoveLocation(udg_bad_armor_looper_from_loc)
            • Else - Actions
              • -------- carry/ reduce array --------
              • Unit - Kill bad_armor_particles[((bad_armor_looper x 3) + 0)]
              • Unit - Kill bad_armor_particles[((bad_armor_looper x 3) + 1)]
              • Unit - Kill bad_armor_particles[((bad_armor_looper x 3) + 2)]
              • Set A_ALLUNITS_ARMOR[bad_armor_found] = (A_ALLUNITS_ARMOR[bad_armor_found] - 3.00)
              • Set bad_armor_particles[((bad_armor_looper x 3) + 0)] = bad_armor_particles[((bad_armor_counter x 3) + 0)]
              • Set bad_armor_particles[((bad_armor_looper x 3) + 1)] = bad_armor_particles[((bad_armor_counter x 3) + 1)]
              • Set bad_armor_particles[((bad_armor_looper x 3) + 2)] = bad_armor_particles[((bad_armor_counter x 3) + 2)]
              • Set bad_armor_each_duration[bad_armor_looper] = bad_armor_each_duration[bad_armor_counter]
              • Set bad_armor_each_flag[bad_armor_looper] = bad_armor_each_flag[bad_armor_counter]
              • Set bad_armor_target_id[bad_armor_looper] = bad_armor_target_id[bad_armor_counter]
              • Set bad_armor_counter = (bad_armor_counter - 1)
          • Set bad_armor_found = 0
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • bad_armor_counter Less than or equal to 0
            • Then - Actions
              • Game - Display to (All players) the text: armor off
              • Trigger - Turn off armorLOOP <gen>
            • Else - Actions
would this type of indexing be safe? are these triggers leakless?

please let me know :|
 
Last edited:
use triggering unit instead of dying unit.

change this
  • For each (Integer bad_armor_paticle_looper) from 0 to 2, do (Actions)
  • Loop - Actions
  • Set bad_armor_LOCAL_particle = bad_armor_particles[((bad_armor_looper x 3) + bad_armor_paticle_looper)]
  • Set bad_armor_LOCAL_angle = (Facing of bad_armor_LOCAL_particle)
  • Set bad_armor_LOCAL_angle = (bad_armor_LOCAL_angle + 90.00)
  • Set bad_armor_looper_to_loc = (bad_armor_looper_from_loc offset by 3.00 towards bad_armor_LOCAL_angle degrees)
  • Unit - Move bad_armor_LOCAL_particle instantly to bad_armor_looper_to_loc, facing bad_armor_LOCAL_angle degrees
  • Custom script: call RemoveLocation(udg_bad_armor_looper_to_loc)
  • Set bad_armor_LOCAL_angle = 0.00
  • Custom script: set udg_bad_armor_LOCAL_particle = null
  • Custom script: call RemoveLocation(udg_bad_armor_looper_from_loc)
to this
  • For each (Integer bad_armor_paticle_looper) from 0 to 2, do (Actions)
  • Loop - Actions
  • Set bad_armor_LOCAL_particle = bad_armor_particles[((bad_armor_looper x 3) + bad_armor_paticle_looper)]
  • Set bad_armor_LOCAL_angle = (Facing of bad_armor_LOCAL_particle)
  • Set bad_armor_LOCAL_angle = (bad_armor_LOCAL_angle + 90.00)
  • Set bad_armor_looper_to_loc = (bad_armor_looper_from_loc offset by 3.00 towards bad_armor_LOCAL_angle degrees)
  • Unit - Move bad_armor_LOCAL_particle instantly to bad_armor_looper_to_loc, facing bad_armor_LOCAL_angle degrees
  • Custom script: call RemoveLocation(udg_bad_armor_looper_to_loc)
  • Set bad_armor_LOCAL_angle = 0.00
  • Custom script: set udg_bad_armor_LOCAL_particle = null
u should also think about changing the names of ur variables they are hard to read. make them short and simple. when i do MUI triggers i use eIndexNameOfSpell.

for loops without arrays u can just use tempInt instead of Integer bad_armor_loope
also u can use a temp unit variable for this Last created unit. a temp variable is faster than last created unit

this is also a very bad idea
  • Countdown Timer - Start bad_armor_TIMER as a Repeating timer that will expire in 0.03 seconds
its a repeating timer and should only be started in ur bad_armor_skill_INIT trigger and only ended in the loop trigger. you should check when to start it and when to end it.

also not sure y u loop in ur unit dies trigger that is very inefficient to do.
 
Level 5
Joined
Sep 22, 2012
Messages
90
@deathismyfriend:
the bad armor loc from is on outer scope and i'll also be fixing this as you said. Is the indexing safe?? are there leaks??

<about dying unit to get index>
why is it inefficient to use dying unit to the array? from what i know as long as the corpse exist, the units is still there but on war 3 engine its status is "DEAD". any solutions to that?
 
Last edited:
ooo this.
  • Set bad_armor_looper_from_loc = (Position of A_ALLUNITS_UNITS[bad_armor_found])
  • For each (Integer bad_armor_paticle_looper) from 0 to 2, do (Actions)
  • Loop - Actions
  • Set bad_armor_LOCAL_particle = bad_armor_particles[((bad_armor_looper x 3) + bad_armor_paticle_looper)]
  • Set bad_armor_LOCAL_angle = (Facing of bad_armor_LOCAL_particle)
  • Set bad_armor_LOCAL_angle = (bad_armor_LOCAL_angle + 90.00)
  • Set bad_armor_looper_to_loc = (bad_armor_looper_from_loc offset by 3.00 towards bad_armor_LOCAL_angle degrees)
  • Unit - Move bad_armor_LOCAL_particle instantly to bad_armor_looper_to_loc, facing bad_armor_LOCAL_angle degrees
  • Custom script: call RemoveLocation(udg_bad_armor_looper_to_loc)
  • Set bad_armor_LOCAL_angle = 0.00
  • Custom script: set udg_bad_armor_LOCAL_particle = null
  • Custom script: call RemoveLocation(udg_bad_armor_looper_from_loc)
i see that now. u may want to test this im not sure but i dont think it leaks. you can still take out that last remove location as u change the location and remove and null it at the end of the loop. so it is already destroyed. as for ur triggers i dont believe it leaks and the indexing looks safe only thing i advise changing is make seperate unit arrays for these
  • Unit - Kill bad_armor_particles[((bad_armor_looper x 3) + 0)]
  • Unit - Kill bad_armor_particles[((bad_armor_looper x 3) + 1)]
  • Unit - Kill bad_armor_particles[((bad_armor_looper x 3) + 2)]
it will let u have more instances of the spell. right now the spell can only have 2730 instances. if thats enough dont change it but if u think ull come close to that which i doubt u will i would change it. its also easier to edit if u do change it.
 
Status
Not open for further replies.
Top