Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-18-2003, 03:08 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
Scripting Tutorial for Beginners

Okay, i first made this tutorial in a text file, but i thougt it was much more useful to post it here

Graal Scripting Tutorial for Beginners v1.0
1. Introduction
2. “if”
3. timeout - *under construction*
4. setting flags and strings - *under construction*
5. triggeraction - *under construction*

1.-Introduction
Well, this is the Graal Scripting Tutorial for Beginners I made!
Here I will explain you certain basics of GScripting. Just check it out. If something is new/important in a example, it is italic or underlined.
Okay, I hope you know how to open the editor. Open Graal, click on training, then when it’s loaded press F4. Now, create a new level. Click on the guy with the black hair and drag it in the field, then click again to place it. Just click on “close” when the window pop-ups. Double-click on a NPC to open the editor. Now, get the NPC to do something!

2.-“if”
The if command is practically the most important in Gscripting.
If something happens, for example the player touches the npc or says something, a certain event will occur. The script system will recognize this, and if you want the npc to do something when this happens, you need the if command, or some of the others that we won’t discuss here. These events are called “flags”.

Okay, go to the empty space and type in

if (playertouchsme)
message Keep your hands off me!;

Now, close the editor and click on “Play” or press P. Now, touch the NPC. It will say something
As you see, the event is within brackets (). There always is one bracket.
Now, off for a longer script. The NPC will push you away and take some of your health. If we have a longer script, we put that in an other type of brackets {}.

if (playertouchsme){
message Keep your hands off me!;
hurt 1;
}

Test it once again. Nice, no? Try to make some nice funny thingies with the following commands:
Events/Flags:
playerenters - The player enters the level
playertouchsme - The player touches the NPC
wa**** - The NPC was hit by the players’ sword

Commands:
hurt amount; - Hurt an certain amount of damage
message message; - Make the NPC say something (appear above head)
say2 text; - Make the npc say something. Use #b for a new alinea.
hide; - Hide the npc
show; - show the npc

Remember that all commands need to end with ;

2.2-Two flags
Had fun? Now off to something a bit harder. You can say something yourself by pressing
TAB and then type something, and afterwards press Enter. Press TAB again to continue playing.

if (playerchats&&strequals(#c,hello)){
Message good day!;
}

Go play the level and say “hello”. The NPC will say something back.
Have you noticed that if you open a new bracket, you will have to close it again?

About the Events:
Playerchats is if the player says something
&& means “and”
strequals(#c,hello) means if #c (the chat text of the player) is the same as what is typed after the comma. Try this with other chat texts, too.

Now, we’re gonna get the player a hat!

if (playerchats&&strequals(#c,hat please!)){
message here you go!;
setplayerprop #P1,hat0.png;
}

Play and say “hat please!”. You will get a cool helmet. Now, copy this NPC, but change it a bit. The script must contain strequals(#P1,hat0.png). Make it that if the player touches this new NPC, and he has the helmet, he gets another hat, and that hat is hat19.png, and the NPC must say something.

If done well, it should look like this:
if (playertouchsme&&strequals(#P1,hat0.png)){
message here, a nice crown!;
setplayerprop #P1,hat19.png;
}
That was quite hard, no?
But we go on. Now with variables and sub-flags.

2.3-Variables and sub-flags

if (playertouchsme){
players[index].rupees+=10;
}
if (playerchats&&strequals(#c,buy hat)){
if (playerrupees=>10){
message Fine.;
setplayerprop #P1,hat20.png;
players[index].rupees-=10;
sleep 2;
message ;
}
if (playerrupees=<10){
message You don’t have enough money!;
sleep 3;
message ;
}
}

Now, because this is quite hard, let’s do it slow and clearly.

players[index].rupees+=10;
This will make the money (rupees) of the player go up by 10. You can also use
playerrupees+=10; what is easier and shorter. Players[index].rupees is called a variable. Other useful variables are players[index].x, players[index].y, players[index].darts and players[index].bombs.

players[index].rupees-=10;
The same as above, except that the player loses rupees

if (playerrupees=>10){ and if (playerrupees=<10){
if the amount of money of the player is ten or more, the commands in the event will happen. Did you notice that there can be flags IN a flag? It is, that if the player says “buy hat” and he has enough rupees (playerrupees=>10), he gets the hat but loses 10 rupees, but if he hasn’t 10 rupees, (playerrupees=<10) the shopkeeper will say that he hasn’t enough money. This is to make the script much easier etc. We will call this “sub-flags”. Remember that you can also have more sub-flags and still they both work. For example, you can have
if (playertouchsme){
if (players[index].bombs=<50){
players[index].bombs=50;
}
if (players[index].darts=<50){
players[index].darts=50
}
}
and if both bombs and arrows are less then 50 you will get 50 of both, if only the arrows are less then 50 you gain 50 arrows, and if only the bombs are less then 50, you get 50 of those. If you want that if the bombs of the player are less then 50 and the arrows too, you get 50 of both, but if there are less then 50 arrows and more than 50 bombs, you won’t get anything, you should have players[index].darts=<50 and players[index].bombs=<50 linked together in one flag with &&.

sleep 3;
This is for the NPC to wait three seconds. In this seconds, almost nothing happens or can happen. Here it is for the NPC to say something, wait three seconds and then say nothing.

That was hard, no? I hope you still understand it ;-)
Now, there are many other flags and commands. You can find them in the commands next to the editor. Make one NPC that contains all the three practices, but also:
A script if you press A, then you say something.
A script that will say some text with say2 when you throw something against it
A script like in a shop and it sells you a better sword
If the NPC was shot with an arrow, hurt the player

Make another NPC that goes to your weapons when you enter and when you fire it you heal some hearts and the npc gets destroyed. Make the image beer.png



3.-timeout
Timeout is one of the most important commands of GScript. Here is how it works:
if (playerenters){
putleaps 5,x,y;
timeout = 1;
}
if (timeout){
putleaps 5,x,y;
}
As you see, if the player enters you see the water at the place of the NPC. After one second, you see the water again and from then no more. You can use timeout for a loop.

if (playerenters){
putleaps 5,x,y;
timeout = 1;
}
if (timeout){
putleaps 5,x,y;
timeout = 1;
}
Now, the water will come back every time. As you see, timeout can be quite handy =)


I also attached to file in .zip here, it looks a lot better then this.
Attached Files
File Type: zip scriptingtutorial.zip (8.1 KB, 578 views)
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:35 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.