Lua:Getting Started

From Fortress Forever Wiki
Jump to: navigation, search


Alright, because of the spotty knowledge about lua and how to get everything working correctly, I have put together this thread. It is divided into 4 parts:

1. Setting up basic entities (spawns, resupply bags, etc.) 2. Setting up spawn turrets 3. Setting up locations 4. Setting up your gametype (teamplay or CTF)

I am also assuming you have set up Hammer for FF (you can use FF textures, entities, etc).

Before starting, you need to have two things:

* your map, open in Hammer,
* and a lua file, opened through a text editor. 

If you don't have a Lua file, create it with a text editor as mapname.lua (for example, ff_well.lua). This file should be in the same directory your BSP will be in (for the FF beta, it is SteamApps\SourceMods\ff_beta\maps\ )




1. Basic Entities

You will probably want some basic FF entities for your map. These include Spawns, Resupply Bags, Armor, Health Kits and Grenade Bags. This section will teach you how to get all of these working in your map.

1. Spawns. To get spawn points working correctly, place info_ff_teamspawn point-based entities where you would like players to spawn. Once you have these entities, enter a name for each one on each team. For example, all of the spawn points you want the Green team to spawn at would be named greenspawn. Spawn points for red would each be named redspawn, for blue bluespawn and for yellow yellowspawn. It is important that when you name your entities, you make sure they are all lowercase. Hammer will try to automatically make the first letter uppercase, but the entities won't work right. However you do it, make sure the text is all lowercase.

2. Resupply Goodies For the next four items (Resupply bags, Armor, Health, and Grenades) you start the same way: create a point-based info_ff_script entity. Place it where you want the goodie to be. Change its name to one of the following things to get it to become what you want. Again, it is important that when you name your entities, you make sure they are all lowercase.

a. Resupply bags - For the basic resupply bags, name them color_ammobackpack. For example, if I wanted resupply bags that only the Green team could use, I would name each one green_ammobackpack. The same rule applies for all of the other colors. If you want a pack anyone can use, name it ammobackpack.

b. Armor Kits - For armor, name them color_armorkit. For example, if I wanted armor kits that only the Green team could use, I would name each one green_armorkit. The same rule applies for all four colors. If you want armor anyone can use, name it armorkit.

c. Health Kits - For health kits, name them color_healthkit. For example, if I wanted health kits only the Green team could use, I would name each one green_healthkit. The same rule applies for all four colors. If you want a health kit anyone can use, name it healthkit.

d. Grenade Packs - For back packs containing grenades, name them color_grenadebackpack. For example, if I wanted a grenade pack only the Green team could use, I would name them each green_grenadebackpack. This rule applies to all four colors. If you want a grenade pack anyone can use, name it grenadebackpack

e. Big Packs - For back packs containing everything but grenades, name them color_bigpack. For example, if I wanted a big pack only the Green team could use, I would name them each green_bigpack. This rule applies to all four colors. If you want a big pack anyone can use, name it bigpack


2. Spawn Turrets

Spawn turrets are those pesky turrets that pop down when an enemy enters your spawn and kills them. They can only be on the ceiling. To get these to work, create a point-based ff_miniturret entity. Depending on the team you want it to defend for, name it respawnturret_color. For example, if I want to put spawn turrets in the Green team's spawn to shoot red, blue, or yellow team members who enter the green spawn, I would name them each respawnturret_green. The same rule applies for all four colors. Remember, it is important that when you name your entities, you make sure they are all lowercase.

Next, you open your map's lua file (the second of the two files you need open), and enter this line of text on a blank line at the top: IncludeScript("base_respawnturret"); This makes the turrets you created in Hammer work. Save your map's lua file.


3. Locations

Locations are those areas that appear on the bottom left of your screen, showing you where you are. When you build your map, you customize these locations by creating brush-based entities wherever players enter or exit each area. For example, if I have a map that is just two rooms with a doorway connecting them, I would want players who pass through the doorway to see that they are either in "North Room" or "South Room". I will teach you how to do this using this simple example, but the rule is the same for whether you have 1 entrance to your room, or 12 entrances.

1. First, create a brush, and texture it with the orange trigger texture. Make sure it is large enough to completely cover the entrance to your location.

2. Second, turn that brush into a trigger_ff_script entity. Name it location_roomname. For example, if the name of the location I was identifying was "North Room", I would name the trigger_ff_script location_northroom.

3. Do the above two steps for each entrance to your room. Make sure they all have the same name, and be sure that when you name your entities, you they are all lowercase.

4. Now, open up your lua file again. Enter the following text on a new line near the top: IncludeScript("base_location"); But we aren't finished yet. Scroll down to the bottom of your lua file. We are going to enter new text.

5. On a new line, we are going to tell FF the name we want the player to see for our location. Enter the following text: location_northroom = location_info:new({ text = "North Room", team = Team.kGreen }) Of course replace location_northroom with the name you gave your trigger_ff_script entities and replace "North Room" with whatever name you want players to see for your room. The last piece you need to check is at the end, where it says team = Team.kGreen. This is here because on my map, the north room belongs to the Green team. For your map, change this to correspond to whichever team controls the location (kRed, kYellow, or kBlue instead of kGreen). If it is neutral territory, change it to say team = NO_TEAM

6. Do the above steps for each of your locations, and it should work in game!


4. Setting Up Your Gametype

Thanks to the FF team implementing lua, there are nearly limitless gametypes we can create as mappers for FF. These instructions, however, will only show you how to set up two basic game types: teamplay and CTF.

The setup for teamplay is relatively simple: At the top of your map's lua file, add the following text: IncludeScript("base_teamplay"); Wala! there you go. Save your lua file and you can do team deathmatch or what have you!

For CTF, the set up takes a little more. It begins similarly, however.

1. At the top of your map's lua file, add the following text: IncludeScript("base_ctf");

2. Next, you have to create the flag. Find the location where you want the flag, and create a point-based info_ff_script entity. Name it color_flag. For example, since the flag I am creating is for the Green team, I would name it green_flag. Again, be sure that when you name your entities, you they are all lowercase. The entity's base will be the bottom point of the flag pole.

3. Finally, we create the capture point. Find where you want the capture point to be, and create a brush that the player can walk into to capture the flag. Texture it with the orange trigger texture, and turn it into a trigger_ff_script entity. Now, name it color_cap, with the color corresponding to the team which captures the flag at that point. For example, I am creating a capture point where the green team brings enemy flags to score points. I would name my entity green_cap.

And that is all! Save your map's lua file, compile your map and load it up. All of the above features should work.