From a592704f4d2baa8f56f7dd6ded23fa4c25b2018d Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Tue, 19 Jun 2018 08:54:44 -0300 Subject: Weather System core, fully working --- npc/functions/weather.txt | 138 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 npc/functions/weather.txt (limited to 'npc/functions/weather.txt') diff --git a/npc/functions/weather.txt b/npc/functions/weather.txt new file mode 100644 index 000000000..ea10a3c0d --- /dev/null +++ b/npc/functions/weather.txt @@ -0,0 +1,138 @@ +// TMW2 scripts. +// Authors: +// Jesusalva +// Description: +// Controls world seasons. RESPECT MASK_* VARS ON CONSTANTS DB + +000-0,0,0,0 script #WeatherCore NPC_HIDDEN,{ + end; + +OnInit: + // Bind commands + bindatcmd "wsnow", "#WeatherCore::OnSnow", 80, 80, 1; + bindatcmd "wrain", "#WeatherCore::OnRain", 80, 80, 1; + bindatcmd "wsand", "#WeatherCore::OnSand", 80, 80, 1; + bindatcmd "wevil", "#WeatherCore::OnEvil", 80, 80, 1; + bindatcmd "wnight", "#WeatherCore::OnNight", 80, 80, 1; + bindatcmd "wclear", "#WeatherCore::OnClear", 80, 80, 1; + + + // Determine which maps are subject to weather, and how weather works: + // eg. it will never snow on a desert, or a sandstorm on icelands. + .wcore = htnew; + + // Deserts + htput(.wcore, "003-1", "desert"); + htput(.wcore, "004-1", "desert"); + htput(.wcore, "004-2", "desert"); + htput(.wcore, "009-1", "desert"); + htput(.wcore, "010-1", "desert"); + htput(.wcore, "010-2", "desert"); + + // Woodlands + htput(.wcore, "005-1", "woodland"); + htput(.wcore, "012-1", "woodland"); + htput(.wcore, "014-1", "woodland"); + htput(.wcore, "014-2", "woodland"); + htput(.wcore, "014-3", "woodland"); + + // Icelands + htput(.wcore, "001-7", "iceland"); + + // No "end" here, so server starts with weather +OnMinute00: +OnMinute15: +OnMinute30: +OnMinute45: + + debugmes "[Weather.sys] Total Maps = " + htsize(.wcore); + .@hti = htiterator(.wcore); + for(.@key$ = htinextkey(.@hti); hticheck(.@hti); .@key$ = htinextkey(.@hti)) { + + // PvP Maps are immune to weather changes (eg. during sieges) + // I could use getmapmask, but this is simpler. + if (getmapflag(.@key$, mf_pvp)) + continue; + + // Local variables: .@key$ .@type .@r + .@type$=htget(.wcore, .@key$); + .@r=rand(0,10000); + + // Remove all current masks, and add rain/snow/sand + if (.@type$ == "desert") { + if (.@r < 10) + setmapmask .@key$, MASK_RAIN; + else if (.@r < 100) + setmapmask .@key$, MASK_SANDSTORM; + else + setmapmask .@key$, MASK_NONE; + + } else if (.@type$ == "woodland") { + if (.@r < 100) + setmapmask .@key$, MASK_RAIN; + else if (.@r < 120) + setmapmask .@key$, MASK_SANDSTORM; + else if (.@r < 140) + setmapmask .@key$, MASK_SNOW; + else + setmapmask .@key$, MASK_NONE; + + } else if (.@type$ == "iceland") { + if (.@r < 10) + setmapmask .@key$, MASK_RAIN; + else if (.@r < 100) + setmapmask .@key$, MASK_SNOW; + else + setmapmask .@key$, MASK_NONE; + + } else { + debugmes "Warning warning, blame Saulc! Weather system error on map "+.@key$; + announce("ERROR BLAME SAULC! WEATHER SYSTEM CORRUPTED. KILLING MAP SERVERS.", bc_all); + atcommand "@mapexit"; + } + + // Is it night time? + // For convenience, night time is from 00:15 to 00:45, every hour. + // 2 = GETTIME_MINUTE + if (gettime(2) >= 15 && gettime(2) < 45) + addmapmask .@key$, MASK_NIGHT; + else if (getmapmask(.@key$) & MASK_NIGHT) + removemapmask .@key$, MASK_NIGHT; + + } + htidelete(.@hti); + debugmes "[Weather.sys] Weather reloaded"; + end; + +// Some commands, for GMs manually override weather +OnRain: + getmapxy(.@key$,.@a,.@b,0); + addmapmask .@key$, MASK_RAIN; + end; + +OnSand: + getmapxy(.@key$,.@a,.@b,0); + addmapmask .@key$, MASK_SANDSTORM; + end; + +OnSnow: + getmapxy(.@key$,.@a,.@b,0); + addmapmask .@key$, MASK_SNOW; + end; + +OnNight: + getmapxy(.@key$,.@a,.@b,0); + addmapmask .@key$, MASK_NIGHT; + end; + +OnEvil: + getmapxy(.@key$,.@a,.@b,0); + addmapmask .@key$, MASK_EVILSANCTUM; + end; + +OnClear: + getmapxy(.@key$,.@a,.@b,0); + setmapmask .@key$, MASK_NONE; + end; + +} -- cgit v1.2.3-70-g09d2 From 577b6b5249794a5f3b5c9600c637c8e82429f1dd Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Tue, 19 Jun 2018 09:01:15 -0300 Subject: Sanitization. Useful commands: @wsnow @wrain @wsand @wevil @wnight @wclear Weather won't affect anything on gameplay yet. --- npc/functions/weather.txt | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'npc/functions/weather.txt') diff --git a/npc/functions/weather.txt b/npc/functions/weather.txt index ea10a3c0d..17894535e 100644 --- a/npc/functions/weather.txt +++ b/npc/functions/weather.txt @@ -7,6 +7,7 @@ 000-0,0,0,0 script #WeatherCore NPC_HIDDEN,{ end; + OnInit: // Bind commands bindatcmd "wsnow", "#WeatherCore::OnSnow", 80, 80, 1; @@ -104,35 +105,48 @@ OnMinute45: debugmes "[Weather.sys] Weather reloaded"; end; + // Function to check stuff + // WeatherSwitch ( MASK ) + function WeatherSwitch { + // Get map + getmapxy(.@key$,.@a,.@b,0); + + // Sanitize + .@m$ = htget(.wcore, .@key$, "Not found"); + + // Change Weather or abort + if (.@m$ == "Not found") + dispbottom l("Command not permitted on this map! Check npc/functions/weather.conf"); + else + addmapmask(.@key$, MASK_RAIN); + return; + } + // Some commands, for GMs manually override weather OnRain: - getmapxy(.@key$,.@a,.@b,0); - addmapmask .@key$, MASK_RAIN; + WeatherSwitch(MASK_RAIN); end; OnSand: - getmapxy(.@key$,.@a,.@b,0); - addmapmask .@key$, MASK_SANDSTORM; + WeatherSwitch(MASK_SANDSTORM); end; OnSnow: - getmapxy(.@key$,.@a,.@b,0); - addmapmask .@key$, MASK_SNOW; + WeatherSwitch(MASK_SNOW); end; OnNight: - getmapxy(.@key$,.@a,.@b,0); - addmapmask .@key$, MASK_NIGHT; + WeatherSwitch(MASK_NIGHT); end; OnEvil: - getmapxy(.@key$,.@a,.@b,0); - addmapmask .@key$, MASK_EVILSANCTUM; + WeatherSwitch(MASK_EVILSANCTUM); end; +// Clear works on any map OnClear: getmapxy(.@key$,.@a,.@b,0); - setmapmask .@key$, MASK_NONE; + setmapmask(.@key$, MASK_NONE); end; } -- cgit v1.2.3-70-g09d2 From 781d1fd070e7565af741a8606447cd1a98f7f076 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Tue, 19 Jun 2018 09:07:17 -0300 Subject: @wnight should, in theory, do what @night would do and could affect skills. Don't talk about ingrav with me, Saulc. That skill is no more. --- npc/functions/weather.txt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'npc/functions/weather.txt') diff --git a/npc/functions/weather.txt b/npc/functions/weather.txt index 17894535e..cc7285721 100644 --- a/npc/functions/weather.txt +++ b/npc/functions/weather.txt @@ -7,6 +7,20 @@ 000-0,0,0,0 script #WeatherCore NPC_HIDDEN,{ end; +/* + * removemapflag("", ) + * setmapflag("", {, }) + * getmapflag("", ) + + mf_snow: 16 + + mf_jexp: 39 + mf_bexp: 40 + + setmapflag(.@key$, mf_nightenabled); + removemapflag(.@key$, mf_nightenabled); + +*/ OnInit: // Bind commands @@ -95,10 +109,13 @@ OnMinute45: // Is it night time? // For convenience, night time is from 00:15 to 00:45, every hour. // 2 = GETTIME_MINUTE - if (gettime(2) >= 15 && gettime(2) < 45) + if (gettime(2) >= 15 && gettime(2) < 45) { + setmapflag(.@key$, mf_nightenabled); addmapmask .@key$, MASK_NIGHT; - else if (getmapmask(.@key$) & MASK_NIGHT) + } else if (getmapmask(.@key$) & MASK_NIGHT) { + removemapflag(.@key$, mf_nightenabled); removemapmask .@key$, MASK_NIGHT; + } } htidelete(.@hti); -- cgit v1.2.3-70-g09d2