aslain.dev
0%
01 Hizmetler 02 Hakkımda 03 Projeler 04 Stack 05 Blog 06 İletişim
← Tüm makaleler Metin2

Metin2 Pet System: A Guide to Adding Pets

The Metin2 pet system is how you manage the companions that follow your character, grant passive bonuses and can even level up. On classic servers a pet is purely cosmetic, while a modern pet system brings feeding, levels, bonuses and sometimes skills. In this guide I explain how the system works, where pet bonuses come from, the feeding mechanic, and the exact steps to add a brand new pet model to your server.

How the pet system works

In Metin2 a pet is, in practice, a special mob entry. The character activates the pet from a summon item in the inventory (an egg, a whistle or a collar); this is a USE type item, and using it spawns a temporary entity bound to the player. The pet is not created as an enemy on the ground but as an NPC that follows its owner.

  • Summon item — defined in item_proto, usually with type = USE and a sub type along the lines of USE_PET.
  • Pet model — maps to a vnum in mob_proto; its visuals come from a .gr2 model file on the client side.
  • Behaviour — the spawning code locks the pet to its owner; it does not attack, it simply stays nearby (except for battle-pet variants).

The newer pet systems (the add-on commonly referred to as the "pet system") layer levels, a hunger bar, duration and bonuses on top of this base structure. Those layers are mostly driven by the quest engine (Lua) and a few extra tables.

Where pet bonuses come from

Pet bonuses are temporary stat boosts applied to the player carrying the pet. You can wire them up in two main ways:

  • Item bonuses — define bonuses directly on the summon item through item_proto (for example APPLY_MAX_HP, APPLY_ATT_SPEED). They apply while the pet is active.
  • Quest-based bonuses — if you want bonuses that scale with pet level, adding them from a Lua quest through calls like apply_bonus is far more flexible.

The example below is simplified quest logic that grants the player an attack bonus based on the pet's level when it is summoned:

quest pet_bonus begin
    state start begin
        when 53001.use begin
            local lvl = pc.getqf("pet_level")
            -- +5 attack value per level
            apply.apply("ATT_GRADE_BONUS", lvl * 5, 60 * 30)
            chat("Your pet empowers you!")
        end
    end
end

The key point: tie the bonus duration to the pet's duration and reapply the bonus consistently when the pet is summoned or recalled. Otherwise a player can exploit it by repeatedly resummoning the pet.

The feeding mechanic

Feeding is the part of the pet system that keeps the player engaged. The logic is: the pet has a hunger/satiety value that decays over time, and the player refills it with a special pet food item. If satiety hits zero, the pet stops giving bonuses or disappears.

  • Store the satiety value in a quest flag on the player: pc.setqf("pet_food", 100).
  • Decay the value regularly with a timer (quest when … with timer).
  • When the pet food item is used, raise the value and prevent it from exceeding the cap (e.g. 100).
quest pet_feed begin
    state start begin
        when 53010.use begin
            local food = pc.getqf("pet_food")
            food = math.min(food + 25, 100)
            pc.setqf("pet_food", food)
            item.remove()
            chat("Pet satiety: "..food.."/100")
        end
    end
end

You can combine feeding with the level system: as the pet is fed it earns a small pet_exp value, levels up at set thresholds and its bonuses grow. This loop encourages the player to tend to the pet regularly.

Steps to add a new pet model

Adding a visually new pet to your server requires files on both the client and the server. The order is as follows:

  • 1. Model files: place the new pet's .gr2 model and animation files, along with the texture (.dds) files, into the appropriate pack folder on the client.
  • 2. mob_proto entry: add the pet to mob_proto under a new vnum, as an NPC/pet type with its speed and size values. The server must read this entry correctly.
  • 3. Client definition: match the client-side mob_proto (or .txt definition) and the model path; the link between the vnum and the .gr2 file must be correct.
  • 4. Summon item: create a new item_proto entry and bind it, when used, to the quest or code path that summons the pet with this new vnum.
  • 5. Localization: add the pet's and the item's name/description in the locale files.

When testing, go step by step: first, does the item appear in the inventory; then, does the pet spawn when used; then, are the model and animation correct; and finally, does the bonus/feeding loop work. Isolating each step makes debugging far easier.

Common mistakes

  • Invisible pet: the vnum exists on the server but the model path does not match on the client — it spawns but stays invisible. mob_proto must be consistent on both sides.
  • Bonus stays permanent: the bonus is not cleared when the pet is recalled. Tie the duration to the pet's lifetime and reset the bonus on recall.
  • proto mismatch: the client and server item_proto/mob_proto versions differ; this shows up as an "unknown item" or a crash. Always distribute the same proto to both sides.

Frequently Asked Questions

Can a pet harm the character or attack?

A standard pet only follows its owner and does not attack. If you want a "battle pet" you have to define a separate behaviour (mob AI) and code the pet to attack enemies; that is a different development task from the classic follow pet.

Will the pet disappear if I do not feed it?

That depends entirely on your system design. A common approach is for the pet to stop giving bonuses once satiety hits zero; on some servers the pet is recalled completely. You define the logic in the Lua quest.

Is a pet level system mandatory?

No. For a simple cosmetic pet, just a summon item and a model are enough. Levels, feeding and bonus layers are optional features added to increase player engagement.

Want a solid, exploit-proof pet system for your server? I can build and test the whole flow — adding a pet model, the feeding mechanic and the bonuses — from start to finish. Get in touch to talk about your project.

Devamı için