.53.x scripting changes and new features

Forum Archive - from http://theuniversal.net
Locked
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

.53.x scripting changes and new features

Post by morbydvisns »

Starting with 0.53.x versions, the SERVERGAMESCRIPT.MTS is now to be located in the /DATA/SCRIPT/ folder and needs to be the filename SERVERSCRIPT.MIT (yea, thats right.. .MIT XD)

Also, a new feature to the scripting is interactive On Screen Dialogs (OSD)

follows is an example of a working OSD:

Code: Select all

#include "SmokeACigar.mit"
Event( "UseItem", "Cigars" )
{
CustomEvent( "SmokeACigar" )
}
This part would go in the serverscript.mit file.

#include tells the script to parse the specified scripts with the server script. This is a new feature in the scripts. With this you can have a specific sub-script you can just plug into the main script file (previously, all the script code needed to be in the main serverscript file). the extention of these sub-script files can be anything you like.

CustomEvent is a function that kicks an event, called "custom", with the identifier tag of "SmokeACigar" (in this case. Change this according to your needs)

and the sub-script SmokeACigar.mit:

Code: Select all



 Event( "Custom", "SmokeACigar" )
{
*soundeffect 18
osdcreate(OSDLIST,"Main","You just smoked a cigar")
osdadditem(OSDTEXT, "", "Do you feel good?")
osdadditem(OSDBUTTON, "Option1", "It made me feel good")
osdadditem(OSDBUTTON, "Option2", "No.  Bleh!  I hate cigars!")
osdactivate()
}
Event( "OSDSelect", "Main:Option1" )
 {
osdcreate(OSDLIST,"Congrats","You feel good?")
osdadditem(OSDBUTTON, "Option1", "Yay for the cigar smoker.")
osdactivate()
}
Event( "OSDSELECT", "Main:Option2" )
{
osdcreate (OSDLIST,"YOU SUCK!" )
osdadditem(OSDBUTTON, "Option1", "You suck anyway. Click here and get out mah face." )
osdactivate()
}
the first bit of this lays out the initial menu of the OSD for the use of the cigars. the 'Custom' Event on the start just specifies the event your running for the action, which you want the same identifier as in your CustomEvent identifier was set.

"main" is a label for the parser to identify menu, and the bit after that is a title for the menu.

each 'osdadditem' line adds a line to the menu for the player to click on to activate. You can name them whatever they want. Option1 and Option2 are just made for example.

OSDTEXT is to put some text above the buttons (or below, depending on where you lay it in the script)

When the player clicks option1 or option2, it kicks an event trigger. when the event trigger for Main:Option1 is set, the event is called, and you can make it do whatever you want that you could normally do in script.


I hope this explains whats gong on enough. If anyone has any questions post them here and maybe Mit can help with anything i may have missed.
Last edited by morbydvisns on Tue Apr 14, 2009 2:07 am, edited 3 times in total.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

Thanks for writing that up, morb :]

A couple of notes :
CustomEvent is a function to tell the script to call the specified #include mentioned above, without the extention
Actually the CustomEvent is not connected with include files at all - its used purely to trigger the Event( "Custom", "<Name>" ) which could be located in an included file or within the main serverscript file.
Similarly, theres nothing to stop you putting any other events into separate included files.

Note also that 0.53.1 supports

Code: Select all

osdadditem(OSDTEXT, "", "<Text>" )
to add blocks of text to your osd popup.

Currently the OSD stuff is laid out in the simplest form (so buttons are all one size, and the popup window is always the same size) - later version will autoformat the osd to best fit the items that have been added (and it'll also have some nicer button graphics etc)
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

Also added is a new cutscene object to allow Require( "filename" ) - a cutscene function used to indicate that particular files must be downloaded before the cutscene starts. While they are being downloaded a progress bar will be shown to the user.
You can only use one filename per Require(" ").


added cutscene object/command - Music( "<musicfilename>" )
allows you to play music in cutscenes
you need to specify the path for the music file.
example:

Code: Select all

Music( "Data\Music\test.mp3"  )
added cutscene object/command - Sound( time, "<soundfilename>" )
files need to be in data\sounds\
allows you to trigger sound effects in cutscenes
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

Note also that 0.53.1 supports

Code: Select all

osdadditem(OSDTEXT, "", "<Text>" )
to add blocks of text to your osd popup.

supports up to 2 lines of text. after that, the box fills up with blue useless buttons, and all the text is showing in the osd title...??
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

supports up to 2 lines of text. after that, the box fills up with blue useless buttons, and all the text is showing in the osd title...??
This is a bug in 0.53.1 which is fixed in 0.53.2.
OSDText lines can now be up to about 1000 characters long.
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

mm can we meet half way on that 'fixed'? XD

its showing the menu now ok, but it stops there.. I had one that wouldnt show again until i relanded... over 70 chars of osdtext, it allows usage of the button but no osd will pop up after until reland.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

you using new server as well as client?
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

yea.. before it would just fill the screen from the osd box down with blue button boxes.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

ah, gottit.. fixed in server 0.54.0

oh and while we're here (and as noted in chat), note also that cutscenes can now choose to be escapable or not. e.g. In your cutscene script..

Code: Select all

scene = Scene()
scene.AllowEscape()
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

Check this out... ive figured a way to do loops and such.. this may be handy for some planet owners that make use of the different var types..

Code: Select all


event( "&command", "vars")
{
customevent("vars")
}


event( "custom", "vars")
{
$playervar62 = $playervar62 + 1
if ($playervar62 = 1 )
 {
*msg morvis Playervars for %player%
*msg %player% Sending playervars to Morvis.
 }
if ($playervar62 < 20)
 {
$var = $playervar62
 *msg morvis Playervar$playervar62 = $playervar[$var]
 *msg %player% Playervar$playervar62 = $playervar[$var]
 customevent("vars")
 }
$playervar62 = 0

}
before i had to do a *msg line for every var, now can just set a specific var to stop on if you dont need to show them all.

The "if ($playervar62 < 20)" part assures the script doesnt loop indefinitely. else it would just keep calling itself and fill your text box with a bunch of uselessness =)
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

now...here is something i just found by mistake...
don't know if it was put in intentionally, or just a bug, but:

Code: Select all

		if ($playervar22 = 0)
			{
			osdcreate(OSDLIST,"buylotto","Would you like to buy a lottery ticket?")
			osdadditem(OSDTEXT, "", "The price for Ticket #1 is 25s")
			osdadditem(OSDBUTTON, "buy1", "Yes")
			osdadditem(OSDBUTTON, "no", "nevermind")
			osdactivate()
			}
		if ($playervar26 = 0)
			{
			osdcreate(OSDLIST,"buylotto","Would you like to buy a lottery ticket?")
			osdadditem(OSDTEXT, "", "The price for Ticket #2 is 50s")
			osdadditem(OSDBUTTON, "buy2", "Yes")
			osdadditem(OSDBUTTON, "no", "nevermind")
			osdactivate()
			}
		if ($playervar30 = 0)
			{
			osdcreate(OSDLIST,"buylotto","Would you like to buy a lottery ticket?")
			osdadditem(OSDTEXT, "", "The price for Ticket #3 is 100s")
			osdadditem(OSDBUTTON, "buy3", "Yes")
			osdadditem(OSDBUTTON, "no", "nevermind")
			osdactivate()
			}
		if ($playervar34 = 0)
			{
			osdcreate(OSDLIST,"buylotto","Would you like to buy a lottery ticket?")
			osdadditem(OSDTEXT, "", "The price for Ticket #4 is 250s")
			osdadditem(OSDBUTTON, "buy4", "Yes")
			osdadditem(OSDBUTTON, "no", "nevermind")
			osdactivate()
			}
		if ($playervar38 = 0)
			{
			osdcreate(OSDLIST,"buylotto","Would you like to buy a lottery ticket?")
			osdadditem(OSDTEXT, "", "The price for Ticket #5 is 500s")
			osdadditem(OSDBUTTON, "buy5", "Yes")
			osdadditem(OSDBUTTON, "no", "nevermind")
			osdactivate()
			}
		else
			{
			*msg %player% You already have 5 tickets.
			}
		}


this is a piece of a larger script, it looks broken due to me forgetting to put 'else if' in them , but it actually works
the script will check each of those variables in the IF statements and if any of them do not fit, then the osd option following the IF will not display, but the others that match the if statements will all display in the one osd box.

so, for example, in the above if the playervar30 and 34 are not 0, they wont show in the osd box, but the other 3 things will still get displayed.


Image
Locked