mike@jbgames
 

Scripting Tutorial

Up
Scripting
Objects
Weapons
Waypoints

On This Page
SC Files
+ Creating
+ Exporting
+ Callbacks
SC Commands
+ "If" Statements
+ Syntax
Comments
Sector-Triggered Commands
Help
 

Recommended Resources

Notepad++

Free replacement for Wordpad. The program has syntax highlighting (making parts of the script easier to tell apart), and support for 30+ languages. Make sure to use "C" to properly utilize it.

Info & Download

 

Meteor 2 Scripting Documentation

Directory for all SC commands.

Go

 

Welcome to my complete scripting tutorial for newbies. After you finish reading this, you should have a good idea of how to create basic scripts for any M2 map, and should expand your current knowledge of C syntax and help you to recognize errors. Keep in mind that much of the info is subject to change while new versions of Meteor 2 come out. If so, I'll update asap.


SC Files
Creating
Before anything: In windows explorer, go to Tools>Folder Options. Click the 'view' tab and find "Hide extensions for known file types," and make sure the box is not checked (see pic).

To create a new .sc file, bring up your maps folder (usually games\meteor2\base\maps) and right-click in an inactive space in the maps folder. Point to new, then Text Document. Name this file the exact filename your map is, then type ".sc" at the end of it. For example, if my map was called "basealpha.map", then the script's name would be "basealpha.sc". If you get "If you change this file extension, it may become unusable. Are you sure?", click yes. Then, open your newly created script file. It will offer you a choice of a program to open the SC with. Tick "always use this program to open this type of file," and click Wordpad, or if you downloaded Notepad++, use that.

Now, paste this into your SC file:
 

#title ""
#author "your name here"

#include meteor2

export OnMapStart;

void OnMapStart()
{

}



Export Section
Under the:

#title ""
#author "your name here"

#include meteor2


you will find the export section. Here, you must use the export command. This command is used to tell Meteor 2 what callbacks you'll be using in the callbacks section. A callback is literally a trigger, which fires when something special happens. For example,

 

OnWaypointReached_5()


This is a callback. This particular one activates code below it when any unit reaches waypoint ID 5. The object's ID is NOT defined in the callback text. You must use an "if" statement (talked about later on) to set a specific object ID to activate the callback with. This callback's export command would be:
 

export OnWaypointReached_5;



Callbacks Section
Under the export section you can start scripting. All of the callbacks can be found in the M2 documentary (at the top of this page).

 

When using callbacks, there are three things to remember:

1) Callbacks do NOT use a semicolon ";" after them.

2) Callbacks have parenthesis "()" after them, which contain the callback's parameters. (OnWaypointReached's only parameter is "ObjectId", which is a variable that contains the ID of the object.)

3) Callbacks always have "void" in front of them.

 

Example:

void OnWaypointReached_5()

{

 

}

This is a complete block of coding that will recognize when any object bound to a waypoint hits waypoint ID 5. Such a callback will activate any SC commands or "if" statements between the brackets, in the blue space.


Both sections together

Here is what your SC file should look like:
The file (so far) prepares a trigger for when any unit hits waypoint ID 5.
 

#title ""
#author "your name here"

#include meteor2
export OnWaypointReached_5;

 
void OnWaypointReached_5()
{

}
 


 


 
 = Universal Beginning of ALL script documents

 
 = Export Section

 
 = Triggers Section


SC Commands
Syntax
Meteor 2 uses the programming language C's syntax. Things you'll need to know about such a syntax:

1) At the end of all SC commands, C uses a semicolon ";" to signal that the command has terminated. Note that you do NOT use a semicolon at the end of callbacks, if statements, or brackets.

2) C uses brackets "{}" to organize parts of the script. Brackets are used to contain code under any callback or if statement.


Example:

SC_BindObjectToWaypoint(10,39);

This command binds object ID 10 to waypoint ID 39.

BindObjectToWaypoint <-- The command desired


SC_BindObjectToWaypoint <-- The prefix on EVERY SC command


SC_BindObjectToWaypoint(???,???) <-- The parameters of the command, in this particular command, the first param is the object's ID and the second is the waypoint's. Note that commands can have more than one param.


SC_BindObjectToWaypoint(???,???); <-- The semicolon which indicates a terminated line


"If" Statements
"If" statements check whether a given condition is true.

 

Example:

void OnWaypointReached_5()
{
    if (<VALUE 1> == <VALUE 2>)
    { 
    Code here is activated if Value 1 is equal to Value 2.
    }


Code here is outside of the if statement's brackets, meaning it is executed anyway, no matter if the if statement is true.
}


<VALUE 1> is the variable or "Get" command checking to see if
<VALUE 2> is == to each other. If so, code contained in the {} brackets is activated. void OnWaypointReached_5() is the callback, activating the code below it, enclosed in brackets, which is the if statement.

== is the "Operator" in the if statement, and can be replaced by:

Operator Definition
= = <VALUE 1> is equal to <VALUE 2>
!= <VALUE 1> is NOT equal to <VALUE 2>
> <VALUE 1> is greater than <VALUE 2>
< <VALUE 1> is less than <VALUE 2>
>= <VALUE 1> is greater than or equal to <VALUE 2>
<= <VALUE 1> is less than or equal to <VALUE 2>

Example:

void OnWaypointReached_5()
{
   
if ( SC_GetItemCount("Bullet") >= 500 )

    {
    SC_GameMessage("You have 500 bullets");
    }

}

This block of coding sends the player a message ("You have 500 bullets") if two conditions are true:

1) Any object has hit waypoint ID 5.

2) The amount of the item named "Bullet" which the player currently holds is greater than to equal to 500.

 

Notice that the line with the if statement and the callback does NOT have a semicolon at the end, but the SC command does.

 


Comments
If you put a // in front of anything, the proceeding text will be completely ignored by Meteor 2.

// this is a comment

// SC_SetObjectHidden(1,0);

"this is a comment" and "SC_SetObjectHidden(1,0);" would both be completely ignored by Meteor 2.

 


Sector-Triggered Commands

Please note: In this section, "<TRIGGER>" is a variable you come up with, not simply "<TRIGGER>".
To activate SC commands when the player walks onto a certain sector, you can either type them into the scripting box in the Map Sector Properties, or if you have excessive coding, then you can place such SC commands into your script. Essentially, your are creating your own callback.

 

This is done by using the run command. The run command looks up your custom named callback, and executes its code.

Scripting Screenshot


To execute code under your callback named "<TRIGGER>", you treat it like any other callback. In your SC file, export this trigger by this code in the export section:

export <TRIGGER>;

 

And this in the callbacks section:

void <TRIGGER>()
{
//when the player walks over your sector, code here would be executed.
}

 

 

Example:

export bullets;

 

void bullets()
{
   
if ( SC_GetItemCount("Bullet") >= 500 )

    {
    SC_GameMessage("You have 500 bullets");
    }

}

The above block of coding would send the player "You have 500 bullets" when the player walks over the sector you've associated "bullets" with, but only if the player does have 500 bullets.

Help
If you're stumped and would like your script checked, please sign up to the JBServer.com forums and post under Help.

Go to the JBServer.com: Meteor 2 forum
Sign up

You can also send it to me at mikeMX3000@yahoo.com.