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. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  4. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  5. The results are out! Check them out.
    Dismiss Notice
  6. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  7. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  8. 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.

Ralle's Tower Defence Guide

Discussion in 'General Mapping Tutorials' started by Ralle, Aug 12, 2006.

  1. Ralle

    Ralle

    Owner

    Joined:
    Oct 6, 2004
    Messages:
    11,219
    Resources:
    22
    Tools:
    3
    Maps:
    5
    Tutorials:
    14
    Resources:
    22
    Ralle's Tower Defence Guide

    Table of Contents

    Intro


    I will start off by explaining what a Tower Defense is. A Tower Defense (or TD) is a genre of WarCraft 3 Custom Scenarios (maps). All towers, upgrades, builders creeps are different. You usually start with some unit called a builder which you can build towers with. The towers you can build vary in quality, skills, speed etc.. and ofcourse, the price. After around 30 seconds to 1 minute monsters spawn in different locations and start moving. These monsters don't attack unless you block their way of moving. This means that you can make a maze for the monsters to stay for a longer time in your area:

    image1.jpg
    Example #1 (a maze)
    image2.jpg
    Example #2 (a lineup)
    As you see in these two examples the units will have to move much longer to escape the towers in example #1. If you count the squares the units have to move to, until they are safe, it will be:
    example #1: 13
    example #2: 6
    This means that the towers in example #1 can hit the creeps for a greater amount of time than the towers in example #2.

    So if monsters pass your maze they will most likely walk into another players maze and probably after that walk into some kind of gate or boat. When they enter it, all players will lose a life which they have a limited amount of. So when the amount of lives pass 0, all players will lose the game.

    When all creeps in a TD are dead, the next level will start, this level have either stronger or more creeps. After around 20-30 levels of creeps you will often win the game.

    Normally every player in a TD each have their own spot and a creep resource. But sometimes people like to build in eachother's spots which cause lots of angry faces. This is also a thing we can prevent in the coming tutorial.




    Terrain


    The terrain is very important for a TD. It needs to be fair for all players though it not always is. Some player spots are often the "best" and in some spots people often leave because they are bored in that spot. But making all spots equal is a good thing. There is no formula of making the terrain so I will just show you 3 examples of how the terrain could look like:

    Balanced Terrain
    burbenog.jpg
    wintermaul.jpg
    warhammer.jpg

    Example #1 (Burbenog TD)
    Burbenog TD is quite hard, but it features some good things. All player spots are 100% fair to each other. Every player gets an equal amount of creeps and have equal starting points. This is the only TD of it's kind.

    Example #2 (Wintermaul TD)
    Wintermaul have very different spots. Some players only gets their creeps but they get a lot. Then some players get the leaks of other players + a little resource from their own spawn. And Player 9 (gray) only get leaks from other players.

    Example #3 (Warhammer 40k TD)
    Warhammer 40k TD have quite equal spots for all players except for Player 9 (gray) he gets everyone's leaks which can vary a lot. Sometimes everyone leaks and he gets it all (if he can handle it) and sometimes he gets nothing.

    Terrain Creation
    Now I am going to make a very simple terrain. I will make a spawn for units a place they go to and turn around and walk into a base which is where they have to go in order to make you lose a life.
    1.jpg
    Progress #1 (just terrain)
    2.jpg
    Progress #2 (now I added regions)
    After making the terrain I added 3 regions. Red, Blue and Green.
    The Red one is the place where the creeps spawn.
    The Blue one is where the creeps go into and then go on to the green place.
    The Green is the place they enter to make you lose a life and then disappear.




    The Trigger Core


    Every TD needs triggers to make the creeps move the right way, not attacking, take lives from the team etc.. No Custom Map will work without triggers. You can learn about triggers other places in the trigger tutorial forum.

    Notes
    The Tower Defense system in this tutorial was based on what I used for Warhammer 40,000 TD and what DukeWintermaul did on his as well.

    Variables
    Below is a list of the variables we are going to use for this tutorial:
    Name Type Initial Value Array
    Lives Integer 25 No
    Levels_Amount Integer 3 No
    Levels_Units Unit-Type N/A Yes 3 (same as above)
    Levels_Units_Count Integer N/A Yes 3 (same as above)
    Levels_Current Integer 0 No
    Timer Timer N/A No
    loc Point N/A No


    Initialization
    The trigger below will set our values.
    • Initialization
      • Events
        • Map initialization
      • Conditions
      • Actions
        • -------- This is where we set which unit spawns on each level --------
        • Set Levels_Units[1] = Peasant
        • Set Levels_Units[2] = Footman
        • Set Levels_Units[3] = Knight
        • -------- This is the amount of units to spawn on each level --------
        • Set Levels_Units_Count[1] = 10
        • Set Levels_Units_Count[2] = 10
        • Set Levels_Units_Count[3] = 40


    Start Game
    A unit is from beginning, placed on a location in the map. This is because we will trigger our "Next Level" trigger by killing that unit which leads to Player 12's food used becoming 0.
    • StartGame
      • Events
        • Time - Elapsed game time is 1.00 seconds
      • Conditions
      • Actions
        • Unit - Kill Peasant 0000 <gen>
        • Game - Display to (All players) the text: Welcome to ....


    Next Level
    This trigger will execute every time Player 12 has 0 units. Which means every time a level is over and when the dummy peasant dies.
    The level will be increased and a timer for the next level has begun.
    • NextLevel
      • Events
        • Player - Player 12 (Brown)'s Food used becomes Equal to 0.00
      • Conditions
      • Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Levels_Current Equal to Levels_Amount
          • Then - Actions
            • Player Group - Pick every player in (All players) and do (Actions)
              • Loop - Actions
                • Game - Victory (Picked player) (Show dialogs, Show scores)
          • Else - Actions
        • Set Levels_Current = (Levels_Current + 1)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Levels_Current Equal to 1
          • Then - Actions
            • -------- Give everyone a few more seconds to start their base --------
            • Countdown Timer - Start Timer as a One-shot timer that will expire in 50.00 seconds
            • Game - Display to (All players) the text: The game will start...
          • Else - Actions
            • -------- Normal start --------
            • Countdown Timer - Start Timer as a One-shot timer that will expire in 25.00 seconds
            • Game - Display to (All players) the text: The next level will...
        • Countdown Timer - Create a timer window for Timer with title Level


    Timer Expires
    • NextLevel Timer
      • Events
        • Time - Timer expires
      • Conditions
      • Actions
        • Countdown Timer - Destroy (Last created timer window)
        • Unit - Create Levels_Units_Count[Levels_Current] Levels_Units[Levels_Current] for Player 12 (Brown) at (Center of Red <gen>) facing Default building facing degrees
        • Game - Display to (All players) the text: The level has begun!


    Red To Blue
    This trigger will run every time a unit owned by Player 12 (creeps) enters region Red. It will then be ordered to enter region Blue:
    • RedToBlue
      • Events
        • Unit - A unit enters Red <gen>
      • Conditions
        • (Owner of (Entering unit)) Equal to Player 12 (Brown)
      • Actions
        • Set loc = (Center of Blue <gen>)
        • Unit - Order (Entering unit) to Move To loc
        • Custom script: call RemoveLocation(udg_loc)


    Blue To Green
    This trigger will run every time a unit owned by Player 12 (creeps) enters region Blue. It will then be ordered to enter region Green:
    • BlueToGreen
      • Events
        • Unit - A unit enters Blue <gen>
      • Conditions
        • (Owner of (Entering unit)) Equal to Player 12 (Brown)
      • Actions
        • Set loc = (Center of Green <gen>)
        • Unit - Order (Entering unit) to Move To loc
        • Custom script: call RemoveLocation(udg_loc)


    Green -> Lives Lost
    When a unit owned by Player 12 enters region Green, the variable called "lives" will be set to "lives"-1 and the unit will be killed.
    If then "lives" equal to 0, it will pick al players and defeat them.
    • GreenToDead
      • Events
        • Unit - A unit enters Green <gen>
      • Conditions
        • (Owner of (Entering unit)) Equal to Player 12 (Brown)
      • Actions
        • Unit - Kill (Entering unit)
        • Set Lives = (Lives - 1)
        • Game - Display to (All players) the text: (You have lost a life! You currently have + ((String(Lives)) + lives left!))
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Lives Equal to 0
          • Then - Actions
            • Player Group - Pick every player in (All players) and do (Actions)
              • Loop - Actions
                • Game - Defeat (Picked player) with the message: Defeat!
          • Else - Actions





    Builders and Towers


    Making builders and towers for a TD is straight forward and the easiest part but I still have a few things to say about it.
    The builder in a Tower Defense is often an invulnerable, non-blocking, non-attacking unit which you use for building your towers. It is often nescessary to build more than one tower at a time, which is a hell if you cannot. If you want your builder to build like the undead acolyte, simply change the race of your builder to undead.
    The builder should definitely be an air unit so it can move around on the whole map with no problems. Having the builder stuck between two towers defines a poor TD.
    Base all your towers off a Sentry Tower and you will be okay.


    Bonus Features



    Sell Tower System
    Making a sell-system for your Tower Defense takes time, but is worth it.
    Go through ALL your towers and set
    Code (Text):
    [B]Stats - Point Value[/B] = [B]Stats - Gold Cost[/B]
    If the unit is an upgrade, set it to this:
    Code (Text):
    [B]Stats - Point Value[/B] = [B]Stats - Gold Cost[/B] (Base Unit) + [B]Stats - Gold Cost[/B] (Upgrade Unit).
    But only if you want the player to receive the full amount paid for the upgrade + the base unit.

    When all this is done, create an ability, base it off Warstomp and set all the values to neutral values (damage, animation, effect, hero ability).
    Then make a trigger like this:
    • SellTower
      • Events
        • Unit - A unit Begins casting an ability
      • Conditions
        • (Ability being cast) Equal to Sell Tower
        • ((Casting unit) is A structure) Equal to True
      • Actions
        • Player - Add ((Point-value of (Casting unit)) x (3 / 4)) to Player 1 (Red) Current gold
        • Unit - Remove (Triggering unit) from the game
    Look at the first action. I am multiplying the Point Value with 3/4 which means the player receives 75% of the price I paid for it. It is better to set the amount of money received in the trigger instead of doing it when setting the point value.

    Boot Player System
    Booting players is always nice, in this system I will set an admin to do the booting, the default admin will be Player 1, but if you are in the game, it will assign you instead.
    For this system, you will need a variable:
    Name Type Initial Value Array
    Admin Player N/A No
    Here's the triggers:

    Assign Admin
    You will ofcourse need to add more of the events if you are more than 3 players.
    • Assign Admin
      • Events
        • Time - Elapsed game time is 1.00 seconds
        • Player - Player 1 (Red) leaves the game
        • Player - Player 2 (Blue) leaves the game
        • Player - Player 3 (Teal) leaves the game
      • Conditions
      • Actions
        • -------- Set default admin --------
        • Set Admin = Player 1 (Red)
        • Player Group - Pick every player in (All players) and do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Or - Any (Conditions) are true
                  • Conditions
                    • (Admin slot status) Not equal to Is playing
                    • (Name of (Picked player)) Equal to Ralle
              • Then - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • ((Picked player) slot status) Equal to Is playing
                  • Then - Actions
                    • Set Admin = (Picked player)
                  • Else - Actions
              • Else - Actions


    Boot Player
    When typing "-boot #" a player with the id of # will be booted.
    You will ofcourse need to add more of the events if you are more than 3 players.
    • BootPlayer
      • Events
        • Player - Player 1 (Red) types a chat message containing -boot as A substring
        • Player - Player 2 (Blue) types a chat message containing -boot as A substring
        • Player - Player 3 (Teal) types a chat message containing -boot as A substring
      • Conditions
        • (Substring((Entered chat string), 1, 6)) Equal to -boot
      • Actions
        • Player Group - Pick every player in (All players) and do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • ((Picked player) slot status) Equal to Is playing
              • Then - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Substring((Entered chat string), 7, 8)) Equal to (String((Player number of (Picked player))))
                  • Then - Actions
                    • Game - Defeat (Picked player) with the message: Defeat!
                    • Unit - Remove (Picked unit) from the game
                  • Else - Actions
              • Else - Actions


    I added the map I made all the triggers with. If you test it, better type in 'iseedeadpeople' because you will have no units to work with ;)

    ~by Ralle
     

    Attached Files:

    Last edited: Feb 12, 2009
  2. Ralle

    Ralle

    Owner

    Joined:
    Oct 6, 2004
    Messages:
    11,219
    Resources:
    22
    Tools:
    3
    Maps:
    5
    Tutorials:
    14
    Resources:
    22
    just a little bump. I moved this and it was at the end.
     
  3. operator

    operator

    Joined:
    Feb 9, 2006
    Messages:
    1,670
    Resources:
    1
    Maps:
    1
    Resources:
    1
    The triggers are leaking, but that's not important. Good tutorial, Ralle :)
     
  4. Ralle

    Ralle

    Owner

    Joined:
    Oct 6, 2004
    Messages:
    11,219
    Resources:
    22
    Tools:
    3
    Maps:
    5
    Tutorials:
    14
    Resources:
    22
    Tell me what to do then, I would love to learn about leaks.
     
  5. GST_Nemisis

    GST_Nemisis

    Joined:
    Jan 5, 2005
    Messages:
    3,600
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Leaks are like those cartons of milk that you open and then leave at the back of your fridge, or behind your sofa, or in some forgotten corner of your room. eventually these milk cartons build up and start to smell which creates a bad situation for everybody.

    using that analogy, switch milk carton for memory address and smell for lag.

    one way i know leaks occur is when you create a location by making something happen at a place on the map. this location is written to the memory but is not removed so it just clogs it up. in your case it is ordering the units to move i think. to get rid of them you need to use some custom jass command that i dont know, as i am no expert on leaks.

    this is however, a good tutorial, gj :) i would give your rep, but when i try to it complains for some reason.
     
  6. Chaos Overlord

    Chaos Overlord

    Joined:
    Feb 1, 2007
    Messages:
    1,097
    Resources:
    0
    Resources:
    0
    *sighs* great.... now I am making a TD. I had no intention, not even a thought of making one, but now I am. Lol your tut makes it look so easy.
     
  7. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Most common leaks are Unit Groups and Locations.

    How to fix locs up (didn't see any Unit Groups)

    In;

    • Unit - Create 1 unit at [color=red]Somewhere[/color]


    If Somewhere is a function, like (Position of (Unit)) or (Center of (Region)), it will leak.

    Instead, first, make a Point variable. (I like to call mine loc)

    Then,

    • Set loc = Somewhere
    • Unit - Create 1 unit at loc
    • Custom script: call RemoveLocation( [color=red]udg_[/color]loc )


    As you can see, all "global" variables are prefixed by udg_ when used in JASS.

    Anyways, that cleans the leak!

    Also, sidenote;

    Triggering Unit > Casting Unit
     
  8. Katu

    Katu

    Joined:
    Apr 13, 2007
    Messages:
    249
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    I won't use this tutorial because I don't want to make a TD, but for ones who want, this is extremely useful. So +rep
     
  9. Ralle

    Ralle

    Owner

    Joined:
    Oct 6, 2004
    Messages:
    11,219
    Resources:
    22
    Tools:
    3
    Maps:
    5
    Tutorials:
    14
    Resources:
    22
    I will have this in mind when making maps from now on!
    Any more things to remember?
     
  10. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    -Replace (Casting Unit) with (Triggering Unit)

    -You forgot to fix the leaks :p

    -Array indexes [can] start at 0, but that's not a big problem

    All I noticed for now.
     
  11. Wolverabid

    Wolverabid

    Joined:
    Oct 23, 2006
    Messages:
    8,303
    Resources:
    5
    Tutorials:
    5
    Resources:
    5
    Tutorial Approved

    ~ Thread moved to General Mapping Tutorials.
     
  12. Horn

    Horn

    Joined:
    Mar 31, 2004
    Messages:
    938
    Resources:
    20
    Models:
    14
    Icons:
    1
    Skins:
    3
    Tutorials:
    2
    Resources:
    20
    Pretty comprehensive. There's obvious limits when you don't use JASS, but for beginners this is very handy.

    I wouldn't use global variables for locations when you could be getting multiple calls at the same time, it may end up making a mess.
     
  13. panther-anthro

    panther-anthro

    Joined:
    Oct 23, 2006
    Messages:
    361
    Resources:
    2
    Maps:
    2
    Resources:
    2
    So, why shouldn't they use multiple location variables at once? I use about 80 at once for Sereg D`or, and I have 0 issues. Just took a long time to make.
     
  14. Horn

    Horn

    Joined:
    Mar 31, 2004
    Messages:
    938
    Resources:
    20
    Models:
    14
    Icons:
    1
    Skins:
    3
    Tutorials:
    2
    Resources:
    20
    I mean if you have multiple triggers being called and they all use one global variable to assign the point/location, it may get switched before a trigger has finished, causing problems.
     
  15. panther-anthro

    panther-anthro

    Joined:
    Oct 23, 2006
    Messages:
    361
    Resources:
    2
    Maps:
    2
    Resources:
    2
    I Know what your saying, but it's never happened to me. Make sure to Use customs to delete the point after always, and set the point before. Double check as well.
     
  16. Horn

    Horn

    Joined:
    Mar 31, 2004
    Messages:
    938
    Resources:
    20
    Models:
    14
    Icons:
    1
    Skins:
    3
    Tutorials:
    2
    Resources:
    20
    You obviously didn't know what I was saying since you said
    and

    Plus your map is not a Tower defence, spawning dozens of units in the same location at once using just one point variable.