Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-23-2009, 12:19 AM
Jman9912 Jman9912 is offline
Registered User
Join Date: Jun 2001
Location: North Carolina
Posts: 114
Jman9912 is on a distinguished road
Send a message via AIM to Jman9912
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;
}
}

Reply With Quote
  #2  
Old 11-23-2009, 02:04 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Use a timeout, and possibly timevar to gauge the time so it's around the same for everybody.
__________________
Quote:
Reply With Quote
  #3  
Old 11-23-2009, 02:18 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
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);
  }

__________________
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 11-23-2009, 07:17 AM
Jman9912 Jman9912 is offline
Registered User
Join Date: Jun 2001
Location: North Carolina
Posts: 114
Jman9912 is on a distinguished road
Send a message via AIM to Jman9912
Ah Thank you. Yeah the GS1 is still coming out. How exactly would the timevar work?
Reply With Quote
  #5  
Old 11-23-2009, 04:04 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Jman9912 View Post
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);

__________________
Quote:
Reply With Quote
  #6  
Old 11-23-2009, 05:47 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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?
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #7  
Old 11-23-2009, 08:10 PM
Riot Riot is offline
Delteria Management
Join Date: Nov 2003
Location: Seminole County, Florida
Posts: 280
Riot is on a distinguished road
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.
Reply With Quote
  #8  
Old 11-23-2009, 08:25 PM
Jman9912 Jman9912 is offline
Registered User
Join Date: Jun 2001
Location: North Carolina
Posts: 114
Jman9912 is on a distinguished road
Send a message via AIM to Jman9912
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.

Last edited by Jman9912; 11-23-2009 at 08:47 PM..
Reply With Quote
  #9  
Old 11-23-2009, 09:46 PM
Riot Riot is offline
Delteria Management
Join Date: Nov 2003
Location: Seminole County, Florida
Posts: 280
Riot is on a distinguished road
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.
Reply With Quote
  #10  
Old 11-24-2009, 11:38 AM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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.
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #11  
Old 11-24-2009, 02:37 PM
Jman9912 Jman9912 is offline
Registered User
Join Date: Jun 2001
Location: North Carolina
Posts: 114
Jman9912 is on a distinguished road
Send a message via AIM to Jman9912
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);

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 09:39 AM.


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