PDA

View Full Version : Model Race Timer Script


_Z3phyr_
07-12-2007, 03:01 PM
(... or any other kind of time challenge script, given various changes)

Another thing that I wanted to do was create quests and stuff. In Graal, quests are synonomous with mundane crap like "go deliver this letter" or "go kill this monster in a tower" and I wanted to make stuff that I usually see in other RPG games not anything specific, mind you, but general models of quests that I've never seen on any server. I'm not talented at creating puzzles or whatever, and I'm sure you're better than me at it so blah. With this Race thing, I was thinking that races could be used in a quest somehow how exactly, I forget to be honest.

Attached is the level file in which the script is put to use feel free to download, but don't count on it working unless you have a server to upload and warp to.

To keep in line with my habits of explaining things, I'll elaborate on the concept and how it works.

The level contains three main NPCs: The Goal line (for counting laps), the Block (as in most race events on servers, there's a wall or something to prevent the players from crossing the line to start so they're all together and start even), and the Timer. The commands for start and end are pretty self-explanatory: /go and /stop. Make sure you're on the right side of the goal line before you begin since the 'block' is on the right side.

The timer is probably the most important part of the script. It is made for just use in that one level, but I'm sure you can figure out how to make it work outside of the level later on. It's very simple. this.t0 and this.t1 mean beginning and ending times, and are used to get the final time.

It's stupidly easy to make a countdown script ("do this in 5 seconds or you lose!") for a quest or puzzle, but perhaps you can use this for a race event to keep track of fastest record times (horse race???).



PS -- in case for whatever reason you can't download the .nw, here are the three scripts themselves. I'm sure you can figure out how to use them.
//#CLIENTSIDE
//"The Goal Line"
function onCreated() {
setshape(1,16,16*6);
dontblock();
drawunderplayer();
}
function onPlayerenters() {
finish();
}
function onPlayerleaves() {
finish();
}
function onPlayertouchsme() {
if (client.questxRACE>0) {
if (this.lap<3) {
this.lap++;
if (this.lap==3) { chat = "Final lap!"; }
else { chat = "Lap" SPC this.lap @ "!"; }
} else { finish(); }
}
}
function finish() {
client.questxRACE = null;
this.lap = null;
chat = "say /go to begin; /stop to end if you cannot do the 3 laps";
}//#CLIENTSIDE
//"The Block"
function onCreated() {
setshape(1,16,16*6);
blockagain();
}
function onPlayerchats() {
if (player.chat=="/go") {
client.questxRACE = 1;
hide();
}
if (player.chat=="/stop") {
client.questxRACE = null;
show();
}
}
function onPlayerenters() { this.setTimer(.1); }
function onTimeout() {
if (client.questxRACE in {null,0}) {
show();
this.setTimer(0);
}
this.setTimer(.2);
}//#CLIENTSIDE
//The "timer"
function onPlayerenters() {
client.questxRACE = this.t0 = this.t1 = null;
this.setTimer(.05);
}
function onPlayerleaves() {
client.questxRACE = null;
}
function onTimeout() {
if (client.questxRACE>0) {
this.t0 = timevar2;
this.t1 = 0; this.t1 += .1;
chat = this.t1;
} else if (this.t1>0 || this.t0>0) {
chat = "Your Final Time:" SPC abs((this.t1+this.t0)-this.t0);
if (client.questxRACErecord in {null,0}) {
client.questxRACErecord = 318;
}
if (abs((this.t1+this.t0)-this.t0)<client.questxRACErecord) {
client.questxRACErecord = abs((this.t1+this.t0)-this.t0);
}
this.t1 = this.t0 = null;
}
this.setTimer(.05);
}

xXziroXx
07-12-2007, 03:07 PM
Upon quickly looking at the scripts themselves, I get the feeling that it could have been done alot smoother.. the scripts come off as sloppy to me. But hey, that's just my initial thoughts.

_Z3phyr_
07-13-2007, 01:23 AM
It was something I was working on just before I left, and I didn't give myself too much time with it all. I had modeled it after the events i had done, so if there is a better way of doing the race, feel free and i'll replace it