Jump to content

[C++] Prevent Feeding The Horse When It Is Already Full


Recommended Posts

  • Active+ Member
Posted (edited)

INTRODUCTION & PROBLEM

Hello, as you know in the horse system in the game, the player can feed his horse in an unlimited number of times, this will not cause an overflow problem due to the controls in the codes, but I think feeding a horse whose health is already full does not benefit the player.

WHY & WHAT DID WE CHANGE?

We made sure that the horse refuses to be fed when its health reaches the maximum level and the player receives an information message, and we also added extra controls.

UPDATE - 20/06/2024

With @ HFWhite's contribution, we updated the fix for be effective. 🤙

HOW TO DO?

First, open the "horse_rider.cpp" file.

This is the hidden content, please

Then, open the "cmd_general.cpp" file.

This is the hidden content, please

Then open the "questlua_horse.cpp" file.

This is the hidden content, please

Now we need to change one last thing in our .quests, open the SF quest folder and find&open the "horse_menu.quest"

This is the hidden content, please

Finally, open the "locale_string.txt" and added to the end;

This is the hidden content, please

Best regards, MT2Dev.

Edited by MT2Dev
Big update.
  • Metin2 Dev 27
  • Good 5
  • Love 8

spacer.png

©

Link to comment
Share on other sites

  • 2 weeks later...
  • Active+ Member
Posted (edited)


horse_rider.cpp:146:3: error: 'ChatPacket' was not declared in this scope
   ChatPacket(CHAT_TYPE_INFO, LC_TEXT ("HORSE_HEALTH_ALREADY_FULL"));

I included char.h..

 

@ MT2Devany suggestions?

Edit: Also it does not work. It still feeds the horse and -1 the item when feeding...

Edited by HFWhite

spacer.png

Link to comment
Share on other sites

  • Active+ Member
Posted (edited)

Anyway, found a better and easier fix.

in cmd_general.cpp in the do_user_feed_horse command add this inside:

This is the hidden content, please

no need to modify the horse_rider.cpp

open questlua_horse.cpp and find int horse_feed(lua_State* L)

under

LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

add:

This is the hidden content, please

Edited by HFWhite
  • Metin2 Dev 8
  • Love 1
  • Love 1

spacer.png

Link to comment
Share on other sites

  • Active+ Member
On 6/18/2024 at 11:52 PM, HFWhite said:

Anyway, found a better and easier fix.

in cmd_general.cpp in the do_user_feed_horse command add this inside:
 

Hidden Content

 

    unsigned char horselevel = ch->GetHorseLevel(); 

    if (ch->GetHorseHealth() >= c_aHorseStat[horselevel].iMaxHealth)
    {
        ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT ("Calu iti transmite: sunt full coaie"));
        return;
    }

 

 

no need to modify the horse_rider.cpp

open questlua_horse.cpp and find int horse_feed(lua_State* L)

under

LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

add:

 

Hidden Content

 

        unsigned char horselevel = ch->GetHorseLevel(); 

        if (ch->GetHorseHealth() >= c_aHorseStat[horselevel].iMaxHealth)
        {
            ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT ("Calu iti transmite: sunt full coaie"));
            return 0;
        }

 

 

Thank you for your contribution, I am updating the topic. 👌

spacer.png

©

Link to comment
Share on other sites

  • Active+ Member

@ MT2Dev update the post with the following:

 

You need to also update the quest horse_menu.quest to stop the -1 of the food when the horse;s health is 100%.

In order to do that search for:

 

                    if pc.countitem(food) > 0 then
                            pc.removeitem(food, 1)
                            horse.feed()


and replace with:

This is the hidden content, please

  • Metin2 Dev 4
  • Good 1
  • Love 1

spacer.png

Link to comment
Share on other sites

  • Active+ Member
Just now, Werwolf94 said:

Sadly any of your solutions won't prevent the player to feed the horse via drag&drop a hay from inventory to the horse.
I think for the simpliest prevention it's enough to check the horse health at the horse_menu.quest as HFWhite said at the last comment.

I didn't even think that was an option, the drag and drop wtf 

spacer.png

Link to comment
Share on other sites

  • Active+ Member
1 hour ago, Werwolf94 said:

I also don't beleive it when I first saw it's possible, but here is the proof (as you can see your quest solution worked well for me):

 

Honestly, I didn't know that horses could be fed by dragging until you wrote this comment 😂, we can solve this via .quest i guess, it will be enough to add the same control to the function that feeds horses by dragging. (Idk the quest file, but i will take a look at this)

 

@Werwolf94

After a quick look, thats what i find in serverside src; 

// In char_item.cpp find the; bool CHARACTER::CanReceiveItem (LPCHARACTER from, LPITEM item) const

// Then find this;

		case 20101:
		case 20102:
		case 20103:
			if (item->GetVnum() == ITEM_REVIVE_HORSE_1)
			{
				if (!IsDead())
				{
					from->ChatPacket (CHAT_TYPE_INFO, LC_TEXT ("죽지 않은 말에게 선초를 먹일 수 없습니다."));
					return false;
				}

				return true;
			}
			else if (item->GetVnum() == ITEM_HORSE_FOOD_1)
			{
				if (IsDead())
				{
					from->ChatPacket (CHAT_TYPE_INFO, LC_TEXT ("죽은 말에게 사료를 먹일 수 없습니다."));
					return false;
				}

				return true;
			}
			else if (item->GetVnum() == ITEM_HORSE_FOOD_2 || item->GetVnum() == ITEM_HORSE_FOOD_3)
			{
				return false;
			}
			break;

// So this is drop&drag feature for some horse vnums, if you want to disable this, just comment ITEM_HORSE_FOOD_1 else if but if we want to control this too, change like this and try again;

		case 20101:
		case 20102:
		case 20103:
			if (item->GetVnum() == ITEM_REVIVE_HORSE_1)
			{
				if (!IsDead())
				{
					from->ChatPacket (CHAT_TYPE_INFO, LC_TEXT ("죽지 않은 말에게 선초를 먹일 수 없습니다."));
					return false;
				}

				return true;
			}
			else if (item->GetVnum() == ITEM_HORSE_FOOD_1)
			{
				if (IsDead())
				{
					from->ChatPacket (CHAT_TYPE_INFO, LC_TEXT ("죽은 말에게 사료를 먹일 수 없습니다."));
					return false;
				}

				// DevFix 100
				unsigned char horselevel = from->GetHorseLevel();   // DevFix 122
				if (from->GetHorseHealth() >= c_aHorseStat[horselevel].iMaxHealth)
				{
					from->ChatPacket (CHAT_TYPE_INFO, LC_TEXT ("HORSE_HEALTH_ALREADY_FULL"));
					return false;
				}

				return true;
			}
			else if (item->GetVnum() == ITEM_HORSE_FOOD_2 || item->GetVnum() == ITEM_HORSE_FOOD_3)
			{
				return false;
			}
			break;

// ATTANTION! That code block just for item vnum 50054, test this if that one work well i will give update about all vnums for sure.

 

Edited by MT2Dev

spacer.png

©

Link to comment
Share on other sites

  • Active+ Member
41 minutes ago, NeeveS said:

Thanks for the content!


The horse after being killed, if the player teleports, it returns with 100% health.
In other words, the horse will never starve.

 

Hi there.

To be honest, all the changes we've made in this topic are related to horse feeding functions, so I don't think this is causing the problem you mentioned. Could you have accidentally removed an existing system while adding it? Or is there a possibility that this problem existed before adding this system? Regards.

spacer.png

©

Link to comment
Share on other sites

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