Jump to content

Recommended Posts

  • Active+ Member
Posted (edited)

! I've only used it on my test server !

This is the hidden content, please

Set item id under "high_item" event flag to highlight the item name with different color (/e high_item IDOFITEM)

Usage:

/drop_simul IDOFMOB AMOUNT

Result:

spacer.png

 

Edited by m2Ciaran
typo
  • Metin2 Dev 45
  • Good 8
  • muscle 1
  • Love 2
  • Love 17
Link to comment
Share on other sites

  • Active+ Member

Hello,

Thank you for the code posted.

I encountered a few issues with it, including a memory leak, so I've optimized and fixed it. Example:

spacer.png

 

Code:

ACMD(do_drop)
{
    char arg1[256], arg2[256];

    two_arguments(argument, arg1, sizeof(arg1), arg2, sizeof(arg2));

    if (!*arg1 || !*arg2)
    {
        ch->ChatPacket(CHAT_TYPE_INFO, "Syntax: drop_simul <mob vnum> <count>");
        return;
    }

    DWORD vnum = 0, loopCount = 0;
    str_to_number(vnum, arg1);
    str_to_number(loopCount, arg2);

    std::unordered_map<DWORD, long long> givenItems;

    LPCHARACTER pkAttacker = CHARACTER_MANAGER::instance().SpawnMobRandomPosition(vnum, ch->GetMapIndex());
    if (!pkAttacker)
        return;

    for (DWORD count = 0; count < loopCount; ++count)
    {
        std::vector<LPITEM> vecItems;
        if (ITEM_MANAGER::instance().CreateDropItem(pkAttacker, ch, vecItems))
        {
            for (LPITEM item : vecItems)
            {
                if (!item)
                {
                    sys_err("item null in vector");
                    continue;
                }

                givenItems[item->GetVnum()] += item->GetCount();
                sys_log(0, "DROP_ITEM_SIMULATE: %s by %s", item->GetName(), ch->GetName());
            }
        }
    }

    ch->ChatPacket(CHAT_TYPE_PARTY, "############### |cFF6d8cf2|H|h%dx %s|h|r DROP SIMULATION ###############", loopCount, pkAttacker->GetName());

    for (const auto& info : givenItems)
    {
        DWORD dwItemVnum = info.first;
        long long itemCount = info.second;
        LPITEM pItem = ITEM_MANAGER::instance().CreateItem(dwItemVnum, itemCount, 0, true);

        if (pItem)
        {
            const char* color = (pItem->GetVnum() == quest::CQuestManager::instance().GetEventFlag("high_item")) ? "|cFFf77f77" : "|cFFf5ef78";
            ch->ChatPacket(CHAT_TYPE_PARTY, "Simulated item %s|H|h%s|h|r, %d pieces", color, pItem->GetName(), itemCount);
            M2_DESTROY_ITEM(pItem);
        }
    }

    M2_DESTROY_CHARACTER(pkAttacker);
}

 

  • Metin2 Dev 1
Link to comment
Share on other sites

  • Active Member
On 3/11/2024 at 4:05 PM, Chitra said:

Hello,

Thank you for the code posted.

I encountered a few issues with it, including a memory leak, so I've optimized and fixed it. Example:

spacer.png

 

Code:

ACMD(do_drop)
{
    char arg1[256], arg2[256];

    two_arguments(argument, arg1, sizeof(arg1), arg2, sizeof(arg2));

    if (!*arg1 || !*arg2)
    {
        ch->ChatPacket(CHAT_TYPE_INFO, "Syntax: drop_simul <mob vnum> <count>");
        return;
    }

    DWORD vnum = 0, loopCount = 0;
    str_to_number(vnum, arg1);
    str_to_number(loopCount, arg2);

    std::unordered_map<DWORD, long long> givenItems;

    LPCHARACTER pkAttacker = CHARACTER_MANAGER::instance().SpawnMobRandomPosition(vnum, ch->GetMapIndex());
    if (!pkAttacker)
        return;

    for (DWORD count = 0; count < loopCount; ++count)
    {
        std::vector<LPITEM> vecItems;
        if (ITEM_MANAGER::instance().CreateDropItem(pkAttacker, ch, vecItems))
        {
            for (LPITEM item : vecItems)
            {
                if (!item)
                {
                    sys_err("item null in vector");
                    continue;
                }

                givenItems[item->GetVnum()] += item->GetCount();
                sys_log(0, "DROP_ITEM_SIMULATE: %s by %s", item->GetName(), ch->GetName());
            }
        }
    }

    ch->ChatPacket(CHAT_TYPE_PARTY, "############### |cFF6d8cf2|H|h%dx %s|h|r DROP SIMULATION ###############", loopCount, pkAttacker->GetName());

    for (const auto& info : givenItems)
    {
        DWORD dwItemVnum = info.first;
        long long itemCount = info.second;
        LPITEM pItem = ITEM_MANAGER::instance().CreateItem(dwItemVnum, itemCount, 0, true);

        if (pItem)
        {
            const char* color = (pItem->GetVnum() == quest::CQuestManager::instance().GetEventFlag("high_item")) ? "|cFFf77f77" : "|cFFf5ef78";
            ch->ChatPacket(CHAT_TYPE_PARTY, "Simulated item %s|H|h%s|h|r, %d pieces", color, pItem->GetName(), itemCount);
            M2_DESTROY_ITEM(pItem);
        }
    }

    M2_DESTROY_CHARACTER(pkAttacker);
}

 

Still have memory leak. Check "CreateDropItem" function definition.

Link to comment
Share on other sites

  • 3 weeks later...

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.