Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 03-25-2009, 12:05 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Very nice! You might want to add an onInitialized() function to start the timer for when the server restarts (onCreated won't be called).
__________________
Reply With Quote
  #3  
Old 03-25-2009, 12:06 AM
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
Quote:
Originally Posted by cbk1994 View Post
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!
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #4  
Old 03-27-2009, 03:49 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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.
__________________
Reply With Quote
  #5  
Old 03-27-2009, 04:24 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
Quote:
Originally Posted by Chompy View Post
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.

Quote:
Originally Posted by Chompy View Post
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.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #6  
Old 03-31-2009, 03:43 AM
xfazex xfazex is offline
Registered User
Join Date: Feb 2009
Location: Eastern Shore, Maryland USA
Posts: 81
xfazex is an unknown quantity at this point
Send a message via AIM to xfazex Send a message via MSN to xfazex Send a message via Yahoo to xfazex
Wow, really nice dude.
Reply With Quote
  #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
  #8  
Old 06-06-2012, 06:35 PM
Fanty Fanty is offline
Registered User
Join Date: Mar 2012
Posts: 7
Fanty is on a distinguished road
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
Reply With Quote
  #9  
Old 06-07-2012, 12:58 AM
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
Quote:
Originally Posted by Fanty View Post
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.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #10  
Old 06-07-2012, 01:20 AM
greggiles greggiles is offline
Registered User
greggiles's Avatar
Join Date: Sep 2007
Posts: 149
greggiles has a spectacular aura about
rep ++
Reply With Quote
  #11  
Old 06-07-2012, 02:15 AM
Rave_J Rave_J is offline
Graal Developer
Join Date: Feb 2006
Location: Texas
Posts: 848
Rave_J can only hope to improve
Send a message via AIM to Rave_J Send a message via MSN to Rave_J Send a message via Yahoo to Rave_J
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
__________________
Graal Developer
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 03:03 PM.


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