Jump to content

Cannot attack mob if my level is too hight


Recommended Posts

  • Contributor

This little code let you not attack mob if difference between you level and mob lever is over 15

 

//Battle.cpp

//in bool battle_is_attackable(LPCHARACTER ch, LPCHARACTER victim) search:



    if (victim->IsDead())

        return false;

   

//Add Under:



    if (!(victim->IsPC()))

    {

        if (ch->GetLevel() - victim->GetLevel() > 15)

        {

            return false;

        }
      
    }

 

This is the hidden content, please

Edited by TokiSan
  • Metin2 Dev 5
  • Good 3
  • Love 4
Link to comment
Share on other sites

  • Forum Moderator
On 1/17/2021 at 1:17 AM, TokiSan said:

 

 

    if (!(victim->IsPC()))
    {

        if (ch->GetLevel() - victim->GetLevel() > 15)
        {
            return false;

        }
        else
        {
            return true;

        }
    }

 

 

Thanks for release, but there's something wrong.

First, you've to put the condition after it's checking the safe zone and others, you made a return true without checking those as well. (things will going wrong)

Second, you'll get a negative number if:

int player = 50;
int victim = 80;
int diff = player - victim;
cout << (diff > 15) << endl;
// -30 > 15 ? = false

You've to use std::abs for getting the absolute value.

The code should look like:

This is the hidden content, please

Basically you can't attack a mob if:

  • playerLevel = 50
  • monsterLevel = 66

or:

  • playerLevel = 66
  • monsterLevel = 50
Edited by VegaS™
  • Metin2 Dev 2
  • Good 3
  • Love 1
Link to comment
Share on other sites

  • Contributor
28 minutes ago, VegaS™ said:

 

Thanks for release, but there's something wrong.

First, you've to put the condition after it's checking the safe zone and others, you made a return true without checking those as well. (things will going wrong)

Second, you'll get a negative number if:



int player = 50;
int victim = 80;
int diff = player - victim;
cout << (diff > 15) << endl;
// -30 > 15 ? = false

You've to use std::abs for getting the absolute value.

The code should look like:



if (ch && victim && !victim->IsPC())
{
	static const BYTE DIFFERENCE_LEVEL_ATTACK = 15;
	if (std::abs(ch->GetLevel() - victim->GetLevel()) > DIFFERENCE_LEVEL_ATTACK)
		return false;
}

 

Basically you can't attack a mob if:

  • playerLevel = 50
  • monsterLevel = 66

or:

  • playerLevel = 66
  • monsterLevel = 50

Umh I thank you for the answer, but what interested me was just the case where a player's level was higher than that of a monster. In fact, when you do a boss event, several bosses of different levels are spawned. That way I just wanted to prevent larger levels from take bosses to the smallest levels. About the opposite, who care. If you want attack op boss your problem. 

 

Btw it's a code that I wrote fast, I don't know if you need to Insert the trigg for ATTR_BANPK. Tomorrow I'll watch it better. 

Edited by TokiSan
Link to comment
Share on other sites

  • Forum Moderator

I didn't said that you've to insert something, I mean that structure of your condition, it's non-sense, if (condition) retun false else return true;

Because there're other checks which has to be checked, before you return that true, was enough just to return false if the condition was fulfilled, that's all.

 

Quote

but what interested me was just the case where a player's level was higher than that of a monster.

 

Quote

difference between you level and mob lever is over 15

Difference means (x-y).

Your code is bugged, please try to run it.

This is the hidden content, please

I'm talking about the conditions and math itself, they're totally wrong.

If you really want to check just if the player level is higher than monster then you've to do this:

if ((ch->GetLevel() > victim->GetLevel()) && (ch->GetLevel() - victim->GetLevel()) > 15)

 

So, in that way you're not comparing a negative number with a positive one, you'll be fine.

But yeah.. who cares about math rules in metin2? 🤨

 

Btw, if someone uses your code how it's right now, and there's a guy who knows some basics of reverse engineering, can modify the function IsInSafe in someone's client and make it return false all of the time, he can start a party...

He can kill everybody from every place, even in the safe zone since you made a return true at the beginning of the function.

Edited by VegaS™
  • Good 2
  • Love 1
Link to comment
Share on other sites

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.