User Tools

Site Tools


scripting:other_language_features

This is an old revision of the document!


Includes

Rather than having all of your script code in the one 'ServerScript.mit' file, it is expected that you will split your script across multiple files, with each file usually relating to one area of your game-world. (e.g. You may have a file to handle all the usable items on your world, or one for handling a particular cutscene or scripted building).

To link files into your script, use the format..

<codedoc> #include “<FILENAME>” </codedoc> e.g. ServerScript.mit <codedoc> #include “CrowTournament.mit” </codedoc> CrowTournament.mit <codedoc> Event( “Custom”, “StartCrowTournament” ) {

  • say Crow Tournament commencing

… } </codedoc> Keeping related code separated like this can make it easier to share script across worlds - e.g. You could add your crow tournament feature to another world by copying the CrowTournament.mit file across and including it from the ServerScript.

Timers

When you want to trigger an event at a certain time, you can add a timer using the script system function sysSetTimer. You specify the time delay and the name of an event to trigger.

Sleep command

Calling the Sleep function pauses the Event for a specified period of time (in 1/10th second steps). You can, for instance, write a small script that triggers a particle effect on a player, waits for a second, then triggers another particle effect. Example

Event( "UseItem", "Potion" )
{
    $loop = 0
    while ( $loop < 10 )
    {
        // Trigger effect
        *playereffect 6 $gPlayerID $gPlayerID 1
        // Wait one second
        Sleep(10)
        $loop += 1
    }
}

Functions

Functions are defined in your script as shown in this example:

<codedoc> Function IsItemASword( $itemNum ) {

if ( $itemNum = 112 )		// Sword
{
	return( 1 )
}
else if ( $itemNum = 113 )	// Sword 2	
      {
	return( 1 )
}
return( 0 )

} </codedoc>

This example function would be called from another part of your script like this: <codedoc>

$isSword = IsItemASword( $gTaskItem1 )

</codedoc>

Functions can have any number of parameters, and always return a value.

The 'Sleep' command cannot be used from within a function.

Custom Events

You can add your own custom events, and then trigger them from a command. (And hence, you can trigger custom events from within other events). When you trigger a custom event in your script, the new event is executed immediately and the main event waits until it completes or when the new event sleeps.

A custom event is defined as shown:

<codedoc>

 Event( "Custom", "YourCustomEventName" )
 {
    *say My Custom Event has been triggered for %PLAYER%
 }

</codedoc>

This custom event can be triggered using the command *event or *eventallonline (*eao for short). e.g. <codedoc>

  • event Bob YourCustomEventName

</codedoc> would display My Custom Event has been triggered for Bob.

Be very careful with events calling other events, particularly when using *eventallonline or Sleeps. Many commands (*addbackgroundmodel for instance) replicate to everyone present, so mistakenly having an event triggered for all players can produce confusing and nasty side-effects. (e.g. For *addbackgroundmodel, duplicate models would be added to the map multiple times and the server could waste an awful lot of your bandwidth telling everyone about again and again..)
scripting/other_language_features.1580255404.txt.gz · Last modified: 2020/01/28 17:50 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki