Here is something you can take a look at. Only creates a climate for an area. Documented within script. The system adjusts the weather based on the month, last month, next month, day of the month, hour of day, morning, day, evening, night with a mind on continuity.
/*::////////////////////////////////////////////////////////////////////////////
//:: Name: KMdS PNP Hard Core Rule Set 1.0
//:: System: KMdS Weather System
//:: FileName Area_environ_HB
//:: Copyright (c) 2008 Michael Careaga
//::////////////////////////////////////////////////////////////////////////////
This sets he weather and with the include HC_Inc_HTF.nss
will modify the hunger/thirst/fatigue rates it fitting.
This weather script should be placed on an invisible placeable's
HB event. The check for weather will be run once every hour and will check on
the variables set on the placeable for the desired climate type for
the area in which the placeable is located.
Temperature for the area is also set. I use this in a seperate heartbeat
script to run any climate base effects on the creatures/players in an area.
Variables to be set upon the environment object located in every area...
MIDMONTH_TEMPERATURE_1
MIDMONTH_TEMPERATURE_2
MIDMONTH_TEMPERATURE_3
MIDMONTH_TEMPERATURE_4
MIDMONTH_TEMPERATURE_5
MIDMONTH_TEMPERATURE_6
MIDMONTH_TEMPERATURE_7
MIDMONTH_TEMPERATURE_8
MIDMONTH_TEMPERATURE_9
MIDMONTH_TEMPERATURE_10
MIDMONTH_TEMPERATURE_11
MIDMONTH_TEMPERATURE_12
HOURLY_TEMPERATURE_VARIABLE_0
HOURLY_TEMPERATURE_VARIABLE_1
HOURLY_TEMPERATURE_VARIABLE_2
HOURLY_TEMPERATURE_VARIABLE_3
HOURLY_TEMPERATURE_VARIABLE_4
HOURLY_TEMPERATURE_VARIABLE_5
HOURLY_TEMPERATURE_VARIABLE_6
HOURLY_TEMPERATURE_VARIABLE_7
HOURLY_TEMPERATURE_VARIABLE_8
HOURLY_TEMPERATURE_VARIABLE_9
HOURLY_TEMPERATURE_VARIABLE_10
HOURLY_TEMPERATURE_VARIABLE_11
HOURLY_TEMPERATURE_VARIABLE_12
HOURLY_TEMPERATURE_VARIABLE_13
HOURLY_TEMPERATURE_VARIABLE_14
HOURLY_TEMPERATURE_VARIABLE_15
HOURLY_TEMPERATURE_VARIABLE_16
HOURLY_TEMPERATURE_VARIABLE_17
HOURLY_TEMPERATURE_VARIABLE_18
HOURLY_TEMPERATURE_VARIABLE_19
HOURLY_TEMPERATURE_VARIABLE_20
HOURLY_TEMPERATURE_VARIABLE_21
HOURLY_TEMPERATURE_VARIABLE_22
HOURLY_TEMPERATURE_VARIABLE_23
CHANCE_OF_PRECIPITATION
CHANCE_OF_CONTINUED_PRECIPITATION
Variables searched for from the defined functions.
Set a value to these using the appropriate skyboxes defined below
int nClear = GetLocalInt(oObject, "CLEAR");
int nStorm = GetLocalInt(oObject, "STORM");
int nCold = GetLocalInt(oObject, "COLD");
int nIcy = GetLocalInt(oObject, "ICY");
SKYBOX_NONE = 0;
SKYBOX_GRASS_CLEAR = 1;
SKYBOX_GRASS_STORM = 2;
SKYBOX_DESERT_CLEAR = 3;
SKYBOX_WINTER_CLEAR = 4;
SKYBOX_ICY = 5;
Notes on pertinent info for functions defined
WEATHER_INVALID = -1;
WEATHER_CLEAR = 0;
WEATHER_RAIN = 1;
WEATHER_SNOW = 2;
WEATHER_USE_AREA_SETTINGS = -1;
//:://////////////////////////////////////////////
//:: Created By: KMdS
//:: Created On: 04/26/2008
//::////////////////////////////////////////////*/
void SetAreaEnvironmentAndTemperature(object oObject = OBJECT_SELF);
void main()
{
object oArea = GetArea(OBJECT_SELF);
// Initiate a looping count so that we process subroutines at whatever
// count we need to.
// Default is whatever number of rounds are in an game hour +1 for counter reset
int nHBDelayProcessingCount = 60+1;
int nHBDelay = GetLocalInt(OBJECT_SELF, "HBDELAY");
if (nHBDelay < nHBDelayProcessingCount)
SetLocalInt(OBJECT_SELF, "HBDELAY", nHBDelay+1);
else{
SetLocalInt(OBJECT_SELF, "HBDELAY", 1);
nHBDelay = 1;
}
// Only process when loop counter at modulo 60 results in 0...(for
// first iteration and every following IG hour)
nModuloResult = nHBDelay%60;
if (nModuloResult == 0)
//Set the areas current temperature
SetAreaEnvironmentAndTemperature();
}
#include"HC_Inc_HTF"
void SetAreaEnvironmentAndTemperature(object oObject = OBJECT_SELF)
{
/****************************
MONTHLY TEMPERATURE
*****************************/
int nCalendarMonth = GetCalendarMonth();
string sMonth = IntToString(nCalendarMonth);
int nCurrentMonthlyBaseTemp = GetLocalInt(oObject, "MIDMONTH_TEMPERATURE_"+sMonth);
/****************************
DAILY TEMPERATURE ADJUSTMENTS
*****************************/
// Determine which month to use for tamperature adjustment, the month before
// or the month after the current one
int nDateBaseTempAdjustment = 0;
int nCurrentDay = GetCalendarDay();
if(nCurrentDay < 15)
{
int nCalendarMonth = GetCalendarMonth();
if(nCalendarMonth == 1)
sMonth = "12";
else
sMonth = IntToString(nCalendarMonth-1);
int nTemperatureAdjustment = GetLocalInt(oObject, "MIDMONTH_TEMPERATURE_"+sMonth);
nTemperatureAdjustment -= nCurrentMonthlyBaseTemp;
nTemperatureAdjustment /= 14;
nTemperatureAdjustment*= (15 - nCurrentDay);
nDateBaseTempAdjustment = nTemperatureAdjustment;
}
else
{
int nCalendarMonth = GetCalendarMonth();
if(nCalendarMonth == 12)
sMonth = "1";
else
sMonth = IntToString(nCalendarMonth+1);
int nTemperatureAdjustment = GetLocalInt(oObject, "MIDMONTH_TEMPERATURE_"+sMonth);
nTemperatureAdjustment -= nCurrentMonthlyBaseTemp;
nTemperatureAdjustment /= 14;
nTemperatureAdjustment *= (nCurrentDay-14);
nDateBaseTempAdjustment = nTemperatureAdjustment;
}
int nDateBaseTemperature = nCurrentMonthlyBaseTemp + nDateBaseTempAdjustment;
/*******************************
HOURLY TEMPERATURE ADJUSTMENTS
*******************************/
int nHour = GetTimeHour();
string sHour = IntToString(nHour);
int nHourlyTemperatureAdjustment = GetLocalInt(oObject, "HOURLY_TEMPERATURE_VARIABLE_"+sHour);
/*******************************
RANDOM TEMPERATURE ADJUSTMENTS
*******************************/
// Introduce a +/- 12 degree variable weighted toward +/- 5 degrees
int RandomTemperatureVariable = d4(- 20;
/*******************************
CURRENT TEMPERATURE
*******************************/
int nCurrentTemperature = nDateBaseTemperature + nHourlyTemperatureAdjustment + RandomTemperatureVariable;
/**********************************************************
CURRENT WEATHER AND WEATHER RELATED TEMPERATURE ADJUSTMENTS
**********************************************************/
// We can only have weather in an exterior environment
object oArea = GetArea(oObject);
if(!GetIsAreaInterior(oArea)){
int nChanceOfPrecip = GetLocalInt(oObject, "CHANCE_OF_PRECIPITATION");
int nChanceOfContinuedPrecip = GetLocalInt(oObject, "CHANCE_OF_CONTINUED_PRECIPITATION");
//int nChanceOfLightning = GetLocalInt(oObject, "CHANCE_OF_LIGHTNING");
int nClear = GetLocalInt(oObject, "CLEAR");
int nStorm = GetLocalInt(oObject, "STORM");
int nCold = GetLocalInt(oObject, "COLD");
int nIcy = GetLocalInt(oObject, "ICY");
int nWeather = GetWeather(oArea);
// If precipitating
if(nWeather > 0)
{
// but should stop...
if(d100() > nChanceOfContinuedPrecip)
{
SetWeather(oArea, WEATHER_CLEAR);
nCurrentTemperature += 15;
if(nCurrentTemperature < 0)
SetSkyBox(nIcy, oArea);
else if(nCurrentTemperature < 32)
SetSkyBox(nCold, oArea);
else
SetSkyBox(nClear, oArea);
}
// and should continue...
else
{
// If raining but is 32 or below, change to snow
if(nCurrentTemperature <= 32 && nWeather == WEATHER_RAIN)
SetWeather(oArea, WEATHER_SNOW);
// If snowing but is 33 or above, change to rain
else if(nCurrentTemperature > 32 && nWeather == WEATHER_SNOW)
SetWeather(oArea, WEATHER_RAIN);
}
}
else if(!nWeather)
{
// but should start...
if(d100() < nChanceOfPrecip)
{
nCurrentTemperature -= 15;
SetSkyBox(nStorm, oArea);
// If 32 or below, snow
if(nCurrentTemperature <= 32)
SetWeather(oArea, WEATHER_SNOW);
// If 33 or above, rain
else if(nCurrentTemperature > 32)
SetWeather(oArea, WEATHER_RAIN);
}
// should continue clear...
else
{
if(nCurrentTemperature < 0)
SetSkyBox(nIcy, oArea);
else if(nCurrentTemperature < 32)
SetSkyBox(nCold, oArea);
else
SetSkyBox(nClear, oArea);
}
}
}
/***************************************
FULLY ADJUSTED CURRENT TEMPERATURE
***************************************/
// Store the current temperature on the Environment object
SetLocalInt(oArea, "CURRENT_TEMPERATURE", nCurrentTemperature);
/**********************************************
HUNGER, THIRST, FATIGUE ADJUSTMENTS TO AREAS
**********************************************/
float HTFAdjustment = 1.00f + IntToFloat(abs(nCurrentTemperature - 65))/100;
float HAdjustment = pow(IntToFloat(DEFHUNGERCONSUMERATE), HTFAdjustment)/DEFHUNGERCONSUMERATE;
float TAdjustment = pow(IntToFloat(DEFTHIRSTCONSUMERATE), HTFAdjustment)/DEFTHIRSTCONSUMERATE;
float FAdjustment = pow(IntToFloat(DEFFATIGUECONSUMERATE), HTFAdjustment)/DEFFATIGUECONSUMERATE;
// Set consumtion rates for hot conditions
if (nCurrentTemperature > 65)
SetAllStagesAndHTFConsumeRates(oArea, HAdjustment, TAdjustment, FAdjustment,
HAdjustment, TAdjustment, FAdjustment,
HAdjustment, TAdjustment, FAdjustment,
HAdjustment, TAdjustment, FAdjustment);
// Set consumtion rates for cold conditions
if (nCurrentTemperature < 65)
SetAllStagesAndHTFConsumeRates(oArea, HAdjustment, 0.0, FAdjustment,
HAdjustment, 0.0, FAdjustment,
HAdjustment, 0.0, FAdjustment,
HAdjustment, 0.0, FAdjustment);
}