Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-03-2010, 10:27 PM
ChainGang_DX ChainGang_DX is offline
Animations Artist On Era
ChainGang_DX's Avatar
Join Date: Mar 2010
Location: Texas
Posts: 35
ChainGang_DX is an unknown quantity at this point
Send a message via AIM to ChainGang_DX
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?
__________________



Scoper Zephlyn (Sat Oct 15 14:53:42 2011):
owned.
Reply With Quote
  #2  
Old 04-04-2010, 03:21 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
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.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #3  
Old 04-04-2010, 03:32 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by LoneAngelIbesu View Post
hours = int(jailTimeinSeconds / 3600);
minutes = int((jailTimeinSeconds % 3600) / 60);
Should always use int() when dividing, if you need it to be an integer.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #4  
Old 04-04-2010, 05:32 AM
ChainGang_DX ChainGang_DX is offline
Animations Artist On Era
ChainGang_DX's Avatar
Join Date: Mar 2010
Location: Texas
Posts: 35
ChainGang_DX is an unknown quantity at this point
Send a message via AIM to ChainGang_DX
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?
__________________



Scoper Zephlyn (Sat Oct 15 14:53:42 2011):
owned.
Reply With Quote
  #5  
Old 04-04-2010, 09:57 AM
ChainGang_DX ChainGang_DX is offline
Animations Artist On Era
ChainGang_DX's Avatar
Join Date: Mar 2010
Location: Texas
Posts: 35
ChainGang_DX is an unknown quantity at this point
Send a message via AIM to ChainGang_DX
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");




}
}
}

__________________



Scoper Zephlyn (Sat Oct 15 14:53:42 2011):
owned.
Reply With Quote
  #6  
Old 04-04-2010, 07:13 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
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

__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #7  
Old 04-05-2010, 12:27 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by LoneAngelIbesu View Post
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).
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #8  
Old 04-05-2010, 01:29 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Switch View Post
Everything should be serverside for a jail system (except the GP tools).
Enlighten me.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
Reply


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


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