1. The long-awaited results for Concept Art Contest #11 have finally been released!
    Dismiss Notice
  2. Join Texturing Contest #30 now in a legendary battle of mythological creatures!
    Dismiss Notice
  3. The Aftermath has been revealed for the 19th Terraining Contest! Be sure to check out the Results and see what came out of it.
    Dismiss Notice
  4. Hivers united and created a bunch of 2v2 melee maps. Vote for the best in our Melee Mapping Contest #4 - Poll!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

General Spell Creation

Discussion in 'Trigger (GUI) Editor Tutorials' started by Chaosy, Jun 11, 2013.

  1. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,529
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17

    General Spell Creation - by Chaosy


    Introduction


    Hello, I thought it would be nice of me to upload a little guide/tutorial on how to create spells in general with triggering.
    In almost every spell you use a config trigger, one cast trigger and one looping trigger so this tutorial will help you creating almost any spell.
    Please notice I don't say that my way to trigger is the best one but it's the way I like the most.

    How skilled do I need to be to understand and use this tutorial?


    You need to understand the triggering in general, you need to know how to use actions events and so on.

    Ready? Let's go then


    So to start with we need a spell idea, I will simply create a spell that damages a unit by X every Y seconds for Z seconds.
    So now that you got a spell you want to create we can start triggering, first off we need to create the setup trigger.
    • setup trigger
      • Events
        • Map initialization
      • Conditions
      • Actions
        • Hashtable - Create a hashtable
        • Set SS_hash = (Last created hashtable)
        • Set SS_damage[1] = 5.00
        • Set SS_damage[2] = 10.00
        • Set SS_damage[3] = 15.00
        • Set SS_time = 2.00
        • Set SS_duration = 10.00
        • Set SS_ability = Storm Bolt

    You may notice that the name is SS_X. The SS stands for some spell, and we use that kind of variable name to make the name unique. So if your spell is named Fire Dagger, you should use FD_X.

    So to explain the variables, we have 3 real variables: SS_time is how often we will damage the unit, SS_damage is how much damage the spell will deal per tick, and SS_duration is the duration of the spell obviously.
    Note: The array stands for the level of the ability so the spell will deal 5 damage every 3 seconds at level 1 and 10 damage at level 2.

    Next up is the cast trigger.
    • cast
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to SS_ability
      • Actions
        • Set SS_handle = (Target unit of ability being cast)
        • Hashtable - Save 0.00 as (Key SS_handle) of 1 in SS_hash
        • Hashtable - Save SS_duration as (Key SS_handle) of 2 in SS_hash
        • Hashtable - Save Handle Of(Triggering unit) as (Key SS_handle) of 3 in SS_hash
        • Hashtable - Save (Level of SS_ability for (Triggering unit)) as (Key SS_handle) of 4 in SS_hash
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (SS_group is empty) Equal to True
          • Then - Actions
            • Trigger - Turn on loop <gen>
          • Else - Actions
        • Unit Group - Add (Target unit of ability being cast) to SS_group


    and then the loop trigger.

    • loop
      • Events
        • Time - Every 0.10 seconds of game time
      • Conditions
      • Actions
        • Unit Group - Pick every unit in SS_group and do (Actions)
          • Loop - Actions
            • Set SS_handle = (Picked unit)
            • Set SS_counter = ((Load (Key SS_handle) of 1 from SS_hash) + 0.10)
            • Hashtable - Save SS_counter as (Key SS_handle) of 1 in SS_hash
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • SS_counter Greater than or equal to SS_time
              • Then - Actions
                • Hashtable - Save 0.00 as (Key SS_handle) of 1 in SS_hash
                • Unit - Cause (Load (Key SS_handle) of 3 in SS_hash) to damage (Picked unit), dealing SS_damage[(Load (Key SS_handle) of 4 from SS_hash)] damage of attack type Spells and damage type Normal
                • Hashtable - Save ((Load (Key SS_handle) of 2 from SS_hash) - SS_time) as (Key SS_handle) of 2 in SS_hash
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Load (Key SS_handle) of 2 from SS_hash) Less than or equal to 0.00
                  • Then - Actions
                    • Unit Group - Remove (Picked unit) from SS_group
                    • Hashtable - Clear all child hashtables of child (Key SS_handle) in SS_hash
                    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (SS_group is empty) Equal to True
                      • Then - Actions
                        • Trigger - Turn off (This trigger)
                      • Else - Actions
                  • Else - Actions
              • Else - Actions

    If you don't know how hashtables work this will indeed be very confusing to you, so I will try to explain how it works.

    Hashtables are an action we can use to make the spell MUI. They save something and locks it with 2 keys. I will try explain in a odd way, but I think it is easier.
    So let's say we have a bank, firstly we need to create the bank right? We should put this in the setup trigger:
    • Actions
      • Hashtable - Create a hashtable
      • Set SS_hash = (Last created hashtable)

    Now, if we want to put something into the bank we need a account.
    So for example, I can store 0.00 into the bank, but then I need to tell which account I want to put it in.
    • Actions
      • Hashtable - Save 0.00 as (Key (Target unit of ability being cast)) of 1 in SS_hash

    this saves 0.00 in the account called (Key (Target unit of ability being cast)) + 1

    now the 0.00 is successfully stored. And then we can unload it.
    • Set SS_counter = ((Load (Key (Picked unit)) of 1 from SS_hash) + 0.10)

    If you have coded before this is basically a 2d array. For example.
    • Actions
      • Set array_one[1] = 64
      • Set array_one[2] = 86
      • Set array_one[3] = 33
      • Set array_two[1][1] = 34
      • Set array_two[1][2] = 55
      • Set array_two[1][3] = 75


    That is basically what a hashtable is. If you study my code example I am sure you will understand.

    If you don't understand me you should check out a tutorial:
    http://www.hiveworkshop.com/forums/...9/complete-beginners-guide-hashtables-197381/
    http://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/hashtables-mui-133407/
     

    Attached Files:

    Last edited: Aug 10, 2014
  2. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,193
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    • Don't destroy SS_Group
    • Store the damage when the ability is cast, load it in the looping trigger.
      Currently the caster can learn the ability while the damage over time is running, and benefit from
      higher ability level than what is was when it was cast
    • Turn the looping trigger off when the group is empty
    • The initialization trigger has the actions twice
    • You should swap the usage of parent and child keys, currently when you try to flush the data, it doesn't do that

    Currently this looks like a short hashtable demonstration. You need to improve this guide a lot.

    Pro tip: Wrap the trigger tags in [stable][/stable] tags.
     
  3. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,529
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    1. my bad I added that the last second because I saw a leak. Did not think.
    2. indeed, will do
    3. ok
    4. no? I just didnt add the hasshtable in the first trigger to avoid confuseon.
    5. should I flush the parent insted?

    I guess it is, not my intention tho

    will do
     
  4. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,532
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    u should store picked unit to a temp variable for speed and efficiency.

    in ur cast trigger u use target unit of ability being cast a lot. u should use the variable that it is stored into. better yet use a temp variable for key (Target unit of ability being cast))

    for the last one u should also store key( picked unit) into a variable and use that.

    on a side note: i dont like the way u config since it needs so many variables in order to work. But thats just an opinion. it is still a viable way.
     
  5. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,853
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    You should also teach them how to use an Indexed Array. If they keep making spells with hashtables,you are going to have a bad time.
     
  6. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    you should include in your tutorials how configurable works, not only damage and time but dummys and effects, also preloadings...

    using an array in a non-dynamic way, such as [1][2][3] is no good practice unless you pick it randomly using GetRandomInt...

    indexing is the best way for spells except when your storing something outside the casted spell, then use HT...
     
  7. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,529
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    @variables
    I could indeed add more variables but I want a demo code short and simple, variables ruin the readability too. Just personal opinion I guess.

    @handle
    I didnt want to confuse someone even more that is why I didnt add it. but I guess its needed.

    @index
    I dont use it because it completely destroys the reabability. and bad in which way? because you hit the hashtable limit? you got to think smart use 5 spells per hashtable or even more if you want to.

    @setup
    yes, I will include effect setup and explain. ty
    and in which way is that bad? thats the only way I have seen.
     
  8. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,532
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    variables if named correctly are easier to read than tons of picked unit and other things.

    indexing is a lot better IMO, but i dont believe there is a hashtable spell tutorial. So this might be a good idea. Although u should still encourage everyone to go for efficiency. So indexing is a much better solution in that respect.

    Also teaching new ppl how to make spells more efficient by storing things into variables should always be done. y teach someone the wrong way just because its easier to read ? IMO its not easier to read.

    This should stay a hashtable spell tutorial but u should note the pros and cons of hashtables vs indexing.

    u could also link tutorials like mine to this and if this gets approved i will gladly link this in mine as an alternative to indexing for spells.
     
  9. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,529
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    as said just a personal opinion.will fix it.

    there is actually a spell example in the hashtable and MUI tutorial but alternatives is allways good. People should go for whatever they like the most, however I should mention pros and cons.


    could link your tut insted of explaining indexing since I cant work with it myself.

    will do a big update on this as soon as possible but I got prom stuff today so will most likely be tomarrow.
     
  10. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,853
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Im sure you know that you can only have 255 hashtables.
     
  11. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,529
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    thats why you use many spells with the same hashtable.

    also 255 spells is much anyway, will not be a issue in most maps.
     
  12. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,532
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    definitely true.
    one other thing u should tell them is how to properly store multiple spells into one hashtable. and tell them that as the hashtable gets bigger it gets much much slower than indexing with arrays.
     
  13. 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
    1 hashtable can be enough for spells of a whole map if there is no super duper hyper mega complex spell...
     
  14. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,532
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    ya that is true but the decrease in speed is not good at all. especially when a lot of spells are running at the same time trying to read and write from that hashtable
     
  15. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,853
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Please use the [stable][/stable] tags outside the trigger tags. It is stretching my PAGE!
     
  16. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,529
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    ok, made a small update:
    I now use stable tags
    I added handle variables to the triggers
    I fixed 2 buggs within the triggers
    I now turn of the trigger when group is empty
    Setup no longer got the actions twice

    Will fix the indexing pros and cons thingy later
     
  17. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,532
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    what about the inefficiency thing with using picked unit so many times, and key ( picked unit)
     
  18. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,529
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    1. there is no longer a key picked unit I replaced them with handles
    2. picked unit is used twice
     
  19. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,532
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    u already store it here Set SS_handle = (Picked unit)
    so u should use that variable instead of picked unit.

    also key SS_handle is used quite a bit so that should also be stored into a temp variable.
     
  20. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,529
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    I lost you somewhere mate.
    1. yes it is stored once
    2. I do use that..