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 == NULL) this.size = { 1, 1 };
show();
setImgPart("mal_tb_startgate.png", 0, 0, this.size[0]*16, this.size[1]*16);
setShape(1, this.size[0]*16, this.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.pl: players) {
if (temp.pl.guild in serveroptions.staffguilds.tokenize(",")) continue;
this.eventParticipants.add(temp.pl);
}
if (this.eventParticipants.size() < 3) {
for (temp.pl: this.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(1, x + width/2, y, z, "mal_startrace");
scheduleevent(6.6, "onTriggerNPCs", "");
scheduleevent(20, "onCloseEvent", "");
}
function onCloseEvent() show();
function onTriggerNPCs()
{
hideImg(1);
hide();
for (temp.npc: npcs) {
temp.npc.trigger("StartingEvent", "");
}
}
Finish line
PHP Code:
function onCreated()
{
this.db = findNPC("Control-Events");
if (this.shape == NULL) this.shape = { 1, 1 };
save[0] = this.shape[0], save[1] = this.shape[1];
setShape(1, this.shape[0]*16, this.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 == NULL) temp.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.account, player.communityname };
this.db.(@"event_" @ temp.eventName).races ++;
if (this.db.(@"event_" @ temp.eventName).races == 1) {
this.db.(@"event_" @ temp.eventName).firstWinner = { player.account, player.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.item, temp.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.pl: players) {
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", x, y);
changeImgPart(200, 0, 0, this.size[0]*16, this.size[1]*16);
changeImgVis(200, 0);
}