Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Events System (Automated hosting included) (https://forums.graalonline.com/forums/showthread.php?t=84823)

xXziroXx 03-24-2009 11:48 PM

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 "";



cbk1994 03-25-2009 12:05 AM

Very nice! You might want to add an onInitialized() function to start the timer for when the server restarts (onCreated won't be called).

xXziroXx 03-25-2009 12:06 AM

Quote:

Originally Posted by cbk1994 (Post 1477527)
Very nice! You might want to add an onInitialized() function to start the timer for when the server restarts (onCreated won't be called).

Done!

Chompy 03-27-2009 03:49 PM

I would like if it were customizable :] (More variables that you could edit at the top)

Also, I see there's an array for event prizes, yet no note where to add the "additem" code to the winning players? :o

I really like systems like this, things that automates something that a player would do. ^^

xXziroXx 03-27-2009 04:24 PM

Quote:

Originally Posted by Chompy (Post 1478405)
I would like if it were customizable :] (More variables that you could edit at the top)

I don't really think it needs to be any more customizeable then it already is. :oo:

Quote:

Originally Posted by Chompy (Post 1478405)
Also, I see there's an array for event prizes, yet no note where to add the "additem" code to the winning players? :o

This system starts and ends events. Everything in between you'll have to script yourself.

xfazex 03-31-2009 03:43 AM

Wow, really nice dude.

xXziroXx 04-16-2009 05:12 PM

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);



Fanty 06-06-2012 06:35 PM

I don't get how to start an event!
 
First time posting something here,
i want to ask you how to mass out an event,the level name is event_chance.nw.
So i should be able to but i say StartEvent Chance and it doesn't work.
Is this even an Event System that does this... ^^^
Thanks if you reply

xXziroXx 06-07-2012 12:58 AM

Quote:

Originally Posted by Fanty (Post 1696578)
First time posting something here,
i want to ask you how to mass out an event,the level name is event_chance.nw.
So i should be able to but i say StartEvent Chance and it doesn't work.
Is this even an Event System that does this... ^^^
Thanks if you reply

I think you're in way over your head. The only hint I can give you is to utilize the function onHostEvent.

greggiles 06-07-2012 01:20 AM

rep ++

Rave_J 06-07-2012 02:15 AM

glad u release this :) but i still like to be like old era was like making events rare to host due ec coins are rare but this would be good for classic style servers


All times are GMT +2. The time now is 06:59 PM.

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