Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Day/Night system (https://forums.graalonline.com/forums/showthread.php?t=134257030)

Jman9912 11-23-2009 12:19 AM

Day/Night system
 
I'm working on a basic day night system for practice. Here is what I have so far as it is really basic. Still adapting to GS2. I was wondering if anyone could give me any suggestions and help me improve on it.

NPC Code:

//#CLIENTSIDE
function onCreated() {
client.time=0;
Initialize();
}

function Initialize() {
for (client.time == 0;client.time <= 23;client.time++) {
if (client.time >= 0 && client.time<2) {
seteffect 0,0,0,.7;
}

if (client.time >=3 && client.time <= 5) {
seteffect 0,0,0,.5
}

if (client.time >= 6 && client.time <=8) {
seteffect 0,0,0,.3;
}

if (client.time >=9 && client.time <=12) {
seteffect 0,0,0,.1;
}

if (client.time >=13 && client.time <=17) {
seteffect 0,0,0,0;
}

if (client.time >=18 && client.time <=21) {
seteffect 0,0,0,.3;
}

if (client.time >=22 && client.time <=24) {
seteffect 0,0,0,.5;
}

sleep(2);

if (client.time==24) {
client.time = 0;
}
echo(client.time);
showtext(128,50,150,$pref::graal::defaultfontname, "bc","Time: " @ client.time @ ":00");
changeimgvis 128,4;
}
}


fowlplay4 11-23-2009 02:04 AM

Use a timeout, and possibly timevar to gauge the time so it's around the same for everybody.

Switch 11-23-2009 02:18 AM

seteffect and changeimgvis should have parenthesis around the params. The image ID shouldn't be less than 200 if it's meant to only show on one player's screen, and the x/y coordinates are tile-based in the level, not pixel-based on the screen. In the for loop you need to set "client.time", not check it, and it won't get to 24 since your loop wants it to be less than or equal to 23. Otherwise, I agree with what Jer said.

Also, use PHP tags instead of CODE tags. It's easier to read.
Here's some of what you have fixed:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
client.time=0;
  
Initialize();
}

function 
Initialize() {
  for (
client.time 0;client.time <= 24;client.time++) {
    if (
client.time >= && client.time<2) {
      
seteffect(000.7);
    } 

    if (
client.time >=&& client.time <= 5) {
      
seteffect(000.5);
    }

    if (
client.time >= && client.time <=8) {
      
seteffect(000.3);
    }

    if (
client.time >=&& client.time <=12) {
      
seteffect(000.1);
    }

    if (
client.time >=13 && client.time <=17) {
      
seteffect(0000);
    }

    if (
client.time >=18 && client.time <=21) {
      
seteffect(000.3);
    }
    
    if (
client.time >=22 && client.time <=24) {
      
seteffect 0,0,0,.5;
    }

    
sleep(2);

    if (
client.time==24) {
      
client.time 0;
    }
    echo(
client.time);
    
showtext(20050150$pref::graal::defaultfontname"bc""Time: " client.time ":00");
    
changeimgvis(2004);
  }



Jman9912 11-23-2009 07:17 AM

Ah Thank you. Yeah the GS1 is still coming out. How exactly would the timevar work?

fowlplay4 11-23-2009 04:04 PM

Quote:

Originally Posted by Jman9912 (Post 1539820)
Ah Thank you. Yeah the GS1 is still coming out. How exactly would the timevar work?

Basically, with the usage of the mod operator (percent sign), you'll get a value between 0 and 24, which you can base your day night system around but timevar increments once every five seconds.

Due to the forums protection replace [percent] in the script with an actual percent sign.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
setTimer(0.05);
}

function 
onTimeout() {
  
// To get your 24 hour time
  
temp.current_time timevar [percent24;
  
// Do stuff with it
  // Continue Timing Out
  
setTimer(5);



Liberated 11-23-2009 05:47 PM

i gave it a try too, but neither the minutes, nor the hours are accurate for my timezone,(off by like 20 minutes and like 5hours), and i think atleast the minutes should be accurate, right?

Riot 11-23-2009 08:10 PM

timevar isn't meant to give your local time. It increases by 1 every 5 seconds, and I believe is based off of when Graal2001 went online.

Jman9912 11-23-2009 08:25 PM

I see. So I could just set the client.time variable to timevar with a mod of 24.

I'm wanting a full day to last about 3 hours in-game. Would this be the most efficient way for that? This seems like a full day would be an actual 24 hours.

I was playing around a bit with it and did temp.timevar = timevar % 24;

It goes up by 10 every time it's called and keeps going up.

Riot 11-23-2009 09:46 PM

If you use 1 timevar tick is equal to 1 hour, an in-game day will take 2 minutes.

It would probably be better to use timevar as minutes:
(replace [p] with a percent sign....)

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
onTimeout();
}

function 
onTimeout() {
  
temp.minutes timevar [p60;
  
temp.hours int(timevar 60) [p24;
  
temp.display =  (temp.hours 10 "0" "") @ temp.hours ":" @ (temp.minutes 10 "0" "") @ temp.minutes;

  
with (findimg(200)) {
    
text "Time: " temp.display;
    
font "Arial";
    
5;
    
5;
    
layer 4;
  }
  
  
setTimer(5);


This will display the time in the top-left corner of your screen using timevar as a synchronized timer.

Liberated 11-24-2009 11:38 AM

I made a script that holds a day on graal equal to a day irl, containing the clock that riot just showed, and your effects, i now know how effects work :P
you can use it if you want, it's mostly your work anyway.
I also made it run synchronised to atleast 4-5 seconds on my own time.

PHP Code:

//#CLIENTSIDE
function onCreated()
{
  
settimer(0.05);
}
function 
onTimeOut()
{
  
this.acc = (((timevar*5)/3600)[percent24)-5.441;
  
this.time int(this.acc);
  
temp.time this.time ":" int((this.acc this.time)*60);
  if (
client.time >= && client.time<2
  {
      
seteffect(000.7);
  } 

  if (
this.time >= && this.time <= 5
  {
    
seteffect(000.5);
  }
  else if (
this.time >= && client.time <= 8
  {
    
seteffect(000.3);
  }

  else if (
this.time >= && this.time <= 12)
  {
    
seteffect(000.1);
  }

  else if (
this.time >= 13 && this.time <= 17
  {
    
seteffect(000.0);
  }
  else if (
this.time >= 18 && this.time <= 21
  {
    
seteffect(000.3);
  } 
  else
  {
    
seteffect 0,0,0.5;
  }
  
with (findimg(200))
  { 
    
text "Time: " temp.time
    
font "Arial"
    
5
    
5
    
layer 4
  }
  
settimer(1);


you do have to replace the [percent] with a real percent sign tho.

Jman9912 11-24-2009 02:37 PM

Nice. Here is what i'm working with so far. It's got a few errors that i'm working on atm. I'm currently tweaking trying to fix the problems. Too much nyquil in my system atm lol. Damn flu....

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
onTimeout();
}

function 
onTimeout() {
  
temp.minutes timevar [percent60;
  
temp.hours int(timevar 60) [percent24;
  
temp.display =  (temp.hours 10 "0" "") @ temp.hours ":" @ (temp.minutes 10 "0" "") @ temp.minutes;
  
with (findimg(200)) {
    
text "Time: " temp.display;
    
font "Arial";
    
5;
    
screenheight 25;
    
layer 4;
  }
  
if (
temp.hours >&& temp.hours <= 20) {
this.sunrise=0;
seteffect(0,0,0,0);
echo(
"5");
}


if (
temp.hours >22) {
echo(
"2");
seteffect(0,0,0,0);
this.sunset=0;
}

if (
temp.hours==&& temp.sunrise ==0) {
temp.sunrise=1;
echo(
temp.sunrise);
Sunrise();
}

if (
temp.hours==21 && this.sunet==0) {
temp.sunset=1;
Sunset();
}

if (
temp.hours 4) {
seteffect(0,0,0,.5);
echo(
"3");
}



  
setTimer(5);
}

function 
onPlayerChats() {
player.chat.tokenize;
if (
params[0]=="sunrise") {
Sunrise();
}
if (
params[0]=="sunset") {
Sunset();
}
}

function 
Sunrise() {
seteffect(0,0,0,0.4);
sleep(2);
seteffect(0,0,0,0.3);
sleep(2);
seteffect(0,0,0,0.2);
sleep(2);
seteffect(0,0,0,0.1);
sleep(2);
seteffect(0,0,0,0);
}

function 
Sunset() {
seteffect(0,0,0,0.1);
sleep(2);
seteffect(0,0,0,0.2);
sleep(2);
seteffect(0,0,0,0.3);
sleep(2);
seteffect(0,0,0,0.4);
sleep(2);
seteffect(0,0,0,.5);




All times are GMT +2. The time now is 01:23 PM.

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