DAZZLE'S UPGRADE PACK

If you haven't already done so, upgrade your game by downloading Dazzle's all-in-one upgrade pack. It comes with everything you need for today's servers. Does your blue bar freeze when joining servers? Do you lag in games? Do you get an annoying siren in Phobik's Servers? This is what you need. CLICK HERE TO DOWNLOAD.

Basic Function Tutorial - Originally By Sersh

Modding questions, answers, help.....

Moderators: Warfare, Moderator, Admin

User avatar
Cassie
Veteran Member
Veteran Member
Posts: 371
Joined: Fri Dec 29, 2006 4:45 am
Location: Belgium, Ghent

Basic Function Tutorial - Originally By Sersh

Post by Cassie »

Basic Function Scripting Tutorial

Prologue
This was created by Sersh, credit for the texts and informations go to him.
Don't be intimidated, this is not really that hard.
I broke this up as much as I could to make it as easy as possible.

Part #1: The First Functions
I will explain what they are and what they mean one by one.

1. A OnEnter
This means that when your tank touches/enters an object, something happens.

It will look like this:

Code: Select all

function FUNCTIONNAME::OnEnter(%db, %this, %tank)
{
}
Notice I highlighted FUNCTIONNAME, you can change this to whatever you want, but I would keep it short and simple.

Now, I will explain how to add things to make it actually "do" something. :)

1. B What Can It Do?
If you want to give the person that enters extra points, use this:

Code: Select all

%tank.incScore(3,3);
If you add this exact line it will give the player 3 points when entering the object.
To change how many points are given just change the numbers.

You function should look like this now

Code: Select all

function FUNCTIONNAME ::onenter(%db, %this, %tank)
{
%tank.incScore(3,3);
}
Okay! That wasn't really that hard, wasn't it?
If your already confused, better stop reading.

2.A Adding The Object To A Mission

Place an object in ModWizard where-ever you want the object that has the function to be.
Make sure that this is the actual object you want to add the function to or this won't really work.
Save it.
Now scroll down to where you see the object in the .mis file.
This part is a bit tricky so pay attention!

In the .mis file, you should see something like this:

Code: Select all

new TSStatic() {
position = "-15.0168 -3.39374 231.699";
rotation = "-0.207608 -0.144924 -0.967417 103.418";
scale = "1 1 1";
shapeName = "game/data/shapes/Green/rockgreen05.dts";
treeLighting = "0";
lightBoost = "0";
};
Now, right under that you add this:

Code: Select all

new PowerUp() {
dataBlock = "Reload";
position = "106.898 -46.88 206.269";
rotation = "-0.0203159 -0.00403374 0.999785 209.782";
scale = "1 1 1";
lightBoost = "0";
};
Now all you have to do is copy the "TSStatic's" (the object you placed) position and rotation,
and put it in the PowerUp's position and rotation.

It should look like this:

Code: Select all

new PowerUp() {
dataBlock = "Reload";
position = "-15.0168 -3.39374 231.699";
rotation = "-0.207608 -0.144924 -0.967417 103.418";
 scale = "1 1 1";
lightBoost = "0";
};
Notice how now the rotation and position are the same as the object's?

B.2 Adding the function to the object
Now this part is really easy.

Remember how I said to remember the FUNCTIONNAME in this?

Code: Select all

function FUNCTIONNAME::OnEnter(%db, %this, %tank)
{
%tank.incScore(3,3);
}
Say you want to name it "pointgiver", you'd put this:

Code: Select all

function pointgiver::OnEnter(%db, %this, %tank)
Now, to make it so the function work all you have to do is this:

Remember the power up thing I just told you about? Go back to it and do this:

Change It To:

Code: Select all

new PowerUp() {
dataBlock = "pointgiver";
position = "-15.0168 -3.39374 231.699";
rotation = "-0.207608 -0.144924 -0.967417 103.418";
scale = "1 1 1";
lightBoost = "0";
};
(If you didn't notice I changed "reload" into "pointgiver".

Ok you still aren't done yet though
This is just "making the power-up" so the game knows what "pointgiver" means.
Right under:

Code: Select all

function pointgiver::OnEnter(%db, %this, %tank)
{
%tank.incScore(3,3);
}
Put this:

Code: Select all

datablock powerupdata(pointgiver)
 {
category = "PowerUp";
shape = "game/data/shapes/Common/reload.dts";
type = "bounce";
shadow = true;
shadowAnimation = true;
startOn = true;
minOff = 1; 
maxOff = 2; 
Sound = "PupOnSound";
soundOff = "PupOffSound";
};
So now, those things put together should look like:

Code: Select all

function pointgiver::OnEnter(%db, %this, %tank)
{
%tank.incScore(3,3);
}
datablock powerupdata(pointgiver)
{
category = "PowerUp";
 shape = "game/data/shapes/Common/reload.dts";
 type = "bounce";
shadow = true;
shadowAnimation = true;
startOn = true;
minOff = 1; 
maxOff = 2; 
Sound = "PupOnSound";
soundOff = "PupOffSound";
};
B.3
Remember this?

Code: Select all

new TSStatic() {
position = "-15.0168 -3.39374 231.699";
rotation = "-0.207608 -0.144924 -0.967417 103.418";
scale = "1 1 1";
 shapeName = "game/data/shapes/Green/rockgreen05.dts";
treeLighting = "0";
lightBoost = "0";
};
You can now delete it. :P

Okay! If you made it until here and your not confused yet! Great!

C.1 Where To Place?

C.1.1

Code: Select all

function pointgiver::OnEnter(%db, %this, %tank)
{
%tank.incScore(3,3);
}
datablock powerupdata(pointgiver)
{
category = "PowerUp";
shape = "game/data/shapes/Common/reload.dts";
type = "bounce";
shadow = true;
shadowAnimation = true;
startOn = true;
minOff = 1; 
maxOff = 2; 
Sound = "PupOnSound";
soundOff = "PupOffSound";
};


Goes above the //--- OBJECT WRITE BEGIN --- at the top of the .mis-file.

C.1.2
The:

Code: Select all

new PowerUp() {
dataBlock = "pointgiver";
position = "-15.0168 -3.39374 231.699";
rotation = "-0.207608 -0.144924 -0.967417 103.418";
scale = "1 1 1";
lightBoost = "0";
};
Goes right above the "//--- OBJECT WRITE END ---" part of your.mis file

C.2 Functions

Code: Select all

%tank.incScore(3,3);
Gives the tanker 3 extra points

Code: Select all

%tank.hurtMe(999);
Will damage (and eventually kill) the tanker's tank.

Code: Select all

messageall(10,"YOUR MESSAGE HERE",10);
Will plop the YMH-text into the TT-window (on the same place as where the kill-messages are)

Code: Select all

centerprintall("YOUR MESSAGE HERE",4,4);
Will plop the YMH-text into the TT-window (big letters in the center, "CenterPrint")

Code: Select all

bottomprintall("YOUR MESSAGE HERE",4,4);
Will plop the YMH-text into the TT-window (big letters on the bottom, "BottomPrint")

Code: Select all

messageall(10,%tank.client.namebase SPC "YMH",10);
Will plop the Tankers Name + YMH-text into the TT-window, BP and CP are aviable too

You can also put them together. Like this:

Code: Select all

function pointgiver::OnEnter(%db, %this, %tank)
{
%tank.hurtme(999);
%tank.incScore(3,3);
messageall(10,%tank.client.namebase SPC "picked up the bonus!",10);
}
If you put this, it will kill you, give you three points, and say "(name) picked up the bonus!"

Okay! These are the real basics of scripting.
For more information on scripting, visit these sites/threads:
[/url]
Bloop?
Popped Bot Head
Popped Bot Head
Posts: 246
Joined: Fri Dec 29, 2006 10:34 am
Location: Brigadoon

Post by Bloop? »

what's the relevance of the %db %this %tank bit?
User avatar
Sersh
New Brainjar
New Brainjar
Posts: 59
Joined: Fri Feb 16, 2007 2:34 pm
Location: Austin Texas

Glad to see you still have this.

Post by Sersh »

For the record, I am very impressed with your modification and in no way offended of you using it. I think you made it ALOT easier by adding screenshots. Kudos.

Great job.

-Sersh

Who is online

Users browsing this forum: ClaudeBot [Bot] and 21 guests