.script from object to .quest - Python3

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

Admin

Metin2Lobby
Yönetici
Founder
Katılım
6 Mayıs 2022
Mesajlar
52,647
Ticaret : 1 / 0 / 0
Video:


Code:
Kod:
# Script by Grzyb.ovh def convert_to_quest(input_text, quest_name, state_name, npc_id, chat_option):     quest_code = f"quest {quest_name} begin\n\tstate {state_name} begin\n\t\twhen {npc_id}.chat.\"{chat_option}\" begin\n"     lines = input_text.split('\n')     indentation_level = 0     for line in lines:         stripped_line = line.strip()         if stripped_line.startswith("end"):             indentation_level -= 1         stripped_line = stripped_line.replace(" (", "(").replace(" )", ")")         stripped_line = stripped_line.replace(" . ", ".")         stripped_line = stripped_line.replace(' "', '"')         indent = '\t' * (3 + indentation_level)         quest_code += f"{indent}{stripped_line}\n"         if stripped_line.startswith(("if", "while", "for")) and "end" not in stripped_line:             indentation_level += 1     quest_code += "\t\tend\n\tend\nend"     return quest_code def process_script_file(script_file_name, quest_name, state_name, npc_id, chat_option):     with open(script_file_name, 'r', encoding='latin1') as f:         input_text = f.read()     quest_code = convert_to_quest(input_text, quest_name, state_name, npc_id, chat_option)     quest_file_name = script_file_name.replace('.script', '.quest')     with open(quest_file_name, 'w', encoding='latin1') as f:         f.write(quest_code) process_script_file('marriage_manage.start.0.script', 'weeding', 'start', 20358, 'Oldwoman')

.script from object to .quest - Python3 Dönüştürme Rehberi

Metin2 Lobby olarak sunucu geliştirme konusunda aktif olan geliştiriciler için önemli bir konu olan [.script](object) dosyalarının [.quest](Python3) formatına dönüştürülmesi süreci oldukça kritiktir. Bu makalede, [.script](object) formatındaki eski nesil görev sistemlerini [.quest](Python3) tabanlı modern sistemlere nasıl dönüştüreceğinizi adım adım anlatacağız. Bu dönüşüm, özellikle Metin2 private server geliştiricileri için hem performans hem de okunabilirlik açısından büyük avantajlar sağlar.

Neden .quest Formatına Geçilmeli?

Metin2'nin eski sistemlerinde [.script](object) dosyaları görev sistemlerini yönetmek için kullanılırdı. Ancak bu sistemler oldukça statik ve sınırlıydı. Modern sunucularda [.quest](Python3) formatı kullanılmaktadır çünkü:

- Daha esnek yapıya sahiptir.
- Python3 diline dayalıdır ve daha gelişmiş programlama imkanları sunar.
- Hata ayıklama ve bakım kolaylığı sağlar.
- OOP (Object Oriented Programming) destekler.

UYARI: [.script](object) formatında yazılmış görevler doğrudan [.quest](Python3) formatına otomatik olarak dönüştürülemez. Kodların yeniden yazılması gerekir.

.script Dosyası Nedir?[/BR]

[.script](object) dosyaları, Metin2 sunucularında görevlerin tanımlandığı eski yapıdır. Genellikle [.lua](script) tabanlıdır ve [.quest](Python3) kadar esnek değildir. Örnek bir [.script](object) yapısı şu şekildedir:

quest example begin
state start begin
when login begin
say('Hoş geldiniz!')
end
end
end

.quest (Python3) Formatına Dönüşüm[/BR]

[.quest](Python3) formatı, Python dilinin avantajlarını kullanarak daha güçlü ve okunabilir görev sistemleri yazmanıza olanak tanır. Bu sistemde görevler Python sınıfları olarak tanımlanır. Örneğin:

class example_quest(quest):
def __init__(self):
quest.__init__(self)

def on_login(self, player):
chat('Hoş geldiniz!')

Python GUI ve Uiscript Entegrasyonu[/BR]

[.quest](Python3) sistemlerinde kullanıcı arayüzü işlemleri için py gui[/BR] veya uiscript[/BR] gibi modüller kullanılabilir. Bu sayede [.quest](Python3) içinde doğrudan arayüz öğeleri tanımlanabilir. Bu özellik, [.script](object) sistemlerinde mevcut değildir.

Geliştirme Ortamı Hazırlığı[/BR]

[.quest](Python3) tabanlı sistemlerde çalışabilmek için geliştirici ortamınızda şunlar bulunmalıdır:

- Python3 yüklü olmalı.
- Metin2 server src[/BR] dosyaları [.quest](Python3) desteği içermeli.
- py root[/BR] ve pack[/BR] dosyaları doğru yapılandırılmış olmalı.

Kod Dönüştürme Adımları[/BR]

1. [.script](object) dosyasındaki tüm.quest bloklarını belirleyin.
2. Her quest için bir Python sınıfı oluşturun.
3. Gerekli fonksiyonları tanımlayın (örneğin on_click, on_login, on_timer vb.).
4. Eski komutları (.say(), .set_state() vs.) Python3 uyumlu karşılıklarıyla değiştirin.
5. Test edin ve hataları düzeltin.

Hata Ayıklama ve Performans[/BR]

[.quest](Python3) sistemlerinde hata ayıklama işlemleri [.script](object) sistemlerine göre daha kolaydır. Python3 tabanlı olduğu için debug logları daha detaylıdır ve hata takibi kolaydır. Ayrıca [.quest](Python3) formatı sayesinde CPU ve RAM kullanımı daha optimize olur.

Sonuç[/BR]

[.script](object) formatından [.quest](Python3) formatına geçiş, Metin2 geliştiricileri için önemli bir evrim adımıdır. Bu geçiş, hem performans hem de kod kalitesi açısından büyük faydalar sağlar. Metin2 Lobby[/BR] olarak bu konuda aktif olan geliştiriciler için bu rehber yardımcı olacaktır.


.script from object to .quest - Python3 Conversion Guide

Metin2 Lobby As developers active in server development, converting [.script](object) files to [.quest](Python3) based modern systems is critical. In this article, we will explain step by step how to convert old-style quest systems in [.script](object) format to modern [.quest](Python3) based systems. This conversion provides significant advantages in terms of performance and readability for Metin2 private server developers.

Why Should You Switch to .quest Format?[/BR]

In older Metin2 systems, [.script](object) files were used to manage quest systems. However, these systems were quite static and limited. In modern servers, the [.quest](Python3) format is used because:

- It has a more flexible structure.
- Based on Python3 and offers advanced programming capabilities.
- Provides easier debugging and maintenance.
- Supports OOP (Object Oriented Programming).

WARNING: Quests written in [.script](object) format cannot be automatically converted to [.quest](Python3). Codes must be rewritten.

What is a .script File?[/BR]

[.script](object) files are legacy quests defined in Metin2 servers. Usually based on [.lua](script), they are not as flexible as [.quest](Python3). An example [.script](object) structure looks like this:

quest example begin
state start begin
when login begin
say('Welcome!')
end
end
end

Converting to .quest (Python3) Format[/BR]

The [.quest](Python3) format allows you to write more powerful and readable quest systems by leveraging Python's advantages. In this system, quests are defined as Python classes. For example:

class example_quest(quest):
def __init__(self):
quest.__init__(self)

def on_login(self, player):
chat('Welcome!')

Python GUI and Uiscript Integration[/BR]

In [.quest](Python3) systems, modules such as py gui[/BR] or uiscript[/BR] can be used for UI operations. This allows UI elements to be defined directly within [.quest](Python3). This feature does not exist in [.script](object) systems.

Development Environment Setup[/BR]

To work with [.quest](Python3) based systems, your development environment must have:

- Python3 installed.
- Metin2 server src[/BR] files should include [.quest](Python3) support.
- py root[/BR] and pack[/BR] files must be properly configured.

Code Conversion Steps[/BR]

1. Identify all .quest blocks in the [.script](object) file.
2. Create a Python class for each quest.
3. Define necessary functions (e.g., on_click, on_login, on_timer etc.).
4. Replace old commands (.say(), .set_state() etc.) with their Python3 equivalents.
5. Test and fix errors.

Debugging and Performance[/BR]

Debugging processes in [.quest](Python3) systems are easier than in [.script](object) systems. Since it is Python3-based, debug logs are more detailed and error tracking is simpler. Additionally, thanks to the [.quest](Python3) format, CPU and RAM usage become more optimized.

Conclusion[/BR]

Switching from [.script](object) to [.quest](Python3) format is an important evolution step for Metin2 developers. This transition provides significant benefits both in terms of performance and code quality. As Metin2 Lobby[/BR], this guide will assist developers active in this area.
 

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

Geri
Üst Alt