|
Tutorial 2
|
|
Step 1: Target Strings
The target strings...
In order to add new targetstrings you need to include
the line:
#strings targetid;
This will look for the file secret ops\language\targetid.eng, if this file does not exist ensure you have created the directory language and compiled tistr.pas and placed it in the language directory of secret ops.
You can then specify object like:
object Midway(Capship)
obj: Midway;
x: 0;
y: 0;
z: 0;
main: M_Midway;
pilot: PILOT_Midway;
direction: 0, 0, 0;
targstr: targetid["Midway"];
end;
notice the line:
targstr: targetid["Midway"];
The names you can use can be found in tistr.pas, if you want to use different names you will have to replace one of the "NULL" options with the text that you want to use and then recompile tistr.pas.
targstr:
can also be followed by an integer, eg 0 or 1 and this will toggle between naming the ship after the type of ship it is and the name of the object.
Step 2: Creating capships
Certain ships (ie those with components) such as the midway must be defined as Capships as opposed to Ships ie:
object Midway(Capship)
instead of
object Alpha1(Ship)
object Midway(Capship)
obj: Midway;
x: 0;
y: 0;
z: 0;
main: M_Midway;
pilot: PILOT_Midway;
direction: 0, 0, 0;
targstr: targetid["Midway"];
end;
The line
direction: 0, 0, 0;
specifiys the direction the capship faces in degrees on the x, y and finally z axis.
Capships should not use SF_ActivateSelf in their main function instead a nav point should activate them using the code
SF_ActivateObject(object name, 0); (make the 0 a 1 if you want the capship to jump in)
for more information on nav points see the end of this tutorial.
Step 3: The IF statement
Sometimes in a function you will only want to perform a set of code if certain condition is met, for example say you only want a nav point to be active when the players ship is currently in it...
if (NAV_WithinSphere(Player)) then begin
NAV_ActivateSelf; //(can only be performed in a nav
points function)
end;
so the if statement is used by:
if(condition) then begin
code to be performed;
any more code;
end;
The above code only cheques for a true or false value, however you could cheque a variable, for example
if(aliensalive=6) then begin
end;
'=' ie is the same as is not the only condition that can be used to check a condition there is also:
' < ' less than, is the first variable smaller than the second eg if(aliensdead < aliensalive) then...
' > ' greater than, is the first variable larger than the second
Step 4: The while statement
Sometimes we will want to repeat code again and again while a condition is true, remember that the automatic value is true so if you do not specify a variable the result will always be true ie:
while(1) do begin
end;
will create an infinate loop, so say for example we wanted to constantly cheque if the player was in the navpoint
while(1) do begin
if (NAV_WithinSphere(Player)) then begin
NAV_ActivateSelf;
end;
end;
Step 5: The until statement
The until statement will repeat the code until the condition is met (ie the reverse of the while loop), this can be useful when waiting for an event, it is presented in the form
until(condition) do begin
end;
so say for example we also wanted to check when a player LEFT a navpoint as well...
until(NAV_WithinSphere(Player)=false) do begin
AI_WaitSeconds(1);
end;
NAV_DeactivateSelf;
once the player is no longer in the nav AI_WaitSeconds(1) will no longer be performed, instead it will continue onto NAV_DeactivateSelf;
Step 6: Calling functions
Sometimes objects will use the same sections of code as eachother but not exactly the same functions, or their functions will get too long to be manageable and you'll want to break them down into smaller functions.
To create a new function which can be accessed by another first decide on its name, then decide on any variables from the function calling it that you wish to pass to this one. A function recieving no values will take the form:
function name;
begin
end;
and will be called by the code:
name;
eg the function F_Landing would look like
function F_Landing;
begin
end;
and be called by:
F_landing;
A function recieving variables would look like:
function name (variable 1, variable 2)
begin
end;
and be called by
name(first variable being passed, second varaible being passed);
Step 7: Spawning Fighters
The following code can be run from any nav points function (or any function which it calls upon) NAV_CreateShip(shipId, pilot, 0, @main, @death, x, y, z);
the shipid can be found in ship.pas, unlike when simply declaring an object a spawned ship must have a shipId as opposed to obj, this shipId is an integar.
Using step 5 we can create a new function to spawn multiple fighters at a time, lets call this function F_Spawn:
function F_Spawn(shipid, count, x, y, z);
var ox,
oy,
oz;
//
// this function spawns "count" ships of type "shipID"
// at coordinates near the ox, oy, oz
//
begin
while(count > 0) do begin
ox := x + SYS_Random(2000) + 1000;
oy := y + SYS_Random(200) + 100;
oz := z + SYS_Random(2000) + 1000;
NAV_CreateShip(shipId, PILOT_Confed, 0, @M_Spawn, @D_Spawn, ox, oy, oz);
count := count - 1;
end;
end;
The easiest way to create fighters with different pilots is to make another version of the function eg F_SpawnAlien. If you do not want the fighter to have a death routine simply put no code in the function D_Spawn. SYS_Random() picks a random number between 0 and the number in the brackets. So for example calling the function using:
F_Spawn(14, 5, 1000, 3000, 500);
would spawn 5 devastators near the co-ordiantes (1000, 3000, 500) each devastator would have the pilot CONFED, the main function M_Spawn and the death function D_Spawn.
Step 8: Code neccessary for multiple nav points
It is obviously possible to declare more than one navpoint, however before doing so you should be aware of some basic code:
SF_BindToActionSphere(nav point number);
This should be placed in an objects main function, it will make the object only viewable on the radar in the specified nav, not including this or setting it to 0 will mean that the object will appear in the radar at every nav point.
SF_AutopilotDisable;
SF_AutopilotEnable;
SF_AutopilotResumeNormal;
There are times when you will want to control whether the pilot can autopilot or not, these functions will override the normal settings (autopilot available whenever an enemy is not present)
NAV_SetPlayerNav(nav point number);
This will be placed inside a navs main function and is used to determine which nav point autopiloting should take the player to next.
At this point we have learned a lot about using nav points correctly so I shall provide you with a new example main function for a nav point called nav 1:
function M_Nav1;
var
setup = true;
begin
while(1) do begin
if (NAV_WithinSphere(Player)) then begin
NAV_ActivateSelf;
if (setup) then begin
**CODE TO BE PERFORMED ON FIRST ONLY TIME IN NAV**
setup := false;
end;
NAV_SetPlayerNav(2);
while(NAV_WithinSphere(Player)) do begin
AI_WaitSeconds(1);
end;
NAV_DeactivateSelf;
end;
AI_WaitSeconds(1);
end;
end;
Step 9: Setting mission success and failure
When the conditions have been met to make the mission a success or a failure use the following code:
SF_SetMissionSuccess;
or
SF_SetMissionFailure;
Step 10: Ending the mission
When the conditions have been met to mean that the mission is completed use the code:
SF_Exit;
This will end the mission.
----------------------------------------
----------------------------------------
T E S T Y O U R S E L F
----------------------------------------
----------------------------------------
Ok I know there is a lot to digest here but ofcourse I'm always more than happy to help with any problems that you may have.
So without any further ado here is the homework:
Create a mission with two nav points. At navpoint 1 the player and fairly close to him the midway (this would be a good time to experiment with the distances in order to get a feel for them). Remember to ensure that the Midway is bound to nav 1. On the setup of nav point 2 spawn 5 fighters in the nav point using a modified version of F_Spawn; give them bug pilots and align them all to hostile. Once the player has killed all the bugs end the mission.
TIP: In order to determine when all the bugs are dead create the global variable aliensalive
var aliensalive = 5;
in the death function used by the bug fighters use the code
aliensalive = aliensalive - 1;
use a while and an if statement in whichever part of the code you feel is apporopriate to constantly check is aliensalive is = 0 and if it is end the mission.
|
|