From 448da7a00502e65bcd4f1c9c2814e77da67658b5 Mon Sep 17 00:00:00 2001 From: MajorXAcE Date: Fri, 26 Aug 2016 15:06:22 -0400 Subject: [PATCH] Weather Update --- ..._object_player_stats_updateTemperature.sqf | 190 ++++++++++++++++++ .../ExileClient_system_snow_thread_update.sqf | 68 +++++++ .../ExileServer_system_weather_initialize.sqf | 10 +- PTWS.ini | 11 + README.md | 15 +- Server Files/@ExileServer/addons/PTWS.pbo | Bin 4067 -> 8754 bytes .../@ExileServer/addons/PTWS/config.cpp | 8 +- .../@ExileServer/addons/PTWS/config.sqf | 5 + .../@ExileServer/addons/PTWS/initServer.sqf | 2 +- .../addons/PTWS/scripts/fn_controlWeather.sqf | 63 ++++++ .../addons/PTWS/scripts/fn_saveDate.sqf | 9 + .../addons/PTWS/scripts/fn_saveWeather.sqf | 10 + .../addons/PTWS/scripts}/fn_timeAcc.sqf | 25 ++- .../addons/PTWS/scripts/insertPTWS.sqf | 15 +- .../addons/PTWS/scripts/startPTWS.sqf | 104 ++++++---- Trashbin/config.cpp | 30 --- Trashbin/fn_saveDate.sqf | 13 -- Trashbin/initServer.sqf | 17 -- 18 files changed, 457 insertions(+), 138 deletions(-) create mode 100644 Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileClient_object_player_stats_updateTemperature.sqf create mode 100644 Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileClient_system_snow_thread_update.sqf create mode 100644 Server Files/@ExileServer/addons/PTWS/scripts/fn_controlWeather.sqf create mode 100644 Server Files/@ExileServer/addons/PTWS/scripts/fn_saveDate.sqf create mode 100644 Server Files/@ExileServer/addons/PTWS/scripts/fn_saveWeather.sqf rename {Trashbin => Server Files/@ExileServer/addons/PTWS/scripts}/fn_timeAcc.sqf (81%) delete mode 100644 Trashbin/config.cpp delete mode 100644 Trashbin/fn_saveDate.sqf delete mode 100644 Trashbin/initServer.sqf diff --git a/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileClient_object_player_stats_updateTemperature.sqf b/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileClient_object_player_stats_updateTemperature.sqf new file mode 100644 index 0000000..acd27ab --- /dev/null +++ b/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileClient_object_player_stats_updateTemperature.sqf @@ -0,0 +1,190 @@ +/** + * ExileClient_object_player_stats_updateTemperature + * + * Exile Mod + * www.exilemod.com + * © 2015 Exile Mod Team + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + */ + +private["_timeElapsed","_forcedBodyTemperatureChangePerMinute","_wetnessChangePerMinute","_altitude","_isSwimming","_bodyTemperature","_bodyWetness","_temperatureConfig","_fromDayTimeTemperature","_toDayTimeTemperature","_environmentTemperature","_playerIsInVehicle","_playerVehicle","_isFireNearby","_startPosition","_endPosition","_intersections","_isBelowRoof","_clothingColdProtection","_movementInfluence","_regulation","_environmentInfluence"]; +/* +// PTWS Season Temperature Control +*/ + +_month = date select 1; +_season = ""; + +_WinterEnd = 1; +_SpringEnd = 4; +_SummerEnd = 7; +_FallEnd = 10; + +if ((_month > _WinterEnd) && (_month <= _SpringEnd)) then // The season will be the month after _PreviousSeasonEnd and the months upto and including _ThisSeasonEnd ex. Spring starts on Feb and ends in Apr. +{ + _season = "Spring"; +}; + +if ((_month > _SpringEnd) && (_month <= _SummerEnd)) then +{ + _season = "Summer"; +}; + +if ((_month > _SummerEnd) && (_month <= _FallEnd)) then +{ + _season = "Fall"; +}; + +if (_month == 11 || _month == 12 || _month == 1) then +{ + _season = "Winter"; +}; + +//diag_log format["PTWS - Current Season:%1",_season]; + +_seasonDaytimeTemperature = []; + +//Switches the daytimeTemperature array based on the season, this replace the values in the mission config. +switch (_season) do { + case "Winter": { _seasonDaytimeTemperature = [-6.93,-5.89,-4.42,-3.40,-2.68,-1.10,1.48,2.63,3.40,4.66,5.32,6.80,6.80,5.32,4.66,3.40,2.63,1.48,-1.10,-2.68,-3.40,-4.42,-5.89,-6.93,-7.93]; }; + case "Spring": { _seasonDaytimeTemperature = [9,11,14,17,20,24,26,27,28,28,28,27,26,28,28,28,27,26,24,20,17,14,11,9,8]; }; + case "Summer": { _seasonDaytimeTemperature = [15.93,16.89,18.42,20.40,22.68,25.10,27.48,29.63,31.40,32.66,33.32,33.80,33.80,33.32,32.66,31.40,29.63,27.48,25.10,22.68,20.40,18.42,16.89,15.93,15.93]; }; + case "Fall": { _seasonDaytimeTemperature = [-2.00,-1.77,-1.12,-0.10,1.24,2.78,4.40,6.00,7.46,8.65,9.50,9.90,9.90,9.50,8.65,7.46,6.00,4.40,2.78,1.24,-0.10,-1.12,-1.77,-2.00,-2.00]; }; +}; + +//diag_log format["PTWS - Current Temperature Array:%1",_seasonDaytimeTemperature]; + +/* +// PTWS Season Temperature Control +*/ +_timeElapsed = _this; +_forcedBodyTemperatureChangePerMinute = 0; +_wetnessChangePerMinute = -0.1; +_altitude = ((getPosASL player) select 2) max 0; +_isSwimming = (_altitude < 0.1) || (underwater player); +_bodyTemperature = ExileClientPlayerAttributes select 5; +_bodyWetness = ExileClientPlayerAttributes select 6; +_temperatureConfig = missionConfigFile >> "CfgExileEnvironment" >> worldName >> "Temperature"; +//_fromDayTimeTemperature = (getArray (_temperatureConfig >> "daytimeTemperature")) select (date select 3); +//_toDayTimeTemperature = (getArray (_temperatureConfig >> "daytimeTemperature")) select ((date select 3) + 1); +_fromDayTimeTemperature = _seasonDaytimeTemperature select (date select 3); +_toDayTimeTemperature = _seasonDaytimeTemperature select ((date select 3) + 1); +_environmentTemperature = [_fromDayTimeTemperature, _toDayTimeTemperature, (date select 4) / 60] call ExileClient_util_math_lerp; +_environmentTemperature = _environmentTemperature + overcast * (getNumber (_temperatureConfig >> "overcast")); +_environmentTemperature = _environmentTemperature + rain * (getNumber (_temperatureConfig >> "rain")); +_environmentTemperature = _environmentTemperature + windStr * (getNumber (_temperatureConfig >> "wind")); +_environmentTemperature = _environmentTemperature + _altitude / 100 * (getNumber (_temperatureConfig >> "altitude")); +if (_isSwimming) then +{ + _environmentTemperature = _environmentTemperature + (getNumber (_temperatureConfig >> "water")); +}; +ExileClientEnvironmentTemperature = _environmentTemperature; +_playerIsInVehicle = false; +_playerVehicle = vehicle player; +if !(_playerVehicle isEqualTo player) then +{ + try + { + if (_playerVehicle isKindOf "Exile_Bike_QuadBike_Abstract") throw false; + if (_playerVehicle isKindOf "Exile_Bike_OldBike") throw false; + if (_playerVehicle isKindOf "Exile_Bike_MountainBike") throw false; + throw true; + } + catch + { + _playerIsInVehicle = _exception; + }; +}; +if (_playerIsInVehicle) then +{ + if (isEngineOn _playerVehicle) then + { + _forcedBodyTemperatureChangePerMinute = 0.05; + _wetnessChangePerMinute = -0.5; + } + else + { + _forcedBodyTemperatureChangePerMinute = 0.01; + _wetnessChangePerMinute = -0.2; + }; +} +else +{ + if (_isSwimming) then + { + _wetnessChangePerMinute = 99999; + } + else + { + _isFireNearby = [ASLtoAGL (getPosASL player), 5] call ExileClient_util_world_isFireInRange; + if (_isFireNearby) then + { + _forcedBodyTemperatureChangePerMinute = 1; + _wetnessChangePerMinute = -0.5; + } + else + { + if (rain > 0.1) then + { + _startPosition = getPosASL player; + _endPosition = [_startPosition select 0, _startPosition select 1, (_startPosition select 2 ) + 10]; + _intersections = lineIntersectsSurfaces [_startPosition, _endPosition, player, objNull, false, 1, "GEOM", "VIEW"]; + _isBelowRoof = !(_intersections isEqualTo []); + if !(_isBelowRoof) then + { + _wetnessChangePerMinute = rain; + }; + }; + }; + }; +}; +_bodyWetness = ((_bodyWetness + _wetnessChangePerMinute / 60 * _timeElapsed) max 0) min 1; +if (ExileClientEnvironmentTemperature > 25) then +{ + _forcedBodyTemperatureChangePerMinute = 0.5; +}; +if (_forcedBodyTemperatureChangePerMinute > 0) then +{ + _bodyTemperature = _bodyTemperature + _forcedBodyTemperatureChangePerMinute / 60 *_timeElapsed; +} +else +{ + _clothingColdProtection = 0; + if !((uniform player) isEqualTo "") then + { + _clothingColdProtection = _clothingColdProtection + 0.25; + }; + if !((headgear player) isEqualTo "") then + { + _clothingColdProtection = _clothingColdProtection + 0.05; + }; + if !((vest player) isEqualTo "") then + { + _clothingColdProtection = _clothingColdProtection + 0.10; + }; + _clothingColdProtection = ((_clothingColdProtection * (1 - (_bodyWetness * 0.5))) max 0) min 1; + _movementInfluence = 0; + if ((getPos player) select 2 < 0.1) then + { + _movementInfluence = (37 - _bodyTemperature) * (1 - (_bodyWetness * 0.5)) * 0.075 * (vectorMagnitude (velocity player))/6.4; + }; + if (_bodyTemperature < 37) then + { + _regulation = 0.1; + } + else + { + _regulation = -0.1; + }; + _environmentInfluence = (1 - _clothingColdProtection) * (-0.2 + 0.008 * ExileClientEnvironmentTemperature); + _bodyTemperature = _bodyTemperature + (_regulation + _movementInfluence + _environmentInfluence) / 60 *_timeElapsed; +}; +_bodyTemperature = _bodyTemperature min 37; +if (_bodyTemperature < 35) then +{ + player setDamage ((damage player) + 0.1/60*_timeElapsed); +}; +ExileClientPlayerAttributes set [6, _bodyWetness]; +ExileClientPlayerAttributes set [5, _bodyTemperature]; diff --git a/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileClient_system_snow_thread_update.sqf b/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileClient_system_snow_thread_update.sqf new file mode 100644 index 0000000..e41e79e --- /dev/null +++ b/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileClient_system_snow_thread_update.sqf @@ -0,0 +1,68 @@ +/** + * ExileClient_system_snow_thread_update + * + * Exile Mod + * www.exilemod.com + * © 2015 Exile Mod Team + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + */ + +private["_enableSnow","_surfaceTypes","_posASL"]; +_enableSnow = false; +_posASL = (getPosASL player select 2); +/* +if (rain < 0.01) then +{ + _surfaceTypes = getArray (missionConfigFile >> "CfgExileEnvironment" >> worldName >> "Snow" >> "surfaces"); + if ((surfaceType (getPos player)) in _surfaceTypes) then + { + _enableSnow = true; + ExileSnowClose attachTo [vehicle player, [0, 4, 1]]; + ExileSnowNear attachTo [vehicle player, [0, 4, 1.5]]; + ExileSnowFar attachTo [vehicle player, [0, 4, 2]]; + }; +}; +if (_enableSnow) then +{ + ExileSnowClose attachTo [vehicle player, [0, 4, 1]]; + ExileSnowNear attachTo [vehicle player, [0, 4, 1.5]]; + ExileSnowFar attachTo [vehicle player, [0, 4, 2]]; + ExileSnowClose setDropInterval 0.01; + ExileSnowNear setDropInterval 0.01; + ExileSnowFar setDropInterval 0.01; +} +else +{ + ExileSnowClose setDropInterval 0; + ExileSnowNear setDropInterval 0; + ExileSnowFar setDropInterval 0; +}; +*/ +_environmentTemperatureValue = format ["%1", [ExileClientEnvironmentTemperature, 1] call ExileClient_util_math_round]; +_environmentTemperature = parseNumber _environmentTemperatureValue; +//diag_log format["PTWS - Current Temperature:%1",_environmentTemperature]; +if ((0 >= _environmentTemperature) && (overcast >= 0.3)) then +{ + _enableSnow = true; + ExileSnowClose attachTo [vehicle player, [0, 4, 1]]; + ExileSnowNear attachTo [vehicle player, [0, 4, 1.5]]; + ExileSnowFar attachTo [vehicle player, [0, 4, 2]]; +}; + +if (_enableSnow) then +{ + ExileSnowClose attachTo [vehicle player, [0, 4, 1]]; + ExileSnowNear attachTo [vehicle player, [0, 4, 1.5]]; + ExileSnowFar attachTo [vehicle player, [0, 4, 2]]; + ExileSnowClose setDropInterval 0.01; + ExileSnowNear setDropInterval 0.01; + ExileSnowFar setDropInterval 0.01; +} +else +{ + ExileSnowClose setDropInterval 0; + ExileSnowNear setDropInterval 0; + ExileSnowFar setDropInterval 0; +}; \ No newline at end of file diff --git a/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileServer_system_weather_initialize.sqf b/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileServer_system_weather_initialize.sqf index cafdd5b..8d25396 100644 --- a/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileServer_system_weather_initialize.sqf +++ b/Mission Files/mpmissions/Exile.Yourmap/PTWS/ExileServer_system_weather_initialize.sqf @@ -10,24 +10,22 @@ */ private["_useRealTime","_useStaticTime","_staticTime","_changetime"]; -call ExileServer_system_weather_thread_weatherSimulation; +//call ExileServer_system_weather_thread_weatherSimulation; _useRealTime = getNumber (configFile >> "CfgSettings" >> "Time" >> "useRealTime"); _useStaticTime = getNumber (configFile >> "CfgSettings" >> "Time" >> "useStaticTime"); _staticTime = getArray (configFile >> "CfgSettings" >> "Time" >> "staticTime"); -/* if(_useStaticTime isEqualTo 1)then { - setDate _staticTime; + //setDate _staticTime; } else { if(_useRealTime isEqualTo 1)then { - setDate ExileServerStartTime; + //setDate ExileServerStartTime; }; }; -*/ forceWeatherChange; _changetime = round(getNumber (configFile >> "CfgSettings" >> "Weather" >> "interval") * 60); -[_changetime, ExileServer_system_weather_thread_weatherSimulation, [], true] call ExileServer_system_thread_addTask; +//[_changetime, ExileServer_system_weather_thread_weatherSimulation, [], true] call ExileServer_system_thread_addTask; true \ No newline at end of file diff --git a/PTWS.ini b/PTWS.ini index 7a5e5ea..3acf61f 100644 --- a/PTWS.ini +++ b/PTWS.ini @@ -13,7 +13,18 @@ Number of Inputs = 1 SQL1_INPUTS = 1 OUTPUT = 1 +[getWeather] +SQL1_1 = SELECT weather FROM ptws WHERE DateID = ? +Number of Inputs = 1 +SQL1_INPUTS = 1 +OUTPUT = 1 + [setDate] SQL1_1= UPDATE ptws SET date = ? WHERE DateID = ? Number of Inputs = 2 SQL1_INPUTS = 1,2 + +[setWeather] +SQL1_1= UPDATE ptws SET weather = ? WHERE DateID = ? +Number of Inputs = 2 +SQL1_INPUTS = 1,2 diff --git a/README.md b/README.md index b679c96..e8a15b3 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,20 @@ # PTWS ####Persistent Time and Weather System -PTWS is a script made for Exile that allows time (and hopefully weather soon) to persist through server restarts. This is far from done but I think in its current state it is still useful for RP, or for people who want to run their servers on smaller time multipliers and still have their players experience a full day/night cycle. +PTWS is a script made for Exile that allows time and weather to persist through server restarts. It also has seasons defined by months that will change the temperature. #### Features * Persistent time (year, month, day, hour, minute) +* Persistent weather +* Dynamic weather (thanks to code34's Real weather) +* Seasons that change the temperature +* Snow based on temperature and current overcast * Time accleration #### To-do List -* Add Persistent weather -* Configure seasons based on months +* ~Add Persistent weather~ +* ~Configure seasons based on months~ +* Make the seasons affect more than the temperature * ???? ## Installation @@ -27,7 +32,9 @@ PTWS is a script made for Exile that allows time (and hopefully weather soon) to ##### Mission 1) Copy `PTWS` from `Mission Files\mpmissions\Exile.Yourmap` into the root of your Exile.Yourmap folder. -2) Open your `config.cpp` in your mission folder and edit your `CfgExileCustomCode` and add a new line inside like this: +2) Open your `config.cpp` in your mission folder and edit your `CfgExileCustomCode` and add a two new lines inside like this: `ExileServer_system_weather_initialize = "PTWS\ExileServer_system_weather_initialize.sqf"` +`ExileClient_object_player_stats_updateTemperature = "PTWS\ExileClient_object_player_stats_updateTemperature.sqf"` +`ExileClient_system_snow_thread_update = "PTWS\ExileClient_system_snow_thread_update.sqf"` #### You are done! diff --git a/Server Files/@ExileServer/addons/PTWS.pbo b/Server Files/@ExileServer/addons/PTWS.pbo index dec13f1f4f58f17833a0150dbd4dbc373f2cca60..ec14c010f7720f2cde9660d862e087164d5fda06 100644 GIT binary patch literal 8754 zcmdT}O>ZMf86FNG9F!yX8cT>|>9w7Y4NEdJS|?6+g2qV{d&Ufz$f|Ug?Pl8Dp04&d z-t1iX0sH`d0|yXCgmx}_<-h?UafUMz2gHr%eXF|N?bw-NgoMaU($!UOz29F|eNV^g z*}eH6Hwt@xzv7NYyzZ=Zo?XrH=E*9c4(~K*dHbOMKA0ESrSJd-g`p7=vmcijy0&n@ULe*60ljZ;uR)GAKS+MQMg`VYhJy^F)Q z9U7;gI+1gb{&x)MAAbC{laB4?*~1N_*5aVoKa+_&PYksNd(R2H(ht2RYo8XC_Z}v#2?s0+}8`cH>sMg3xKGo&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5j zsbix-6%v-`VLDLB2jmq92Tuu>SmFBL6+(tt^gL|)TyOTbUg{4)3^c^?vix%-MhQJU zJf(4)_f`~HU&Fl!Y-. + */ + +private ["_lastrain","_rain","_overcast","_fogValue","_fogDecay","_fogHeight"]; +_lastrain = 0; +_rain = 0; +_overcast = 0; +_fogValue = 0; +_fogDecay = 0; +_fogHeight =0; + +_overcast = random 1; +if(_overcast > 0.5) then { + _rain = random 0.5; +} else { + _rain = 0; +}; + +if((date select 3 > 5) and (date select 3 <10)) then { + _fogValue = 0.2 + (random 0.8); + _fogDecay = 0.2; + _fogHeight = random 20; +} else { + if((_lastrain > 0.6) and (_rain < 0.2)) then { +_fogValue = random 0.4; +_fogDecay = 0; +_fogHeight = 0; + } else { +_fogValue = 0; +_fogDecay = 0; +_fogHeight = 0; + }; +}; + +if(random 1 > 0.5) then { "wind case 1"; + _wind = [random 7, random 7, false]; +} else { + _wind = [random 3, random 3, false]; +}; +_lastrain = _rain; + +wcweather = [_rain, [_fogValue,_fogDecay,_fogHeight], _overcast, _wind, date]; +60 setRain (wcweather select 0); +60 setfog (wcweather select 1); +60 setOvercast (wcweather select 2); +setwind (wcweather select 3); diff --git a/Server Files/@ExileServer/addons/PTWS/scripts/fn_saveDate.sqf b/Server Files/@ExileServer/addons/PTWS/scripts/fn_saveDate.sqf new file mode 100644 index 0000000..35467ac --- /dev/null +++ b/Server Files/@ExileServer/addons/PTWS/scripts/fn_saveDate.sqf @@ -0,0 +1,9 @@ +private["_currentdate","_data","_extDB2Message"]; +_currentdate = date; +_data = +[ + _currentdate, + PTWS_ID +]; +_extDB2Message = ["setDate", _data] call ExileServer_util_extDB2_createMessage; +_extDB2Message call ExileServer_system_database_query_fireAndForget; \ No newline at end of file diff --git a/Server Files/@ExileServer/addons/PTWS/scripts/fn_saveWeather.sqf b/Server Files/@ExileServer/addons/PTWS/scripts/fn_saveWeather.sqf new file mode 100644 index 0000000..81a7112 --- /dev/null +++ b/Server Files/@ExileServer/addons/PTWS/scripts/fn_saveWeather.sqf @@ -0,0 +1,10 @@ +private["_currentWeather","_data","_extDB2Message"]; +_windDB = [wind select 0, wind select 1, false]; +_currentWeather = [overcast,rain,fogParams,_windDB,gusts,lightnings,waves]; +_data = +[ + _currentWeather, + PTWS_ID +]; +_extDB2Message = ["setWeather", _data] call ExileServer_util_extDB2_createMessage; +_extDB2Message call ExileServer_system_database_query_fireAndForget; \ No newline at end of file diff --git a/Trashbin/fn_timeAcc.sqf b/Server Files/@ExileServer/addons/PTWS/scripts/fn_timeAcc.sqf similarity index 81% rename from Trashbin/fn_timeAcc.sqf rename to Server Files/@ExileServer/addons/PTWS/scripts/fn_timeAcc.sqf index 366aa39..7c28281 100644 --- a/Trashbin/fn_timeAcc.sqf +++ b/Server Files/@ExileServer/addons/PTWS/scripts/fn_timeAcc.sqf @@ -1,13 +1,12 @@ -//Can't be called by ExileServer_system_thread_addTask for some reason. -//Borrowed the the template from second_coming's occupation mod. -private["_timeMultiplier"]; -if (daytime > PTWS_timeAccNightStart || daytime < PTWS_timeAccDayStart) then -{ - _timeMultiplier = PTWS_timeAccMultiplierNight; -} -else -{ - _timeMultiplier = PTWS_timeAccMultiplierDay; -}; - -if(timeMultiplier != _timeMultiplier) then { setTimeMultiplier _timeMultiplier; }; +//Borrowed the the template from second_coming's occupation mod. +private["_timeMultiplier"]; +if (daytime > PTWS_timeAccNightStart || daytime < PTWS_timeAccDayStart) then +{ + _timeMultiplier = PTWS_timeAccMultiplierNight; +} +else +{ + _timeMultiplier = PTWS_timeAccMultiplierDay; +}; + +if(timeMultiplier != _timeMultiplier) then { setTimeMultiplier _timeMultiplier; }; diff --git a/Server Files/@ExileServer/addons/PTWS/scripts/insertPTWS.sqf b/Server Files/@ExileServer/addons/PTWS/scripts/insertPTWS.sqf index b8f65df..c7dc751 100644 --- a/Server Files/@ExileServer/addons/PTWS/scripts/insertPTWS.sqf +++ b/Server Files/@ExileServer/addons/PTWS/scripts/insertPTWS.sqf @@ -1,12 +1,5 @@ -private["_dateID"]; +private ["_insertDatabaseID"]; if (!isServer) exitWith {}; - -missionNamespace setVariable ["PTWS",PTWS_ID]; -PTWS_DB_ID = missionNamespace getVariable "ExileDatabaseID"; - -if (isNil "PTWS_DB_ID") then -{ -_dateID = format["createDate:%1", missionNamespace getVariable "PTWS"] call ExileServer_system_database_query_insertSingle; -missionNamespace setVariable ["ExileDatabaseID", _dateID]; -_dateID; -}; +//None of my checks work for the database entry work :/ +_insertDatabaseID = format["createDate:%1", PTWS_ID] call ExileServer_system_database_query_insertSingle; +_insertDatabaseID; \ No newline at end of file diff --git a/Server Files/@ExileServer/addons/PTWS/scripts/startPTWS.sqf b/Server Files/@ExileServer/addons/PTWS/scripts/startPTWS.sqf index 694985d..464026a 100644 --- a/Server Files/@ExileServer/addons/PTWS/scripts/startPTWS.sqf +++ b/Server Files/@ExileServer/addons/PTWS/scripts/startPTWS.sqf @@ -1,11 +1,8 @@ -private["_dateID","_date","_saveddate","_currentdate","_data","_extDB2Message","_timeMultiplier"]; +private["_saveddate","_savedWeather","_overcast","_rain","_fog","_wind","_gusts","_lightnings","_waves","_timeforecast","_timeforecastMinutes"]; if (!isServer) exitWith {}; -missionNamespace setVariable ["PTWS",PTWS_ID]; - -_dateID = missionNamespace getVariable "PTWS"; -_date = format ["getDate:%1", _dateID] call ExileServer_system_database_query_selectFull; -_saveddate = (_date select 0) select 0; +_saveddate = format ["getDate:%1", PTWS_ID] call ExileServer_system_database_query_selectSingleField; +_savedWeather = format ["getWeather:%1", PTWS_ID] call ExileServer_system_database_query_selectSingleField; if (typeName _saveddate isEqualTo "ARRAY") then { @@ -18,42 +15,69 @@ else diag_log format["PTWS - No saved date found, loading PTWS_StartingDate:%1",PTWS_StartingDate]; }; -if (true) then +if (typeName _savedWeather isEqualTo "ARRAY") then { - diag_log "PTWS - SaveDate Initialised"; - //[60, PTWS_fnc_saveDate, [], true] call ExileServer_system_thread_addTask; //This doesn't work for some reason :/ - while {true} do - { - _dateID = missionNamespace getVariable "PTWS"; - _currentdate = date; - _data = - [ - _currentdate, - _dateID - ]; - _extDB2Message = ["setDate", _data] call ExileServer_util_extDB2_createMessage; - _extDB2Message call ExileServer_system_database_query_fireAndForget; - //Borrowed the template from second_coming's occupation mod. - if (PTWS_timeAcc) then - { - if (daytime > PTWS_timeAccNightStart || daytime < PTWS_timeAccDayStart) then - { - _timeMultiplier = PTWS_timeAccMultiplierNight; - } - else - { - _timeMultiplier = PTWS_timeAccMultiplierDay; - }; - - if(timeMultiplier != _timeMultiplier) then { setTimeMultiplier _timeMultiplier; }; - }; - uiSleep 60; - }; + diag_log format["PTWS - Loading last saved weather : %1", _savedWeather]; + _overcast = _savedWeather select 0; + _rain = _savedWeather select 1; + _fog = _savedWeather select 2; + _wind = _savedWeather select 3; + _gusts = _savedWeather select 4; + _lightnings = _savedWeather select 5; + _waves = _savedWeather select 6; + + 0 setovercast _overcast; + 0 setrain _rain; + 0 setfog _fog; + setwind _wind; + 0 setgusts _gusts; + 0 setlightnings _lightnings; + 0 setwaves _waves; + forceWeatherChange; +} +else +{ + diag_log format["PTWS - No saved weather found, loading PTWS_StartingWeather:%1",PTWS_StartingWeather]; + _overcast = PTWS_StartingWeather select 0; + _rain = PTWS_StartingWeather select 1; + _fog = PTWS_StartingWeather select 2; + _wind = PTWS_StartingWeather select 3; + _gusts = PTWS_StartingWeather select 4; + _lightnings = PTWS_StartingWeather select 5; + _waves = PTWS_StartingWeather select 6; + + 0 setovercast _overcast; + 0 setrain _rain; + 0 setfog _fog; + setwind _wind; + 0 setgusts _gusts; + 0 setlightnings _lightnings; + 0 setwaves _waves; + forceWeatherChange; }; -/* + +diag_log "PTWS - SaveDate Initialized"; +//Thanks WolfkillArcadia! +[60, PTWS_fnc_saveDate, [], true] call ExileServer_system_thread_addTask; + +diag_log "PTWS - SaveWeather Initialized"; +[60, PTWS_fnc_saveWeather, [], true] call ExileServer_system_thread_addTask; + +if(PTWS_weatherChangeMin > PTWS_weatherChangeMax) exitwith {hint format["PTWS - Max time: %1 must to be higher than Min time: %2", PTWS_weatherChangeMax, PTWS_weatherChangeMin];}; +_timeforecast = PTWS_weatherChangeMin; + +if !(PTWS_weatherChangeFast) then { + _timeforecast = PTWS_weatherChangeMin + (random (PTWS_weatherChangeMax - PTWS_weatherChangeMin)); +}; + +diag_log "PTWS - ControlWeather Initialized"; +_timeforecastMinutes = [_timeforecast,"HH:MM:SS"] call BIS_fnc_secondsToString; +diag_log format ["PTWS - Time until next forecast:%1",_timeforecastMinutes]; +[_timeforecast, PTWS_fnc_controlWeather, [], true] call ExileServer_system_thread_addTask; + if (PTWS_timeAcc) then { - diag_log "PTWS - TimeAcc Initialised"; - //[60, PTWS_fnc_timeAcc, [], true] call ExileServer_system_thread_addTask; //Help please? + diag_log "PTWS - TimeAcc Initialized"; + [60, PTWS_fnc_timeAcc, [], true] call ExileServer_system_thread_addTask; }; -*/ + diff --git a/Trashbin/config.cpp b/Trashbin/config.cpp deleted file mode 100644 index 515e111..0000000 --- a/Trashbin/config.cpp +++ /dev/null @@ -1,30 +0,0 @@ -class CfgPatches -{ - class PTWS { - units[] = {}; - weapons[] = {}; - requiredVersion = 0.1; - requiredAddons[] = {}; - author[]= {"MajorXAcE"}; - }; -}; - -class CfgFunctions { - class PTWS { - class main { - class postInit - { - postInit = 1; - file = "\PTWS\initServer.sqf"; - }; - }; - /* - class compiles - { - file = "\PTWS\scripts"; - class saveDate {}; - class timeAcc {}; - }; - */ - }; -}; \ No newline at end of file diff --git a/Trashbin/fn_saveDate.sqf b/Trashbin/fn_saveDate.sqf deleted file mode 100644 index 0d324d5..0000000 --- a/Trashbin/fn_saveDate.sqf +++ /dev/null @@ -1,13 +0,0 @@ -//Can't be called by ExileServer_system_thread_addTask for some reason. -private["_dateID","_currentdate","_data","_extDB2Message"]; -missionNamespace setVariable ["PTWS",PTWS_ID]; - -_dateID = missionNamespace getVariable "PTWS"; -_currentdate = date; -_data = -[ - _currentdate, - _dateID -]; -_extDB2Message = ["setDate", _data] call ExileServer_util_extDB2_createMessage; -_extDB2Message call ExileServer_system_database_query_fireAndForget; \ No newline at end of file diff --git a/Trashbin/initServer.sqf b/Trashbin/initServer.sqf deleted file mode 100644 index df2f718..0000000 --- a/Trashbin/initServer.sqf +++ /dev/null @@ -1,17 +0,0 @@ -[] spawn -{ - waitUntil {time > 0}; - diag_log "PTWS - Loading Config"; - - // Get the config for PTWS - call compile preprocessFileLineNumbers "\PTWS\config.sqf"; - - if(isNil "PTWS_CompiledOkay") exitWith { diag_log "PTWS - Failed to read config.sqf, check for typos."; }; - - diag_log "PTWS - Initialised"; - - // Start PTWS - []execVM "\PTWS\scripts\insertPTWS.sqf"; - sleep 1; - []execVM "\PTWS\scripts\startPTWS.sqf"; -}; \ No newline at end of file