summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2020-06-01 05:24:22 +0200
committerGitHub <noreply@github.com>2020-06-01 05:24:22 +0200
commitf1734dcd29ae8177fde4df78d78ed8c7c086d599 (patch)
tree64f11a4a8e4fadb48651116f3ccb7cc9ceed2142
parentf0aef9c8d8278b593b9de86148417c2aee78ab54 (diff)
parentc54623866cc7764ce6b2c0844c7d98a80b5f0592 (diff)
downloadhercules-f1734dcd29ae8177fde4df78d78ed8c7c086d599.tar.gz
hercules-f1734dcd29ae8177fde4df78d78ed8c7c086d599.tar.bz2
hercules-f1734dcd29ae8177fde4df78d78ed8c7c086d599.tar.xz
hercules-f1734dcd29ae8177fde4df78d78ed8c7c086d599.zip
Merge pull request #2758 from Kenpachi2k13/loudhailer
Add loudhailer() script command
-rw-r--r--db/pre-re/item_db.conf2
-rw-r--r--db/re/item_db.conf2
-rw-r--r--doc/script_commands.txt10
-rw-r--r--src/map/clif.c4
-rw-r--r--src/map/clif.h2
-rw-r--r--src/map/script.c45
6 files changed, 62 insertions, 3 deletions
diff --git a/db/pre-re/item_db.conf b/db/pre-re/item_db.conf
index 493a758cc..cc7f5040d 100644
--- a/db/pre-re/item_db.conf
+++ b/db/pre-re/item_db.conf
@@ -68730,7 +68730,7 @@ item_db: (
}
Script: <"
input @megaphone$;
- announce strcharinfo(PC_NAME) + ": " + @megaphone$,bc_all,0xFF0000;
+ loudhailer(@megaphone$);
end;
">
},
diff --git a/db/re/item_db.conf b/db/re/item_db.conf
index 408fb3ef8..c653fcf0b 100644
--- a/db/re/item_db.conf
+++ b/db/re/item_db.conf
@@ -88610,7 +88610,7 @@ item_db: (
}
Script: <"
input @megaphone$;
- announce strcharinfo(PC_NAME) + ": " + @megaphone$,bc_all,0xFF0000;
+ loudhailer(@megaphone$);
end;
">
},
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index a585695bd..2fc6a95e5 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -7527,6 +7527,16 @@ if GID is not given use the attached player.
//=====================================
---------------------------------------
+*loudhailer("<message>"{, "<color>"})
+
+Announces a colored text in '<char_name> Shouts : <message>' format.
+<color> must be a string in "RRGGBB" format. If <color> is omitted,
+white ("FFFFFF") will be used.
+This command is specially created for the Megaphone_ item (12221),
+but will work in NPCs, too.
+
+---------------------------------------
+
*announce("<text>", <flag>{, <fontColor>{, <fontType>{, <fontSize>{, <fontAlign>{, <fontY>}}}}})
This command will broadcast a message to all or most players, similar to
diff --git a/src/map/clif.c b/src/map/clif.c
index 5cc11c494..8688ee771 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -6235,7 +6235,7 @@ static void clif_displaymessage_sprintf(const int fd, const char *mes, ...)
/// 009a <packet len>.W <message>.?B
static void clif_broadcast(struct block_list *bl, const char *mes, int len, int type, enum send_target target)
{
- int lp = (type&BC_COLOR_MASK) ? 4 : 0;
+ int lp = ((type & BC_COLOR_MASK) != 0 || (type & BC_MEGAPHONE) != 0) ? 4 : 0;
unsigned char *buf = NULL;
nullpo_retv(mes);
@@ -6247,6 +6247,8 @@ static void clif_broadcast(struct block_list *bl, const char *mes, int len, int
WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
else if( type&BC_WOE )
WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
+ else if ((type & BC_MEGAPHONE) != 0)
+ WBUFL(buf, 4) = 0x6363696d; // If there's "micc" at the beginning of the message, the game client will recognize message as 'Megaphone shout'.
memcpy(WBUFP(buf, 4 + lp), mes, len);
clif->send(buf, WBUFW(buf,2), bl, target);
diff --git a/src/map/clif.h b/src/map/clif.h
index fdaaf85e3..e43aad808 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -146,6 +146,8 @@ typedef enum broadcast_flags {
BC_WOE = 0x20,
BC_COLOR_MASK = 0x30, // BC_YELLOW|BC_BLUE|BC_WOE
+ BC_MEGAPHONE = 0x40,
+
BC_DEFAULT = BC_ALL|BC_PC|BC_YELLOW
} broadcast_flags;
diff --git a/src/map/script.c b/src/map/script.c
index 763a6c51c..682e665b6 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -12533,6 +12533,50 @@ static BUILDIN(mobattached)
return true;
}
+/**
+ * Announces a colored text in '<char_name> Shouts : <message>' format.
+ * Default color is white ("FFFFFF").
+ *
+ * This is a special use case of packet 0x009a where the message's first 34 bytes
+ * are reserved for string "micc" (4B) which identifies the broadcast as megaphone shout,
+ * the character's name (24B) and the text color (6B).
+ *
+ * 009a <packet len>.W <micc>.4B <char name>.24B <color>.6B <message>.?B
+ *
+ * @code{.herc}
+ * loudhailer("<message>"{, "<color>"});
+ * @endcode
+ *
+ **/
+static BUILDIN(loudhailer)
+{
+ const char *mes = script_getstr(st, 2);
+ size_t len_mes = strlen(mes);
+
+ Assert_retr(false, len_mes + 33 < CHAT_SIZE_MAX); // +33 because of the '<char_name> Shouts : ' message prefix.
+
+ const char *color = script_hasdata(st, 3) ? script_getstr(st, 3) : "FFFFFF";
+
+ Assert_retr(false, strlen(color) == 6);
+
+ struct map_session_data *sd = script->rid2sd(st);
+
+ if (sd == NULL)
+ return false;
+
+ char mes_formatted[CHAT_SIZE_MAX + 30] = "";
+
+ strcpy(mes_formatted, sd->status.name);
+ strcpy(mes_formatted + 24, color);
+ safesnprintf(mes_formatted + 30, CHAT_SIZE_MAX, "%s Shouts : %s", sd->status.name, mes);
+
+ size_t len_formatted = 30 + strlen(sd->status.name) + 10 + len_mes + 1;
+
+ clif->broadcast(&sd->bl, mes_formatted, (int)len_formatted, BC_MEGAPHONE, ALL_CLIENT);
+
+ return true;
+}
+
/*==========================================
*------------------------------------------*/
static BUILDIN(announce)
@@ -27352,6 +27396,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(detachnpctimer,"?"), // detached the player id from the npc timer [Celest]
BUILDIN_DEF(playerattached,""), // returns id of the current attached player. [Skotlex]
BUILDIN_DEF(mobattached, ""),
+ BUILDIN_DEF(loudhailer, "s?"),
BUILDIN_DEF(announce,"si?????"),
BUILDIN_DEF(mapannounce,"ssi?????"),
BUILDIN_DEF(areaannounce,"siiiisi?????"),