[C++][Lua] A function that assumes items and a start game

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

Admin

Metin2Lobby
Yönetici
Founder
Katılım
6 Mayıs 2022
Mesajlar
52,647
Ticaret : 1 / 0 / 0
Receive items the first time you log in to the server.
Contains the lua function in C ++ and the quest.
This function allows you to receive the item and put it on. If you want to use it elsewhere, remember to check if the user has the equipment on.



Settings
Kod:
local item = {   ['all'] = {  -- Items for everyone     {ITEM_ID, COUNT}, -- count OR "EQ" If I give EQ, the item will be put on the character   },   [1] = {       -- Warrior     {ITEM_ID, ITEM_ID},   -- Put on     {ITEM_ID, ITEM_ID}    -- Equipment   },   [2] = {       -- Ninja     {ITEM_ID, ITEM_ID},   -- Put on     {ITEM_ID, ITEM_ID}    -- Equipment   },   [3] = {       -- Sura     {ITEM_ID, ITEM_ID},   -- Put on     {ITEM_ID, ITEM_ID}    -- Equipment   },   [4] = {       -- Shaman     {ITEM_ID, ITEM_ID},   -- Put on     {ITEM_ID, ITEM_ID}    -- Equipment   } }

Also you can add
Kod:
ds.give_qualification()     -- Alchemy horse.set_level(1)          -- Horse level pc.set_skill_level(122, 2)  -- Gives 2 combos pc.set_skill_level(131, 10) -- Summon a horse horse.ride()

Notification
Kod:
chat("Have a nice game!")

Do you need a quest, system or www? Write to me, I can create everything. (Full STACK, Web (PHP, JS, SQL, HTML, CSS), Server (C ++, Python, Lua))
Discord Alerin#5559
[C++] ve [Lua] ile Oyun Başlatan ve Eşyaları Kontrol Eden Bir Fonksiyon

Metin2 Quest sistemleri, sunucu tarafında oyun akışını yönlendiren en temel yapılardandır. Bu sistemler sayesinde oyunculara görevler verilebilir, ödüller dağıtabilir ve belirli eylemlere göre oyun içi tepkiler alınabilir. Özellikle Lua dilinde yazılmış quest dosyaları, Metin2 sunucularında yüksek esneklik sağlar. Bu makalede, C++ ve Lua arasında entegre çalışan, eşya kontrolü yapan ve oyun başlatma işlemini gerçekleştiren bir fonksiyonu inceleyeceğiz.

Temel Lua Quest Yapısı
Metin2'de bir quest dosyası genellikle Lua diliyle yazılmaktadır. Questler, belirli tetikleyicilere göre çalışır. Örneğin, bir NPC ile konuşulduğunda, belirli bir eşya kullanıldığında veya belirli bir konuma gidildiğinde bir quest aktif olabilir. Questlerin temel yapı taşları şunlardır:

- Quest Başlangıcı: quest quest_adı begin
- State Yapısı: state statü_adı begin
- Trigger Kullanımı: when tetikleyici begin

C++ ile Lua Fonksiyonlarını Entegre Etme
C++ kodları, Lua yorumlayıcısına bağlanarak Lua fonksiyonlarını çağırabilir. Bu sayede sunucu tarafında daha gelişmiş kontroller yapılabilir. Örneğin, oyuncunun envanterinde belirli bir eşyanın olup olmadığını kontrol eden bir Lua fonksiyonu yazabiliriz. Ardından C++ tarafında bu fonksiyonu çağırarak, oyun başlatma işlemi için gerekli koşulları sağlayabiliriz.

Örnek Lua Fonksiyonu:
Kod:
[B]function check_items_and_start_game(player_name)[/B][BR][/BR][B]local player = GetPlayerByName(player_name)[/B][BR][/BR][B]if not player then return false end[/B][BR][/BR][B]local required_item_vnum = 71007 -- Örnek Item VNUM[/B][BR][/BR][B]if pc.count_item(required_item_vnum) >= 1 then[/B][BR][/BR][B]pc.remove_item(required_item_vnum, 1) -- Eşyayı sil[/B][BR][/BR][B]game.start_new_game() -- Oyunu başlat[/B][BR][/BR][B]return true[/B][BR][/BR][B]else[/B][BR][/BR][B]syschat('Gerekli eşya envanterinizde yok.')[/B][BR][/BR][B]return false[/B][BR][/BR][B]end[/B][BR][/BR][B]end[/B]


C++ Tarafında Fonksiyon Çağrısı
Aşağıdaki örnek, C++ koduyla Lua yorumlayıcısı üzerinden Lua fonksiyonunu çağırmaktadır:

Kod:
[B]lua_getglobal(lua_state, 'check_items_and_start_game');[/B][BR][/BR][B]lua_pushstring(lua_state, player_name.c_str());[/B][BR][/BR][B]lua_pcall(lua_state, 1, 1, 0);[/B][BR][/BR][B]bool success = lua_toboolean(lua_state, -1);[/B]


Quest Trigger Kullanımı
Bu fonksiyonu bir quest tetikleyicisi ile bağlamak da mümkündür. Örneğin, bir NPC'nin sağ tıklandığında bu fonksiyonun çalışması sağlanabilir:

Kod:
[B]when 20004.click with pc.getqf('game_started') == 0 begin[/B][BR][/BR][B]local result = check_items_and_start_game(pc.get_name())[/B][BR][/BR][B]if result then[/B][BR][/BR][B]pc.setqf('game_started', 1)[/B][BR][/BR][B]end[/B][BR][/BR][B]end[/B]


Hata Ayıklama ve Debugging
Quest sistemlerinde karşılaşılan hatalar genellikle Lua tarafında oluşur. Hata ayıklama için syschat komutu kullanılabilir. Ayrıca quest logları izlenerek hatalar tespit edilebilir. Özellikle item VNUM hataları, eksik eşya kontrolleri veya geçersiz fonksiyon çağrıları sık karşılaşılan sorunlardır.

Sonuç
C++ ve Lua arasındaki entegrasyon sayesinde Metin2 sunucularında güçlü quest sistemleri geliştirilebilir. Eşya kontrolleri, oyun başlatma işlemleri gibi işlemler Lua fonksiyonları ile kolayca yapılabilir. Bu yapı sayesinde hem performans hem de esneklik sağlanır. Quest geliştirme sürecinde dikkat edilmesi gereken en önemli konulardan biri doğru tetikleyici kullanımı ve hata yönetimidir.


A Function That Uses C++ and Lua to Assume Items and Start a Game

Metin2 quest systems are among the most fundamental structures that direct in-game flow on the server side. These systems allow quests to be given to players, rewards distributed, and in-game responses triggered based on specific actions. Especially quests written in Lua provide high flexibility for Metin2 servers. In this article, we will examine a function that operates through integrated C++ and Lua code, controls items, and handles starting a game.

Basic Lua Quest Structure
In Metin2, a quest file is generally written in Lua. Quests run based on specific triggers. For instance, a quest can activate when talking to an NPC, using a certain item, or reaching a specific location. Basic components of quests include:

- Quest Begin: quest quest_name begin
- State Structure: state state_name begin
- Trigger Usage: when trigger begin

Integrating Lua Functions with C++
C++ code can connect to the Lua interpreter and call Lua functions. This allows more advanced controls on the server side. For example, you can write a Lua function to check whether a specific item exists in the player's inventory. Then, from the C++ side, you can call this function to meet conditions necessary for starting the game.

Sample Lua Function:
Kod:
[B]function check_items_and_start_game(player_name)[/B][BR][/BR][B]local player = GetPlayerByName(player_name)[/B][BR][/BR][B]if not player then return false end[/B][BR][/BR][B]local required_item_vnum = 71007 -- Example Item VNUM[/B][BR][/BR][B]if pc.count_item(required_item_vnum) >= 1 then[/B][BR][/BR][B]pc.remove_item(required_item_vnum, 1) -- Remove item[/B][BR][/BR][B]game.start_new_game() -- Start game[/B][BR][/BR][B]return true[/B][BR][/BR][B]else[/B][BR][/BR][B]syschat('Required item is not in your inventory.')[/B][BR][/BR][B]return false[/B][BR][/BR][B]end[/B][BR][/BR][B]end[/B]


Calling the Function in C++
The following example demonstrates calling the Lua function from C++ via the Lua interpreter:

Kod:
[B]lua_getglobal(lua_state, 'check_items_and_start_game');[/B][BR][/BR][B]lua_pushstring(lua_state, player_name.c_str());[/B][BR][/BR][B]lua_pcall(lua_state, 1, 1, 0);[/B][BR][/BR][B]bool success = lua_toboolean(lua_state, -1);[/B]


Using Quest Triggers
You can also bind this function to a quest trigger. For example, clicking an NPC can trigger this function:

Kod:
[B]when 20004.click with pc.getqf('game_started') == 0 begin[/B][BR][/BR][B]local result = check_items_and_start_game(pc.get_name())[/B][BR][/BR][B]if result then[/B][BR][/BR][B]pc.setqf('game_started', 1)[/B][BR][/BR][B]end[/B][BR][/BR][B]end[/B]


Debugging and Error Handling
Errors in quest systems often occur on the Lua side. You can use the syschat command for debugging. Additionally, reviewing quest logs can help detect errors. Common issues include incorrect item VNUMs, missing item checks, or invalid function calls.

Conclusion
Integration between C++ and Lua allows powerful quest systems to be developed on Metin2 servers. Actions like item checks and game startup procedures can be easily handled with Lua functions. This structure provides both performance and flexibility. One of the most important considerations during quest development is proper trigger usage and error management.
 

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

Benzer konular

Geri
Üst Alt