Modding, Mission Design, and Coding > The FRED Workshop

Karajorma's Advanced FRED2 Lessons

<< < (2/7) > >>

what's with the tech room mission simulator ? I hear only to banters in mission two, when I start it in the sim.
Maybe it is bad luck, but...

Only two?

Yeah I think I know the cause of that. I think the game is loading persistent variables in the techroom instead of defaulting to the initial value set by the FREDder as it was originally designed to do by Goober. I'll have to test it and see if I'm right. It shouldn't be hard to fix if that is the case.

Let me guess. When you completed the campaign the last time you played it you had to play the mission 3 (or possibly 4)  times before you completed mission 2, right? Try restarting the campaign and see if that gives you more sets of banter (You'll need to press CTRL + SHIFT + S in the flight simulator in order to get access to BoaL again once you reset of course).

yes, i choose tried high difficulty last time and had to repeat it about 4 or 5 times. The Raiders were no problem, the Asteroids were deadly  :)

worked, hearing all banters again :yes:

You can find part one here.

Well I did say I might do a part two based on King of the Hill and since I recently got a request for it, here goes. :) For those who haven't played it King of the Hill is a multiplayer TvT mission with a bit of a twist. Instead of winning by destroying the enemy forces the idea was to enter and hold an area of space for predetermined length of time (2 minutes) without dying. The first player to enter the area is King of the Hill. He remains the king until he either exits the area or is killed. At this point the player who has been in the area the longest becomes the new king.

Doing this required very heavy use of variables. I'm assuming that anyone reading this has already read the section in my FAQ on using variables and at least has an idea how to create and modify variables even if they don't understand exactly how or why to use them.

Setting up the constants

As I did in Birth of a Legend I've set up two variables to act as constants. In this case they are true constants because I never alter them during the mission.

CONST-KotH-Distance is the radius of the area that the player has to hold in order to win. In this case 1km.
CONST-WinningCount is the amount of time the player needs to hold the hill in order to win. 120 seconds in this case.

By setting these constants and using them in the mission I left myself some wiggle room if I found during balancing that they were too big or too small. All I'd have to do is alter the constant and the rest of the mission would automatically update.

Who is the King?

The first problem that needs solving is telling who is going to be King. To do that I need to determine who has been in a certain area of space for the longest time. So I added a waypoint in the middle of the hill area and simply added to a variable every time the ship in question was close to it. The event has a high repeat count and a 1 second interval same as many of the events in this mission. This event checks Green 1. Obviously I needed a separate variable and event for each ship.

Then I needed a similar event resetting the counter if the ship left the hill area. This was basically the reverse of the previous event. Finally I needed an event to check who had been on the hill the longest. Again I needed one of these for each ship.

REQ-King-check is simply a boolean which tells me if I need to crown a new king. The CurrentKing variable however is a little more interesting. Due to the way FRED sanity checks everything on mission load this had to point at a ship on mission load. I solved this by adding a stealthed fighter miles off in the distance called A Ship. Both variables are string variables. I could have used a number variable for the first one (with 0 representing false and 1 representing true) but I've always preferred to use a proper Boolean hence the YES/NO options.

The upshot of this event is that if Green 1 has been on the hill longer than anyone else he'll become king.

Requesting A New King

 If the player who was king exited the game or the hill someone else should become king. This was fairly simple.

Setting this variable to YES triggers another event which in turn resets the king.

The programmers amongst you will recognise this as a crude attempt at a function/method call in FRED. :)

I did things this way because when first designed there were several ways that a king could be reset and it made sense to have that in its own event rather than copying and pasting it into multiple places. Later on I trimmed out the other paths and was left with this rather strange piece of code as a result.

As you can see the event sets everything back to its default state except for REQ-King-check which as you saw above tells the game to select a new king. KingCount is a simple counter which is counting how long the king has been king. It's updated in the same way as counters for each ship were updated except that instead of testing green 1 etc it simply tests the distance CurrentKing is from the node.

Saying who is king

Next came a few events to notify the players who was winning. These ended up a little more complicated than they absolutely needed to be because rather than reporting how long someone has been king for in seconds it does it in second and minutes. (Someone sent me a suggestion that I should do this along with an edited mission but I'll be damned if I can remember who!).

First I only want updates every 10 seconds so we test whether KingCount is exactly divisible by 10 using the mod SEXP. We test the value of WinningShip because we don't want to send messages after someone has won.

Since I want to give a special warning when someone is one minute or 30 seconds from winning I test that's not true.

The action part of the event then sets the value of a couple of variables which will be used in the message. The message text is as follows

--- Quote ---$CurrentKing holds the hill and has been king of the hill for $KingMin minutes $KingSec seconds.
--- End quote ---

FS2 checks if there is a variable with the name following the $ symbol and replaces it with the value if there is. Since these messages will be played on the client machines as well as the host all variables used in messages had to be marked as network variables so that they were also updated on the client machines. If this wasn't done the messages would have outputted the default values for the variables in every message. Only variables that were used in messages were marked this way though. The game is updating several variables every second and it would completely lag everything if all the updates of those were sent out to the clients. Furthermore the clients wouldn't do anything with them anyway!

A similar event and message were used when the clock was still under 60 seconds for any ship (rather than "y holds the hill and has been king of the hill for 0 minutes x seconds").

Anyway, those were the more complicated problems I remember having in the mission.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version