diff --git a/changelog.txt b/changelog.txt
index c7e61baf..a5764a2a 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -167,6 +167,7 @@ Cubescript
[*] convertcase - Converts a list of strings to lower/uppercase characters.
[*] testchar - Tests a character argument for certain things. (e.g. echo (testchar a) // Output: 0 // It is not a 0-9 digit.)
[*] testlist - Tests a list argument for certain things. (e.g. echo (testlist "1 2.3 3.14") // Output: 1 // It is a valid list of ints/floats.)
+[*] listaverage - Returns the average of a list of numbers. (Supports ints and floats - e.g. echo (listaverage "2 5 5") // Output: 4.0)
[*] player1 - // TODO explain // Also getposition and positiontype have been removed in favor of this command which does that and a lot more. :p
[*] Multiple Idents - New helper aliases for voting for SURV, TPF, and TLSS. (e.g. /surv ac_desert)
[*] "Sleeps" can be persistent. (3rd argument of "sleep" command)
diff --git a/config/docs.cfg b/config/docs.cfg
index 8f629b71..408a0d68 100644
--- a/config/docs.cfg
+++ b/config/docs.cfg
@@ -251,6 +251,9 @@ docargument [S] [the original string to modify] [] [0];
docargument [T] [the target sub-string to replace] [] [0];
docargument [N] [the new sub-string to replace the target] [] [0];
docexample [echo (strreplace "Hello cruel world" cruel "")] [Output: Hello world];
+docident [listaverage] [Returns the average of a list of numbers.];
+docargument [L] [the list of numbers] [supports ints and floats] [0];
+docexample [echo (listaverage "2 5 5")] [Output: 4.0];
docsection [General]
docident [addserver] [Adds a server to the list of server to query in the server list menu.];
docargument [S] [the address of the server (hostname or IP)] [] [0];
diff --git a/config/scripts.cfg b/config/scripts.cfg
index a60f7c47..00a73b1c 100644
--- a/config/scripts.cfg
+++ b/config/scripts.cfg
@@ -257,6 +257,9 @@ add2list = [ if (strcmp "" (getalias $arg1)) [ $arg1 = $arg2 ] [ $arg1 = (concat
// rrnd - Returns a ranged random integer.
rrnd = [ + (rnd (- $arg2 $arg1)) $arg1 ]
+// listaverage - Returns the average of a list of numbers. (Supports ints & floats - e.g. echo (listaverage "2 5 5") // Output: 4.0)
+listaverage = [ if (&& (listlen $arg1) (testlist $arg1)) [ tmp_sum = 0; loop gsl (listlen $arg1) [ += tmp_sum (at $arg1 $gsl) ]; result (divf $tmp_sum (listlen $arg1)) ] ]
+
// copyent & pasteent - Quickly copy/paste the current closest entity. Initialize the two aliases below as "NULL" for error catching.
// If /config/saved.cfg is readable/writable, errors are only possible up until the very first use of /copyent.
cp_entbuf = NULL; cp_entstr = NULL
diff --git a/config/survival.cfg b/config/survival.cfg
index d3b20abb..fc9171a8 100644
--- a/config/survival.cfg
+++ b/config/survival.cfg
@@ -24,8 +24,6 @@ genSurvDifStr = [
]
]
-genSurvAvgStr = [ if (listlen $arg1) [ tmp_sum = 0; loop gsl (listlen $arg1) [ += tmp_sum (at $arg1 $gsl) ]; result (divf $tmp_sum (listlen $arg1)) ] ]
-
survival = [
kickallbots; tmpSurvSets = $survNumBots; curSurvDifficulty = 0; survLastKill = ""; survTimeBetKills = ""; resetSurvAliases
if (! (checkalias onKill)) [ onKill = "" ]; if (! (strstr $onKill survKills)) [ add2alias onKill [ if $startedSurvival [ += survKills 1; if (! (listlen $survTimeBetKills)) [ survTimeBetKills = (- (millis) $startSurvMillis) ] [ add2list survTimeBetKills (- (millis) $survLastKill) ]; survLastKill = (millis) ] ] ]
@@ -113,7 +111,7 @@ checkzone = [
if (&& (! $startedSurvival) (>= (- (millis) $startPreSurvMillis) $timeUntilTele)) [ teleportPlayer ]
if (&& (>= (- (millis) $lastCheckPoint) $timeBetChkPts) (&& $startedSurvival $gotCheckPoint)) [ increaseDifficulty ]
if (&& (! $startedOBCount) (&& (! (isInZone)) $startedSurvival)) [ startOBCount ]
- if (&& $startedSurvival (&& (! (alive)) (>= (- (millis) $startSurvMillis) 500))) [ finalSurvMillis = (- (millis) $startSurvMillis); endSurvival (concatword (genSurvDifStr) (c 3) " You survived for " (c 5) (divf $finalSurvMillis 1000) (c 3) " seconds, and killed " (c 5) $survKills (c 3) " enemies. Average: " (c 5) (divf (genSurvAvgStr $survTimeBetKills) 1000) (c 3) " seconds between kills.") ]
+ if (&& $startedSurvival (&& (! (alive)) (>= (- (millis) $startSurvMillis) 500))) [ finalSurvMillis = (- (millis) $startSurvMillis); endSurvival (concatword (genSurvDifStr) (c 3) " You survived for " (c 5) (divf $finalSurvMillis 1000) (c 3) " seconds, and killed " (c 5) $survKills (c 3) " enemies. Average: " (c 5) (divf (listaverage $survTimeBetKills) 1000) (c 3) " seconds between kills.") ]
if (&& (! (curteam)) (! $startedSurvival)) [ team RVSF ]; sleep 0 [ checkzone ]
]
]
@@ -138,6 +136,6 @@ endSurvival = [
]
// List of aliases that need to be cleared from saved.cfg on quit:
-survAliases = (concat $survResetAliases "backInZone checkzone curSurvDifficulty endSurvival finalSurvMillis genSurvDifStr genSurvAvgStr increaseDifficulty isInZone midZoneX midZoneY onKill resetSurvAliases setOfcZones setzone startOBCount startOBMillis startSurvival survLastKill survMapIndex survOfcZones survTimeBetKills tmpSCtr tmpSurvCtr tmpSurvInt tmpSurvSets tmp_sum tmp_survstr tmpSurvZone tmpZoneCenter zone aliasinit survResetAliases survAliases")
+survAliases = (concat $survResetAliases "backInZone checkzone curSurvDifficulty endSurvival finalSurvMillis genSurvDifStr increaseDifficulty isInZone midZoneX midZoneY onKill resetSurvAliases setOfcZones setzone startOBCount startOBMillis startSurvival survLastKill survMapIndex survOfcZones survTimeBetKills tmpSCtr tmpSurvCtr tmpSurvInt tmpSurvSets tmp_sum tmp_survstr tmpSurvZone tmpZoneCenter zone aliasinit survResetAliases survAliases")
addListOnQuit $survAliases
\ No newline at end of file
diff --git a/docs/reference.xml b/docs/reference.xml
index 0c450652..78ac8977 100644
--- a/docs/reference.xml
+++ b/docs/reference.xml
@@ -1087,7 +1087,19 @@
-
+
+
+ Returns the average of a list of numbers.
+
+
+
+ Output: 4.0
+
+
+
+
+
+