Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
78 changes: 78 additions & 0 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -23994,6 +24064,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"),
Expand Down Expand Up @@ -24648,6 +24719,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);
Expand Down