Jump to content

Release: Mob Item Adder


EveeX

Recommended Posts


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  32
  • Reputation:   29
  • Joined:  09/16/20
  • Last Seen:  

Mob Item Adder


This mapflag sets more drops for monsters at the map that it's been attached.

You can set up to ~50 more items for mobs.

"drop_per" is the chance of drop, from 1 (0,01%) to 10000 (100%).

There's an example at the screenshot, I setted a Yggdrasil Berry with 100% of chance for the Poring at prt_fild08 map.

You can set a lot of mobs, but you have to set more mapflags for your maps.

Original mod by @zephyr 

Example:

mapname<TAB>mapflag<TAB>mobitemadder<TAB>mob_id,item_id,drop_per{,item_id,drop_per(...)}

 

  • Upvote 1
Link to comment
Share on other sites

  • 3 months later...

  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.02
  • Content Count:  209
  • Reputation:   10
  • Joined:  08/30/19
  • Last Seen:  

Can u update this on latest Git? Thanks!

Link to comment
Share on other sites

  • 1 year later...

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  82
  • Reputation:   2
  • Joined:  04/27/16
  • Last Seen:  

Also looking forward for this getting updated to latest rathena 🙂 

would be amazing ! 

Link to comment
Share on other sites

  • 1 month later...

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  1
  • Reputation:   0
  • Joined:  02/07/24
  • Last Seen:  

I had to make a number of changes to the script, otherwise it didn't work correctly. 

 

src/map/map.cpp

Change 

@@ -2829,6 +2835,27 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)

		if (map_getmapflag(m, MF_MOBITEMADDER)) {
			for (const auto& it : mapdata->mobitemadder_droplist)
			{
				if (it.mob_id == md->mob_id) {

					struct s_mob_drop mobdrop;
					drop_rate = it.item_per;
					mobdrop.nameid = it.item_id;

					if (rand() % 10000 > drop_rate)
						continue;

-					if (!ditem || !itemdb_exists(it.item_id))
+					if (!itemdb_exists(it.item_id))
						continue;
					ditem = mob_setdropitem(&mobdrop, 1, it.mob_id);
					mob_item_drop(md, dlist, ditem, 0, it.item_per, homkillonly);
				}
			}
		}

 

src/map/npc.cpp

new code

case MF_MOBITEMADDER:
{
    if (state) {
        // Copy the string so as not to modify the original string
        char* droplist = strdup(w4);
        if (droplist) {
            char* checkdroplist = strtok(droplist, ", ");
            if (checkdroplist) {
                union u_mapflag_args args = {};
                args.mobitemadder.mob_id = atoi(checkdroplist);

                // Clearing the current item data of a mob before adding new ones
                map_setmapflag(m, MF_MOBITEMADDER, false);

                // Create a temporary array to store added items
                int added_items[50]; // Assume no more than 50 items per monster
                int num_added_items = 0; // Number of items added

                // Process the string and add the items
                while ((checkdroplist = strtok(NULL, ", "))) {
                    args.mobitemadder.item_id = atoi(checkdroplist);
                    if ((checkdroplist = strtok(NULL, ", "))) {
                        args.mobitemadder.item_per = atoi(checkdroplist);
                        // Check to see if the mob already has the item.
                        bool already_added = false;
                        for (int i = 0; i < num_added_items; ++i) {
                            if (added_items[i] == args.mobitemadder.item_id) {
                                already_added = true;
                                break;
                            }
                        }
                        // If the item is not already present on the mob, add it
                        if (!already_added) {
                            map_setmapflag_sub(m, MF_MOBITEMADDER, true, &args);
                            added_items[num_added_items++] = args.mobitemadder.item_id;
                        }
                    }
                }
            }
            free(droplist); // Freeing the allocated memory
        }
    } else {
        map_setmapflag(m, MF_MOBITEMADDER, false);
    }
    break;
}

 

The only problem I have not been able to solve is the duplicate drop if @reloadscript is produced on the server
That is, if you did reloadscript 10 times, the drop will drop in 10 instances.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...