Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-05-2011, 08:57 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Countdown Timer

This is just a simple example of a countdown timer.
First off you will need to place this code into a database NPC on your server.
So go ahead and click add and name it whatever you wish and paste the code into the NPC's script.
PHP Code:
function onCreated() {
  
this.daysleft "10";
  
this.hoursleft "10";
  
this.minutesleft "10";
  
this.secondsleft "10";
  
onTimeout();
}

function 
onTimeout() {
  
this.secondsleft -= 1;
  if (
this.secondsleft == || this.secondsleft 0) {
    
this.minutesleft -= 1;
    
this.secondsleft 60;
  }
  if (
this.minutesleft == || this.minutesleft 0) {
    
this.hoursleft -= 1;
    
this.minutesleft 60;
  }
  if (
this.hoursleft == || this.hoursleft 0) {
    
this.daysleft -= 1;
    
this.hoursleft 24;
  }
  
settimer(1);
}


public function 
GetTimeLeft() {
  return 
"Days: " this.daysleft " Hours: " this.hoursleft " Minutes: " this.minutesleft " Seconds: " this.secondsleft;

To get the time simple place this code into a level NPC.
PHP Code:
function onCreated() {
  
onTimeout();
}

function 
onTimeout() {
  
this.chat NPCNAME.GetTimeLeft();
  
settimer(0.5);

But substiture NPCNAME for whatever you named the database NPC.
-Enjoy

Also for the smart ones out there, I am thinking of making a weapon where a player can set their own countdown.
The only problem so far is how would it countdown if the player is offline?
Of course you could just make a dozen or so server variables but that's a bad way.
Would making a timevar and setting it to a clientr variable work?
But even if it would that would only be good for counting down seconds..
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
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 05:17 AM.


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