Thread: Time Problem
View Single Post
  #5  
Old 10-28-2006, 02:26 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
You should get used to using switches. They are more efficient and keep things a bit more orderly. Not to mention this script is very disorganized, making it utterly annoying to fix. I'm only going to bother with the switches, assuming that you don't know much about using them.


PHP Code:
function onCreated() {      
  switch(
serverr.season) {       
   case 
"spring"this.rights.posconditions "rain,fog,cloudy,clearskies";
                  
this.rights.posmoisture "0,100";
                  
this.rights.postemperature "+50,+70";
                  
this.rights.poswaterlevel "lowtide,naturaltide,hightide";
                  
this.rights.poswindconditions "5,30"; break;
  case 
"summer":  this.rights.posconditions "rain,fog,cloudy,clearskies";
                  
this.rights.posmoisture "0,100";
                  
this.rights.postemperature "+50,100";
                  
this.rights.poswaterlevel "lowtide,naturaltide,hightide";
                  
this.rights.poswindconditions "10,50"; break;
  case 
"fall":    this.rights.posconditions "rain,fog,cloudy,clearskies";
                  
this.rights.posmoisture "0,60";
                  
this.rights.postemperature "40,+70";
                  
this.rights.poswaterlevel "naturaltide,lowtide";
                  
this.rights.poswindconditions "5,30"; break;
  case 
"winter":  this.rights.posconditions "sleet,snow,cloudy,clearskies";
                  
this.rights.posmoisture "0,50";
                  
this.rights.postemperature "-20,+50";
                  
this.rights.poswaterlevel "naturaltide,lowtide";
                  
this.rights.poswindconditions "20,50"; break;
  default:        
this.rights.timeconditions "3";
                  
this.rights.timemoisture "2";
                  
this.rights.timetempature "1";
                  
this.rights.timewaterlevel "6";
                  
this.rights.timewindconditions "4";
                  
this.rights.lastcheckedmoisture "hour";
                  
this.rights.lastcheckedtempature "hour";
                  
this.rights.lastcheckedconditions "hour";
                  
this.rights.lastcheckedwindconditions "hour";
                  
this.rights.lastcheckedwaterlevel "hour";
                  
TimeCheck(); break;
  }
}

function 
ChangeMoisture() {
  switch(
this.rights.weather.conditions) {
    case 
"rain"Weather1(); break;
    case 
"sleet"Weather1(); break;
    case 
"clearskies"Weather2(); break;
    case 
"cloudy"Weather2(); break;
    default: 
this.rights.lastcheckedmoisture "hour"; break;
  }
}

function 
Weather1() {
 if (
this.rights.weather.tempature =< "50"
  
this.rights.weather.moisture "this.rights.weather.moisture+1";
  
//wet and cold adds mositure
}

function 
Weather2() {
  if (
this.rights.weather.tempature => "70")
   
this.rights.weather.moisture "this.rights.weather.moisture-1";
   
//dry and warm removes moisture



etc...


I would have switched all functions that could use it, but the script itself is too disorganized and I don't feel like wasting my time on it when this is example enough.


EDIT: I also noticed that you call a lot of the same flags to the same value in vast areas. I edited some of it in my example, but I didnt fix the first function. You should use seperate functions to make it more efficient.

I.E:

PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
  switch(
player.chat) {
    case 
"hello"ClearChat(); break;
    case 
"hey"ClearChat(); break;
    case 
"wow"ClearChat(); break;
  }
}

function 
ClearChat() {
  
player.chat "";


Also, you should use PHP or Code tags when posting script, mainly to not piss people off by making it difficult to read and having them just avoid reading the script and helping you.
Reply With Quote