Forums Index >> Modding >> ***Very Basic (Funtion) Scripting Tutorial***



Page : <1> :


***Very Basic (Funtion) Scripting Tutorial***

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.

#1 There are a few functions you should get to know before you start.
I will explain what they are and what they mean one by one.

A.1 The first one is "onenter" this means that when your tank touches/enters an object,
something happens.

It will look like this

 

                                        
function FUNCTIONNAME ::onenter(%db, %this, %tank){
}

 

PS: I will talk about how to make the actuall object "have" the function installed in after you know
the basic stuff.

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. :)

A.2
If you want it to give the player that enters the object points, add this:

 

                                        
%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. :)

Your new function should look like this now.

 

                                        
function FUNCTIONNAME ::onenter(%db, %this, %tank)
{
%tank.incScore(3,3);
}

 

Ok, so that wasnt so hard now was it?
Before I start showing you "add-ons" for the funtion,
you need to learn how to add the function to the object.

B.1

Place an object in Modwizard where-ever you want the object that has the function to be.
MAKE SURE that this is the actuall object you want to add the function to or this won't really work.
Save it.
Now scrioll down to where you see the object in the.mis file.
This part gets a little tricky so pay attention. :)

Ok now you should see something like this

 

                                        
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

 

                                        
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" position and rotation,
and put it in the power up's position and rotation.

In the end it will look like this
So in the end it should look like this

 

                                        
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 funtion to the object.
Now this part is really easy.

Remember how I said to remember the FUNCTIONNAME in this?

 

                                        
function FUNCTIONNAME ::onenter(%db, %this, %tank)
{
%tank.incScore(3,3);
}

 

Say you want to name it "pointgiver", you'd put this:

 

                                        
function pointgiver::onenter(%db, %this, %tank)

 

Now, to make it so the function works all you have to do is this:

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

 

                                        
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";
};

 

CHANGE IT TO:

 

                                        
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:

 

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

 

Put this:

 

                                        
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:

 

                                        
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?:

 

                                        
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

OK GREAT JOB IF YOU MADE IT THIS FAR GIVE YOURSELF A PAT ON THE BACK!

A COUPLE MORE THINGS YOU SHOULD KNOW INVOLVING WHERE TO PUT ALL THIS STUFF. :)

THE:

 

                                        
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";
};

 

Go's above the //--- OBJECT WRITE BEGIN --- at the top of the file.

So it should look like this

 

                                        
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";
};
//--- OBJECT WRITE BEGIN ---

 

Ok and if you remembered correctly the:

 

                                        
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";
};

 

Go's right above the "//--- OBJECT WRITE END ---" part of your.mis file

It should look like this

 

                                        
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";
};
//--- OBJECT WRITE END ---

 

Ok so now you know where everything goes.
Now we'll talk about those sweet add ons to your funtion. :)

Starting with just the point giving we will ad on to it.

 

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

 

This gives you three points when you enter the object.

Adding this will make your tank die when you enter the object.

 

                                        
function pointgiver::onenter(%db, %this, %tank)
{
%tank.hurtme(999);
}

 

Now this is one of my favorites:

 

                                        
function pointgiver::onenter(%db, %this, %tank)
{
messageall(10,"YOUR MESSAGE HERE",10);
}

 

Now when you enter the object, it will there will be a messsage at the bottom of the screen
saying whatever you want it to!

And there is also something you can do with this, but it's kinda complicated.

If you want to know who entered the object put this:

 

                                        
function pointgiver::onenter(%db, %this, %tank)
{
messageall(10,%tank.client.namebase SPC "picked up the bonus!",10);
}

 

Now, say a guy name Sersh enters the object, it will say,

Sersh picked up the bonus!

Pretty cool eh?

Oh and dont forget you can add all these together so it looks like this!

 

                                        
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!"

Alright those are just the very first basics of scripting
All I taught you was how to add a funtion.

If you have ANY problems are just questions ask away!

Oh and PS:
@scriptors if I messed something in writing the funtion just tell me and I'll change it.

I really hoped this helped.

-Sersh

Only lethal on days that end with "Y"

Last edited: Sunday, May 21, 2006 at 5:37:28 PM

Saturday, May 13, 2006 at 11:00:31 PM

Looks cool, I'm gonna test it out! Thx for the tutorial Sersh! XD

- C@S

EDIT : can you also make it that it clones, heals, changes tank or so? If yes, plz tell me what you have to fill %)
EDIT² : shouldn't it be "%tank.hurtMe(999);" in case of "%tank.hurtme(999);" Since 'Me' is a object. (I'm not good at this,though)

 

 

 

 

Last edited: Sunday, May 14, 2006 at 2:23:04 AM

Sunday, May 14, 2006 at 12:58:02 AM


 

                                        
function powergate::onenter(%db,%this,%tank)
{
%choice = getRandom($NumPupTypes-1);
%tank.setProjectile($pupTypes[%choice]);
if (isObject(%tank.client))
%tank.client.schedule(1000,"play2D",$pupSnds[%choice]);
}
Datablock PowerUpData(powergate)
{
category = "PowerUp";
shape = "~/data/shapes/common/Recharge.dts";
type = "weapon";
minOff = 1;
maxOff = 1;
startOn = true;
shadow = true;
shadowAnimation = true;
aiPickup = true;
Sound = "PupOnSound";
soundOff = "PupOffSound";
};

 

Remeber the top lines are the actual function the bottom is the creation of the power up type.
I named it power gate, so place a reload gate in mod wiz, copy the position and rotation into the new power up.
If you didnt remember what the power up looks like, here:

 

                                        
new PowerUp() {
dataBlock = "powergate";
position = "-15.0168 -3.39374 231.699";
rotation = "-0.207608 -0.144924 -0.967417 103.418";
scale = "1 1 1";
lightBoost = "0";
};

 

Again, they have to have the same datablockname as the function and new datablock (on the top of your.mis) in order for it to work. See how I named the datablock powergate?

Now I'll explain what most of this means.

 

                                        
function powergate::onenter(%db,%this,%tank)

 

This is creating a new function and it is naming it "powergate". The "onenter" part is self-explanatory.

Now I'll explain what most of the new "datablock" you are making.

Datablock powerupdata(pointgiver) // This is creating a new datablock
{
category = "PowerUp"; // This is to make sure that what category it is in.
shape = "game/data/shapes/Common/reload.dts"; //Change this if you want to change the shape of the object it will be
type = "bounce"; //Thi is explaing what type it is.
shadow = true; // pretty sure this means if it has a shadow or not.
shadowAnimation = true; // again I think it has something to do with th shadow.
startOn = true; // This tells you if you want to have the power up already there when you start the game
minOff = 1; // This tells you how long it will take for it to "come back" once it has been taken (in mili-seconds)
maxOff = 2; // make sure this number is either larger or the same as the above number.
Sound = "PupOnSound"; // What sounds it will make when taking
soundOff = "PupOffSound"; // same.
};

This is creating a new datablock If you noticed right by each line I told you what it does.

Now, say you want to remind yourself about what goes where on the function. Mkae sure you use the //.
What this does is it tells the game to ignore whatever you right after that.
So if I put:

 

                                        
function powergate::onenter(%db,%this,%tank)
{
%choice = getRandom($NumPupTypes-1); // Keep one.
%tank.setProjectile($pupTypes[%choice]);
if (isObject(%tank.client))
%tank.client.schedule(1000,"play2D",$pupSnds[%choice]);
}

 

Then the game would automatically not read the line after "//". Make sense?

Alright I'll keep adding things to this every once and a while.

AGAIN, if you have any questions or problems feel free to ask.

Only lethal on days that end with "Y"

Last edited: Sunday, May 21, 2006 at 5:36:54 PM

Sunday, May 14, 2006 at 6:54:38 AM

Ya, but I just figured out the code tag doesnt work for the new datablock. Check up there to see, it puts it in the box..but it's still capitalized.

Only lethal on days that end with "Y"

Sunday, May 14, 2006 at 7:14:56 AM

Lol A little off-topic but, I really gotta wonder why some of you guys aren't in school. As for me I'm homschooled I finished a few weeks ago. :P

A couple more add-ons for the function.

 

I think you should give credit where credit is do...-CS

 

:P

From chongs soccer script.

 

                                        
function greenpoint::OnEnter(%this,%db,%tank)
{
%team = "greenTeam";
%team.score += 2;
%team.cumScore += 2;
Messageall('MsgTeamScoreChanged', "The green team picked up a bonus", %team.score, %team.cumScore, %team.getId());
}

 

And

 

                                        
function bluepoint::OnEnter(%this,%db,%tank)
{
%team = "blueTeam";
%team.score += 1;
%team.cumScore += 1;
Messageall('MsgTeamScoreChanged', "The blue team scored a goal!", %team.score, %team.cumScore, %team.getId());
}

 

This is a function for your team, In the top one's case it is for the green team. In the bottom one's case it is for the blue team.
What this does is:
Gives the team a point if someone grabs the power up.
I'll try to explain it:

Function bluepoint::OnEnter(%this,%db,%tank) // this creates the function, it is named bluepoint.
{
%team = "blueTeam"; // This tells the game to give the point to the blue team
%team.score += 1; // The 1 shows how many point it will give, because it is 1, it will give your team one point
%team.cumScore += 1; // pretty sure this means about the same as above.
Messageall('MsgTeamScoreChanged', "The blue team got the bonus", %team.score, %team.cumScore, %team.getId()); // this shows a message when someone picks it up.
}

Ok, one more for now. This one is kind of complicated but if you get it right is very usefull to use.

What this does is it only allows a player to get the power up if they have a certain name. This one is used in the soccer script so only the ball can score.

 

                                        
%client = %tank.client;
if(getSubStr(%client.namebase,0,4) $= "YOURNAME")

 

Since this one has an "if" statement it will need it's on little place in the function, like so:

 

                                        
function ::OnEnter(%this,%db,%tank)
{
%client = %tank.client;
if(getSubStr(%client.namebase,0,4) $= "YOURNAME")
{
%tank.hurtme(999);
}
}

 

Alright, enough add-ons.
Wondering what all the "{"'s and "}"'s are for ?
Quite simple

Right after the "function ::OnEnter(%this,%db,%tank)" you'll need to put one "{" meaning the function is open to any thing you add.

Then you will put all the little add ons to the function right after that (after the { )

When you are finished adding things to your function you will need to close it using the }.

Notice the "if" state ment function needs it's own "{"? For every "{" you will need to put a "}" at the end of the function.
That's why there were to }'s at the bottom of that function.

-Sersh

Only lethal on days that end with "Y"

Last edited: Sunday, May 21, 2006 at 5:40:27 PM

Sunday, May 14, 2006 at 7:42:46 AM

Hm...a gametype tutorial would be nice :P But thanks for making this, Ishbuu's confused me. :'( I wonder what gametype I can make...if I figure this out :o.

 

Sunday, May 14, 2006 at 10:13:01 AM

Sersh, You don't need "{" or "}" on any one line conditional statement.

Ritz, I'll right a gametype tutorial.

Sunday, May 14, 2006 at 11:54:43 AM

Oh ok thanks didnt know that. But I guess it still works though eh? XD

Only lethal on days that end with "Y"

Sunday, May 14, 2006 at 1:39:54 PM

Yes,

 

                                        
if (!$ConditionTrue)
return;

 

And

 

                                        
if (!$CondtionTrue)
{
return;
}

 

Would work.

Sunday, May 14, 2006 at 7:11:27 PM


^ DA MAN ^ XD

 

 

 

 

Monday, May 15, 2006 at 2:48:25 AM
b20

Well Sersh, you have came from a bad reputation from the past to a bright one! I'm proud of you very much! Good and easy tutorial also since I'm extreamly newbie at this! (CannedSplam might have an idea on how newbie I am at scripting! :P)

- b20

Wednesday, May 17, 2006 at 3:28:56 PM

Thanks Comp, I'm really not all that good I just fealt like we needed a nice easy function tutorial. :)

Only lethal on days that end with "Y"

Wednesday, May 17, 2006 at 6:53:35 PM

This doesn't cover functions, it merely covers OnEnter, and some static and non static datablocks. There is truly a lot more than just this for "functions."

Cs

Also, you haven't covered nearly as much as needed on OnEnter functions.

 

                                        
function DATABLOCK::OnEnter(%db,%this,%tank) // you should explain what those variables signify, as they are very important
{
%client.hurtme(999);
}

 

Now, sersh, tell me... Would that work?

If so, what would happen?

Now you tell me, what about this:

 

                                        
function BlueCheck()
{
%blue = false;
if (%client.team == "BlueTeam")
%blue = true;

return %blue;
}

 

Now, what would this do? Would it work? What is wrong with this (for Sersh to answer)

It seems that you are teaching things, but not explaining them. Not good....

This is just me trying to teach something... My lesson

This is also me trying to hold back what I really want to say about this "tutorial"

EDIT: I am noticing this:

 


function bluepoint::OnEnter(%this,%db,%tank)
{
%team = "blueTeam";
%team.score += 1;
%team.cumScore += 1;
Messageall('MsgTeamScoreChanged', "The blue team scored a goal!", %team.score, %team.cumScore, %team.getId());
}

 

That can be found word for word in Chongs soccer "script"

Now, there are problems, which you cannot point out, obviously.

Also, since you are supossedlly teaching us, shouldn't you properly explain the function. It is pretty obvious %team.score += 1 will add a point, but why?

Then explain why Messageall('MsgTeamScoreChanged', "The blue team scored a goal!", %team.score, %team.cumScore, %team.getId()); was included, as there is a good reason for that also.

I might also add that these goals, they aren't very good. Notice, anyone can go into it and it wil give a point to the team specified. That, along with making two is unnecessary...

I wont fix these, because I think that you need to understand that finding functions and studying other functions from other people is great, but you aren't learning how it works, you are just learning that this does that... Not why... Not how it goes wrong.... You arent explaining why important things are important.

God its hard to hold back how I really feel.... *self control... Self control... Remember, self control*

Last edited: Saturday, May 20, 2006 at 8:51:30 AM

Saturday, May 20, 2006 at 8:27:55 AM

Function pointgiver::onenter(%db, %this, %tank)
{
%tank.incScore(1,1);
}
Datablock powerupdata(pointgiver)
{
category = "PowerUp";
shape = "game/data/shapes/ogmshapes/checkpoint2/checkpoint.dts";
type = "bounce";
shadow = true;
shadowAnimation = true;
startOn = true;
minOff = 1;
maxOff = 2;
sound = "PupOnSound";
soundOff = "PupOffSound";
};

Ok I used this and apparently, its no cooperating with my mod.

Sunday, May 21, 2006 at 7:23:06 AM

The first letter in ANY line of TorqueScript code should NEVER be capitalized. Uncap everything. IMPORTANT!!!

Sunday, May 21, 2006 at 7:47:56 AM

Leech, you wouldn't want to be contacting sersh for help on this....

Sunday, May 21, 2006 at 7:53:17 AM

Actually CS I fixed it BUMP

Sunday, May 21, 2006 at 8:10:05 AM

Ok sorry that I havnt posted in a while I was away.

@Canned, This is a very basic tutorial I remember when I was trying to understand all this crap and it was very hard.
Trying to explain the functions just makes things harder. This tutorial is for knowing what the very BASIC things are. If you want to get complicated go to Ishbuu, he will be happy and generous to tell you everything you need to know (not). I still dont understand why you still have a grudge.

As for chongs script, THAT IS NOT MINE. I DIDNT SAY IT WAS MINE. I am simply trying to explain things. I'm doing nothing wrong if you think I am report me. I'd be happy to argue with more people...(not)

It's good to see that you fixed it leech sorry I wasnt around to help for a while.

Not so much Peace.

Only lethal on days that end with "Y"

Sunday, May 21, 2006 at 5:30:49 PM

FYI, Im not looking for any explanation from you.... I know that stuff already. 8o

Tuesday, May 23, 2006 at 6:42:35 PM

Sorry, but it really looked like it from my angle...

 

That can be found word for word in Chongs soccer "script"

Leech, you wouldn't want to be contacting sersh for help on this....

 

 

It seems that you are teaching things, but not explaining them. Not good....

This is just me trying to teach something... My lesson

This is also me trying to hold back what I really want to say about this "tutorial"

 

 

I wont fix these, because I think that you need to understand that finding functions and studying other functions from other people is great, but you aren't learning how it works, you are just learning that this does that... Not why... Not how it goes wrong.... You arent explaining why important things are important.

 

I'm serious..I'm really not trying to argue with you... I'm just showing you why I posted that.

 

Only lethal on days that end with "Y"

Last edited: Tuesday, May 23, 2006 at 7:57:09 PM

Tuesday, May 23, 2006 at 7:56:35 PM

Err... Don't make this thread go to a Flamewar and get it locked. This thread IS good.

 

 

 

 

 

Last edited: Sunday, June 04, 2006 at 5:48:04 PM

Tuesday, May 23, 2006 at 8:55:55 PM

Hmm... Late Night Bumpy.
I'm gonna try the new functions, too, now. :)

 

 

 

 

Sunday, June 04, 2006 at 5:49:19 PM

This is in "The Modding Resource" so it doesn't need to be bumped, but thanks anyway. ;)

Only lethal on days that end with "Y"

Sunday, June 04, 2006 at 8:16:48 PM

This is to "CONFUSING." sorry...

My Web Site- GameForums.com On Sunday, August 34 2006 become a member of my forums with many game topics!
-Gort

Thursday, June 29, 2006 at 2:36:52 PM

 

 

TorqueScript is case-sensitive

 

I don't know why noone correct DJ... Probably didn't notice, but thats wrong. TSL Is NOT case-sensitive. Unlike other languages if you create a variable names %hello you can call it by using %HeLlO ot %hellO. If you name a function startGame, you can call it sTarTgAme or whatever. It's just more "correct" in terms of easyness for the eyes, if you capitalize letters after a "space" (for example, a function that consists of 2 words like hurt + me, we'd capitalize the "m" to denote a space between "hurt" and "me") but this is completely optional to the scriptor


Friday, July 07, 2006 at 2:51:46 PM

Can we stop bumping this

Friday, July 07, 2006 at 5:25:19 PM

Aye, moderators may lock this. Just please dont delete it because it is in the modding resourse.

-Sersh

Only lethal on days that end with "Y"

Saturday, July 08, 2006 at 8:58:19 AM

Very good sersh

But I want to ask

How to make a reaload

That the first tank enter it get 5 point

And the second tank get 4 point........etc

Tell me how sersh :)

 

Saturday, July 08, 2006 at 10:16:34 AM

Well, I'm not exactly sure how to make a datablock function change after one thing has gone through it. All though T-Bone had his own way of doing it.

He'd line up 3 reload gates in a line (One each behind each other.)
Then He'd make em all teleporters.
He would make the first one 5 points.
The seconed one 4 points.
The third one 3 points.

Get what I mean? It would look something like this.

------- (reload gate)
If your tank was following where the arrow is pointing.

|
|
|
V

---5----
---4----
---3----

If you really want to know how to do this (Changing a datablock function) Ask a more experienced scriptor like Warfare or Canned)

-Sersh

Only lethal on days that end with "Y"

Last edited: Saturday, July 08, 2006 at 10:41:21 AM

Saturday, July 08, 2006 at 10:40:25 AM

It can be done with packages, ifs... And, well... Maybe something else :P


Saturday, July 08, 2006 at 11:49:34 AM

Sorry for bumping this, but I have a little question. How to set this thing like (in messageall)

 

*Cassie* PBx : (GreenTeam) : Has Teleported To The Seats!

 


I tryed this

 

Messageall(10,%tank.client.namebase SPC ": (" %client.team ") :" "Teleported To The Seats!",10);

 


But that gave this syntax error in console

 

Messageall(10,%tank.client.namebase SPC ": (" %client.#t#eam ") :" "Teleported To The Seats!",10);

 

Ty, Cassie.

 

 

 

 

Monday, July 10, 2006 at 9:12:59 AM

Page : <1> :

insert quote insert url insert email insert image bold italic underline superscript subscript horizontal rule : : Help on using forum codes

Add comment:

HTML is disabled within comments, but ZBB Code is enabled.

Back to the top

Web site designed, maintained and funded by -z- and Dan MacDonald