View Single Post
  #7  
Old 04-16-2009, 05:12 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Examples on how to provide events with a startgate/finish line. Some parts are obviously only Maloria related, but they should show the general idea behind it.



Startgate
PHP Code:
function onCreated()
{
  
// DO NOT REMOVE!
  
level.startGate this;
  
// ---------------
  
  
if (this.size == NULLthis.size = { 1};
  
show();
  
setImgPart("mal_tb_startgate.png"00this.size[0]*16this.size[1]*16);
  
setShape(1this.size[0]*16this.size[1]*16);
  
blockAgain();
}

function 
onPlayerChats()
{
  if (
player.guild != "Events Team") return;
  
  if (
player.chat == "/et_start"onStartEvent();
}

function 
onStartEvent()
{
  if (
serverr.hostedEvent[1] != "-1") return;
  if (
this.isRunning) return;
  
  
// Abort if there's not at least 3 participants
  
this.eventParticipants = new[0];
  for (
temp.plplayers) {
    if (
temp.pl.guild in serveroptions.staffguilds.tokenize(",")) continue;
    
    
this.eventParticipants.add(temp.pl);
  }
  
  if (
this.eventParticipants.size() < 3) {
    for (
temp.plthis.eventParticipants) {
      
temp.pl.client.messages.add("Event aborted due to lack of players!");
    }
    echo(
"[event_startgate] Error: Event aborted due to lack of players (" this.eventParticipants.size() @ ")!");
    
    
findNPC("Control-Events").onEndEvent();
    return;
  }
  
  
this.isRunning true;
  
showAni(1width/2yz"mal_startrace");
  
  
scheduleevent(6.6"onTriggerNPCs""");
  
scheduleevent(20"onCloseEvent""");
}

function 
onCloseEvent() show();

function 
onTriggerNPCs()
{
  
hideImg(1);
  
hide();

  for (
temp.npcnpcs) {
    
temp.npc.trigger("StartingEvent""");
  }


Finish line
PHP Code:
function onCreated()
{
  
this.db findNPC("Control-Events");
  
  if (
this.shape == NULLthis.shape = { 1};
  
save[0] = this.shape[0], save[1] = this.shape[1];
  
  
setShape(1this.shape[0]*16this.shape[1]*16);
  
  
this.medals = { "gold""silver""bronze" };
  
//getRecord();
}

function 
onTimeOut()
{
  if (
this.isRunning) {
    
this.timer += .1;
    
    
setTimer(.1);
  }
  
  
this.attr[5] = this.timer;
}

function 
onPlayerTouchsMe()
{
  
// Event isn't running
  
if (!this.isRunning) return;
  
// Player is on staff tag
  
if (player.guild in serveroptions.staffguilds.tokenize(",")) return;
  
// Player wasn't here when the event started
  
if (!(player.account in this.eventParticipants)) return;
  
// Player already finished
  
if (player.account in this.winners) return;
  
  
// First to finish!
  
if (this.winners == NULL) {
    
temp.eventName this.db.hostedEvent[0];
    
temp.event = new TStaticVar();
    
temp.event.copyFrom(this.db.(@"event_" temp.eventName));
    
    if (
temp.event.recordTime == NULLtemp.event.recordTime NULL;
    
    if (
this.timer temp.event.recordTime || temp.event.recordTime == NULL) {
      
client.messages.add("You broke the previous record of" SPC temp.event.recordTime "s with" SPC this.timer "s!");
      echo(
player.account SPC "broke the record of" SPC temp.event.recordTime "s in \"" temp.eventName "\"! New record is" SPC this.timer "s!");
      
this.db.(@"event_" temp.eventName).recordTime this.timer;
      
this.db.(@"event_" temp.eventName).recordHolder = { player.accountplayer.communityname };
      
this.db.(@"event_" temp.eventName).races ++;
      
      if (
this.db.(@"event_" temp.eventName).races == 1) {
        
this.db.(@"event_" temp.eventName).firstWinner = { player.accountplayer.communityname };
        
        
temp.item player.createItem("eventtrophy");
        
temp.item.description player.account ": First winner of" SPC temp.eventName "!";
        
player.addItem(temp.item);
      }
    }
    
    
temp.identifier this.db.hostedEvent[1];
    
temp.quantity this.db.hostedEvent[2];
    
temp.item player.createItem(temp.identifier""temp.quantity);
    
player.addItem(temp.itemtemp.quantity);
    
    echo(
player.account SPC "finished event \"" temp.eventName "\" first!");
    
this.db.scheduleevent(30"onEndEvent""");
  }
  
  if (
this.winners.size() < 3) {
    
this.winners.add(player.account);
    
player.chat "Winner #" this.winners.size() @ "!";
    
player.attr[4] = "mal_medal2.gani," this.winners.size() - 1;
    
    if (
this.winners.size() == 3) {
      
this.db.cancelevents("onEndEvent");
      
this.db.scheduleevent(5"onEndEvent""");
    }
  }
}

function 
onStartingEvent()
{
  
this.timer NULL;
  
this.startTime timevar2;
  
this.isRunning true;
  
  
this.eventParticipants = new[0];
  for (
temp.plplayers) {
    if (
temp.pl.guild in serveroptions.staffguilds.tokenize(",")) continue;
    
    
this.eventParticipants.add(temp.pl.account);
  }
  
  
setTimer(.1);
}

//#CLIENTSIDE
function onCreated()
{
  
dontBlock();
  
showFinishLine();
}

function 
showFinishLine()
{
  
this.size = { save[0], save[1] };
  
showImg(200"mal_tb_finishline.png"xy);
  
changeImgPart(20000this.size[0]*16this.size[1]*16);
  
changeImgVis(2000);

__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote