User Tools

Site Tools


scripting:other_language_features

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
scripting:other_language_features [2012/03/25 18:34] – created mitscripting:other_language_features [2025/05/28 16:34] (current) – external edit 127.0.0.1
Line 1: Line 1:
-===== Sleep command ===== 
- 
- 
- 
 ===== Includes ===== ===== 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).  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). 
  
Line 12: Line 7:
 #include "<FILENAME>" #include "<FILENAME>"
 </codedoc> </codedoc>
- 
 e.g. e.g.
- 
 **ServerScript.mit** **ServerScript.mit**
 <codedoc> <codedoc>
 #include "CrowTournament.mit" #include "CrowTournament.mit"
 </codedoc> </codedoc>
- 
 **CrowTournament.mit** **CrowTournament.mit**
 <codedoc> <codedoc>
-Event( "Custom", "StartCrowTournamentUser" )+Event( "Custom", "StartCrowTournament" )
 { {
-    *setcrow 1 +    *say Crow Tournament commencing 
-    *crowlives 5+    ...
 } }
 +</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.
  
-Event( "Custom", "StartCrowTournament" )+===== 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// 
 +<code> 
 +Event( "UseItem", "Potion" )
 { {
-    *say Crow Tournament commencing +    $loop = 0 
-    *eao StartCrowTournamentUser+    while ( $loop < 10 ) 
 +    { 
 +        // Trigger effect 
 +        *playereffect 6 $gPlayerID $gPlayerID 1 
 +        // Wait one second 
 +        Sleep(10) 
 +        $loop += 1 
 +    } 
 +
 +</code> 
 + 
 +===== 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> </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.+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. 
 +<note important> 
 +The 'Sleep' command cannot be used from within a function. 
 +</note> 
 + 
 +===== 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''
 + 
 +<note important> 
 +Be very careful with events calling other events, particularly when using ''*eventallonline'' or ''Sleep''s. 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..
 +</note> 
 + 
 + 
 + 
 + 
 + 
  
scripting/other_language_features.1332700447.txt.gz · Last modified: (external edit)