Jump to content

Fix Lua Kill Event bug about EXP to 0


Ikarus_

Recommended Posts

  • Developer

small code to apply to fix the problem of not starting the kill event (lua) after killing a monster that has set 0 as exp in his mob_proto.

 

Spoiler

service.h or CommonDefines.h


#define __ENABLE_KILL_EVENT_FIX__ //if you want to fix the 0 exp problem about the when kill lua event (recommended)

 

char.h

// search 


        void            DistributeHP(LPCHARACTER pkKiller);
        void            DistributeSP(LPCHARACTER pkKiller, int iMethod=0);

// add under


#ifdef __ENABLE_KILL_EVENT_FIX__
        LPCHARACTER        GetMostAttacked();
#endif


char_battle.cpp

 

// search:


void CHARACTER::Reward(bool bItemDrop)
{
    if (GetRaceNum() == 5001) 
    {
        PIXEL_POSITION pos;

        if (!SECTREE_MANAGER::instance().GetMovablePosition(GetMapIndex(), GetX(), GetY(), pos))
            return;

        LPITEM item;
        int iGold = number(GetMobTable().dwGoldMin, GetMobTable().dwGoldMax);
        iGold = iGold * CHARACTER_MANAGER::instance().GetMobGoldAmountRate(NULL) / 100;
        iGold *= GetGoldMultipler();
        int iSplitCount = number(25, 35);

        sys_log(0, "WAEGU Dead gold %d split %d", iGold, iSplitCount);

        for (int i = 1; i <= iSplitCount; ++i)
        {
            if ((item = ITEM_MANAGER::instance().CreateItem(1, iGold / iSplitCount)))
            {
                if (i != 0)
                {
                    pos.x = number(-7, 7) * 20;
                    pos.y = number(-7, 7) * 20;

                    pos.x += GetX();
                    pos.y += GetY();
                }

                item->AddToGround(GetMapIndex(), pos);
                item->StartDestroyEvent();
            }
        }
        return;
    }

    //PROF_UNIT puReward("Reward");
       LPCHARACTER pkAttacker = DistributeExp();

// replace


    if (!pkAttacker)
        return;

// with this


#ifdef __ENABLE_KILL_EVENT_FIX__
    if (!pkAttacker && !(pkAttacker = GetMostAttacked()))
        return;
#else
    if (!pkAttacker)
        return;
#endif

 

// search :


LPCHARACTER CHARACTER::DistributeExp()


//* put BEFORE THIS   -> WARNING BEFORE AND NOT UNDER
//* put BEFORE THIS   -> WARNING BEFORE AND NOT UNDER
//* put BEFORE THIS   -> WARNING BEFORE AND NOT UNDER
//* put BEFORE THIS   -> WARNING BEFORE AND NOT UNDER
//* put BEFORE THIS   -> WARNING BEFORE AND NOT UNDER
//* put BEFORE THIS   -> WARNING BEFORE AND NOT UNDER
//* put BEFORE THIS   -> WARNING BEFORE AND NOT UNDER


#ifdef __ENABLE_KILL_EVENT_FIX__
LPCHARACTER CHARACTER::GetMostAttacked() {

    int iMostDam=-1;
    LPCHARACTER pkChrMostAttacked = NULL;
    auto it = m_map_kDamage.begin();

    while (it != m_map_kDamage.end()){
        //* getting information from the iterator
        const VID & c_VID = it->first;
        const int iDam    = it->second.iTotalDamage;

        //* increasing the iterator
        ++it;

        //* finding the character from his vid
        LPCHARACTER pAttacker = CHARACTER_MANAGER::instance().Find(c_VID);

        //* if the attacked is now offline
        if (!pAttacker)
            continue;
        
        //* if the attacker is not a player
        if( pAttacker->IsNPC())
            continue;
        
        //* if the player is too far
        if(DISTANCE_APPROX(GetX()-pAttacker->GetX(), GetY()-pAttacker->GetY())>5000)
            continue;

        if (iDam > iMostDam){
            pkChrMostAttacked = pAttacker;
            iMostDam = iDam;
        }
    }

    return pkChrMostAttacked;
}
#endif


 

 

This is the hidden content, please

bye bye

source : me

  • Metin2 Dev 18
  • Confused 1
  • Good 4
  • Love 5

My youtube channel  on which you can see my works here

Link to comment
Share on other sites

  • Developer
3 hours ago, sheinfeld said:

It doesnt work, "undefined reference to `CHARACTER::GetMostAttacked()'"

you didn't installed correctly

 

 

2 hours ago, WeedHex said:

So ugly with define. 

If you rly want macro, define in main file cuz you use just one time.

void CHARACTER::Reward(bool bItemDrop) Function is default shitty.

The macro defines are usefull to find the code interesting a fix/implementation and to take trace of the changes made 

  • Love 1

My youtube channel  on which you can see my works here

Link to comment
Share on other sites

  • 2 months 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.