[Solved] Help!: Making Score-Based Player owned Creep Level respawning possible somehow

Level 5
Joined
Jun 24, 2024
Messages
59
Hi all,

this may be a bit longer post then usually, i could not wrap my head around it for a couple of days now..
My Idea for a trigger (or multiple co-working) is as followed:

Based on an game idea and a similar map i saw years ago i am currently building a Arena-Survival type map which includes:
Players spawning with one random creep (Main creep, no more non summon units) of level 1 in the beginning.
Players can roam and kill critters to gain points.
Point requirements for level ups are Level 10 for level 2, 20 for 3, 30 for 4,.. ect. - Player kills give 10.
For the point system i'm using a simple integer array with 100-point steps to make counting easier.
Meaning Level 2 is reached with 10+, Level 3 with 120+, Level 4 with 230+ ect.

Now when a player dies, he looses 105 Points which is roundabout 1 level, depending on current score (for safety of exactly hitting cap -5 extra)
He then gets a current score check (not total score - different counter) and should respawn with the correct creep level depending on score.
E.g. Player unit (not summon) dies with 220 Points, it gets reduced to 115 - Player should get one level 2 unit (at random point currently)

But that's the point where my triggers seem to break, i either manage to get multiple respawns for the same player increasing their amounts seemingly random
or they do not respawn at all anymore after dying at certain situations.

My overly complicated code with bad code and gaps in the scoreing...:

Leveling the Main unit

  • PlayerLeveling
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Player number of (Owner of (Killing unit))) Less than or equal to 8
      • (Owner of (Dying unit)) Equal to Neutral Hostile
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • And - All (Conditions) are true
                • Conditions
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 10
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 99
              • And - All (Conditions) are true
                • Conditions
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 120
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 199
              • And - All (Conditions) are true
                • Conditions
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 230
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 299
              • And - All (Conditions) are true
                • Conditions
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 340
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 399
              • And - All (Conditions) are true
                • Conditions
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 450
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 499
              • And - All (Conditions) are true
                • Conditions
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 560
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 599
              • And - All (Conditions) are true
                • Conditions
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 670
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 699
              • And - All (Conditions) are true
                • Conditions
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 780
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 799
              • And - All (Conditions) are true
                • Conditions
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 1000
                  • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 2000
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 10
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 99
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 100
              • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 2
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 2 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 120
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 199
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 200
              • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 3
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 3 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 230
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 299
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 300
              • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 4
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 4 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 340
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 399
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 400
              • For each (Integer A) from 1 to 6, do (Actions)
                • Loop - Actions
                  • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 5
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 5 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 450
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 499
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 500
              • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 6
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 6 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 560
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 599
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 600
              • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 7
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 7 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 670
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 699
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 700
              • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 8
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 8 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 780
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 799
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 900
              • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 9
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 8 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 990
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 1000
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 1000
              • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 9
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 9 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Greater than or equal to 1000
              • ScorePlayerArray[(Player number of (Owner of (Killing unit)))] Less than or equal to 2000
            • Then - Actions
              • Set VariableSet ScorePlayerArray[(Player number of (Owner of (Killing unit)))] = 9999
              • Set VariableSet LevelPlayerArray[(Player number of (Owner of (Killing unit)))] = 10
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Killing unit))) and do (Actions)
                • Loop - Actions
                  • For each (Integer A) from 1 to 6, do (Actions)
                    • Loop - Actions
                      • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • Unit - Replace (Picked unit) with a (Random level 10 creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
                      • Skip remaining actions
            • Else - Actions
        • Else - Actions
          • Skip remaining actions
Player Dying Event (note: 4 second wait timer is deactivated):

  • PlayerDying new
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
      • Unit - A unit owned by Player 2 (Blue) Dies
      • Unit - A unit owned by Player 3 (Teal) Dies
      • Unit - A unit owned by Player 4 (Purple) Dies
      • Unit - A unit owned by Player 5 (Yellow) Dies
      • Unit - A unit owned by Player 6 (Orange) Dies
      • Unit - A unit owned by Player 7 (Green) Dies
      • Unit - A unit owned by Player 8 (Pink) Dies
    • Conditions
      • ((Dying unit) is Summoned) Equal to False
    • Actions
      • Custom script: local integer playerNum
      • Set VariableSet TempIntegerNew[0] = (Player number of (Owner of (Dying unit)))
      • Custom script: set playerNum = udg_TempIntegerNew[0]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • ScorePlayerArray[TempIntegerNew[0]] Less than 0
              • ScorePlayerArray[TempIntegerNew[0]] Greater than or equal to 1000
        • Then - Actions
          • Set VariableSet ScorePlayerArray[TempIntegerNew[0]] = 0
          • Set VariableSet LevelPlayerArray[TempIntegerNew[0]] = 1
        • Else - Actions
      • Custom script: set udg_TempIntegerNew[0] = playerNum
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ScorePlayerArray[TempIntegerNew[0]] Less than 900
        • Then - Actions
          • Wait 4.00 seconds
          • Game - Display to (All players) for 5.00 seconds the text: (respawning + (String(TempIntegerNew[0])))
          • Unit - Create 1 (Random level LevelPlayerArray[TempIntegerNew[0]] creep unit-type) for (Player(TempIntegerNew[0])) at (Random point in Trees <gen>) facing Default building facing degrees
          • Unit - Add Inventory (Hero) to (Last created unit)
          • Camera - Pan camera for (Owner of (Last created unit)) to (Position of (Last created unit)) over 1.00 seconds
          • Special Effect - Create a special effect at (Position of (Last created unit)) using Abilities\Spells\Human\ReviveHuman\ReviveHuman.mdl
        • Else - Actions
          • Game - Display to (All players) for 5.00 seconds the text: (Error on respawning + (String(TempIntegerNew[0])))
Please enlighten me on how to setup this idea correctly, i'm starting to go crazy :)

I thought about a Level integer set for every player and reset of the score, checking leveling requirements with "x*level" but had no luck implementing it correctly so far.

Regards
SMOrc
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Here's a fixed PlayerDying trigger, you don't need any Custom Script, (Triggering unit) will remain usable even after the Wait:
  • PlayerDying new
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
      • Unit - A unit owned by Player 2 (Blue) Dies
      • Unit - A unit owned by Player 3 (Teal) Dies
      • Unit - A unit owned by Player 4 (Purple) Dies
      • Unit - A unit owned by Player 5 (Yellow) Dies
      • Unit - A unit owned by Player 6 (Orange) Dies
      • Unit - A unit owned by Player 7 (Green) Dies
      • Unit - A unit owned by Player 8 (Pink) Dies
    • Conditions
      • ((Triggering unit) is Summoned) Equal to False
    • Actions
      • Set VariableSet TempIntegerNew[0] = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • ScorePlayerArray[TempIntegerNew[0]] Less than 0
              • ScorePlayerArray[TempIntegerNew[0]] Greater than or equal to 1000
        • Then - Actions
          • Set VariableSet ScorePlayerArray[TempIntegerNew[0]] = 0
          • Set VariableSet LevelPlayerArray[TempIntegerNew[0]] = 1
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ScorePlayerArray[TempIntegerNew[0]] Less than 900
        • Then - Actions
          • Wait 4.00 game-time seconds
          • Set VariableSet TempIntegerNew[0] = (Player number of (Owner of (Triggering unit)))
          • Game - Display to (All players) for 5.00 seconds the text: (respawning + (String(TempIntegerNew[0])))
          • Unit - Create 1 (Random level LevelPlayerArray[TempIntegerNew[0]] creep unit-type) for (Player(TempIntegerNew[0])) at (Random point in Trees <gen>) facing Default building facing degrees
          • Unit - Add Inventory (Hero) to (Last created unit)
          • Camera - Pan camera for (Owner of (Last created unit)) to (Position of (Last created unit)) over 1.00 seconds
          • Special Effect - Create a special effect at (Position of (Last created unit)) using Abilities\Spells\Human\ReviveHuman\ReviveHuman.mdl
        • Else - Actions
          • Game - Display to (All players) for 5.00 seconds the text: (Error on respawning + (String(TempIntegerNew[0])))
^ Note that this leaks multiple Points -> (Position of X) but I didn't bother addressing then.

Also, make sure that you check for an actual (Killing unit) before referencing it. A unit can be killed by "nothing" which would break your trigger:
  • Conditions
    • (Killing unit) Not equal to No unit
    • (Player number of (Owner of (Killing unit))) Less than or equal to 8
    • (Owner of (Dying unit)) Equal to Neutral Hostile

Then here's a map I made showing an optimized version of your triggers. It might be missing one or two things since I didn't fully understand what you were trying to achieve. As you can see, clever usage of For Loops and Arrays can go a very long way. You should almost never be using a big chain of If Then Elses, and if you find yourself doing that then try to stop yourself and break the habit. In my example you can see how I create a reversed For Loop which counts down instead of up, this is how I can easily check for Level ups using one If Then Else.

Here are the triggers if you can't open the map:
  • Level Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- Experience needed to reach each level: --------
      • Set VariableSet Level_Breakpoints[1] = 0
      • Set VariableSet Level_Breakpoints[2] = 100
      • Set VariableSet Level_Breakpoints[3] = 200
      • Set VariableSet Level_Breakpoints[4] = 300
      • -------- --------
      • -------- Maximum level you can reach: --------
      • Set VariableSet Level_Cap = 4
  • Level Add Kill Exp
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
      • (Killing unit) Not equal to No unit
      • (Player number of (Owner of (Killing unit))) Less than or equal to 8
    • Actions
      • Set VariableSet Level_PN = (Player number of (Owner of (Killing unit)))
      • -------- --------
      • -------- Add experience: --------
      • Set VariableSet Player_Experience[Level_PN] = (Player_Experience[Level_PN] + 50)
      • -------- --------
      • -------- Check if a new level has been reached: --------
      • Trigger - Run Level Calculate <gen> (ignoring conditions)
      • -------- --------
      • -------- Respawn the creep: --------
      • Set VariableSet Creep_Respawning = (Triggering unit)
      • Trigger - Run Creep Respawn <gen> (ignoring conditions)
  • Level Calculate
    • Events
    • Conditions
    • Actions
      • -------- Note: --------
      • -------- Run this trigger after setting Level_PN and changing Player_Experience[]. --------
      • -------- --------
      • Game - Display to (All players) for 5.00 seconds the text: (|cff808080Exp: |r + (String(Player_Experience[Level_PN])))
      • -------- --------
      • -------- This is a reverse For Loop, it starts at Level_Cap and works it's way down to 0: --------
      • Set VariableSet Level_Index = Level_Cap
      • For each (Integer Level_Loop) from 1 to Level_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Player_Level[Level_PN] Less than Level_Index
              • Player_Experience[Level_PN] Greater than or equal to Level_Breakpoints[Level_Index]
            • Then - Actions
              • Set VariableSet Player_Level[Level_PN] = Level_Index
              • Game - Display to (All players) for 5.00 seconds the text: (|cff00ff00New Level: |r + (String(Player_Level[Level_PN])))
              • Skip remaining actions
            • Else - Actions
          • Set VariableSet Level_Index = (Level_Index - 1)
  • Creep Respawn
    • Events
    • Conditions
    • Actions
      • -------- Note: --------
      • -------- Run this trigger after setting Level_PN and Creep_Respawning. --------
      • -------- --------
      • Custom script: local unit u = udg_Creep_Respawning
      • Custom script: local integer pn = udg_Level_PN
      • -------- --------
      • Wait 4.00 game-time seconds
      • -------- --------
      • Custom script: set udg_Level_PN = pn
      • Custom script: set udg_Creep_Respawning = u
      • Custom script: set u = null
      • -------- --------
      • -------- Respawn the creep using the player's Level: --------
      • Unit - Replace Creep_Respawning with a (Random level Player_Level[Level_PN] creep unit-type) using The new unit's max life and mana
      • -------- --------
      • Special Effect - Create a special effect attached to the overhead of (Last created unit) using Abilities\Spells\Other\TalkToMe\TalkToMe.mdl
      • Special Effect - Destroy (Last created special effect)
      • -------- --------
      • Game - Display to (All players) for 5.00 seconds the text: (|cffffff00Respawn Level: |r + (String(Player_Level[Level_PN])))

Note that you start at Level 0 in my map, which I doubt you want.
To fix that, you can set the Initial Value of Player_Level to 1 inside of the Variable Editor:
1743170367372.png

You may also want to add extra logic to prevent a unit from going above or below certain Levels.

To do this, you can use the Max function:
  • Set VariableSet Player_Experience[Level_PN] = (Player_Experience[Level_PN] - 50)
  • Set VariableSet Player_Experience[Level_PN] = (Max(Player_Experience[Level_PN], 0))
Max() picks the larger of the two numbers, so if Player_Experience goes negative then it will be smaller than 0, and 0 will be picked since it's larger.

Then you can use the Min() function, which picks the smaller of two numbers, to prevent Player_Experience from going above a limit:
  • Set VariableSet Player_Experience[Level_PN] = (Player_Experience[Level_PN] + 50)
  • Set VariableSet Player_Experience[Level_PN] = (Min(Player_Experience[Level_PN], 99999))
 

Attachments

  • Level Logic 1.w3m
    21 KB · Views: 4
Last edited:
Level 5
Joined
Jun 24, 2024
Messages
59
This helps a lot like always, thank you!
This makes me rethink my whole approach on the editor logic.Tho i have made the mistakes before and you corrected it ^^
I don't fully understand the process logic but i managed to transfer your example to my needs:

Killscore:
  • HIVE Level Add Kill Exp
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
      • (Killing unit) Not equal to No unit
      • (Player number of (Owner of (Killing unit))) Less than or equal to 8
    • Actions
      • Set VariableSet HIVELevel_PN = (Player number of (Owner of (Killing unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Rabbit
        • Then - Actions
          • Set VariableSet HIVEPlayer_Experience[HIVELevel_PN] = (HIVEPlayer_Experience[HIVELevel_PN] + 1)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Chicken
            • Then - Actions
              • Set VariableSet HIVEPlayer_Experience[HIVELevel_PN] = (HIVEPlayer_Experience[HIVELevel_PN] + 2)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Triggering unit)) Equal to Raccoon
                • Then - Actions
                  • Set VariableSet HIVEPlayer_Experience[HIVELevel_PN] = (HIVEPlayer_Experience[HIVELevel_PN] + 3)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of (Triggering unit)) Equal to Stag
                    • Then - Actions
                      • Set VariableSet HIVEPlayer_Experience[HIVELevel_PN] = (HIVEPlayer_Experience[HIVELevel_PN] + 4)
                    • Else - Actions
                      • Set VariableSet HIVEPlayer_Experience[HIVELevel_PN] = (HIVEPlayer_Experience[HIVELevel_PN] + 10)
      • Trigger - Run HIVE Level Calculate <gen> (ignoring conditions)
Point calculator:
  • HIVE Level Calculate
    • Events
    • Conditions
    • Actions
      • -------- --------
      • Game - Display to (Player group((Player(HIVELevel_PN)))) for 5.00 seconds the text: (|cff808080Exp: |r + (String(HIVEPlayer_Experience[HIVELevel_PN])))
      • -------- This is a reverse For Loop, it starts at Level_Cap and works it's way down to 0: --------
      • Set VariableSet HIVELevel_Index = HIVELevel_Cap
      • For each (Integer HIVELevel_Loop) from 1 to HIVELevel_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HIVEPlayer_Level[HIVELevel_PN] Less than HIVELevel_Index
              • HIVEPlayer_Experience[HIVELevel_PN] Greater than or equal to HIVELevel_Breakpoints[HIVELevel_Index]
            • Then - Actions
              • Set VariableSet HIVEPlayer_Level[HIVELevel_PN] = HIVELevel_Index
              • Game - Display to (Player group((Player(HIVELevel_PN)))) for 5.00 seconds the text: (|cff00ff00New Level: |r + (String(HIVEPlayer_Level[HIVELevel_PN])))
              • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Player(HIVELevel_PN))) and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is Summoned) Equal to False
                    • Then - Actions
                      • For each (Integer A) from 1 to 6, do (Actions)
                        • Loop - Actions
                          • Hero - Drop (Item carried by (Picked unit) in slot (Integer A)) from (Picked unit).
                      • Unit - Replace (Picked unit) with a (Random level HIVEPlayer_Level[HIVELevel_PN] creep unit-type) using The old unit's relative life and mana
                      • Unit - Add Inventory (Hero) to (Last replaced unit)
                    • Else - Actions
              • Skip remaining actions
            • Else - Actions
          • Set VariableSet HIVELevel_Index = (HIVELevel_Index - 1)
Player Respawner:
  • PlayerDying new
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
      • Unit - A unit owned by Player 2 (Blue) Dies
      • Unit - A unit owned by Player 3 (Teal) Dies
      • Unit - A unit owned by Player 4 (Purple) Dies
      • Unit - A unit owned by Player 5 (Yellow) Dies
      • Unit - A unit owned by Player 6 (Orange) Dies
      • Unit - A unit owned by Player 7 (Green) Dies
      • Unit - A unit owned by Player 8 (Pink) Dies
    • Conditions
      • ((Triggering unit) is Summoned) Equal to False
    • Actions
      • Set VariableSet HIVELevel_PN = (Player number of (Triggering player))
      • Set VariableSet TempIntegerNew[0] = (Player number of (Owner of (Triggering unit)))
      • Set VariableSet HIVEPlayer_Experience[HIVELevel_PN] = (HIVEPlayer_Experience[HIVELevel_PN] - (HIVEPlayer_Level[HIVELevel_PN] x 10))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • HIVEPlayer_Experience[HIVELevel_PN] Less than 0
        • Then - Actions
          • Set VariableSet HIVEPlayer_Experience[HIVELevel_PN] = 0
        • Else - Actions
      • Set VariableSet HIVEPlayer_Level[HIVELevel_PN] = (HIVEPlayer_Level[HIVELevel_PN] - 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • HIVEPlayer_Level[HIVELevel_PN] Less than 1
        • Then - Actions
          • Set VariableSet HIVEPlayer_Level[HIVELevel_PN] = 1
        • Else - Actions
      • Unit - Create 1 (Random level HIVEPlayer_Level[HIVELevel_PN] creep unit-type) for (Owner of (Triggering unit)) at (Random point in Trees <gen>) facing Default building facing degrees
      • Unit - Add Inventory (Hero) to (Last created unit)
      • Camera - Pan camera for (Owner of (Last created unit)) to (Position of (Last created unit)) over 1.00 seconds
      • Special Effect - Create a special effect at (Position of (Last created unit)) using Abilities\Spells\Human\ReviveHuman\ReviveHuman.mdl
      • Special Effect - Destroy (Last created special effect)
Now, i had an old Scoreboard setup with a multiboard and the old Parameters/variables.
How can i rethink the approach to show current score, player kills and level of each player from 1-8?

Old:

  • Scoreboardrefresh Copy
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Multiboard - Set the text for (Last created multiboard) item in column 2, row 2 to (String(HIVEPlayer_Level[HIVELevel_PN]))
      • Multiboard - Set the text for (Last created multiboard) item in column 2, row 3 to (String(LevelPlayerArray[(Player number of Player 2 (Blue))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 2, row 4 to (String(LevelPlayerArray[(Player number of Player 3 (Teal))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 2, row 5 to (String(LevelPlayerArray[(Player number of Player 4 (Purple))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 2, row 6 to (String(LevelPlayerArray[(Player number of Player 5 (Yellow))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 2, row 7 to (String(LevelPlayerArray[(Player number of Player 6 (Orange))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 2, row 8 to (String(LevelPlayerArray[(Player number of Player 7 (Green))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 2, row 9 to (String(LevelPlayerArray[(Player number of Player 8 (Pink))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 3, row 2 to (String(ScorePlayerTotalArray[(Player number of Player 1 (Red))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 3, row 3 to (String(ScorePlayerTotalArray[(Player number of Player 2 (Blue))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 3, row 4 to (String(ScorePlayerTotalArray[(Player number of Player 3 (Teal))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 3, row 5 to (String(ScorePlayerTotalArray[(Player number of Player 4 (Purple))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 3, row 6 to (String(ScorePlayerTotalArray[(Player number of Player 5 (Yellow))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 3, row 7 to (String(ScorePlayerTotalArray[(Player number of Player 6 (Orange))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 3, row 8 to (String(ScorePlayerTotalArray[(Player number of Player 7 (Green))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 3, row 9 to (String(ScorePlayerTotalArray[(Player number of Player 8 (Pink))]))
      • Multiboard - Set the text for (Last created multiboard) item in column 4, row 2 to (String((Player 1 (Red) Current lumber)))
      • Multiboard - Set the text for (Last created multiboard) item in column 4, row 3 to (String((Player 2 (Blue) Current lumber)))
      • Multiboard - Set the text for (Last created multiboard) item in column 4, row 4 to (String((Player 3 (Teal) Current lumber)))
      • Multiboard - Set the text for (Last created multiboard) item in column 4, row 5 to (String((Player 4 (Purple) Current lumber)))
      • Multiboard - Set the text for (Last created multiboard) item in column 4, row 6 to (String((Player 5 (Yellow) Current lumber)))
      • Multiboard - Set the text for (Last created multiboard) item in column 4, row 7 to (String((Player 6 (Orange) Current lumber)))
      • Multiboard - Set the text for (Last created multiboard) item in column 4, row 8 to (String((Player 7 (Green) Current lumber)))
      • Multiboard - Set the text for (Last created multiboard) item in column 4, row 9 to (String((Player 8 (Pink) Current lumber)))
It looks like this at the moment of testing, but i fail to show scores:

  • Scoreboardrefresh
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 2 to 9, do (Actions)
        • Loop - Actions
          • For each (Integer B) from 1 to 8, do (Actions)
            • Loop - Actions
              • Set VariableSet HIVELevel_PN_Score = (Player number of (Player((Integer B))))
          • Multiboard - Set the text for (Last created multiboard) item in column 2, row (Integer A) to (String(HIVEPlayer_Level[HIVELevel_PN]))
          • Multiboard - Set the text for (Last created multiboard) item in column 3, row (Integer A) to (String(HIVEPlayer_Experience[HIVELevel_PN]))
          • Multiboard - Set the text for (Last created multiboard) item in column 4, row (Integer A) to (String(((Player((Integer B))) Current lumber)))
I'm sure i don't need two loops intertwined, this causes problems 100%.
What i don't figure out is how to get player stats from the Player Arrays without an event reference and without using integers to get their respective numbers and then go through rows 2-9 in the multiboard to add* / periodically refresh* the Score, Total Exp-Points and player kills.


Add edit:
Also i have some sort of very basic AI for computer players and i want to periodically get Exp, depending on the chosen difficulty.
Since the Add-EXP cheat code for player 1 can add and recalculate, can i copy that logic to add X exp to every player that is controlled by a computer every Y seconds, changing X to regard the difficulty? Or of course i make 4 different, initial off triggers that each get turned on (only one) and X is a fixed number. --- Done, works! ---

Edit2:

I also had multiple case testing with computer players and the code above, that when units died and had a random creep unit (together with a certain score), they would respawn and die instantly, then respawn double the units. I can't pinpoint the reason and exact situation, but it has to be something either in the code of respawn or the calculator..
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
1) I suggest using your own unique Integer variable instead of (Integer A) or (Integer B) in your For Loops, especially if the Event is something that can be triggered by another trigger (ie: A unit Dies).

2) I would replace (Last created multiboard) with an actual Variable. It's inefficient to constantly call that function to find the last created multiboard, and it's unsafe if you ever create more than one.

3) PlayerDying new looks like it would run whenever a Dummy unit dies and other unwanted things. It probably needs more Conditions to filter out unwanted results.

4) You're not filtering Dead units out of your Unit Groups. Pick every unit will literally pick every unit, dead or alive. Unit Groups also do not automatically remove Dead units. They function this way to enable you to trigger effects similar to Animate Dead or Resurrection. Note that units with the Locust ability are excluded from any "Add nearby units to group" functions, which is convenient since we wouldn't want to target them anyway.

5) You leak Points/Unit Groups throughout. Leaks won't necessarily ruin your map but in triggers that fire often (A unit Dies) it's smart to handle them with care.
 
Last edited:
Level 5
Joined
Jun 24, 2024
Messages
59
Hey Uncle, i'm reviving this already solved Post with a different question to your quite nice EXP System:
I mainly want to ask, if it would be possible to take this system, change some events on how the player gets exp and use it as a permanent progression system as other maps do with player savestates (Maybe even auto save/load). Or would it be easier to take an already existing system from the Hive Workshop and change it to my needs? I have never even seed Save/Load Code so far, so no idea what i'm getting myself into ^^

Edit: If this topic goes beyond the scope of an "simple question" i can create another post for it.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I don't see why not, you're simply increasing an Integer whenever something happens.

Save/Load systems, at least the ones limited to Jass, are designed to only save Integers, so it will be an easy implementation since that's what you're working with already.
 
Top