HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Rank Display Tutorial

08-31-2002, 02:09 AM#1
Guest
I didn't know if anyone might be interested in this...it's a simple idea I came up with to avoid letting the food counter go to waste in maps where it's not really doing anything useful.

-----
* Rank Display Tutorial by all_your_base

-----
Introduction:

Ever notice how in many custom games, the food counter is left unused? Oftentimes the game concepts map-makers come up with and create in WorldEdit make use of gold and lumber, but simply don't need to do anything with food. The food counter just sits there and does whatever it pleases - it goes up when a player gets more units/buildings, and goes down when they lose them - but it never actually serves a practical purpose during the game. Such games usually also have some implementation of score-keeping, whether it be kills, gold, lumber, points, etc.

That's where this guide comes in. If you're not using the food counter for anything in your game, why not use it as a rank display? Using a few triggers and variables, you can get your food counter to display a player's rank based on the game's score, as well as the number of participants. It adds both convenience and functionality.

The food counter is ideal for this because it usually shows a pair of numbers (in X/Y format) - where X is the food used and Y is the food cap. Essentially, the food used (X) will become the player's rank and the food cap (Y) will become the number of participants. This format is just like the ones found in racing games - where a pair of numbers is almost always provided to show you where you rank in the field.

-----
Maps that can't benefit from this guide include the following:

1) Maps that use either food number for a particular purpose
2) Maps that need the upkeep feature
3) Maps that need any unit/building to use or supply food

If your map falls into any of the above categories, stop right now. This guide won't do you a lick of good. In fact, just the opposite is true - you'll completely mess up your game! If none of the above apply to you, keep reading...

-----
Getting started:

The first thing you'll have to do is open up your map and enter the Unit Editor. Select each unit and building used in your game, one by one, and set both the "Supply Cost" and "Supply Produced" to zero. (Otherwise, those units/buildings will change the counter when built, killed, or otherwise introduced/implemented.)

With that (hopefully) simple step out of the way, it's time to move on to the variables. You'll need to create three of 'em to make your counter work. Add the following to your map's list of variables:

1) Count - Integer - 12
2) Flag - Boolean Array - None
3) Rank - Integer Array - None

You can use different variable names if you like - but you'll have to remember to use your substitutes in all of the following steps. The variable type/initial value, on the other hand, aren't optional.

-----
Triggers:

Now it's time to put those variables to work and make your counter tick (not literally, of course! :) You're going to need three different triggers to get your counter working. You can create them in any folder you like, but I recommend creating a separate folder for them (it'll help keep your triggers organized.)

You should still be in the Trigger Editor from when you created your variables. Create a new category named "Rank Display" (unless you have other placement or naming plans!) Create your first trigger within the new folder, "Setup".

NOTE: If, for some reason, you left the "Melee Initialization" trigger in your map, you can skip the event of the following trigger and just insert the following action. This doesn't mean the counter will be melee-compatible, though :\

TRIGGER: "Setup"
EVENTS:
- Time - Elapsed game time is 0.00 seconds
CONDITIONS:
- None
ACTIONS:
- For each (Integer A) from 1 to 12, do (Set Flag[(Integer A)] = False)

The sole purpose of that trigger is to set the stage for the next one, "Count". Don't actually insert the above action into the following trigger, however, or you'll mess it up.

The "Count" trigger will determine how many active players are in your game. Set it up as follows:

TRIGGER: "Count"
EVENTS:
- Time - Elapsed game time is 0.00 seconds
- Time - Every 1.00 seconds of game time
CONDITIONS:
- None
ACTIONS:
- For each (Integer A) from 1 to 12, do (If ((((Player((Integer A))) slot status) Not equal to Is playing) and (Flag[(Integer A)] Equal to False)) then do (Set Count = (Count - 1)) else do (Do nothing))
- For each (Integer A) from 1 to 12, do (If ((((Player((Integer A))) slot status) Not equal to Is playing) and (Flag[(Integer A)] Equal to False)) then do (Set Flag[(Integer A)] = True) else do (Do nothing))

My apologies if the above seems like a mess. Perhaps I should explain how it works...

What the first action does is check each player to see if that player is active. If not, the "Count" variable has one point subtracted from it. The "Count" variable, if you didn't figure it out already, is the one that the game uses to determine the total number of players that are active in the game.

What the second action does is "flag" the first action so it doesn't fire more than once on each inactive player. Without this "flag", the game would be tricked into thinking there are a negative number of participants, because it would be lowering the "Count" variable over and over again for each inactive player.

In this way, only the two actions need to be created to check all players, instead of creating a separate event for each player to check their activity.

Now you can move on to the last trigger, "Calculate", which is what makes the whole counting system tick. This is the most complex trigger, with the second action actually placing a "For" loop within another, so brace yourself and break each action down, one by one:

TRIGGER: "Calculate"
EVENTS:
- Time - Elapsed game time is 0.00 seconds
- Time - Every 1.00 seconds of game time
CONDITIONS:
- None
ACTIONS:
- For each (Integer A) from 1 to 12, do (Set Rank[(Integer A)] = Count + 1))
- For each (Integer A) from 1 to 12, do (For each (Integer B) from 1 to 12, do (If ((((Player((Integer A))) Current SCORE) Greater than or Equal to ((Player((Integer B))) Current SCORE)) and (((Player((Integer B))) slot status) Equal to Is playing)) then do (Set Rank[(Integer A)] = (Rank[(Integer A)] - 1)) else do (Do nothing)
- For each (Integer A) from 1 to 12, do (Player - Set (Player((Integer A))) Food used to Rank[(Integer A)])
- For each (Integer A) from 1 to 12, do (Player - Set (Player((Integer A))) Food cap to (Count)

Note that in both of the places where it says SCORE, that indicates where you should insert whatever variable you're using for your game's score - whether it's "Current Gold", "Current Lumber", etc.

You may have also figured out by now that all of those "1 to 12" specifications in the "For" loops represent players 1 thru 12. If your particular map doesn't have 12 players, don't worry. You won't need to change them.

Anyway...I'm sure you're getting sick of creating "For" loops by now :þ You can relax - you're done with all of that. Here's a breakdown of how the above actions work:

The first action basically "sets the stage" for the second action, which does all the calculating. If this first action weren't implemented, the second would quickly drive each player's "rank" deep into negative numbers. Obviously, we don't want that :D

The second action is the meat and potatoes of the rank display. What it does is check each player (with variable A) and in turn, compares that player's score with the entire list of players in the game, represented by variable B. Each time it finds a player (B) that has a lower score than the one whose rank is being calculated (A), the action reduces that player's "Rank" variable by one point. (When I say "reduce", I mean raise the player's rank, because lower numbers represent higher ranks.) The second condition of the "If" statement ensures that the game doesn't treat inactive players as participants when calculating each player's rank.

The third and fourth triggers display for each player their own rank and the total number of participants, respectively.

-----
Conclusion:

So there you have it. There's no need to put that food counter to waste anymore! It's a perfectly good resource that can be used for many different things. This is only one idea on how an otherwise pointless food counter in a custom game can be used for something practical. This system would work very well in certain types of games, like madness maps which almost always have kill scores for each player. but don't actually involve building or training anything.

And that (finally) concludes the tutorial. You can reach me at [email protected] with any questions or comments you might have.
Enjoy @_@