viewing paste addmonsterdrop | C

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
Index: src/map/script.c
===================================================================
--- src/map/script.c    (revision 17322)
+++ src/map/script.c    (working copy)
@@ -15156,21 +15156,50 @@
    return 0;
 }
 
-/* Work In Progress [Lupus]
 BUILDIN_FUNC(addmonsterdrop)
 {
-   int class_,item_id,chance;
-   class_=script_getnum(st,2);
+   struct mob_db *mob;
+   int item_id,rate,i,c = 0;
+
+   mob = mob_db(script_getnum(st,2));
+
    item_id=script_getnum(st,3);
-   chance=script_getnum(st,4);
-   if(class_>1000 && item_id>500 && chance>0) {
-       script_pushint(st,1);
-   } else {
-       script_pushint(st,0);
+   rate=script_getnum(st,4);
+
+   if(!itemdb_exists(item_id)){
+       ShowError("addmonsterdrop: Nonexistant item %d requested.\n", item_id );
+       return 1;
    }
+
+   if(mob) { //We got a valid monster, check for available drop slot
+       for(i = 0; i < MAX_MOB_DROP; i++) {
+           if(mob->dropitem[i].nameid) { 
+               if(mob->dropitem[i].nameid == item_id) { //If it equals item_id we update that drop
+                   c = i;
+                   break;
+               }
+               continue;
+           }
+           c = i;
+       }
+       if(c) { //Fill in the slot with the item and rate
+           mob->dropitem[c].nameid = item_id;
+           mob->dropitem[c].p = (rate > 10000)?10000:rate;
+       }
+       else //No place to put the new drop
+           return 0;
+   }
+   else {
+       ShowWarning("addmonsterdrop: bad mob id given %d\n",script_getnum(st,2));
+       return 1;
+   }
+
+   script_pushint(st,1);
+   return 0;
+
 }
 
-BUILDIN_FUNC(delmonsterdrop)
+/*BUILDIN_FUNC(delmonsterdrop)
 {
    int class_,item_id;
    class_=script_getnum(st,2);
@@ -18051,6 +18080,7 @@
    BUILDIN_DEF(disguise,"i"), //disguise player. Lupus
    BUILDIN_DEF(undisguise,""), //undisguise player. Lupus
    BUILDIN_DEF(getmonsterinfo,"ii"), //Lupus
+   BUILDIN_DEF(addmonsterdrop,"iii"), //Akinari [Lupus]
    BUILDIN_DEF(axtoi,"s"),
    BUILDIN_DEF(query_sql,"s*"),
    BUILDIN_DEF(query_logsql,"s*"),
Viewed 788 times, submitted by Guest.