summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/script_commands.txt21
-rw-r--r--src/map/script.c78
2 files changed, 99 insertions, 0 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 92fb53445..5c730106b 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -3305,6 +3305,27 @@ Notice that NPC objects disabled with disablenpc() will still be located.
---------------------------------------
+*getmapinfo(<info>{, "<map name>"})
+*getmapinfo(<info>{, <map id>})
+
+This command returns various information about a specific map. If the second
+argument is omitted, it will try to use the map of the attached NPC, or the
+map of the attached player if the NPC can't be found.
+
+Valid <info> are:
+ MAPINFO_NAME name of the map
+ MAPINFO_ID numeric ID of the map
+ MAPINFO_ZONE name of the zone used by the map
+ MAPINFO_SIZE_X width of the map (cells on the x axis)
+ MAPINFO_SIZE_Y height of the map (cells on the y axis)
+
+Examples:
+ getmapinfo(MAPINFO_ID, "map name"); // ID from name
+ getmapinfo(MAPINFO_NAME, 3); // name from ID
+ getmapinfo(MAPINFO_ZONE); // zone, ie Normal, PvP, Jail, ...
+
+---------------------------------------
+
*getunits(<type>, <variable>, <limit>, "<map>"{, <x1>, <y1>, <x2>, <y2>})
This function searches a whole map or area for units and adds their GID to
diff --git a/src/map/script.c b/src/map/script.c
index da079c082..e2f53088c 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -12779,6 +12779,76 @@ BUILDIN(setmapflagnosave) {
return true;
}
+enum mapinfo_info {
+ MAPINFO_NAME,
+ MAPINFO_ID,
+ MAPINFO_SIZE_X,
+ MAPINFO_SIZE_Y,
+ MAPINFO_ZONE
+};
+
+BUILDIN(getmapinfo)
+{
+ enum mapinfo_info mode = script_getnum(st, 2);
+ int16 m;
+
+ if (script_hasdata(st, 3)) {
+ if (script_isstringtype(st, 3)) {
+ const char *str = script_getstr(st, 3);
+ m = map->mapname2mapid(str);
+ } else {
+ m = script_getnum(st, 3);
+ }
+ } else {
+ struct block_list *bl = NULL;
+
+ if (st->oid) {
+ bl = map->id2bl(st->oid);
+ } else if (st->rid) {
+ bl = map->id2bl(st->rid);
+ }
+
+ if (bl == NULL) {
+ ShowError("script:getmapinfo: map not supplied and NPC/PC not attached!\n");
+ script_pushint(st, -3);
+ return false;
+ }
+
+ m = bl->m;
+ }
+
+ if (m < 0) {
+ // here we don't throw an error, so the command can be used
+ // to detect whether or not a map exists
+ script_pushint(st, -1);
+ return true;
+ }
+
+ switch (mode) {
+ case MAPINFO_NAME:
+ script_pushconststr(st, map->list[m].name);
+ break;
+ case MAPINFO_ID:
+ script_pushint(st, m);
+ break;
+ case MAPINFO_SIZE_X:
+ script_pushint(st, map->list[m].xs);
+ break;
+ case MAPINFO_SIZE_Y:
+ script_pushint(st, map->list[m].ys);
+ break;
+ case MAPINFO_ZONE:
+ script_pushstrcopy(st, map->list[m].zone->name);
+ break;
+ default:
+ ShowError("script:getmapinfo: unknown option in second argument (%u).\n", mode);
+ script_pushint(st, -2);
+ return false;
+ }
+
+ return true;
+}
+
BUILDIN(getmapflag)
{
int16 m,i;
@@ -24012,6 +24082,7 @@ void script_parse_builtin(void) {
BUILDIN_DEF(isloggedin,"i?"),
BUILDIN_DEF(setmapflagnosave,"ssii"),
BUILDIN_DEF(getmapflag,"si"),
+ BUILDIN_DEF(getmapinfo,"i?"),
BUILDIN_DEF(setmapflag,"si?"),
BUILDIN_DEF(removemapflag,"si"),
BUILDIN_DEF(pvpon,"s"),
@@ -24670,6 +24741,13 @@ void script_hardcoded_constants(void)
script->set_constant("DRESSROOM_OPEN", DRESSROOM_OPEN, false, false);
script->set_constant("DRESSROOM_CLOSE", DRESSROOM_CLOSE, false, false);
+ script->constdb_comment("getmapinfo options");
+ script->set_constant("MAPINFO_NAME", MAPINFO_NAME, false, false);
+ script->set_constant("MAPINFO_ID", MAPINFO_ID, false, false);
+ script->set_constant("MAPINFO_SIZE_X", MAPINFO_SIZE_X, false, false);
+ script->set_constant("MAPINFO_SIZE_Y", MAPINFO_SIZE_Y, false, false);
+ script->set_constant("MAPINFO_ZONE", MAPINFO_ZONE, false, false);
+
script->constdb_comment("Renewal");
#ifdef RENEWAL
script->set_constant("RENEWAL", 1, false, false);