Jump to content

Cannot attack mob if my level is too hight


Recommended Posts

  • VIP

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;

        }
      
    }

 

Hidden Content

    Give reaction to this post to see the hidden content.

Edited by TokiSan
  • Love 2
Link to comment
  • Moderator
31 minutes ago, 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:

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
Edited by VegaS™
Link to comment
  • VIP
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
  • 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.

// Example program
#include <iostream>
#include <string>

int main()
{
    int playerLevel = 50;
    int victimLevel = 66;
    int difference = playerLevel - victimLevel;
    if (difference > 15)
        printf("You can't attack this mob! Difference level: %d", difference);
    else
        printf("You can attack this mob! Difference level: %d", difference);
        
    return 0;
}

 

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™
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • 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.