• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Stuck on Figuring Out How to Merge & Upgrade Towers.

Status
Not open for further replies.
Level 9
Joined
Feb 3, 2006
Messages
326
Hey everyone, I'm been stuck on this for awhile now, trying to figure it out.

Basically...
  • You have 5 Towers that will be randomly chosen when you click 'Create Tower'
  • I want to be able to make it so players can change these towers to different types of towers.
  • When merging 2 of the same level and type, you get a new tower which has a higher level (2x Level 1 towers Merge into 1 Level 2 Tower)
  • The merged tower is randomly chosen from the type of towers you have already chosen.

Idea.jpg



I'm struggling tying to figure this out, it's pretty complex from my point of view. Hopefully someone may have an idea on this!
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,867
Can the towers that are spawned "when a button is clicked" merge as well? Or is this merging reserved only for the Towers chosen by the player?

And correct me if I'm wrong but let's say you have chosen:
2x Scout Towers (Level 1)
1x Guard Tower (Level 1)
1x Arcane Tower (Level 1)
1x Cannon Tower (Level 1)

If you merge the 2x Scout Towers, you can get one of the four following results:
Scout Tower (Level 2)
Guard Tower (Level 2)
Arcane Tower (Level 2)
Cannon Tower (Level 2)

Correct? And if so, how does it handle multiple copies of the same type of tower when choosing a tower at random?

Using the example below, would your merge results be a 50/50 chance for one or the other, or a 40% chance for scout tower and 60% chance for guard tower:
2x Scout Towers
3x Guard Towers

Edit:
I attached an example map of what I believe you wanted. I wasn't sure how you wanted everything to function mechanically so I used chat commands as the means to create the towers. I wasn't sure how you plan on choosing where to spawn new towers so I left that aspect of it working but unfinished.
 

Attachments

  • Merge Towers example 1.w3m
    24.1 KB · Views: 28
Last edited:
Level 9
Joined
Feb 3, 2006
Messages
326
Can the towers that are spawned "when a button is clicked" merge as well? Or is this merging reserved only for the Towers chosen by the player?

And correct me if I'm wrong but let's say you have chosen:
2x Scout Towers (Level 1)
1x Guard Tower (Level 1)
1x Arcane Tower (Level 1)
1x Cannon Tower (Level 1)

If you merge the 2x Scout Towers, you can get one of the four following results:
Scout Tower (Level 2)
Guard Tower (Level 2)
Arcane Tower (Level 2)
Cannon Tower (Level 2)

Correct? And if so, how does it handle multiple copies of the same type of tower when choosing a tower at random?

Using the example below, would your merge results be a 50/50 chance for one or the other, or a 40% chance for scout tower and 60% chance for guard tower:
2x Scout Towers
3x Guard Towers

Edit:
I attached an example map of what I believe you wanted. I wasn't sure how you wanted everything to function mechanically so I used chat commands as the means to create the towers. I wasn't sure how you plan on choosing where to spawn new towers so I left that aspect of it working but unfinished.
The spawned towers are the towers that will be merged. The chosen towers are the towers that will be randomly spawned when you press a button to create new random tower.

When merging a spawned tower, you click an ability and select a target. The target has to be the same tower as the casting tower.

I'll download this map when i get home and have a look! Cheers for replying :)

Edit:
So I had a look at it, that was better than I could ever do. My question is, if the player changes one of the towers chosen, how would you change it so the new tower is added to the chosen towers and the previous tower is removed. I have never used hashtables before, they look rather confusing actually haha as I'm not much good with using custom scripts, etc...
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,867
To answer your question, I'm using a Unit Group for each player's Chosen Towers. When merging two towers I simply remove the two merged towers from the unit group and then add the new tower to it. I'll have to adjust this since you don't want Chosen Towers to be able to cast merge.

So Hashtables look intimidating at first but if you understand how Arrays work then you can understand how a Hashtable works.
Hashtables are essentially an Array with an extra Index. Here's an example of that concept, this Array is being used to store each Player's Tower units:
  • PlayerTower[1][1] = SomeTower
  • PlayerTower[1][2] = SomeTower
  • PlayerTower[1][3] = SomeTower
The first [Index] is used to represent the Player's Number, so in the above example I use 1 to represent Player 1 (Red).
The second [Index] is used to represent the actual numbering of the Player's towers, the same way you'd number items in a grocery list (1 = milk, 2 = eggs, etc).

So PlayerTower[1][1] is Red's first tower, PlayerTower[1][2] is Red's second tower, PlayerTower[1][50] is Red's fiftieth tower, etc...
Want to change the player? Simply adjust the first index:
PlayerTower[2][1] is Blue's first tower, PlayerTower[2][2] is Blue's second tower, PlayerTower[2][50] is Blue's fiftieth tower, etc...

See why that's useful? This single Array variable could be used for ALL of the players, instead of creating a new variable for every single player. Designing your maps using this method will make your life a lot easier as it will get rid of unnecessary variables/triggers/work. You should rarely if not ever have copies of variables that are broken up for each player, IE:

  • Player1Tower[1] = SomeTower
  • Player1Tower[2] = SomeTower
  • Player1Tower[3] = SomeTower
  • -- player 2 --
  • Player2Tower[1] = SomeTower
  • Player2Tower[2] = SomeTower
  • Player2Tower[3] = SomeTower
  • -- player 3 --
  • Player3Tower[1] = SomeTower
  • Player3Tower[2] = SomeTower
  • Player3Tower[3] = SomeTower
^ This makes things very difficult since you're now using different Variables for each player. This forces you to design your triggers in a way that creates a lot of extra work and headaches:
  • This is bad
    • Events
      • Player - Player 1 (Red) types a chat message containing kill as An exact match
      • Player - Player 2 (Blue) types a chat message containing kill as An exact match
      • Player - Player 3 (Teal) types a chat message containing kill as An exact match
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Triggering player) Equal to Player 1 (Red)
        • Then - Actions
          • Unit - Kill Player1Tower[1]
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering player) Equal to Player 2 (Blue)
            • Then - Actions
              • Unit - Kill Player2Tower[1]
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Triggering player) Equal to Player 3 (Teal)
                • Then - Actions
                  • Unit - Kill Player3Tower[1]
                • Else - Actions


All of that being said, Hashtables are formatted slightly different than what I've shown above. But this is because they offer some additional features:
  • Actions
    • Unit - Create 1 Guard Tower for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
    • Hashtable - Save Handle of (Last created unit) as 1 of 1 in SomeHashtable
That trigger will save the Handle of the Guard Tower to the Hashtable. The Handle is basically another way of saying it's going to Save that specific Guard Tower to the Hashtable. Each unit has it's own unique handle. This is not to be confused with Unit-TYPE which is shared between all Guard Towers.

So comparing the Hashtable action that I've just shown you to the PlayerTower arrays that I used at the start of my post:
(Last created unit) = SomeTower

As 1 = The second index in PlayerTower[][X], which I used to represent the number of the tower, so 1, 2, 50, etc...

Of 1 = The first index in PlayerTower[X][], which I used to represent the player number of the tower, so 1, 2, 3, etc...

SomeHashtable = The Hashtable that stores all of this data. Each Hashtable acts like a new Array variable. You have to manually create Hashtables yourself and store them using a Hashtable variable so that you can keep track of them. This is similar to how you create a Multiboard if you've done that before.

Note: You can only create up to 256 Hashtables. This is nothing to worry about as a map like this wouldn't even come close to that limit. That being said, a single Hashtable could technically store everything if you designed it to do so. But like I said, this is nothing to worry about.

Here's a more simple use of the Hashtable, where we're saving an Integer in it:
  • Hashtable - Save 50 as 3 of 1 in SomeHashtable.
So we're saving the integer 50 as 3 of 1 in SomeHashtable. So 50 is the value that you want to save, and "as 3 of 1" are the Indexes where you want to store it, in this case 3 would represent the item number and 1 would represent the player number.
So we're saving 50 as Player 1's third Integer value in the Hashtable. This would translate to: PlayerInteger[1][3] = 50

Anyway, I'm glad you've cleared some things up but I still have some questions.
I'm still confused on how you want to Spawn towers in. Do you place them randomly on one of those 15 diamond patches of grass? Or can the player choose where to put their Spawned Towers? Also, can you merge 2 Spawned Towers together? Or does the Spawned Tower have to target a Chosen Tower?

Try to provide as many details as possible, thanks!

Edit: Attached a new version of the map. I THINK I did exactly what you wanted.
I made it so that you can only Merge spawned towers together. When doing so it will create a random tower from your list of Chosen Towers. This resulting tower's level will be equal to the Merged towers Level + 1. So if you merge 2 Level 1 Scout Towers, you could get a Level 2 Scout Tower, or maybe a Level 2 Cannon Tower IF the Cannon Tower was in your Chosen List. The one thing I left out was an example on upgrading/replacing Chosen Towers. It's quite simple though, all you have to do is manage the Unit Group that contains these Chosen Towers. I'm not even sure if it'll be necessary for Upgrading towers as they may still be considered the same unit and never leave the Unit Group in the first place.
 

Attachments

  • Merge Towers v2.w3m
    29.3 KB · Views: 24
Last edited:
Level 9
Joined
Feb 3, 2006
Messages
326
Alright, so I have created it to work 90% perfect, slight fixes are needed but I've set it to the current towers.
I'd have to figure out how to change the chosen towers in the future and make sure the merge works with any new updated towers.

Now, I've attached the map to see for yourself what I mean.
Use the Base to spawn random towers, you gain gold from killing the spawns who endlessly gain health (This is just a temporary placement) and you can merge towers together.

Future Plans:
3 Types of Spawned units - Normal, Fast and Fortified
Boss Rounds ever XX Minutes
If it's every figured out, Many more towers...
Multiplayer!!

Tell me what you think, and see if you understand what I mean :)
Also, modify the Preferences -> Test Map -> 'Use Fixed Random Seed' Uncheck this!
 

Attachments

  • Random Tower TD.w3m
    45.1 KB · Views: 23

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,867
Hey, have you checked out the last map I sent you? I think it's got everything you need, but I understand if it's a bit too much. Hashtables were a pain in the ass to figure out for me as well, but they'll make your life a hell of a lot easier when they finally click.

Anyway, I looked through your map and I feel as though you're on the right track. You're still designing in a way that will make your life harder in the long run (specific variables for specific players), which could be remedied with Hashtables. Also, be careful with using Waits, as they won't play nice in multiplayer and can even cause issues in singleplayer. You should look into tutorials regarding MPI and MUI triggers to get a better understanding of what I mean.

I attached an edited version of your map with some fixes and examples of how you could improve what you already have. You'll see I recreated your Tower Spawning/Merging triggers as well as a new Setup trigger. I took advantage of some of your existing variables in my new stuff.
 

Attachments

  • Random Tower TD Uncle.w3m
    53.6 KB · Views: 19
Level 9
Joined
Feb 3, 2006
Messages
326
Hey, have you checked out the last map I sent you? I think it's got everything you need, but I understand if it's a bit too much. Hashtables were a pain in the ass to figure out for me as well, but they'll make your life a hell of a lot easier when they finally click.

Anyway, I looked through your map and I feel as though you're on the right track. You're still designing in a way that will make your life harder in the long run (specific variables for specific players), which could be remedied with Hashtables. Also, be careful with using Waits, as they won't play nice in multiplayer and can even cause issues in singleplayer. You should look into tutorials regarding MPI and MUI triggers to get a better understanding of what I mean.

I attached an edited version of your map with some fixes and examples of how you could improve what you already have. You'll see I recreated your Tower Spawning/Merging triggers as well as a new Setup trigger. I took advantage of some of your existing variables in my new stuff.
Hey thanks so much for the help, I had a look at the changes and I'm not sure if your merging thing was working properly or not but it'd only ever merge into an Ice Tower Level 2, no matter what level 1 towers I merged.

I will try to look deeper into hashtables and try to figure them out. Thanks again :)
 
Status
Not open for further replies.
Top