Here you'll find some details on the basic 'crow tourney' script i've used on the worlds so far. Its not a completely straightforward example (intermediate coder level 1 :]) but it shouldn't be terribly difficult to add and adapt this to your own world.. and if anyone wants to use it as a basis for something more complicated (team matches, multi-round duels or whatever) feel free to share your own variants. :]
There are 2 files involved in the crow tourney.. one for the script itself, one for the associated cutscene. You can get these files here:
http://theuniversal.net/samples/CrowTou ... Sample.mit
http://theuniversal.net/samples/CrowTou ... Sample.cut
Quick-start guide
If you don't want the gory details, you can include the sample in your own world by following these steps:
1 - Copy those 2 files into your world's Data\Scripts folder
2 - Add the following to your ServerScript.mit file :
Code: Select all
#include "CrowTourneySample.mit"
global $kPlayerVarCrowGameSignUp = 12
4 - Type *event [your_name] Crows to activate the tourney.
The Gory Details
I will now endeavour to explain each and every line.. Open up the sample and read along with mit
Code: Select all
//--------------------------------------------------------
// CrowTourney stuff
//--------------------------------------------------------
// *** Uses $gPlayerVar[$kPlayerVarCrowGameSignUp] to record opt-in state
//--------------------------------------------------------
Unfortunately it has to start a little complicated by mentioning the use of a player var.
As it says, the crow tourney script uses a single player var to record whether or not each player is currently signed up for the tourney.
For Aramathea " $kPlayerVarCrowGameSignUp " is defined in a separate file as such..
Code: Select all
global $kPlayerVarCrowGameSignUp = 12
Ok, thats the hard bit over.. everything else is easy from now on . Next..
Code: Select all
$mCrowTourneyGameHighestScore = 0
$mCrowTourneyGameHighestPlayerID = 0
$mCrowTourneyNumSignups = 0
Code: Select all
//----------------------------------------------------------------
// SignUp Phase
//----------------------------------------------------------------
Code: Select all
//-------------------------------------------------
// Use *event [OWNER] crows
// to start a crow tourney off
//-------------------------------------------------
Event( "Custom", "crows" )
{
$mCrowTourneyGameHighestScore = 0
$mCrowTourneyGameHighestPlayerID = 0
$mCrowTourneyNumSignups = 0
*eao initialsignupmessage
$timerID = sysSetTimer( 30, "SecondSignupMessage", "" )
}
Below the comment is the custom event function that gets triggered when i type that.
The first 3 lines just make sure our module variables are set back to 0. More on those in a bit
The next line :
Code: Select all
*eao initialsignupmessage
The next line then sets a timer so that the event "SecondSignupMessage" is activated after 30 seconds.
Next we have the 'initialsignupmessage' event that is triggered for all users..
Code: Select all
Event( "custom", "initialsignupmessage" )
{
$gPlayerVar[$kPlayerVarCrowGameSignUp] = 0
*msg %PLAYER% 2 min crow tourney starts in 60 seconds. Type &joincrow to sign up
}
Whether or not they do, 30 seconds later that timer we created earlier will be set off, and the next code block is triggered
Code: Select all
Event( "Timer", "SecondSignupMessage" )
{
*soundeffect 24
*say 2 min crow tourney starts in 30 seconds. Type &joincrow to sign up if you haven't already done so
$timerID = sysSetTimer( 25, "CrowTourneyStart", "" )
}
Before we move on to the tourney start, theres the code that handles the user signup..
Code: Select all
Event( "&command", "joincrow" )
{
$ret = CrowTourneySignUp()
}
Code: Select all
Function CrowTourneySignUp( )
{
if ( $gPlayerVar[$kPlayerVarCrowGameSignUp] == 0 )
{
$gPlayerVar[$kPlayerVarCrowGameSignUp] = 1
*say %PLAYER% signed up for the crow tourney
$mCrowTourneyNumSignups = $mCrowTourneyNumSignups + 1
*crowspawn %PLAYER% 162 112
}
else
{
*msg %PLAYER% You're already signed up
}
}
(Note the reason that code is in a function, rather than just being in the &command event, is so that we can call the same block from other places - e.g. we could pop up a little window with a button labelled 'Join the Crow Game'.)
Ok next.. 25 seconds after the second sign up message, the 'CrowTourneyStart' timer event is triggered for the owner.
Code: Select all
Event( "Timer", "CrowTourneyStart" )
{
if ( $mCrowTourneyNumSignups >= 2 )
{
*soundeffect 8
Sleep(60) // 6 seconds (for trumpet sound)
*lockweapons
*resetallcrowscores
*say Crow Tournament commencing!
*eao crowcutscenestart
$timerID = sysSetTimer( 25, "CrowGameLeadInSequence", "" )
}
else if ( $mCrowTourneyNumSignups == 1 )
{
*say Tournaments need at least 2 players..
}
else
{
*say Tournament cancelled
}
}
Code: Select all
Event( "Custom", "crowcutscenestart" )
{
if ( $gPlayerVar[$kPlayerVarCrowGameSignUp] == 1 )
{
*playmusic %PLAYER% http://gameislands.net/gamecontent/genesis/crowtoons/honey-2mincrowedit.mp3
*cutscene %PLAYER% CrowTourneySample.cut
}
}
I'll describe the cutscene separately, but if you open the .cut file you may notice about halfway down the line
Code: Select all
CustomEvent( 5.0,"tourneycutgocrow","0" );
Code: Select all
Event( "Custom", "tourneycutgocrow" )
{
*gocrow %PLAYER%
}
Now remember a little while ago we set up a timer - while the cutscene is still going on the following event will fire :
Code: Select all
Event( "Timer", "CrowGameLeadInSequence" )
{
*say Weapons are locked... Get to your positions.
Sleep(50) // 5 seconds
*say Weapons unlocked in 10 seconds. Ready up!
Sleep (70)
*say 3 seconds..
Sleep(10)
*say 2...
Sleep(10)
*say 1...
Sleep(10)
*unlockweapons
*eao CrowTourneyAddTimer
$timerID = sysSetTimer( 105, "CrowGameEndSequence", "" )
}
Code: Select all
Event( "Custom", "CrowTourneyAddTimer" )
{
if ( $gPlayerVar[$kPlayerVarCrowGameSignUp] == 1 )
{
*onscreentimer %PLAYER%,0,120
}
}
Nearly done now.. On the home stretch..
Our participants have now been flying about blasting each other for almost 2 minutes when the end sequence timer we set off earlier is activated..
Code: Select all
Event( "Timer", "CrowGameEndSequence" )
{
*say ----------------------- 15 seconds remaining ---------------------------------
Sleep (150) // 15 secs
*exitcrowall
*eao showcrowscores
Sleep (50) // 5 secs
.....
Code: Select all
Event( "Custom", "showcrowscores" )
{
if ( $gPlayerRobocrowKills > 0 )
{
*say %PLAYER% - Kills: $gPlayerRobocrowKills Deaths: $gPlayerRobocrowDeaths
// Calc players score
$crowScore = $gPlayerRobocrowKills * 1000
if ( $gPlayerRobocrowDeaths == 0 )
{
$crowScore = $crowScore + 999
}
else
{
$ratio = $gPlayerRobocrowKills * 50
$ratio = $ratio / $gPlayerRobocrowDeaths
$crowScore = $crowScore + $ratio
}
// If score is higher than any others already registered
if ( $crowScore > $mCrowTourneyGameHighestScore )
{
$mCrowTourneyGameHighestScore = $crowScore
$mCrowTourneyGameHighestPlayerID = $gPlayerID
}
}
*fademusic %PLAYER% 5
// Clear the sign up state now, ready for the next game
$gPlayerVar[$kPlayerVarCrowGameSignUp] = 0
}
With that event triggered for all active users, we now go back to the last bit of the endSequence event to finish off..
Code: Select all
$winnerID = $mCrowTourneyGameHighestPlayerID
if ( $winnerID > 0 )
{
$name = sysGetPlayerName( $winnerID )
*say Shamanic crow tournament winner is $name
}
else
{
*say Tournament over - no winner
}
$mCrowTourneyNumSignups = 0
}
Job done.