How to create goals in your level
Okay, so you have a great singleplayer level built up and you want to get the mission objectives working. This can be done by editing only three files, make back ups of your current ones before editing them:
MSGS 7 # Updating this count is vital!!!!!!! |
Fill in as many goals as your level requires, update the message count, and save it to your project directory. Be sure to take note of the goal numbers. That is all the editing required for the cogstrings.uni!
# Generic Goals Script # (c) 1998 Code Alliance symbols message entered message sighted message activated message killed sector goal0sector0 thing SightedThing thing DeadGuy switch TriggerSwitch int done0=0 local int done1=0 local int done2=0 local int done3=0 local end # ======================================================================================== code entered: if((!done0) && (GetSenderRef() == goal0sector0) // when the specified sector is entered //and if it has not been entered yet, then do : { SendMessageEx(GetMasterCOG(), user0, 0, 0, 0, 0); //sends goal 1 to the master cog... done0 = 1; //keep it from happening again Return; } Return; # ........................................................................................ sighted: if (!done1) && (GetSenderRef() == SightedThing) // Make sure it is the correct thing. { SendMessageEx(GetMasterCOG(), user0, 1, 0, 0, 0); // Send objective 2 done1 = 1; } Return; # ........................................................................................ activated: if (!done2) && (GetSenderRef() == TriggerSwitch) // Is it the right switch? { SendMessageEx(GetMasterCOG(), user0, 2, 0, 0, 0); // Send objective 3 done2 = 1; } Return; # ........................................................................................ killed: if(!done3) && (GetSenderRef() == DeadGuy) // Did the right guy die? { SendMessageEx(GetMasterCOG(), user0, 3, 0, 0, 0); // Send objective 4 done3 = 1; } Return; end |
Take note at the IF Statements for every message. They do a simple check to make sure that the correct thing hasn't happend yet and that the occurence is for the correct sector, surface, etc..
As you can see, this cog is pretty simple to understand, granted you know the correct cog functions.
# Generic Master Cog File for goals # (c) 1998 Code Alliance # ======================================================================================== symbols message startup message user0 int player local sound goalsnd=Accomplish1.wav local end # ======================================================================================== code startup: SetMasterCOG(GetSelfCOG()); player = GetLocalPlayerThing(); // Goals SetInv(player, 99, 1000); // These next 5 lines set up the needed goals on the objective // screen at startup // Display at startup of level. SetGoalFlags(player, 0, 1); SetGoalFlags(player, 1, 1); SetGoalFlags(player, 2, 1); SetGoalFlags(player, 3, 1); Return; # ........................................................................................ // The user0 message waits for a message from the goals.cog, nothing will happen // in this message until goals.cog tells it to happen. user0: jkPrintUNIString(player, 350); //prints "mission objective reached" if(GetParam(0) == 0) // If the parameter for goal 1 is met { PlaySoundThing(goalsnd, player, 1.0, -1, -1, 0); //plays sound SetGoalFlags(player, 0, 2); //Sets goal one as accomplished. Print("YourMessage"); //Print the message if you want one Return; } if(GetParam(0) == 1) // If goal 2 is met { PlaySoundThing(goalsnd, player, 1.0, -1, -1, 0); SetGoalFlags(player, 1, 2); Print("YourMessage); Return; } if(GetParam(0) == 2) //Goal Three { SetGoalFlags(player, 2, 2); PlaySoundThing(goalsnd, player, 1.0, -1, -1, 0); Print("YourMessage); } if(GetParam(0) == 3) //Goal Four { SetGoalFlags(player, 3, 2); PlaySoundThing(goalsnd, player, 1.0, -1, -1, 0); Print("YourMessage); // Wait a bit before level ends Sleep(4.0); jkEndLevel(1); Return; } Return; # ........................................................................................ end |
As you can see, the master cog pretty much acts as a relay between the goals.cog and the cogstrings.uni .
If you would like to have a "hidden" objective (I.E. Not known until another objective is met), simply do not add the SetGoalFlags(player, GoalNumber, 1); line for your goal. Place it inside of the if(GetParam(0) == 0) function. This will have it display the next goal only after completing the preceding one.