viewing paste topic/8974- getmapxy_update | Diff

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
 doc/script_commands.txt | 18 ++++++-------
 src/map/script.c        | 67 ++++++++++++++++++++++++++++++++++---------------
 2 files changed, 56 insertions(+), 29 deletions(-)
 
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 218bb48..81f1878 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -3096,7 +3096,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 index>"})
 
 This function will locate a character object, NPC object or pet's 
 coordinates and place their coordinates into the variables specified when 
@@ -3113,16 +3113,16 @@ Type is the type of object to search for:
    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.
+To look for a monster object, monster GID is required. The function will
+always return -1 when search using string.
 
-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 
+The search index is optional. If it is not specified, the location of the 
+invoking character will always be returned for types 0, the location of the
+NPC running this function for type 1.
+If a search index is specified, for types 0 and 1, the character or NPC 
+with the specified name or GID will be located. If type is 2, 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.
+index, it will NOT locate a pet by name.
 
 What a mess. Example, a working and tested one now:
 
diff --git a/src/map/script.c b/src/map/script.c
index 54d8d33..1455a0f 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -14119,58 +14119,85 @@ BUILDIN(getmapxy)
 
    switch (type) {
        case 0: //Get Character Position
-           if( script_hasdata(st,6) )
-               sd=map->nick2sd(script_getstr(st,6));
+           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);
+               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);
+               bl = map->id2bl(st->oid);
            break;
        case 2: //Get Pet Position
-           if(script_hasdata(st,6))
-               sd=map->nick2sd(script_getstr(st,6));
+           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);
+               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));
+           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);
+               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));
+           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);
+               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));
+           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);
+               sd = script->rid2sd(st);
 
            if (sd && sd->ed)
                bl = &sd->ed->bl;
 
Viewed 1210 times, submitted by AnnieRuru.