summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/script_commands.txt20
-rw-r--r--src/map/script.c27
2 files changed, 46 insertions, 1 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index a0e3a783d..1737f8796 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -8046,6 +8046,26 @@ Example:
---------------------------------------
+*chr(<int>)
+
+Returns a char from its ASCII value.
+
+Example:
+
+ chr(99); //returns "c"
+
+---------------------------------------
+
+*ord(<chr>)
+
+Returns the ASCII value of char <chr>.
+
+Example:
+
+ ord("c"); //returns 99
+
+---------------------------------------
+
*setchar(<string>, <char>, <index>)
Returns the original string with the char at the specified index set to
diff --git a/src/map/script.c b/src/map/script.c
index 38931bd11..ef63697a7 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -5197,7 +5197,7 @@ int script_load_translation(const char *file, uint8 lang_id)
VECTOR_TRUNCATE(msgstr);
continue;
}
-
+
if (strncasecmp(line, "msgid \"", 7) == 0) {
VECTOR_TRUNCATE(msgid);
for (i = 7; i < len - 2; i++) {
@@ -15455,6 +15455,29 @@ BUILDIN(charat) {
}
//=======================================================
+// chr <int>
+//-------------------------------------------------------
+BUILDIN(chr)
+{
+ char output[2];
+ output[0] = script_getnum(st, 2);
+ output[1] = '\0';
+
+ script_pushstrcopy(st, output);
+ return true;
+}
+
+//=======================================================
+// ord <chr>
+//-------------------------------------------------------
+BUILDIN(ord)
+{
+ const char *chr = script_getstr(st, 2);
+ script_pushint(st, *chr);
+ return true;
+}
+
+//=======================================================
// setchar <string>, <char>, <index>
//-------------------------------------------------------
BUILDIN(setchar)
@@ -21075,6 +21098,8 @@ void script_parse_builtin(void) {
BUILDIN_DEF(getstrlen,"s"), //strlen [Valaris]
BUILDIN_DEF(charisalpha,"si"), //isalpha [Valaris]
BUILDIN_DEF(charat,"si"),
+ BUILDIN_DEF(chr,"i"),
+ BUILDIN_DEF(ord,"s"),
BUILDIN_DEF(setchar,"ssi"),
BUILDIN_DEF(insertchar,"ssi"),
BUILDIN_DEF(delchar,"si"),