For more information, check out the help page for add_mob_script.
Once you've learned the basics of scripting, it's really not that complicated, and scripts are really entertaining to write. The basic concepts you need to know in scripting are the mob number, the trigger command, the actor number, the discriminator string, the target number, and the precedence. For this tutorial, I'm going to walk you through mob scripting first, and then explain the differences in room and object scripting later. They're all almost identical actually, except for a few concepts, so once you've learned one, the others will be a piece of cake!
Mob number: this is the number of the mob that the script will reside in. The mob the script resides in is the mob that will act out the script.
Trigger command: this is the command that triggers the script. For example, if you want the script to be triggered when someone enters the room, you'd select "enter", or if you wanted it to be triggered when someone drops an object, you'd select "drop".
Actor number: This is the number of the mob which can trigger the script. If you're building a script on Bob the shopkeeper, and you want his script to be triggered when Joe the citizen walks into the room, you'd put Joe's vnum here. If you want anyone to be able to trigger the script, put -1.
The discriminator string: this is an optional entry that can be used to make the script triggered on something exact. For example, if you wanted Bob the shopkeeper's script to be triggered when someone says "hello", you'd put 'hello' here. If you want a script to be triggered when someone tells the mob 'tell me about the mines', you might put 'tell me about the mines' here. This can be something as simple as a word, or as complex as a few sentences. If you want a number for the discriminator string, put 'DESCRIM_' before it, as in 'DESCRIM_100', or it won't work. If you don't want any discriminator string, just put 'NA'.
The target number: This can be either a mob or object number, but it has to be whichever makes sense to the trigger command. If the trigger command is give, it'd need to be an object number, but if it's kill, it'd need to be a mob number. This isn't too commonly used, but it's for cases where you want the script to be triggered on someone doing something to something. For example, if you wanted the script to be triggered when someone gives object 100 to Bob the shopkeeper, you'd put the object's vnum (in this case, 100) here.
Precedence: This controls how important the script is. For example, if Bob the shopkeeper has two scripts, and you want the first script to stop when the second script is triggered, you'd give the first script a precedence of 0 and the second script a precedence of 1. Now let's say you add a third script which you want to override both of the others. You'd have to give the third script a precedence of 2. If you want a fourth script that gets ovverriden by the second and third scripts, you'd set its precedence to 0. To sum all of that up, higher numbers will override lower numbers. Generally you'll just want to have 0 for all the scripts so that they'll all run regardless of each other. NOTE: if several scripts of the same precedence are triggered at the same time, then up to ten of them will be queued, and will run one-after-the-other.
Now that you know what all of these terms mean, you're ready to enter the script itself. Scripts are just a compilation of normal commands, which the mob will act out, so all you need to do here is enter the commands that you want the mob to do. You need to separate the commands with double-semicolons, because these will be treated by the game as single semicolons and separate the different commands in the script. Here's a valid script:
say Hello there!;;bow;;say What's up?;;
You need to put double-semicolons after every command in the script.
You can do more complicated things than that with the actual script, though. For starters, you can make the script pause with the "pause" command. Here's an example:
say Hello there!;;pause 3;;bow;;
The number after the pause is the number of battle ticks that the script will pause for. A battle tick is around 2 seconds, so the script above would pause for 6 seconds or so before continuing. Other valid commands of this type are: pause, exact_damage, oload, mload, affect_hp, affect_mana, affect_mov. See 'help comparators' and 'help does_own' for more information.
You can also add the actor's and target's names to the script. Let's say you've got a script triggered on enter. Shamu strolls into the room, and the script is triggered. %M is the command to fill in the actor's name, so if your script was:
say Hello, %M!;;
Shamu would see:
Bob the shopkeeper says, 'Hello, Shamu!'
Other valid similar commands are:
%M: The actor's name
%m: The target's name if it is a mob
%o: The target's name if it is an object
%S: The name of the room, mob, or object which is executing the script
That's all of the basic scripting functions! You're now capable of making a pretty impressive script!
Don't think that's all there is to scripting, though. It can get a *lot* more complicated than this!
The next significant thing you can do are constructs and conditional commands. You should probably be relatively competent with basic scripting before you try to do anything of this caliber, or even read this section. From here on, uncompiled are scripts are broken up one command per line or easier reading. Take note: this section is a *lot* more complicated!
Let's say you've got a script where you want the mob to say something different based on whether or not the actor has object 100. You would do this with a conditional command. Here's an example:
say Hello;;
say Do you have the 30-foot Q-tip of death?
**%M if does_own 666;;
say Indeed, you have the 30-foot Q-tip of death!;;
else;;
say You lack the 30-foot Q-tip!;;
end;;
In the above script there are two new commands. The first is **%M, which is similar to %M, which you already know specifies the name of the actor mob. **%M specifies that the actor mob is the one who the following command (if does_own 666) is done to. **%M can be used with any command, not just if statements. Valid commands of this type are **%M, **%m, **%S, and **%o, and specify the action that is to be taken by the specified entity (%M, %m, %S, %o).
The second new command is the "if" statement. This is just a conditional command that checks to see if the following statement is true or not. In this case, it's checking to see whether the actor mob owns object 666. (**%M if does_own 666). Valid commands of this type are: does_own, is_in_posn (the specified entity is in the specified position), TRUE, and FALSE.
When using if statements, you need to have an else statement in there somewhere to tell the script what to do if the if statement is false. You also need to have an end statement to tell where the if statement ends. This is so that you can put more commands after the if statement, for example:
say Hello;;
say Do you have the 30-foot Q-tip of death?
**%M if does_own 666;;
say Indeed, you have the 30-foot Q-tip of death!;;
else;;
say You lack the 30-foot Q-tip!;;
end;;
say Thanks for coming.;;
This script is identical to the last, except for the last say command. Here, whether the actor has object 666 or not, the mob will say "Thanks for coming." Here are the two scripts that could happen depending on whether the actor has object 666:
if does_own 666 is true:
say Hello;;
say Do you have the 30-foot Q-tip of death?;;
say Indeed, you have the 30-foot Q-tip of death!;;
say Thanks for coming.;;
if does_own 666 is false:
say Hello;;
say Do you have the 30-foot Q-tip of death?;;
say You lack the 30-foot Q-tip!;;
say Thanks for coming.;;
That pretty much sums it up for the scripts themselves! Read the help file for "add_mob_script" as it's where all the info comes from, and it gives a full listing of everything you can do with scripts.
Room and object scripts follow the same syntax as mob scripts, except they're used on objects and rooms. See the help file for add_mob_script for the different commands you can use in room and object scripts.