summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2019-06-02 23:38:43 +0200
committerGitHub <noreply@github.com>2019-06-02 23:38:43 +0200
commit6772362cf2f0a08502cc7d910ed761d249d0c025 (patch)
tree33c1b15a80f86375b1060b1fb42d8287618d0c81
parent000433f782f10f49582b8290b543d7e941e5f7a7 (diff)
parentd9b7fa499ab5ecae677e53d43057671e43b32248 (diff)
downloadhercules-6772362cf2f0a08502cc7d910ed761d249d0c025.tar.gz
hercules-6772362cf2f0a08502cc7d910ed761d249d0c025.tar.bz2
hercules-6772362cf2f0a08502cc7d910ed761d249d0c025.tar.xz
hercules-6772362cf2f0a08502cc7d910ed761d249d0c025.zip
Merge pull request #2290 from bWolfie/getguildonline
Adds buildin_getguildonline.
-rw-r--r--doc/script_commands.txt12
-rw-r--r--src/map/script.c63
2 files changed, 75 insertions, 0 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 4985b0596..251ce563f 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -3801,6 +3801,18 @@ getarraysize(), because it is not cleared between runs of getguildmember().
For usage examples, see getpartymember().
---------------------------------------
+
+*getguildonline(<guild id>{, <type>});
+
+Returns the amount of players online in the specified guild id.
+Returns -1 if the guild was not found.
+
+Valid <type> are:
+ GUILD_ONLINE_ALL Returns the total amount of players online in the guild.
+ GUILD_ONLINE_VENDOR Returns the total amount of vendors online in the guild.
+ GUILD_ONLINE_NO_VENDOR Returns the total amount of non-vendors online in the guild.
+
+---------------------------------------
//=====================================
2.2 - End of Guild-Related Commands
//=====================================
diff --git a/src/map/script.c b/src/map/script.c
index 3661e5db6..714ece6e8 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -9043,6 +9043,63 @@ static BUILDIN(getguildmember)
return true;
}
+/**
+ * getguildonline(<Guild ID>{, type})
+ * Returns amount of guild members online.
+**/
+
+enum script_getguildonline_types {
+ GUILD_ONLINE_ALL = 0,
+ GUILD_ONLINE_VENDOR,
+ GUILD_ONLINE_NO_VENDOR
+};
+
+BUILDIN(getguildonline)
+{
+ struct guild *g;
+ int guild_id = script_getnum(st, 2);
+ int type = GUILD_ONLINE_ALL, j = 0;
+
+ if ((g = guild->search(guild_id)) == NULL) {
+ script_pushint(st, -1);
+ return true;
+ }
+
+ if (script_hasdata(st, 3)) {
+ type = script_getnum(st, 3);
+
+ if (type < GUILD_ONLINE_ALL || type > GUILD_ONLINE_NO_VENDOR) {
+ ShowWarning("buildin_getguildonline: Invalid type specified. Defaulting to GUILD_ONLINE_ALL.\n");
+ type = GUILD_ONLINE_ALL;
+ }
+ }
+
+ struct map_session_data *sd;
+ for (int i = 0; i < MAX_GUILD; i++) {
+ if (g->member[i].online && (sd = g->member[i].sd) != NULL) {
+ switch (type) {
+ case GUILD_ONLINE_VENDOR:
+ if (sd->state.vending > 0)
+ j++;
+ break;
+
+ case GUILD_ONLINE_NO_VENDOR:
+ if (sd->state.vending == 0)
+ j++;
+ break;
+
+ default:
+ j++;
+ break;
+ }
+ }
+ }
+
+ script_pushint(st, j);
+
+ return true;
+}
+
/*==========================================
* Get char string information by type :
* Return by @type :
@@ -25625,6 +25682,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(getguildmaster,"i"),
BUILDIN_DEF(getguildmasterid,"i"),
BUILDIN_DEF(getguildmember,"i?"),
+ BUILDIN_DEF(getguildonline, "i?"),
BUILDIN_DEF(strcharinfo,"i??"),
BUILDIN_DEF(strnpcinfo,"i??"),
BUILDIN_DEF(charid2rid,"i"),
@@ -26697,6 +26755,11 @@ static void script_hardcoded_constants(void)
script->set_constant("UDT_BODY2", UDT_BODY2, false, false);
script->set_constant("UDT_GROUP", UDT_GROUP, false, false);
+ script->constdb_comment("getguildonline types");
+ script->set_constant("GUILD_ONLINE_ALL", GUILD_ONLINE_ALL, false, false);
+ script->set_constant("GUILD_ONLINE_VENDOR", GUILD_ONLINE_VENDOR, false, false);
+ script->set_constant("GUILD_ONLINE_NO_VENDOR", GUILD_ONLINE_NO_VENDOR, false, false);
+
script->constdb_comment("Renewal");
#ifdef RENEWAL
script->set_constant("RENEWAL", 1, false, false);