Builder:Scripting

From Wormhole Sci-Fi MUD Homepage

Jump to: navigation, search

This brief guide will hopefully be added to by the others who use scripts to enhance their areas. It outlines some of the reserved words that you can use when putting together triggers to make the game more interactive.

Please contribute some material here if you can! -- Artoo


Contents

General scripting practice

A few guidelines for any prospective scripters so that our lives our made easier when we try and help/debug their stuff.

  • All script code should formatted so that the code is easily human-readable. For instance, all code within if/end, while/done and switch/done should be indented by two or more spaces. (Four spaces is the easiest to read but with 80 column screens, we'll settle for two.)
  • Trigger names should try to give an indication as to the purpose of the code behind it. Avoid names like "Mob Trigger #1".
  • Property names should be kept reasonably short and also, where necessary they should contain a unique number pertaining to the mob/room/etc. that they are tied to.
  • Script code should be commented: see below.

Commenting scripts

Please comment every script you write. It will help you when something needs to be debugged six months later, and it'll help other developers to learn the craft. Anything after an asterisk is a comment, and thus ignored by the game.

 * This is a comment
 this is not, and would cause a syntax error


The wait command

Use wait to allow a few seconds to lapse between events. It makes things seem a little more natural. Also, the player DOES NOT SEE any scripted commands executed when they first walk into a room. Always begin such a script with a wait of at least 1 second.

 wait 1s 

During a wait, the player is free to wander off, or do anything they like. (Exception: see the 'lock' command


Player or mobile?

Is the person triggering the script a player? Often, you need to differentiate.

 if %actor.vnum% < 0
   * do something interesting - a player triggered the script
 else
   * do something else - it's just a mobile
 end

Mobiles all have a vnum, but players have the vnum -1. Very often, you don't want mobiles to start scripts running, so this is a common way to begin scripts. Note the if... else... end syntax. You'll be using that a lot.

Making things that don't happen all the time

Use an IF statement, coupled to a random number. Stops scripted quests from becoming too predictable!

 if %random.4% == 1
 say You're lucky... there was only a 25 percent chance of this happening!
 end

About the player

Some useful reserved variables you might want to make use of.

 %actor.practices% -- how many times the player can train
 %actor.inventory% -- the player's inventory
 %actor.gold% -- the player's cash
 %actor.hitp% -- the player's current hitpoints
 %actor.alias% -- the player's name. Use with 'force'

The gender of the subject:

 %actor.sex% -- allows the script to test for male, female (and probably neuter)
 %actor.heshe% -- use in dialogue where mobiles are talking about the player
 %actor.hisher% -- use in dialogue where mobiles are talking about the player
 %actor.himher% -- use in dialogue where mobiles are talking about the player

Loading stuff

Very often, a script requires players to kill something, fetch something, etc., and the dynamic nature of the MUD means that the thing in question has already been killed, junked, teleported away or whatever. Or maybe it only appears during a 'quest'. Anyway, these are the commands you need to know...

 * Loading and equipping a mobile
 %load% mob 1234
 %load% obj 3456
 %load% obj 3457
 %force% m1234 get cloak
 %force% m1234 get belt
 %force% m1234 wear all
 * Note: 'cloak' and 'belt' must be in the namelist of objects 3456 and 3457


Tidying up

Sometimes you need to empty a room, and start afresh. The %purge% command works a lot like the immortal command of the same name.

 wat 6789 %purge%
 wat 6789 %load% obj 2345
 * empty room 6789 of everything, and then load object 2345 there
 * Note the use of 'wat' -- indicates the 'w' means 'world'

Also...

 %purge% leaf
 * a specific item is removed from the game


About the subject that carries the trigger

Useful syntax includes...

 %self.name% -- the namelist of the mobile or object running the script
 %self.shortdesc% -- the short name of the mobile or object; use in messages


Dialogue and plot development

One of the most important things about scripts is being able to give the player some sort of plot development. Instead of the usual 'action' strings that everyone sees, a mobile can ask the player a question, or thank them... or everyone in the room can be told how they've just been thrown to the floor by a massive explosion nearby... your imagination is the limit!

  say Three holes in the ground? Well well well...
 * Mobiles can say, yell and use all normal modes of communication, just as if they were a player
 emote tries to get his NTL broadband working, but fails.
 * Mobiles can emote, of course
 sigh
 * And they can use socials

Mobiles can also be given randomised dialogue, just like in the socials:

 say Is that you, %actor.name%? {Jeepers^Cripes^Holy cow}, I haven't seen you since {Crimewatch^the academy^
 that unfortunate business with the time machine^they outlawed hunting ewoks}.

In addition to text that comes direct from a mobile, you might want to send an echo...

 msend %actor.name% Are you enjoying your little holiday here on the Costa del Korriban?
 * Sends the text only to the player that triggered the script
 * Note the use of 'msend' in a script that is attached to a mobile
 * For room-related scripts, use 'wsend'
 * Note that %echo% also works

You can also send some text to everyone except the one who triggered the script

 %echoaround% %actor.name% Something exciting happens... but %actor.name% doesn't notice...

Using the force command

This works just like the immortal command, but you can have it in a script. Why? Because 'say' is only useful if the trigger is running on the mobile that you want to have speaking. With 'force' you can have others in the room talking as well. And, of course, you can force them to do anything a player can, such as kill, backstab, eat custard...

 wat 6789 wforce bernard say So, my old nemesis, %actor.name% has returned, eh?
 * A mobile called bernard, in room 6789, delivers this little cliche.

Rewarding the player

 %actor.exp(200)% 
 * Gives the player 200 experience points
 %actor.gold(5000)%
 Gives the player 5000 credits


Forcing the player to endure a script

If you have something important to get through, such as describing a docking sequence where you don't want the player to mess it up by destroying the ship, or something, you can lock their input, such that they're told it's a scripted scene. Use this sparingly!

 input %actor.name% lock partial
 * Player cannot do anything unless they type 'escape', which terminates the script
 input %actor.name% unlock
 * Return normal control to the player


Moving people about

The teleport command is a useful way to shift people around, for example, when you tell them that a bouncer has just thrown them out of a bar, you can send them to the street location outside.

 %teleport% m3456 3001
 * Transfer mobile 3456 to room 3001
 * You might also want to send a message to those in the room, to explain the mobile's disappearance!
 * Note that you can move players about in the same way


Hurting people

Want a room that's unhealthy to remain in? Why not...

 wdamage %actor.name% 5
 wsend %actor.name% The acid burns you!
 wait 4s
 * Attached to a room, this element would cost the player five damage points every 4 seconds
 wdamage m6789 40
 * Hurts mobile 6789 by 40 points
 %damage% %actor.name% (%actor.hitp% / 10%)
 * Takes ten percent of the actor's current hitpoints off them.


Scripted doors

Use a trigger to create the door to a secret passage. For example, a door that appears only when you twist a candlestick, or something. Much more fun that voice-activated exits, keys and so on. Don't forget to purge the exit afterwards.

 * creating an exit:
 wdoor 29916 north room 29917
 wdoor 29916 north flags a
 wecho The door to the north opens.
 wait 15s
 * closing it:
 wdoor 29916 north purge
 wecho The door to the north closes.

Note: the following has also been used successfully...

 %echo% and %door% in place of wecho and wdoor


Setting properties

These are the variables of the Wormhole game, carried by the player.

 setprop actor.property(!my_variable) 1
 * The subject for the trigger now carries a variable called my_variable, with the value of 1
 * The '!' character before the property name specifies it as a Temporary one.
 * Temporary values last only until the player leaves the game.
 setprop actor.property(another_variable) 6
 * The subject for the trigger now carries a variable called another_variable, with the value of 6
 * This one is permanent, and will stay even if the MUD crashes.
 * Use to record particular successes or failures. For example, you could make a mobile thank a
 * player for helping them out, even weeks later (and prevent them being asked to do the same quest again).

Note that %'s need to surround the property when you're calling it, but not when you're assigning it. Example...

 setprop actor.property(hothbounty) %actor.property(hothbounty)% + 15
 * Increases the bounty that the player has earned, because they just did something the Empire approves of

Removing a property...

 delprop actor.property(another_variable)

Have a mobile use a psi power

This will be a common feature, often as a reward when a player has been helpful. Note that it is not necessary to set the mobile to be of a certain class and level... if you use this command, it is assumed that the mobile has the power, and enough mana, etc.

 dg_cast '{heal^armor^phase shift}' %actor.name%
 * uses one of the powers in the list, on the subject

Other useful oddities

What time is it?

 %time.hour% -- the time of day


Identifying someone (player or mobile) at random, in the room

 %random.char%


How many players are in a given room?

 if %people.3456% > 4
   * do something
 end
 * where 3456 is the vnum of the room of interest

Stop a mobile from wandering off in the middle of some dialogue

 nop %self.setflag(!ROAM)%

and...

 nop %self.remflag(!ROAM)%
 * lets it become mobile again

Bitvalues

When writing a 'command' script for an object, the bitvalue tests for the location of the object, so the script will only run under the correct conditions:

1 = equipped 2 = in player inventory 4 = in the room

These bitvalues can be combined, by adding them together, so an item that works when equipped or in the room gets a 5. Immortals, note that your character will not trigger command scripts. Use a mortal testbot.

Force a mobile to help its buddies

This trigger was given to the robots in zone 44, as a "hitpercent" type. When their hitpoints are reduced below a certain percentage (I chose 80%) they will demand help from all others in the room - but only get it from other zone 44 robots. I wrote this instead of simply giving the mobiles a HELPER flag because of the politics of the zone - the mobiles should not help their enemies, the rebels.

 set vroom %actor.room%
 set vfolk %vroom.people%
 while %vfolk%
   set vnextguy %vfolk.next_in_room%
   if %vfolk.vnum% > 0
   * The above indivates the subject is a mobile, not a player
     if %vfolk.vnum% > 4400 and %vfolk.vnum% < 4408
     * If it's one of the mobiles in the vnum range where I made the friendly robots...
      if %vfolk% != %self.id%
      * The above stops the robot trying to force itself, which will produce an error...
         %force% %vfolk% assist operative
       end
     end
   end
   set vfolk %vnextguy%
   * Advance to the next character in the room, and repeat
 done
Personal tools