From 0a6cba4c68521edc6e33cacd6999ab461f8ad6aa Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 17 Feb 2024 22:20:26 -0300 Subject: I wasn't lying, ThinkSome - add the necessary functions so I can keep my word. [01:05] ThinkStorage: Jesusalva when will we be able to take Frostia office...? [01:07] Jesusalva: When we consistently have 20+ players online, I believe Start tracking the average player activity within the weather system. --- npc/functions/array.txt | 11 +++++++++++ npc/functions/event.txt | 2 +- npc/functions/scoreboards.txt | 2 ++ npc/functions/util.txt | 6 ++++++ npc/functions/weather.txt | 4 ++++ 5 files changed, 24 insertions(+), 1 deletion(-) (limited to 'npc/functions') diff --git a/npc/functions/array.txt b/npc/functions/array.txt index d433abd71..fb9c33807 100644 --- a/npc/functions/array.txt +++ b/npc/functions/array.txt @@ -215,6 +215,17 @@ function script array_difference { +// array_avg() +// return the average of every element of the array + +function script array_avg { + .@size = getarraysize(getarg(0)); + .@suma = array_sum(getarg(0)); + return .@suma / .@i; +} + + + // array_shift() // returns the first element of the array and removes it, while shifting left diff --git a/npc/functions/event.txt b/npc/functions/event.txt index 37832a316..e99a57410 100644 --- a/npc/functions/event.txt +++ b/npc/functions/event.txt @@ -191,7 +191,7 @@ OnTimer90000: } // Handle Siege season - if ($EVENT$ == "Siege" && (.users >= 3 || $@GM_OVERRIDE) && !$@MK_SCENE && !$@GM_EVENT && rand2(99999) < .users) { + if ($EVENT$ == "Siege" && (.users >= 3 || $@GM_OVERRIDE) && !$@MK_SCENE && !$@GM_EVENT && rand2(199999) < .users) { $@SIEGE_ABORTED = false; .@towns = rand2(1, 15); kamibroadcast("Monster King! Seize and destroy some towns!", "Moubootaur"); diff --git a/npc/functions/scoreboards.txt b/npc/functions/scoreboards.txt index 7a7ba2e4a..19d93ca09 100644 --- a/npc/functions/scoreboards.txt +++ b/npc/functions/scoreboards.txt @@ -467,6 +467,8 @@ function script HallOfGame { mes l("Planted Trees: %s", fnum($TREE_PLANTED)); mes l("Players Killed in PvP: %s", fnum($PLAYERS_KILLED)); mes l("Monsters Killed in PvE: %s", fnum($MONSTERS_KILLED)); + if (is_staff()) + mesc l("Average user count = %d", GETUSERSAVG()); mes ""; .@s$=(season() == WINTER ? l("Winter") : .@s$); .@s$=(season() == AUTUMN ? l("Autumn") : .@s$); diff --git a/npc/functions/util.txt b/npc/functions/util.txt index 9f1ba71d3..84782e448 100644 --- a/npc/functions/util.txt +++ b/npc/functions/util.txt @@ -1222,6 +1222,12 @@ function script TOP3AVERAGELVL { return ($@hoblvl_value[0]+$@hoblvl_value[1]+$@hoblvl_value[2])/3; } +// Returns the average online activity +// GETUSERSAVG( - ) +function script GETUSERSAVG { + return array_avg($@PLAYER_ACTIVITY); +} + // Grants newcomers exp boost. Returns bonus % // NewcomerEXPDROPUP( - ) function script NewcomerEXPDROPUP { diff --git a/npc/functions/weather.txt b/npc/functions/weather.txt index 5816284de..bf530b114 100644 --- a/npc/functions/weather.txt +++ b/npc/functions/weather.txt @@ -49,6 +49,7 @@ OnInit: // This is weather startup .@init=true; $@WEATHER_NIGHT=is_night(true); + array_pad($@PLAYER_ACTIVITY, 96, 0); .tpc=0; .tcl=0; // Bind commands @@ -117,6 +118,9 @@ OnMinute00: OnMinute15: OnMinute30: OnMinute45: + // Update the online average activity + .@idx = (gettime(GETTIME_HOUR) * 4) + (gettime(GETTIME_MINUTE) / 15); + $@PLAYER_ACTIVITY[.@idx] = getusers(1); // There is no weather in test servers if (debug && !$@GM_OVERRIDE) end; -- cgit v1.2.3-70-g09d2