Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-24-2009, 11:48 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
Events System (Automated hosting included)

I don't think an awful lot of explanation is required, if you got questions, post them. Everything commented with // ** are comments specifically made for this thread, all other comments were there from when I scripted it.

Enjoy! If you like it, don't hesitate to +rep me

Database NPC named "Control-Events" (in my case anyways)
PHP Code:
function onInitialized() onCreated();
function 
onCreated()
{
  
onEndEvent();
  
  
// Prizes
  // ** JUST AN EXAMPLE **
  // { "arc", minQuantity, maxQuantity }
  
this.eventPrizes = {
    { 
"gold"10100 },
    { 
"aurablade"1},
    { 
"combatknife"1},
    { 
"phasonblade"1}
  };
  
  
// ** HOW EVENTS ARE SETUP **
  // Foot Race
  
this.(@"event_Foot Race").level "event_footrace.nw";
  
this.(@"event_Foot Race").startx 8;
  
this.(@"event_Foot Race").starty 60.5;
  
this.(@"event_Foot Race").eventType "Race";
  
// Cave Race
  
this.(@"event_Cave Race").level "event_caverace.nw";
  
this.(@"event_Cave Race").startx 47.5;
  
this.(@"event_Cave Race").starty 53;
  
this.(@"event_Cave Race").eventType "Race";
  
  
// CLEAN UP (DO NOT REMOVE)
  
temp.stringKeys getStringKeys("this.event_");
  for (
temp.stringtemp.stringKeys) {
    if (
temp.string in "_""_0"""NULL }) {
      
this.(@"event_" temp.string) = "";
    }
  }
  
  echo(
getStringKeys("this.event_").size() SPC "events found!");
  
  
setTimer(5);
}

function 
onTimeOut()
{
  
// Is an event still running?
  
if (this.hostedEvent != NULL) {
    
setTimer(60);
    return;
  }
  
  
// Check for ET's on tag
  
for (temp.plallplayers) {
    if (
temp.pl.guild == "Events Team") {
      
temp.eventsTeam.add(temp.pl);
    }
  }
  
  
// Events Team member(s) on tag, aborting
  
if (temp.eventsTeam.size() != NULL) {
    echo(
"[" name "]:" SPC temp.eventsTeam.size() SPC "Events Team member(s) online, aborting...");
    
setTimer(60);
    return;
  }
  
// No Events Team member(s) on tag, continuing
  
else {
    echo(
"[" name "]: No Events Team member(s) found, proceeding...");
    
    
temp.event randomString(getStringKeys("this.event_"));
    
temp.prizeInfo randomString(this.eventPrizes);
    
temp.prize temp.prizeInfo[0];
    
temp.quantity int(random(temp.prizeInfo[1], temp.prizeInfo[2] + 1));
    
    
onHostEvent(temp.eventtemp.prizetemp.quantity);
  }
  
  
setTimer(getEventsTimer());
}

function 
getEventsTimer()
{
  
// Weed out RC's from player count
  
for (temp.plallplayers) {
    if (
temp.pl.level.name != NULL) {
      
temp.players.add(temp.pl);
    }
  }
  
  
temp.playerStages = {
    { 
7},
    { 
310 },
    { 
115 }
  };
  
  for (
temp.stagetemp.playerStages) {
    if (
temp.players.size() >= temp.stage[0]) {
      echo(
"[" name "]: More than" SPC temp.stage[0SPC "players online, setting timer to" SPC temp.stage[1SPC "minutes.");
      return 
temp.stage[1]*60;
    }
  }
  
  echo(
"[" name "]: No players online, setting timer to 20 minutes.");
  return 
20*60;
}

public function 
getEvents()
{
  return 
getStringKeys("this.event_");
}

function 
onHostEvent(eventprizequantity)
{
  if (
this.hostedEvent != NULL) {
    echo(
"[" name "] Error: Attempted to overwrite currently hosted event, aborting...");
    return;
  }
  
  
temp.eventData = new TStaticVar();
  
temp.eventData.copyFrom(this.(@"event_" event));
  
this.hostedEvent = { eventprizequantity };
  
this.eventCalls 1;
  
serverr.hostedEvent = { eventthis.eventCallsquantityfindNPC("ItemCache").getEntry(prize).itemNametemp.eventData.leveltemp.eventData.startxtemp.eventData.starty };
  
  
scheduleEvent(20"onNextCall""");
}

function 
onNextCall()
{
  if (
this.eventCalls <= 3) {
    
this.eventCalls ++;
    
serverr.hostedEvent[1] = this.eventCalls;
    
    
scheduleEvent(20"onNextCall""");
  } else 
scheduleEvent(10"onCloseEvent""");
}

function 
onCloseEvent()
{
  
temp.event = new TStaticVar();
  
temp.event.copyFrom(this.(@"event_" this.hostedEvent[0]));
  
  for (
temp.plallplayers) {
    if (
temp.pl.level.name == temp.event.level) {
      
temp.players.add(temp.pl);
    }
  }
  if (
temp.players.size() == NULL) {
    echo(
"[" name "] Error: Event aborted due to no players attending!");
    
onEndEvent();
    return;
  }
  
  
this.eventCalls NULL;
  
serverr.hostedEvent[1] = -1;
  
  
// ** USED TO START THE EVENT, IT TRIGGERS "onStartEvent" IN A NPC
  // ** PLACED IN THE CURRENT EVENTS LEVEL, THAT HAS THIS IN IT:
  // function onCreated() {
  //   level.startGate = this;
  // }
  
findLevel(temp.event.level).startGate.trigger("StartEvent""");
}

public function 
onEndEvent()
{
  
cancelevents("onEndEvent");
  
  
temp.event = new TStaticVar();
  
temp.event.copyFrom(this.(@"event_" this.hostedEvent[0]));
  
  
warpto(temp.event.leveltemp.event.startxtemp.event.starty);
  for (
temp.plthis.level.players) {
    
temp.pl.setLevel2("events_house.nw"30.530);
  }
  
sendtorc("/updatelevel" SPC this.level.name);
  
// ** WARPS PLAYERS TO THE EVENTS HOUSE
  
warpto("events_house.nw"30.530);
  
  
this.hostedEvent "";
  
serverr.hostedEvent "";

__________________

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

Last edited by xXziroXx; 03-25-2009 at 12:05 AM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.