summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/const.txt8
-rw-r--r--doc/script_commands.txt58
-rw-r--r--src/map/script.c117
3 files changed, 137 insertions, 46 deletions
diff --git a/db/const.txt b/db/const.txt
index a338d300d..56437d2e2 100644
--- a/db/const.txt
+++ b/db/const.txt
@@ -3539,3 +3539,11 @@ SEPTEMBER 9
OCTOBER 10
NOVEMBER 11
DECEMBER 12
+
+UNITTYPE_PC 0
+UNITTYPE_NPC 1
+UNITTYPE_PET 2
+UNITTYPE_MOB 3
+UNITTYPE_HOM 4
+UNITTYPE_MER 5
+UNITTYPE_ELEM 6
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index b676eb7f4..1f6c40996 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -3095,7 +3095,7 @@ cards or if it's signed.
//=====================================
---------------------------------------
-*getmapxy("<variable for map name>",<variable for x>,<variable for y>,<type>{,"<search string>"})
+*getmapxy("<variable for map name>",<variable for x>,<variable for y>,<type>{,"<search parameter>"})
This function will locate a character object, NPC object or pet's
coordinates and place their coordinates into the variables specified when
@@ -3104,24 +3104,27 @@ parameters given were not variables or the search was not successful.
Type is the type of object to search for:
- 0 - Character object
- 1 - NPC object
- 2 - Pet object
- 3 - Monster object
- 4 - Homunculus object
- 5 - Mercenary object
- 6 - Elemental object
-
-While 3 is meant to look for a monster object, no searching will be done
-if you specify type 3, and the function will always return -1.
-
-The search string is optional. If it is not specified, the location of the
-invoking character will always be returned for types 0 and 2, the location
-of the NPC running this function for type 1.
-If a search string is specified, for types 0 and 1, the character or NPC
-with the specified name will be located. If type is 3, the search will
-locate the current pet of the character who's name is given in the search
-string, it will NOT locate a pet by name.
+ UNITTYPE_PC - Character object
+ UNITTYPE_NPC - NPC object
+ UNITTYPE_PET - Pet object
+ UNITTYPE_MOB - Monster object
+ UNITTYPE_HOM - Homunculus object
+ UNITTYPE_MER - Mercenary object
+ UNITTYPE_ELEM - Elemental object
+
+To look for a monster object, monster GID is required. The function will
+always return -1 when search using string.
+
+The search parameter is optional. If it is not specified, the location of the
+invoking character will always be returned for UNITTYPE_PC, the location of the
+NPC running this function for UNITTYPE_NPC. If a search parameter is specified,
+for UNITTYPE_PC and UNITTYPE_NPC, the character or NPC with the specified name
+or GID will be located.
+
+If type is UNITTYPE_PET, UNITTYPE_HOM, UNITTYPE_MER or UNITTYPE_ELEM the search
+will locate the owner's pet/homun/mercenary/elementals if the search parameter
+is not provided. It will NOT locate these object by name, but can be done if GID
+is provided.
What a mess. Example, a working and tested one now:
@@ -3133,7 +3136,7 @@ What a mess. Example, a working and tested one now:
prontera,164,299,3%TAB%script%TAB%Nyah%TAB%730,{
mes "My name is Nyah.";
mes "I will now search for Meh all across the world!";
- if (getmapxy(.@mapname$,.@mapx,.@mapy,1,"Meh")!=0) {
+ if (getmapxy(.@mapname$, .@mapx, .@mapy, UNITTYPE_NPC, "Meh") != 0) {
mes "I can't seem to find Meh anywhere!";
close;
}
@@ -6193,6 +6196,21 @@ and will return the following values:
---------------------------------------
+*getunittype <GID>;
+
+Returns the type of object from the given Game ID. Returns -1 if the given GID
+does not exist. The return values are :-
+
+ UNITTYPE_PC 0
+ UNITTYPE_NPC 1
+ UNITTYPE_PET 2
+ UNITTYPE_MOB 3
+ UNITTYPE_HOM 4
+ UNITTYPE_MER 5
+ UNITTYPE_ELEM 6
+
+---------------------------------------
+
*unitwalk <GID>,<x>,<y>;
*unitwalk <GID>,<target_GID>;
diff --git a/src/map/script.c b/src/map/script.c
index 401b0308a..00985c2a5 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -14132,58 +14132,95 @@ BUILDIN(getmapxy)
switch (type) {
case 0: //Get Character Position
- if( script_hasdata(st,6) )
- sd=map->nick2sd(script_getstr(st,6));
- else
- sd=script->rid2sd(st);
+ if (script_hasdata(st,6)) {
+ if (script_isstringtype(st,6))
+ sd = map->nick2sd(script_getstr(st,6));
+ else
+ sd = map->id2sd(script_getnum(st,6));
+ } else {
+ sd = script->rid2sd(st);
+ }
if (sd)
bl = &sd->bl;
break;
case 1: //Get NPC Position
- if( script_hasdata(st,6) )
- {
+ if (script_hasdata(st,6)) {
struct npc_data *nd;
- nd=npc->name2id(script_getstr(st,6));
+ if (script_isstringtype(st,6))
+ nd = npc->name2id(script_getstr(st,6));
+ else
+ nd = map->id2nd(script_getnum(st,6));
if (nd)
bl = &nd->bl;
- } else //In case the origin is not an npc?
- bl=map->id2bl(st->oid);
+ } else {
+ //In case the origin is not an npc?
+ bl = map->id2bl(st->oid);
+ }
break;
case 2: //Get Pet Position
- if(script_hasdata(st,6))
- sd=map->nick2sd(script_getstr(st,6));
- else
- sd=script->rid2sd(st);
+ if (script_hasdata(st,6)) {
+ if (script_isstringtype(st,6))
+ sd = map->nick2sd(script_getstr(st,6));
+ else {
+ bl = map->id2bl(script_getnum(st,6));
+ break;
+ }
+ } else {
+ sd = script->rid2sd(st);
+ }
if (sd && sd->pd)
bl = &sd->pd->bl;
break;
case 3: //Get Mob Position
- break; //Not supported?
+ if (script_hasdata(st,6)) {
+ if (script_isstringtype(st,6))
+ break;
+ bl = map->id2bl(script_getnum(st,6));
+ }
+ break;
case 4: //Get Homun Position
- if(script_hasdata(st,6))
- sd=map->nick2sd(script_getstr(st,6));
- else
- sd=script->rid2sd(st);
+ if (script_hasdata(st,6)) {
+ if (script_isstringtype(st,6)) {
+ sd = map->nick2sd(script_getstr(st,6));
+ } else {
+ bl = map->id2bl(script_getnum(st,6));
+ break;
+ }
+ } else {
+ sd = script->rid2sd(st);
+ }
if (sd && sd->hd)
bl = &sd->hd->bl;
break;
case 5: //Get Mercenary Position
- if(script_hasdata(st,6))
- sd=map->nick2sd(script_getstr(st,6));
- else
- sd=script->rid2sd(st);
+ if (script_hasdata(st,6)) {
+ if (script_isstringtype(st,6)) {
+ sd = map->nick2sd(script_getstr(st,6));
+ } else {
+ bl = map->id2bl(script_getnum(st,6));
+ break;
+ }
+ } else {
+ sd = script->rid2sd(st);
+ }
if (sd && sd->md)
bl = &sd->md->bl;
break;
case 6: //Get Elemental Position
- if(script_hasdata(st,6))
- sd=map->nick2sd(script_getstr(st,6));
- else
- sd=script->rid2sd(st);
+ if (script_hasdata(st,6)) {
+ if (script_isstringtype(st,6)) {
+ sd = map->nick2sd(script_getstr(st,6));
+ } else {
+ bl = map->id2bl(script_getnum(st,6));
+ break;
+ }
+ } else {
+ sd = script->rid2sd(st);
+ }
if (sd && sd->ed)
bl = &sd->ed->bl;
@@ -16363,6 +16400,33 @@ BUILDIN(pcstopfollow)
// [zBuffer] List of mob control commands --->
//## TODO always return if the request/whatever was successfull [FlavioJS]
+BUILDIN(getunittype) {
+ struct block_list* bl;
+ int value;
+
+ bl = map->id2bl(script_getnum(st,2));
+
+ if (!bl) {
+ ShowWarning("buildin_getunittype: Error in finding object GID %d!\n", script_getnum(st,2));
+ script_pushint(st,-1);
+ return false;
+ }
+
+ switch (bl->type) {
+ case BL_PC: value = 0; break;
+ case BL_NPC: value = 1; break;
+ case BL_PET: value = 2; break;
+ case BL_MOB: value = 3; break;
+ case BL_HOM: value = 4; break;
+ case BL_MER: value = 5; break;
+ case BL_ELEM: value = 6; break;
+ default: value = -1; break;
+ }
+
+ script_pushint(st, value);
+ return true;
+}
+
/// Makes the unit walk to target position or target id
/// Returns if it was successfull
///
@@ -20382,6 +20446,7 @@ void script_parse_builtin(void) {
BUILDIN_DEF(pcblockmove,"ii"),
// <--- [zBuffer] List of player cont commands
// [zBuffer] List of mob control commands --->
+ BUILDIN_DEF(getunittype,"i"),
BUILDIN_DEF(unitwalk,"ii?"),
BUILDIN_DEF(unitkill,"i"),
BUILDIN_DEF(unitwarp,"isii"),