1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

How to create an artificial level-up system

Discussion in 'Trigger (GUI) Editor Tutorials' started by frettory, Nov 22, 2012.

  1. frettory

    frettory

    Joined:
    Jan 19, 2012
    Messages:
    51
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    [point][/point]How to create a level-up system

    Why create a level-up system?

    A level-up system would let non-heroes level up. It is very useful to make units stronger after every kill. It allows you to let the player create "veterans", who are units who deal higher damage due to the unit's experience in combat. Popular maps who use this system include YouTD (towers) and Werewolf: Transylvania (non-hero veteran bonus).

    So how do I make it?

    First, you need to create a hashtable.

    • Hashtable Creation
      • Events
        • Map initialization
      • Conditions
      • Actions
        • Hashtable - Create a hashtable
        • Set Level = (Last created hashtable)

    Then, you need to create a trigger which increases the level of the unit every time it kills something.

    • Level Up System
      • Events
        • Unit - A unit Dies
      • Conditions
      • Actions
        • Hashtable - Save ((Load (Key (Killing unit)) of 1 from Level) + 1) as (Key (Killing unit)) of 1 in Level


    Replace 1 with the name of a spell if you are leveling up a spell.

    If you feel like it, you can turn the system into a "kill X for rank" system, by adding these few lines to the end of the trigger.

    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Load (Key (Killing unit)) of 1 from Level) Equal to 50
      • Then - Actions
        • Hashtable - Save 5 as (Key (Killing unit)) of 1 in Rank
      • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Load (Key (Killing unit)) of 1 from Level) Equal to 29
          • Then - Actions
            • Hashtable - Save 4 as (Key (Killing unit)) of 1 in Rank
          • Else - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Load (Key (Killing unit)) of 1 from Level) Equal to 28
              • Then - Actions
                • Hashtable - Save 3 as (Key (Killing unit)) of 1 in Rank
              • Else - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Load (Key (Killing unit)) of 1 from Level) Equal to 3
                  • Then - Actions
                    • Hashtable - Save 2 as (Key (Killing unit)) of 1 in Rank
                  • Else - Actions
                    • -------- etc... --------


    NOTE: The if/then/elses for the higher ranks be executed first, or it will bug!

    Also, add these lines to the end of Hashtable Creation.

    • Hashtable - Create a hashtable
    • Set Rank = (Last created hashtable)


    The final Level Up System trigger will look like this.

    • Level Up System
      • Events
        • Unit - A unit Dies
      • Conditions
      • Actions
        • Hashtable - Save ((Load (Key (Killing unit)) of 1 from Level) + 1) as (Key (Killing unit)) of 1 in Level
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Load (Key (Killing unit)) of 1 from Level) Equal to 50
          • Then - Actions
            • Hashtable - Save 5 as (Key (Killing unit)) of 1 in Rank
          • Else - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Load (Key (Killing unit)) of 1 from Level) Equal to 29
              • Then - Actions
                • Hashtable - Save 4 as (Key (Killing unit)) of 1 in Rank
              • Else - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Load (Key (Killing unit)) of 1 from Level) Equal to 28
                  • Then - Actions
                    • Hashtable - Save 3 as (Key (Killing unit)) of 1 in Rank
                  • Else - Actions
                    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (Load (Key (Killing unit)) of 1 from Level) Equal to 3
                      • Then - Actions
                        • Hashtable - Save 2 as (Key (Killing unit)) of 1 in Rank
                      • Else - Actions
                        • -------- etc... --------


    Now, how do I actually use this system?

    You can use it for a variety of things, like increasing the damage of a unit for every level or rank he has, or increasing the spell potency, or simply adding more abilities. Just use this segment of a line to load levels,

    • ((Load (key([INSERT UNIT HERE])))) of 1 from Level)


    and this to load ranks.

    • ((Load (key([INSERT UNIT HERE])))) of 1 from Rank)
     

    Attached Files:

    Last edited: Mar 13, 2013
  2. frettory

    frettory

    Joined:
    Jan 19, 2012
    Messages:
    51
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Hope it hadn't been done before! If it had been done before, I will feel so stupid for going all the way to the Hashtables page in hope that hashtables can do this properly instead of just going to the tutorial page.

    Also, this post is not part of the tutorial.
     
  3. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    since you only use one childkey (which is 1), this can be done using an array instead of hashtable... they work much faster and are also easier to deal with...

    also those If-then-elses are better off when nested [put the next if-then on the else of the higher one]... because right now, if a unit is greater than rank 50, it will also trigger the actions for >12,>10,>5 so in the end, the rank 50 unit will have a value of 2 instead of 5...
     
  4. frettory

    frettory

    Joined:
    Jan 19, 2012
    Messages:
    51
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    #1: Can arrays use handles as keys? That is why I used a hashtable.

    #2: Fixed!
     
  5. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    Not sure, but you can always use a unit indexer to obtain a key specific to each unit
     
  6. frettory

    frettory

    Joined:
    Jan 19, 2012
    Messages:
    51
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Arrays cap at 8192. The cap of units are 1080x12=12960, which is bigger than 8192.

    I don't believe that the number of keys in a hashtable caps.

    Furthermore, I want to go to extremely great lengths to make the system both GUI and MUI, which means no 8192-capping arrays.
     
    Last edited: Nov 23, 2012
  7. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    it's just that you can only have a limited hashtable amount (256), a pretty big number...

    8192 is a really huge amount already, remember that this is a level up system which uses 1 instance per unit. I'm sure your map will most probably lag so bad or get a fatal error before you reach 8192 units to use this system on the map... of course you should also be using recycling if you do that to free up spaces occupied by dead units... :)

    anyway, lots of systems/spells here cap at 8192 but they are still considered as MUI...

    you can use game caches too if you really want to avoid caps I think...
     
  8. frettory

    frettory

    Joined:
    Jan 19, 2012
    Messages:
    51
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Fixed!
     
  9. sonofjay

    sonofjay

    Joined:
    Oct 28, 2011
    Messages:
    4,239
    Resources:
    20
    Packs:
    1
    Maps:
    13
    Template:
    5
    Tutorials:
    1
    Resources:
    20
    Hey bro, can you provide as some test map? I really want to test this since it looks a very nice idea.
     
  10. frettory

    frettory

    Joined:
    Jan 19, 2012
    Messages:
    51
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Map uploaded. Also, I added a new section to the tutorial on how to use the system, just to make the tutorial feel complete.
     
    Last edited: Nov 24, 2012
  11. Arhowk

    Arhowk

    Joined:
    Aug 8, 2007
    Messages:
    2,753
    Resources:
    0
    Resources:
    0
    why game caches? if i remember correctly they wont function properly on multiplayer. either use hashtables or arrays.

    arrays wont cap out because the graphical limit for units is closer to 6 grand even if the solid is near 12 grand

    the max for physical hashtables is 256, not hashtable keys. keys are infinite
     
  12. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    Game Caches work in MP, it's just that they aren't saved AFTER the game ends...
     
  13. frettory

    frettory

    Joined:
    Jan 19, 2012
    Messages:
    51
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Since it can be done on a hashtable without key caps, I have decided that this tutorial will use hashtables once more!
     
  14. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    The tutorial is very brief but covers everything needed. You offered an adequate description of the triggers and attached a good test map. Plus, it is a pretty unique idea (at least in my opinion).

    Approved. :)
     
  15. frettory

    frettory

    Joined:
    Jan 19, 2012
    Messages:
    51
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    I am going to update the tutorial so that whizzy animations fit in more nicely.