PDA

View Full Version : Time Problem


Loakey_P2P
10-25-2006, 08:49 AM
ok the first npc involved is a time database which is self sustaining . the npc im making is a self sustaining weather database . the problem seem's to be that it's not checking the time corectly . as all the different aspect's of weather are stored as flag's on the npc and check every so many hour's and altered . i have it pretty much set up but it's not setting the flag's to the right value .

Flag List -
---------------------------------------------------------------------
possable conditions for the weather for all season's .

conditions="rain","snow","sleet","fog","cloudy","clearskies"
humidity="10%","other weather functions like temp or moisture"
moisture="10%","0%-100%","groundmoisture" ,"plantgrowing","plantwatering"
temperature="70","-60 - 90+","groundmoisture","plantgrowth","plantwatering"
waterlevel="hightide","naturaltide","lowtide","raftmovement","waterbaddys"
windconditions="5,100,direction","raftmovement"
---------------------------------------------------------------------
what all the different string's are .

information.pos.strings=possable settings for the season
information.rights=Still Working It , this is just set up for example to show the strings that will be used , their tolerance levels and what they will effect .
information.time.strings=time checked and resetted
information.weather.strings=actual information strings
---------------------------------------------------------------------
the hour the condition was last checked .

rights.lastcheckedconditions=hour
rights.lastcheckedmoisture=hour
rights.lastcheckedtempature=hour
rights.lastcheckedwaterlevel=hour
rights.lastcheckedwindconditions=hour
---------------------------------------------------------------------
possable setting's for the current season .

rights.posconditions=rain,fog,cloudy,clearskies
rights.posmoisture=0,100
rights.postemperature=+50,100
rights.poswaterlevel=lowtide,naturaltide,hightide
rights.poswindconditions=10,50
---------------------------------------------------------------------
the time each condition is checked . hourly rate .

rights.timeconditions=3
rights.timemoisture=2
rights.timetempature=1
rights.timewaterlevel=6
rights.timewindconditions=4
---------------------------------------------------------------------
the real information flag's , or current setting's .

rights.weather.conditions="clearskies"
rights.weather.moisture="10"
rights.weather.temperature="60"
rights.weather.waterlevel="naturaltide"
rights.weather.windconditions="5,north-east"
---------------------------------------------------------------------
my first problem is as i said before a flag isnt setting the right value . instead
of the flag being set to a number its being set to the word . ive tryed several varation's but nothing has worked so far . and i searched throu the wikipidia site but i didnt see any kind of time example in the new gs2 or even a discription .

this.rights.lastcheckedwaterlevel = "hour";

but if this isnt working i wonder if the time checker part will work either but i wont know untill i get least one of them fixed . can anyone help with this , but there is another problem . the old with(getnpc(npcname)){ command . i found a new one in one of our script's but im not sure about how
it send's the informaton and what not . i know nothing about this new command other then the findNPC("NPCnameHere") , "the .guilds.remove" i believe is the word trigger's sent but im not for sure . any help would be greatly appreciated .

findNPC("Control-LocalGuilds").guilds.remove(uppercase(clientr.guild[0]));

Devil
10-25-2006, 09:16 AM
In the flag list, why is there a space in "c learskies"?

Admins
10-25-2006, 12:04 PM
Hmmm there are quite often spaces in the commands you have posted, may be it was copied incorrectly? For the actual problem I would need some part of the code I guess

Loakey_P2P
10-28-2006, 01:23 AM
sorry bout that but no it wasnt an error in the script . it was an error on my part in the copy process but here is the code stefan . the time npc we are sure they are working but the flag's are as minute , hour , ect .
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//Scripter = Loakey_P2P,Loakey Ronso
//information = mostly this will make another variable to the plant growing . which will make the process to grow
//information = stuff vary at times . other stuff will be varying water movement for the raft as well as water baddys
//information = in the end i want this to control rain , snow , ect. as well as string's for thing's mentioned above .
//map info below -
//overworldsize = "54 Levels By 54 Levels"
//corditanitesize = "32400 x 32400"
//x.random(0,32400);
//y.random(0,32400);
//String Info
//rights.time[param]=time between checks
//rights.lastchecked[param]=last time it was checked
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
function onCreated(){ //sets up basic stuff the script need's to function
if(serverr.season == "spring"){ //defines all possable condition's for the seasons
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";
}
if(serverr.season == "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";
}
if(serverr.season == "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";
}
if(serverr.season == "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";
}
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();
}

function ChangeMoisture(){
if(this.rights.weather.conditions == "rain" || "sleet" && this.rights.weather.tempature =< "50"){
this.rights.weather.moisture = "this.rights.weather.moisture+1";
} //wet and cold adds mositure
if(this.rights.weather.conditions == "clearskies" || "cloudy" && this.rights.weather.tempature => "70"){
this.rights.weather.moisture = "this.rights.weather.moisture-1";
} //dry and warm removes moisture
this.rights.lastcheckedmoisture = "hour";
}

function ChangeTempature(){
if(this.rights.weather.conditions == "rain" && this.rights.weather.tempature != "rights.postemperature[1]"){this.rights.weather.tempature = "rights.weather.tempature - random(1,5);";}
if(this.rights.weather.conditions == "snow"){this.rights.weather.tempature = "rights.weather.tempature - random(1,5);";}
if(this.rights.weather.conditions == "sleet"){this.rights.weather.tempature = "rights.weather.tempature - random(1,5);";}
if(this.rights.weather.conditions == "fog"){this.rights.weather.tempature = "rights.weather.tempature - 1";}
if(this.rights.weather.conditions == "cloudy"){this.rights.weather.tempature = "rights.weather.tempature + random(1,5);";}
if(this.rights.weather.conditions == "clearskies"){this.rights.weather.tempature = "rights.weather.tempature + random(1,5);";}
this.rights.lastcheckedtempature = "hour";
}

function ChangeConditions(){
this.newcondition = "random(1,4);";
if(this.newcondition == "1"){this.rights.weather.conditions = "rights.posconditions[0]";}
if(this.newcondition == "2"){this.rights.weather.conditions = "rights.posconditions[1]";}
if(this.newcondition == "3"){this.rights.weather.conditions = "rights.posconditions[2]";}
if(this.newcondition == "4"){this.rights.weather.conditions = "rights.posconditions[3]";}
unset this.newcondition;
this.rights.lastcheckedconditions = "hour";
}

function ChangeWindConditions(){
this.rights.windconditions[0] = "random(rights.poswindconditions[0],rights.poswindconditions[1]);"; // wind speed
this.newdirection = "random(0,7)"; //wind direction - cords like direction .
if(this.newdirection == "0"){this.rights.windconditions[1] = "north";}
if(this.newdirection == "1"){this.rights.windconditions[1] = "north-west";}
if(this.newdirection == "2"){this.rights.windconditions[1] = "west";}
if(this.newdirection == "3"){this.rights.windconditions[1] = "south-west";}
if(this.newdirection == "4"){this.rights.windconditions[1] = "south";}
if(this.newdirection == "5"){this.rights.windconditions[1] = "south-east";}
if(this.newdirection == "6"){this.rights.windconditions[1] = "east";}
if(this.newdirection == "7"){this.rights.windconditions[1] = "north-east";}
unset this.newdirection;
this.rights.lastcheckedwindconditions = "hour";
}

function ChangeTide(){
if(this.rights.weather.moisture => "50" && this.rights.weather.conditions == "rain" || "sleet"){ // Raise Tide
if(this.rights.weather.waterlevel == "lowtide"){
this.rights.weather.waterlevel = "naturaltide";
}
if(this.rights.weather.waterlevel == "naturaltide"){
this.rights.weather.waterlevel = "hightide";
}
if(this.rights.weather.waterlevel == "hightide"){
this.rights.weather.waterlevel = "hightide";
}
}
if(this.rights.weather.moisture =< "50" && this.rights.weather.conditions == "cloudy" || "clearskies"){ //Lower Tide
if(this.rights.weather.waterlevel == "lowtide"){
this.rights.weather.waterlevel = "lowtide";
}
if(this.rights.weather.waterlevel == "naturaltide"){
this.rights.weather.waterlevel = "lowtide";
}
if(this.rights.weather.waterlevel == "hightide"){
this.rights.weather.waterlevel = "naturaltide";
}
this.rights.lastcheckedwaterlevel = "hour";
}
}

function TimeCheck(){
if(hour == "rights.lastcheckedconditions+rights.timeconditions"){ChangeConditions();}
if(hour == "rights.lastcheckedmoisture+rights.timemoisture"){ChangeMoisture();}
if(hour == "rights.lastcheckedtempature+rights.timetempature"){ChangeTempature();}
if(hour == "rights.lastcheckedwaterlevel+rights.timewaterlevel"){ChangeTide();}
if(hour == "rights.lastcheckedwindconditions+rights.timewindco nditions"){ChangeWindConditions();}
if(this.rights.weather.conditions == "rain" && this.rights.weather.tempature => "70"){
this.rights.weather.humidity = this.rights.weather.humidity + 5;
}
if(this.rights.weather.conditions == "rain" && this.rights.weather.tempature =< "70"){
this.rights.weather.humidity = this.rights.weather.humidity - 5;
}
sleep("1800");
TimeCheck();
}

function Acumulation(){
}

the last function hasnt been made yet . that's one i was putting off to last which will be the actual weather showing part . i dont doubt i made several error's in the process but i was more looking for the difacult problem's . and i cant spell .

Gambet
10-28-2006, 02:26 AM
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.



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:


//#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.

Skyld
10-28-2006, 10:59 AM
I.E:


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

switch (player.chat)
{
case "hello":
case "hey":
case "wow":
{
clearChat();
break;
}
}

Loakey_P2P
10-28-2006, 01:19 PM
ok on the first hand , thank's . i dont know about switches , case and break command's , i have seen them used but i myself dont know them . not saying my script isnt organized but it is alot more organzed then some ive seen . mainly by the structure of it (meaning it's all clean and easy to read) . but no one has answered my question about the time checker . just setting the flag to the value of "hour" isnt working , not even "this.hour" . some of the flag's have the same value but there is reasoning behind it . each season has a different set of possable condition's . some may be the same but im not trying to complicate it so i made all different string's . some may have the same value as other's but not all of them . keep in mind that im still working on figureing out the new gscript . ive learned what i can by looking at other script's and seeing how they made thing's happen . but there are still thing's i havent seen used yet or havent figured out how to use or how they work yet . but thank's to everyone for their assistance .

Loakey_P2P
11-05-2006, 02:02 PM
well i guess no one can tell me why im having problem's getting a database npc to check flag's on another database npc ? ive given the code for the weather npc . if you still need more all i can give is the time npc . which isnt that complicated . it's not very long and not very complicated .


function onCreated(){
setTimer(5);
}
function onTimeout(){
this.namesday={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

this.sec = (int(timevar * 5)) % 60;
this.min = (int(timevar / 12) + 4) % 60;
this.hour = (int(timevar / (12 * 60)) + 2) % 24;
this.days = (int(timevar / (12*60*24)) + 31) % 365;
this.years = int(timevar / (12 * 60 * 24 * 365)) + 2001;
this.season = (int(this.days / (365 / 4)) - 3) % 4;
this.leapyear = this.years / 4 == int(this.years / 4);
if(this.season = "0"){setstring serverr.season,spring;this.season = "spring";}
if(this.season = "1"){setstring serverr.season,summer;this.season = "summer";}
if(this.season = "2"){setstring serverr.season,fall;this.season = "fall";}
if(this.season = "3"){setstring serverr.season,winter;this.season = "winter";}
setTimer(5);
}


any help please ? from anyone . after posting it and looking at it a minute i wonder if i shouldnt case the "if(this.season)" parts ?

Skyld
11-05-2006, 02:23 PM
You should never use = for comparison checking. If you are checking a value, it always should be ==.
if (this.season == 0)
Also, don't use setstring. It's outdated.
serverr.season = "spring";

Loakey_P2P
11-05-2006, 03:02 PM
sorry i never even noticed that . but can you tell me how to do the new type of script for the problem im having ?

with(getnpc(Control-WEATHER)){
this.rights.lastcheckedmoisture = "this.hour";
this.rights.lastcheckedtempature = "this.hour";
this.rights.lastcheckedconditions = "this.hour";
this.rights.lastcheckedwindconditions = "this.hour";
this.rights.lastcheckedwaterlevel = "this.hour";
}


i just need this to set the last hour the different part's were checked to set flag's that will be used durring the time out that will check to see if the current time minus the last time it was checked equal's the time param's set between check's . if you can follow that .

ill try to better explain . the first flag's set are the ones that tell the script how many hour's to wait untill checking or changeing a certain weather condition . the following flags are those .

this.rights.timeconditions = "3";
this.rights.timemoisture = "2";
this.rights.timetempature = "1";
this.rights.timewaterlevel = "6";
this.rights.timewindconditions = "4";


the next set of flags are the ones that change each time the weather condition's are checked and possable changed . that's why this has been so important couse i wont be able to start working out the bug's till i get time established .

this.rights.lastcheckedmoisture = "this.hour";
this.rights.lastcheckedtempature = "this.hour";
this.rights.lastcheckedconditions = "this.hour";
this.rights.lastcheckedwindconditions = "this.hour";
this.rights.lastcheckedwaterlevel = "this.hour";


now when you take "time for checks" and add it to the "last checked time" if you have the current time you do another check . but that can be done more then one way i believe . like if you take the "current time" and subtract the "time required" and get the last checked time, do another check .

Gambet
11-05-2006, 04:29 PM
What?

Why are you putting quotes around the this. variables? You do realize that you're setting the value of all of that to "this.hour" and not the VALUE of it? You don't put quotes when setting the value of one variable to another.

this.blah = this.test <---Correct

this.blah = "this.text" <---Incorrect, unless you want this.blah to actually equal the words "this.text"

Skyld
11-05-2006, 04:50 PM
As well as not using quotes, you should not be using getnpc(). For the new scripting engine, we use findnpc():
with (findNPC("NameOfNPC"))
{
// foo
}
Also inside with () blocks, when you want to retrieve this. flags from outside of the with () block, you must use thiso.:

with (findNPC("Control-Weather"))
{
this.rights.lastcheckedmoisture = thiso.hour;
// etc
}

Loakey_P2P
11-05-2006, 09:18 PM
ok that should help me out . i didnt think about qouteing it as being a possable problem . but yes im still not sure what all the commands have changed to , im just recently looking into the wikipidia site for info . but that should help . yea after about an hour of messing with the code in both npc's i got the time checking to work right . now i can check to see if the rest work's and start the accumulation part's . thank's to all who threw in their two cent's . : )