viewing paste getunittype | 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
 db/const.txt     |   8 +++++
 src/map/script.c | 103 ++++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 91 insertions(+), 20 deletions(-)
 
diff --git a/db/const.txt b/db/const.txt
index 3f0fbdb..1be6918 100644
--- a/db/const.txt
+++ b/db/const.txt
@@ -3523,3 +3523,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
\ No newline at end of file
diff --git a/src/map/script.c b/src/map/script.c
index cfc7ed0..de641cf 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -14116,58 +14116,93 @@ 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 {
+                   bl = map->id2bl(script_getnum(st,6));
+                   break;
+               }
+           }
            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 {
+                   bl = map->id2bl(script_getnum(st,6));
+                   break;
+               }
+           }
            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 {
+                   bl = map->id2bl(script_getnum(st,6));
+                   break;
+               }
+           }
            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 {
+                   bl = map->id2bl(script_getnum(st,6));
+                   break;
+               }
+           }
            else
-               sd=script->rid2sd(st);
+               sd = script->rid2sd(st);
 
            if (sd && sd->ed)
                bl = &sd->ed->bl;
@@ -16336,6 +16371,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
 ///
@@ -20355,6 +20417,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"),
 
Viewed 1307 times, submitted by AnnieRuru.