Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Countdown Script (Timer) (https://forums.graalonline.com/forums/showthread.php?t=134258635)

ChainGang_DX 04-03-2010 10:27 PM

Countdown Script (Timer)
 
Well, Ive been having a hard time learning to Script.. but I just wanted a heads up on what to do on a Script for a timer on a jailer.. Like I want the player to see the timer ass in like 00:00:00 , like a countdown. Anyone help me?;)

LoneAngelIbesu 04-04-2010 03:21 AM

You're going to need to use a timeout, or something similar. Since seconds are your smallest unit, make the 'jail time' count in seconds; e.g., 1 hour in jail would be 3600 seconds. Store that somewhere, like a clientr. variable.

Then, format those seconds into the hh:mm:ss format. There are functions in the Code Gallery for that, I think. But it's pretty easy math:
hours = jailTimeinSeconds / 3600
minutes = (jailTimeinSeconds % 3600) / 60
seconds = (jailTimeinSeconds % 3600) % 60
After that, you're going to need to do some special formatting to put zeros in front of single-digit numbers. (As simple as checking if the number < 10.)

Then just display that however you want.

Switch 04-04-2010 03:32 AM

Quote:

Originally Posted by LoneAngelIbesu (Post 1566940)
hours = int(jailTimeinSeconds / 3600);
minutes = int((jailTimeinSeconds % 3600) / 60);

Should always use int() when dividing, if you need it to be an integer.

ChainGang_DX 04-04-2010 05:32 AM

NPC Code:
function onActionServerSide()
{
if (params[0] == "echo")
{
sendtorc("Timer Up!");
//echo("Hello World!");
}
}
//#CLIENTSIDE
function onKeyPressed(code,key)
{
if (key == "1")
{
for (i = 3; i > 0; i --)
{
player.chat = i;
sleep(1);
}

playlooped("beep2.wav");
player.chat = ":end";
//ECHO IS DONE SERVERSIDE
triggerserver("weapon",name,"echo");
sleep(5);
stopsound("beep2.wav");
play("goera3.wav");
}
}




This is the Script i'm trying to make a command that can work by hours minutes and seconds, like 00:00:00. I also Wanna make it stop counting down when I say :end, Help plz?:cool:

ChainGang_DX 04-04-2010 09:57 AM

I've added a token for setting how long you want the timer to go off from. Instead of just using the Auto one by press 1.


NPC Code:
function onActionServerSide()
{
if (params[0] == "echo")
{
sendtorc("Timer Up!");
//echo("Hello World!");
}
}
//#CLIENTSIDE
function onKeyPressed(code,key)
{
if (key == "1")
{
for (i = 3; i > 0; i --)
{
player.chat = i;
sleep(1);
}

playlooped("beep2.wav");
player.chat = ":end";
//ECHO IS DONE SERVERSIDE
triggerserver("weapon",name,"echo");
sleep(5);
stopsound("beep2.wav");
play("goera3.wav");
}
}


function onPlayerChats(who,chat)

{
token = player.chat.tokenize();
if (token[0] == "/countdown" && token[1] != NULL)
{
for (i = token[1]; i > 0; i--)
{

player.chat = i;
sleep(1);
play("beep2.wav");




}
}
}


LoneAngelIbesu 04-04-2010 07:13 PM

Please use the PHP code tags, rather than the NPC code ones.

Your script doesn't have any kind of countdown mechanism. Here's some pseudo-code, just that I'm not doing everything for you.
PHP Code:

function onActionServerside(cmdpl) {
  switch(
temp.cmd) {
    case 
"jailplayer":
      
store jail time for player
      
switch to jail level
      
break;
    case 
"countdown":
      
subtract 1 from jail time
      
break;
    case 
"unjailplayer":
      switch 
level
      
break;
  }
}
//#CLIENTSIDE
function onPlayerEnters() { // There's probably a better way to do this
  
if player.level.name == jail level
    set timer to 1
}
function 
onTimeout() {
  if 
jail time is 0
    convert second to hh
:mm:ss format and display
    set timer to 1
  
else
    
set timer to 0
    trigger 
"unjailplayer" serverside command



Switch 04-05-2010 12:27 AM

Quote:

Originally Posted by LoneAngelIbesu (Post 1567047)
Please use the PHP code tags, rather than the NPC code ones.

Your script doesn't have any kind of countdown mechanism. Here's some pseudo-code, just that I'm not doing everything for you.
PHP Code:

function onActionServerside(cmdpl) {
  switch(
temp.cmd) {
    case 
"jailplayer":
      
store jail time for player
      
switch to jail level
      
break;
    case 
"countdown":
      
subtract 1 from jail time
      
break;
    case 
"unjailplayer":
      switch 
level
      
break;
  }
}
//#CLIENTSIDE
function onPlayerEnters() { // There's probably a better way to do this
  
if player.level.name == jail level
    set timer to 1
}
function 
onTimeout() {
  if 
jail time is 0
    convert second to hh
:mm:ss format and display
    set timer to 1
  
else
    
set timer to 0
    trigger 
"unjailplayer" serverside command



Everything should be serverside for a jail system (except the GP tools).

LoneAngelIbesu 04-05-2010 01:29 AM

Quote:

Originally Posted by Switch (Post 1567097)
Everything should be serverside for a jail system (except the GP tools).

Enlighten me.


All times are GMT +2. The time now is 12:49 AM.

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