[C++] Npc'den Alınan İtemler Üst Üste Gelsin

  • Konbuyu başlatan Konbuyu başlatan Admin
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 0
  • Görüntüleme Görüntüleme 36

Admin

Metin2Lobby
Yönetici
Founder
Katılım
6 Mayıs 2022
Mesajlar
52,647
Ticaret : 1 / 0 / 0
Merhaba,
Npcden tekli item aldığınızda envantere tek tek gelir. Bu şekilde o itemden varsa üst üste gelecektir.

game src/shop.cpp

Kod:
int CShop::Buy(LPCHARACTER ch, BYTE pos)
içinde

bul;
Kod:
item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));

satırı bu şekilde değiştir.
Kod:
{             WORD bCount = item->GetCount();             if (IS_SET(item->GetFlag(), ITEM_FLAG_STACKABLE))             {                 for (WORD i = 0; i < INVENTORY_MAX_NUM; ++i)                 {                     LPITEM item2 = ch->GetInventoryItem(i);                     if (!item2)                         continue;                     if (item2->GetVnum() == item->GetVnum())                     {                         int j;                         for (j = 0; j < ITEM_SOCKET_MAX_NUM; ++j)                             if (item2->GetSocket(j) != item->GetSocket(j))                                 break;                         if (j != ITEM_SOCKET_MAX_NUM)                             continue;                         WORD bCount2 = MIN(ITEM_MAX_COUNT - item2->GetCount(), bCount);                         bCount -= bCount2;                         item2->SetCount(item2->GetCount() + bCount2);                         if (bCount == 0)                             break;                     }                 }                 item->SetCount(bCount);             }             if (bCount > 0)                 item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));             else                 M2_DESTROY_ITEM(item);         }


verdiğim satırı aradığınızda 2 sonuç çıkar. if'in içindeki pazarlar içindir else'nin içindeki npcler içindir.
k envanter için de ise şu kısımları uyarlamanız gerek;
Kod:
INVENTORY_MAX_NUM ch->GetInventoryItem(i) (ch, TItemPos(INVENTORY, iEmptyPos)

iyi kullanımlar.
[C++] Npc'den Alınan İtemler Üst Üste Gelsin


Metin2 özel sunucularında geliştirme yaparken, oyuncuların NPC'lerden eşya alması sırasında bazı durumlarda aynı itemlerin farklı slotlara düşmesi istenmeyen bir durumdur. Bu durumda itemlerin üst üste binerek stacklenmesi sağlanmalıdır. Bu yazıda, C++ dilinde yazılmış bir game core üzerinde NPC üzerinden alınan itemlerin nasıl üst üste ekleneceğini adım adım inceleyeceğiz.

Neden Itemlerin Üst Üste Binmesi Gerekebilir?
Metin2 gibi MMORPG oyunlarında, özellikle PvP sunucularında kullanıcı deneyimi önemlidir. Oyuncuların envanterlerinde fazla boş slot kalması, oyunun akışını yavaşlatır. Aynı zamanda NPC üzerinden sürekli tekrarlayan görevlerde veya hediyelerde, aynı itemlerin farklı slotlara düşmesi kullanıcıyı yorabilir. Bu nedenle itemlerin otomatik olarak stacklenmesi büyük kolaylık sağlar.

C++ Kaynak Kodlarda Nasıl Uygulanır?
Game server tarafında item yönetimi genellikle C++ ile yapılır. Oyuncuya item verme işlemleri, genellikle char_item.cpp ya da benzeri dosyalarda tanımlıdır. Burada item_add fonksiyonu üzerinden verilen itemler kontrol edilmelidir. Eğer aynı item envanterde varsa, onun miktarını artırmak için merge mantığı eklenmelidir.

UYARI: Bu değişiklikler doğrudan sunucu source code'unda yapıldığı için dikkatli olunmalıdır. Hatalı kodlama, sunucuda crash'e neden olabilir. Öncelikle test sunucusunda denemek önemlidir.

Python Script Tarafında Dağınık Eşya Verme Sistemleri
Bazı Metin2 lobby sistemlerinde, NPC dialogları Python ile yönetilir. Bu durumda uiscript dosyalarında item verme komutları yer alır. Burada da stackleme işlemi yapılabilir. Py Root üzerinden item ID'si kontrol edilip, envanterde mevcutsa miktar artırılır. Bu sayede kullanıcıya aynı item birden fazla verilse bile, hepsi tek slotta toplanır.

Stackleme Fonksiyonunun Açıklaması
Yeni bir fonksiyon olarak MergeItemToSlot oluşturulabilir. Bu fonksiyon, önce envanterde aynı itemin olup olmadığını tarar. Eğer bulursa, miktarı artırır; bulamazsa normal şekilde yeni slot'a yerleştirir. Bu mantık hem NPC hediyeleri hem de görev ödülleri için uygulanabilir.

Örnek Kod Yapısı
Kod:
[B]int[/B] MergeItemToSlot([B]int[/B] playerID, [B]int[/B] itemID, [B]int[/B] count) { [BR][/BR]    [B]int[/B] slot = FindExistingItem(playerID, itemID); [BR][/BR]    [B]if[/B] (slot != -1) { [BR][/BR]        IncreaseItemCount(playerID, slot, count); [BR][/BR]        [B]return[/B] slot; [BR][/BR]    } [BR][/BR]    [B]else[/B] { [BR][/BR]        [B]return[/B] AddNewItemToSlot(playerID, itemID, count); [BR][/BR]    }[BR][/BR]}

Auth ve DB Entegrasyonu
Oyun sunucusu ile DB bağlantısı kurulduğunda, item stackleme işlemleri daha güvenli hale getirilebilir. Database seviyesinde de kontrol yapılarak, item verme işlemlerinde herhangi bir veri kaybı yaşanmaz.

Sonuç
Metin2 özel sunucularında NPC üzerinden alınan itemlerin üst üste binmesi, kullanıcı deneyimini ciddi anlamda artırır. C++ tabanlı core sistemlerde küçük değişikliklerle bu özellik kolayca entegre edilebilir. Python tarafında da uiscript ile desteklenen sistemlerde benzer mantık uygulanabilir. Metin2Lobby.com olarak bu gibi gelişmiş sistemler hakkında daha fazla kaynak sunmaya devam ediyoruz.


[C++] Items Received from NPC Should Stack


In Metin2 private servers, while developing, sometimes players receiving items from NPCs cause unwanted behavior where identical items fall into different slots. In such cases, it is better to stack these items automatically. This article will guide you step by step on how to implement stacking of items obtained through NPCs using C++ within a game core.

Why Should Items Stack?
In MMORPG games like Metin2, especially on PvP servers, user experience is crucial. Having too many empty inventory slots can slow down gameplay. Additionally, repetitive quests or rewards from NPCs may cause identical items to occupy multiple slots, which can frustrate players. Therefore, automatically stacking items enhances usability significantly.

How to Implement in C++ Source Code?
Item management in the game server is typically handled with C++. The functions responsible for giving items to players are usually defined in files like char_item.cpp. Here, the item_add function should be modified so that if the same item already exists in the inventory, its quantity is increased rather than adding a new instance in another slot.

WARNING: These modifications are made directly in the server source code, so caution is required. Incorrect coding might cause server crashes. It's recommended to test on a separate server first.

Python Scripts for Scattered Item Systems
In some Metin2 lobby systems, NPC dialogs are managed via Python. In such cases, item distribution commands are located in uiscript files. Stacking logic can also be applied here. By checking the item ID through Py Root, if the item already exists in the inventory, the quantity is increased. Thus, even if the same item is given multiple times, all instances will be grouped into one slot.

Explanation of the Stacking Function
A new function called MergeItemToSlot can be created. It first searches the inventory for an existing item. If found, it increases the quantity; otherwise, it places the new item into an available slot. This logic can be applied to both NPC gifts and quest rewards.

Sample Code Structure
Kod:
[B]int[/B] MergeItemToSlot([B]int[/B] playerID, [B]int[/B] itemID, [B]int[/B] count) { [BR][/BR]    [B]int[/B] slot = FindExistingItem(playerID, itemID); [BR][/BR]    [B]if[/B] (slot != -1) { [BR][/BR]        IncreaseItemCount(playerID, slot, count); [BR][/BR]        [B]return[/B] slot; [BR][/BR]    } [BR][/BR]    [B]else[/B] { [BR][/BR]        [B]return[/B] AddNewItemToSlot(playerID, itemID, count); [BR][/BR]    }[BR][/BR]}

Integration with Auth and DB
When connected to the database, item stacking processes can become more secure. By performing checks at the database level, no data loss occurs during item distribution operations.

Conclusion
Stacking items received from NPCs in Metin2 private servers significantly improves user experience. With small modifications in C++-based core systems, this feature can be easily integrated. Similar logic can also be implemented in Python-based uiscript systems. At Metin2Lobby.com, we continue to provide resources on such advanced systems.
 

Şuan Bu Konuyu Görüntüleyen Kullanıcılar (Toplam : 0, Üye : 0, Misafir : 0)

Benzer konular

Geri
Üst Alt