![]() news about forums links tools tutorials contact |
Capture the Flag - author: crack_addict | |
Note: This was made for Unreal, before UT was released and came with Capture the Flag builtin, so its now kind of obsolete, but I've retained it simply because its a good exercise in making a new gametype.
Since Unreal already has a Team game setup, and CTF requires teams, we only need to subclass the TeamGame class in order to get team support in. In this class we need to make sure the flags get spawned, and handle scoring for teams/individuals.
The number of points to award to the player and team upon a successful capture.
In PostBeginPlay() we search for all FlagSpawnPoints and tell them to spawn a flag. NOTE: This requires that maps need to have FlagSpawnPoints already placed in them in order to properly spawn flags (although you could easily write some code to play FlagSpawnPoints if none are present).
ScoreTeamCapture does exactly what the name implies, it scores points for a capture.
TeamInfo is a class (under the Info class) that is used to store pertinent information about different teams in a Team game. We need to use it to add points to the entire team, as well as the individual capturer.
Find a matching TeamInfo based on Team and then give them some points.
And finally award the person who did the actual capture.
DiscardInventory is called whenever a Pawn dies, and since we don't want a flag destroyed if a player dies we must override this to put it back to its original position. NOTE: It would be a good idea to expand this to drop the flag wherever they died and only send it back after a certain time or if it is touched by a player of the same team. (as in Quake2 CTF and others)
Use FindInvetoryType to get a reference to the flag if the pawn has it, and if so drop it.
DropFrom drops the Inventory item at the specified location and handles removing the item from the player's inventory.
Let the normal DiscardInventory do its work now that we've done what we needed.
This class should be placed where you want the flags to be in the level. The SpawnFlag() function is called at the beginning of the game and creates the actual flag. NOTE: Since FlagSpawnPoint is a subclass of NavigationPoint it will be part of the pathnode table of a level, and as such will be usuable by bots, so it should be relatively simple to alter Unreal's bots to play CTF.
TeamNumber should be set to the owner Team
MyFlag is a local reference of the flag spawned
SpawnFlag() just creates the flag, then sets the Team and InitLocation variables.
This is a normal Pickup item, and we alter the Pickup state (the Touch() function in particular) to check for flag captures...etc. It is created by a FlagSpawnPoint, and it handles the majority of the CTF game code itself.
Team and Initial location
Touch() is called whenever an Actor collides with this Actor, and normally for a Pickup item it would handle adding this item to the inventory of the Pawn if possible. We alter it to see if the PlayerPawn touching us has a flag (for a capture), or if the PlayerPawn is on an opposite team we give the flag to them like a normal item.
If it isn't a playerpawn then can't grab the flag. NOTE: Might be a good idea to change this to Pawn, or add a check for Bots if you want to add Bot support.
If it is on the same team as us then go ahead and check for a capture.
Check for capture by seeing if they have a flag.
Score points, reset flag, and let the world know about it.
If they aren't on the same team then give the flag to them.
Give flag to enemy and let the world know about it.
|