Jelajahi Sumber

Adds script command channel_getopt (#5748)

* Fixes #5728.
* Adds script command channel_getopt to return channel options.
Thanks to @Akkarinage and @Lemongrass3110!
Aleos 4 tahun lalu
induk
melakukan
1a1005435f
2 mengubah file dengan 52 tambahan dan 0 penghapusan
  1. 13 0
      doc/script_commands.txt
  2. 39 0
      src/map/script.cpp

+ 13 - 0
doc/script_commands.txt

@@ -10395,6 +10395,19 @@ Only for public and private channel.
 
 ---------------------------------------
 
+*channel_getopt "<chname>",<option>;
+
+Get option value for the channel. The <option> values are the same as the
+'channel_create' options. Returns true or false except for CHAN_OPT_MSG_DELAY
+which returns an integer.
+
+	// Example to get the delay
+	.delay = channel_getopt("#global",CHAN_OPT_MSG_DELAY);
+
+Only for public and private channel.
+
+---------------------------------------
+
 *channel_setcolor "<chname>",<color>;
 
 To change channel color.

+ 39 - 0
src/map/script.cpp

@@ -23724,6 +23724,44 @@ BUILDIN_FUNC(channel_setopt) {
 	return SCRIPT_CMD_SUCCESS;
 }
 
+/**
+ * Get channel options
+ * channel_getopt <chname>,<option>;
+ */
+BUILDIN_FUNC(channel_getopt) {
+	Channel *ch;
+	const char *chname = script_getstr(st, 2);
+
+	if (!(ch = channel_name2channel((char *)chname, NULL, 0))) {
+		ShowError("buildin_channel_getopt: Channel name '%s' is invalid.\n", chname);
+		script_pushint(st, false);
+		return SCRIPT_CMD_FAILURE;
+	}
+
+	int opt = script_getnum(st, 3);
+
+	switch (opt) {
+		case CHAN_OPT_ANNOUNCE_SELF:
+		case CHAN_OPT_ANNOUNCE_JOIN:
+		case CHAN_OPT_ANNOUNCE_LEAVE:
+		case CHAN_OPT_COLOR_OVERRIDE:
+		case CHAN_OPT_CAN_CHAT:
+		case CHAN_OPT_CAN_LEAVE:
+		case CHAN_OPT_AUTOJOIN:
+			script_pushint(st, (ch->opt & opt) != 0);
+			break;
+		case CHAN_OPT_MSG_DELAY:
+			script_pushint(st, ch->msg_delay);
+			break;
+		default:
+			ShowError("buildin_channel_getopt: Invalid option %d!\n", opt);
+			script_pushint(st, false);
+			return SCRIPT_CMD_FAILURE;
+	}
+
+	return SCRIPT_CMD_SUCCESS;
+}
+
 /**
  * Set channel color
  * channel_setcolor "<chname>",<color>;
@@ -25607,6 +25645,7 @@ struct script_function buildin_func[] = {
 	// Channel System
 	BUILDIN_DEF(channel_create,"ss?????"),
 	BUILDIN_DEF(channel_setopt,"sii"),
+	BUILDIN_DEF(channel_getopt,"si"),
 	BUILDIN_DEF(channel_setcolor,"si"),
 	BUILDIN_DEF(channel_setpass,"ss"),
 	BUILDIN_DEF(channel_setgroup,"si*"),