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;

        }
      
    }

 

GitHub

Edited by TokiSan
  • Love 2
Link to post
  • 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 post
  • 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 post
  • 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 post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.



  • Activity

    1. 3

      Loading index and waypoint files like GF

    2. 222

      WorldEditor ReMIX

    3. 3

      Loading index and waypoint files like GF

    4. 3

      HWID ban

    5. 0

      Auth problem

    6. 2

      Starting a metin2 server on a VPS ?

    7. 3

      Client afk in background - Effects started to fun faster

  • Recently Browsing

    No registered users viewing this page.

Shoutbox

Shoutbox

Chatroom Rules

 

Join our Discord

A request for help = Shoutbox Ban

Be respectful & Respect the rules

 

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