viewing paste dropscript | 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 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
Index: src/map/script.c
===================================================================
--- src/map/script.c    (revision 17322)
+++ src/map/script.c    (working copy)
@@ -15156,33 +15156,105 @@
    return 0;
 }
 
-/* Work In Progress [Lupus]
+/*=======================================================
+ * Add or Update a mob drop [Akinari] 
+ * Original Idea By: [Lupus]
+ *
+ * addmonsterdrop <mob_id or name>,<item_id>,<rate>;
+ *
+ * If given an item the mob already drops, the rate
+ * is updated to the new rate.  Rate cannot exceed 10000
+ * Returns 1 if succeeded (added/updated a mob drop)
+ *-------------------------------------------------------*/
 BUILDIN_FUNC(addmonsterdrop)
 {
-   int class_,item_id,chance;
-   class_=script_getnum(st,2);
+   struct mob_db *mob;
+   int item_id,rate,i,c = 0;
+
+   if(script_isstring(st,2))
+       mob = mob_db(mobdb_searchname(script_getstr(st,2)));
+   else
+       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);
+   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;
+           script_pushint(st,1);
+       } else //No place to put the new drop
+           script_pushint(st,0);
    } else {
-       script_pushint(st,0);
+       ShowWarning("addmonsterdrop: bad mob id given %d\n",script_getnum(st,2));
+       return 1;
    }
+
+   return 0;
+
 }
 
+/*=======================================================
+ * Delete a mob drop [Akinari] 
+ * Original Idea By: [Lupus]
+ *
+ * delmonsterdrop <mob_id or name>,<item_id>;
+ *
+ * Returns 1 if succeeded (deleted a mob drop)
+ *-------------------------------------------------------*/
 BUILDIN_FUNC(delmonsterdrop)
 {
-   int class_,item_id;
-   class_=script_getnum(st,2);
+   struct mob_db *mob;
+   int item_id,i;
+
+   if(script_isstring(st,2))
+       mob = mob_db(mobdb_searchname(script_getstr(st,2)));
+   else
+       mob = mob_db(script_getnum(st,2));
+
    item_id=script_getnum(st,3);
-   if(class_>1000 && item_id>500) {
-       script_pushint(st,1);
+
+   if(!itemdb_exists(item_id)){
+       ShowError("delmonsterdrop: Nonexistant item %d requested.\n", item_id );
+       return 1;
+   }
+
+   if(mob) { //We got a valid monster, check for item drop on monster
+       for(i = 0; i < MAX_MOB_DROP; i++) {
+           if(mob->dropitem[i].nameid == item_id) { 
+               mob->dropitem[i].nameid = 0;
+               mob->dropitem[i].p = 0;
+               script_pushint(st,1);
+               return 0;
+           }
+       }
+       //No drop on that monster
+       script_pushint(st,0);
    } else {
-       script_pushint(st,0);
+       ShowWarning("delmonsterdrop: bad mob id given %d\n",script_getnum(st,2));
+       return 1;
    }
+
+   return 0;
 }
-*/
 
+
 /*==========================================
  * Returns some values of a monster [Lupus]
  * Name, Level, race, size, etc...
@@ -18051,6 +18123,8 @@
    BUILDIN_DEF(disguise,"i"), //disguise player. Lupus
    BUILDIN_DEF(undisguise,""), //undisguise player. Lupus
    BUILDIN_DEF(getmonsterinfo,"ii"), //Lupus
+   BUILDIN_DEF(addmonsterdrop,"vii"), //Akinari [Lupus]
+   BUILDIN_DEF(delmonsterdrop,"vi"), //Akinari [Lupus]
    BUILDIN_DEF(axtoi,"s"),
    BUILDIN_DEF(query_sql,"s*"),
    BUILDIN_DEF(query_logsql,"s*"),
Viewed 770 times, submitted by Guest.