Open new window
Last update:

OasisOLC and Deaths Gate script reference

Script commands

Script commands are commands that have script related interaction. They make up the limited programming language that is part of DG Scripts. More commands for scripts are found on the Game Commands page.

* (comment) nop attach
global context eval
set unset detach
extract if halt
makeuid rdelete remote
return switch case
break done while
wait    

* (comment)

* This is an example of a comment
* because of the *'s the lines aren't parsed,
* so the script still works even if it has a lot of
* explanations built in.
%echo% Trigger firing
* The above line sends the text 'Trigger firing' to the room.

Comments are useful in scripts to document what is happening, for future reference, and for others to see what the script does.

Back to table.

Nop

Usage: nop
* this line will award the 'actor' with a little gold:
nop %actor.gold(10)%

Almost a no-operation. Certain variable/subfield combinations for characters change some attribute about the character. nop allows those changes to be used legally on lines that do not need to process the result.

Back to table.

Attach

Usage: attach vnum id
* This small trigger will attach a trigger to the carrier
* this can for instance be used if you want the mob to change attitude
* by adding another trigger (ie - mob was mad - mob got apple - 
* mob gets a 'nicer' trigger attached
attach 3001 %self.id% 

This command allows a script to attach a trigger (referenced by vnum) to anything capable of receiving triggers, by id number. (%self.id%, %object.id%, and %actor.id% are examples of id numbers, for use with this command.)

Back to table.

Global

Usage: global variablename
* To make a variable 'reachable' from other scripts
* it has to be made 'global'. In this case I make a local known var %has_bribed_guard%
* and make it global. It's a good idea to use this in conjunction with context.
global has_bribed_guard

Used to change a variable from local to global. If a global variable is modified, this command must be used to update the global contents as well.

Back to table.

Context

Usage: context number
* This little script will make sure one %has_said_hello% exist for each player
context %actor.id%
set has_said_hello 1
global has_said_hello
* now only scripts running with context = %actor.id% can access this particular variable.
* however - it's a better idea to use vars set on players - see 'remote'

Changes the "context" of a script to this value. When first run, a script's context is 0. When a variable is made global, it is given the current context. When a variable is accessed, if it must be searched for globally, a "found" variable must either have context 0 or the current context. The net result of this is you may have many global variables in a single script, with the same name, differing only by context. Players may have variables; this mostly removes the need for variable context. Previously, a player's ID could be used as variable context to allow a script to service multiple players at once.

Back to table.

Eval

Usage: eval variable expression
* this example immidiately evaluates the expression below and stores the result in %result%:
eval result %self.hitp% * 100 / %self.maxhitp% 
say My hitpoint percentage is %result%
* this result will not change after the evaluation even if %self.hitp% changes

The eval command is used to set (or create) the specified variable equal to the result of the immediate evaluation of the provided expression. There also exists a "set" command, with the same syntax. Set differs in that the expression is not evaluated until the variable is accessed.

Back to table.

Set

Usage: set variable expression
* this example sets the value of result to '%self.hitp% * 100 / %self.maxhitp%'
set result %self.hitp% * 100 / %self.maxhitp% 
* The %result% var now works as a 'function' every time it's accessed.
say My hitpoint percentage is %result%
%damage% %self% 30
say My hitpoint percentage is %result%

The set command is used to set (or create) the specified variable equal to the  provided expression, which will be evaluated when the variable is accessed. There also exists an "eval" command, with the same syntax. Eval differs in that the expression is evaluated immediately.

Back to table.

Unset

Usage: unset variable
* in this example we have a var %testvar% we no longer need:
set testvar hops happily along
%echo% %self.name% %testvar%
unset testvar
* please note - if we had made the var global, it'd be gone instead.

Remove the variable from the global variables of this script, or if not found there, from the script.

Back to table.

Detach

Usage: detach vnum id
* if we - as described in the attach example, want our mob/obj/room to behave
* differently, it's not always enough to just add another trigger with attach.
* it might be necessary to remove some old ones :
detach 3000 %self.id%

The opposite of attach, this removes a trigger from the specified target.

Back to table.

Extract

Usage: extract to-variable word-number from-text
* could be used to do strange things to what people say:
extract testvar1 1 %speech%
extract testvar2 2 %speech%
extract testvar3 3 %speech%
extract testvar4 4 %speech%
say do you mean %testvar4% %testvar3% %testvar2% %testvar1% ?

Place a specific word from the 'from-text' into a new or existing variable 'to-variable'. Do not enclose the name of the to-variable in %'s.

Back to table.

If

Usage: if (expression)
...
 elseif (expression)
...
 else
...
 end
   if (%arg% == statue) 
   wsend %actor.name% Stealing from the Temple of Nefheistos is certain death!
   else 
   wsend %actor.name%  You don't see a %arg% here.
   end

An 'if' must occur before the other three. If expression evaluates to true (see the Expressions page for more detail on expression evaluation), the statements between the if statement and the next elseif, else, or end are executed. If it stopped at an elseif or else, it scans for the next end, and continues execution at that point. If the expression evaluated to false, it searches for the next elseif, else, or end. If it finds an elseif, it checks that expression. If it is true, it executes the statements between the elseif and the next elseif, else, or end, and then finds the end of the block. If it is false, it continues searching in the same pattern, until a true elseif is found, an else is found, or an end is found. There may be 0 or 1 else statements and 0 or many elseif statements in the block.

Back to table.

Halt

Usage: halt
* This script attacks players of level 20 and above.
* the reason for the use of halt and return 0 is to make sure
* other scripts are checked too.
if %actor.level%<20
  return 0
  halt
end
  %echo% %self.name% yells a Battlecry and throws himself at you.
  mkill %actor%

Terminate the trigger execution.

Back to table.

Makeuid

Usage: makeuid variable id
* We have one mob giving a quest. This mob sets the targets id as a
* global on the player via the 'remote' command, like this:
eval quest_object %obj.id%
remote quest_object %actor.id%
* We then have another mob receiving the quest object, with the following script.
if !(%actor.varexists(quest_object)%)
  return 0
  halt
end
* now we know the player has a quest_object variable
makeuid obj %actor.quest_object%
say Have you brought me %obj.shortdesc%, %actor.name% ?
say You must bring it to me to complete your quest, you know.

Create a new variable with the name given, whose contents shall be suitable for referring to a character, object, or room whose id is provided.

Back to table.

Rdelete

Usage: rdelete variable id
* In the above example, when the quest is fulfilled, we
* need to remove the quest_object variable. this is done like this:
say Thank you, %actor.name% - your quest is completed.
rdelete quest_object %actor.id%

Delete a remote variable from the script referred to by the id of its owner.

Back to table.

Remote

Usage: remote variable id
* Heavily used for questsvars, a global variable can be remoted to
* players as well as mobs. Like in this example (from a bribe trigger):
if !(%actor.varexists(has_insulted_guard)%)
  eval bribe_gold 12000
else  
  eval bribe_gold 120000
end

if %amount% < %bribe_gold%
    if %actor.varexists(has_insulted_guard)%
      say You just don't get it, do you ?
      mkill %actor%
      rdelete has_insulted_guard %actor.id%
      halt
    end
    set has_insulted_guard 1
    remote has_insulted_guard %actor.id%
    say I'm not THAT cheap! GET OUT, and I'll pretend I never saw you.
  else
    set has_bribed_guard 1
    remote has_bribed_guard %actor.id%
    say Fine, get on with it. But I never saw you, ok ?
  end

Create a global variable belonging to a character or player whose id is specified. The variable must first exist in the script that is running.

Back to table.

Return

Usage: return value
   if (%cmd%==w || %cmd%==west)
     if (%actor.race%==dwarf)
       %send% %actor% The door vanishes as if it was never there, and you step through.
       %echoaround% %actor% As %actor.name% steps through the doorway, the door disappears.
       %teleport% %actor% 4010
       %echoaround% %actor% %actor.name% has arrived.
       %force% %actor% look
       * the trigger returns 1 because the actor is allowed to pass.
       return 1
     else
       * the trigger returns 0 so next trigger is checked.
       return 0
     end
   end

Designate the return value for the script, to be set when the script executes halt, wait, or when it runs out of commands.

Back to table.

Switch

Usage: switch expression
   eval line %random.4%
    
   switch %line%
     case 1
       emote sings a merry song about someone named Fulbert and Beatrice.
       break
     case 2
       emote booms out loudly, 'Heigh Ho! Heigh Ho! It's home from work we go!'
       break
     case 3
       emote tries to sing falsetto, but his voice doesn't agree.
       break
     default
       sing
       break
   done

Switch evaluates an expression and looks for a match amongst the case statements that follow. If none of the following case statements are a match, and a default statement exists, the default statement is considered a match. If a match is found, the commands that follow it, up until a done command, are executed.

Back to table.

Case

Usage: case condition
See switch, above

Used to begin a new conditional group in a switch block. See switch, above.

Back to table.

Break

Usage: break
See switch, above

Used to terminate commands in a switch/case block. See switch, above.

Back to table.

Default

Usage: default
See switch, above

Used like "case", but matches any condition not otherwise met.

Back to table.

While

Usage: while expression
  * a small script to make a bomb go off three seconds after it's dropped.
   set room_var %actor.room%
   * Send a message when the bomb goes off.
   wait 3 s
   %echo% The Grenade blasts into smithereens, striking everyone here.
   * Target the first char
   set target_char %room_var.people%
   * Do stuff
   while %target_char%
   * Set the next target before this one perhaps dies.
     set tmp_target %target_char.next_in_room%
   * This is where the good/bad things are supposed to happen.
     %send% %target_char% The explosion hurts you.
     %damage% %target_char% 30
   * Find next target
     set target_char %tmp_target%
   * Loop back
   done

The while command starts a loop, running until the expression becomes zero or negative. This can make permanent loops - be careful. The switch block must be terminated by a done.

Back to table.

Done

Usage: done
See both switch and while, above.

Used to terminate a while or switch block.

Back to table.

Wait

Usage: wait <time> [s]
       wait until <mudtime>
* This script gives the actor 10 seconds to get out.
say GET OUT! NOW!
wait 10 s
mkill %actor%

The wait statement is used to 'pause' the script execution for a period of time. When a script is being executed it will attempt to execute all commands right away. To get small breaks in, and perhaps give the players time to adjust, use the wait command.
If you want to syncronise your script, you can use the 'wait until' feature. It's used like this:

* This script wakes the mob at dawn, and puts him to sleep at night.
wait until 8:00
wake
wait 10
yawn
wait 10
stand
wait 10 s
emote looks sleepy.
wait until 21:00
yawn
wait 10 s
rest
wait 10 s
sleep
Back to table.
© 2005 Thomas Arp (Welcor). All rights reserved.