summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorEPuncker <gm.perflex@gmail.com>2013-10-12 12:08:32 -0300
committerHaru <haru@dotalux.com>2013-10-14 03:50:21 +0200
commit7ddcff9ae2c45659605c649a0af8bb25539ecade (patch)
tree1755708a9681895bdf67b5cb045029f5247e8831 /src/map/script.c
parentca7008b760c6a2561d1a16d8a632fb30de34b360 (diff)
downloadhercules-7ddcff9ae2c45659605c649a0af8bb25539ecade.tar.gz
hercules-7ddcff9ae2c45659605c649a0af8bb25539ecade.tar.bz2
hercules-7ddcff9ae2c45659605c649a0af8bb25539ecade.tar.xz
hercules-7ddcff9ae2c45659605c649a0af8bb25539ecade.zip
Added scriptcommands addmonsterdrop and delmonsterdrop (Missing documentation)
[Edit by Haru: This commit has been amended in order for it to work properly in Hercules, and to correct some flaws of the original version, according to what I said in my review of issue #191. Credits to the original author have been moved to an "Original idea by" comment. Commit authorship is preserved. Documentation will be added in a follow-up commit] Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c134
1 files changed, 108 insertions, 26 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 1bedb78b6..7d92f092a 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -14340,32 +14340,112 @@ BUILDIN(setitemscript)
return true;
}
-/* Work In Progress [Lupus]
- BUILDIN(addmonsterdrop)
- {
- int class_,item_id,chance;
- class_=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);
- }
- }
-
- BUILDIN(delmonsterdrop)
- {
- int class_,item_id;
- class_=script_getnum(st,2);
- item_id=script_getnum(st,3);
- if(class_>1000 && item_id>500) {
- script_pushint(st,1);
- } else {
- script_pushint(st,0);
- }
- }
- */
+/*=======================================================
+ * Temporarily add or update a mob drop
+ * Original Idea By: [Lupus], [Akinari]
+ *
+ * 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 must be in the range [1:10000]
+ * Returns 1 if succeeded (added/updated a mob drop)
+ *-------------------------------------------------------*/
+BUILDIN(addmonsterdrop) {
+ struct mob_db *monster;
+ int item_id, rate, i, c = MAX_MOB_DROP;
+
+ if( script_isstring(st,2) )
+ monster = mob->db(mob->db_searchname(script_getstr(st,2)));
+ else
+ monster = mob->db(script_getnum(st,2));
+
+ if( monster == mob->dummy ) {
+ if( script_isstring(st,2) ) {
+ ShowError("buildin_addmonsterdrop: invalid mob name: '%s'.\n", script_getstr(st,2));
+ } else {
+ ShowError("buildin_addmonsterdrop: invalid mob id: '%d'.\n", script_getnum(st,2));
+ }
+ return false;
+ }
+
+ item_id = script_getnum(st,3);
+ if( !itemdb->exists(item_id) ) {
+ ShowError("buildin_addmonsterdrop: Invalid item ID: '%d'.\n", item_id);
+ return false;
+ }
+
+ rate = script_getnum(st,4);
+ if( rate < 1 || rate > 10000 ) {
+ ShowWarning("buildin_addmonsterdrop: Invalid drop rate '%d'. Capping to the [1:10000] range.\n", rate);
+ rate = cap_value(rate,1,10000);
+ }
+
+ for( i = 0; i < MAX_MOB_DROP; i++ ) {
+ if( monster->dropitem[i].nameid == item_id ) // Item ID found
+ break;
+ if( c == MAX_MOB_DROP && monster->dropitem[i].nameid < 1 ) // First empty slot
+ c = i;
+ }
+ if( i < MAX_MOB_DROP ) // If the item ID was found, prefer it
+ c = i;
+
+ if( c < MAX_MOB_DROP ) {
+ // Fill in the slot with the item and rate
+ monster->dropitem[c].nameid = item_id;
+ monster->dropitem[c].p = rate;
+ script_pushint(st,1);
+ } else {
+ //No place to put the new drop
+ script_pushint(st,0);
+ }
+
+ return true;
+}
+
+/*=======================================================
+ * Temporarily remove a mob drop
+ * Original Idea By: [Lupus], [Akinari]
+ *
+ * delmonsterdrop <mob_id or name>,<item_id>;
+ *
+ * Returns 1 if succeeded (deleted a mob drop)
+ *-------------------------------------------------------*/
+BUILDIN(delmonsterdrop) {
+ struct mob_db *monster;
+ int item_id, i;
+
+ if( script_isstring(st,2) )
+ monster = mob->db(mob->db_searchname(script_getstr(st,2)));
+ else
+ monster = mob->db(script_getnum(st,2));
+
+ if( monster == mob->dummy ) {
+ if( script_isstring(st,2) ) {
+ ShowError("buildin_delmonsterdrop: invalid mob name: '%s'.\n", script_getstr(st,2));
+ } else {
+ ShowError("buildin_delmonsterdrop: invalid mob id: '%d'.\n", script_getnum(st,2));
+ }
+ return false;
+ }
+
+ item_id = script_getnum(st,3);
+ if( !itemdb->exists(item_id) ) {
+ ShowError("buildin_delmonsterdrop: Invalid item ID: '%d'.\n", item_id);
+ return false;
+ }
+
+ for( i = 0; i < MAX_MOB_DROP; i++ ) {
+ if( monster->dropitem[i].nameid == item_id ) {
+ monster->dropitem[i].nameid = 0;
+ monster->dropitem[i].p = 0;
+ script_pushint(st,1);
+ return true;
+ }
+ }
+ // No drop on that monster
+ script_pushint(st,0);
+ return true;
+}
/*==========================================
* Returns some values of a monster [Lupus]
@@ -17669,6 +17749,8 @@ void script_parse_builtin(void) {
BUILDIN_DEF(disguise,"i"), //disguise player. Lupus
BUILDIN_DEF(undisguise,""), //undisguise player. Lupus
BUILDIN_DEF(getmonsterinfo,"ii"), //Lupus
+ BUILDIN_DEF(addmonsterdrop,"vii"),
+ BUILDIN_DEF(delmonsterdrop,"vi"),
BUILDIN_DEF(axtoi,"s"),
BUILDIN_DEF(query_sql,"s*"),
BUILDIN_DEF(query_logsql,"s*"),