Questler için zaman fonksiyonu

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

Admin

Metin2Lobby
Yönetici
Founder
Katılım
6 Mayıs 2022
Mesajlar
52,647
Ticaret : 1 / 0 / 0
Questlerde kullanabileceğiniz o anı alan yada aradaki farkı alan zaman fonksiyonları




  • <li data-xf-list-type="ul">

    [*]get_current_time_ms()



- Milisaniye cinsinden zaman oluşturur
- local zaman1 = get_current_time_ms()



  • <li data-xf-list-type="ul">

    [*]get_current_time_s()



- Saniye cinsinden zaman oluşturur
- local zaman1 = get_current_time_s()



  • <li data-xf-list-type="ul">

    [*]check_time(time1, time2)



- 2 zaman arasındaki farkı verir
- local zaman1 = get_current_time_ms()
- ... fonksiyonlar ...
- local zaman2 = get_current_time_ms()
- local gecen_zaman = check_time(zaman1, zaman2)

*questlua_global.cpp
Arat:
Kod:
[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]int _left_image(lua_State* L)[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]{[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]if (lua_isstring(L, -1))[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]{[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]string s = lua_tostring(L,-1);[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]CQuestManager::Instance().AddScript("[LEFTIMAGE src;"+s+"]");[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]}[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]return 0;[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]}[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]

Altına ekle:
Kod:
[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]int _get_current_time_ms(lua_State* L)[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]{[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]lua_pushnumber(L, (int)get_dword_time());[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]return 1;[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]}[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]int _get_current_time_s(lua_State* L)[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]{[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]int result = (get_dword_time() / 1000) + 0.5;[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]lua_pushnumber(L, (int)result);[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]return 1;[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]}[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]int _check_time(lua_State* L)[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]{[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2))[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]lua_pushnumber(L, 0);[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]int timex = lua_tonumber(L, 1);[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]int timey = lua_tonumber(L, 2);[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]int result = MIN(0, (timey - timex));[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]lua_pushnumber(L, (int)result);[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]return 1;[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]}[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]



Arat:
Kod:
[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]{ "number", _number },[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]

Altına ekle:
Kod:
[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]{ "get_current_time_ms", _get_current_time_ms },[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]{ "get_current_time_s", _get_current_time_s },[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]{ "check_time", _check_time },[/FONT][/COLOR] [COLOR=#BB0000][FONT=Verdana]

Questler için Zaman Fonksiyonu

Metin2 özel sunucularında quest sistemlerinde zaman kontrolü yapmak oldukça önemlidir. Bu özellikle PvP odaklı sunucularda zamanla değişen olaylar, aktivasyonlar veya özel görevler için kullanılır. Questlerde zaman fonksiyonları sayesinde belirli saat aralıklarında, belirli günlerde ya da belirli bir sürenin ardından tetiklenecek eylemleri tanımlayabiliriz.

Zaman Fonksiyonlarının Kullanımı

Metin2 quest sistemlerinde zamanla ilgili bazı özel fonksiyonlar mevcuttur. Bunlar arasında en çok kullanılanlardan bazıları şunlardır:

- get_time(): Sistem saatinin mevcut değerini döndürür. Genellikle Unix timestamp olarak alınır.
- get_locale_time(): Yerel saati döndürür. Formatlı bir şekilde gün, ay, yıl, saat gibi bilgileri almak mümkündür.
- pc.can_wear_item(item_vnum) gibi fonksiyonlarla birlikte zaman kontrolü yapılarak item kullanım süresi sınırlamaları da yapılabilir.

Örnek Kullanım:

Kod:
[BR][/BR]when login with pc.is_gm() begin[BR][/BR]    local current_time = get_time()[BR][/BR]    local formatted_time = get_locale_time()[BR][/BR][BR][/BR]    say('Mevcut zaman: ' .. current_time)[BR][/BR]    say('Yerel zaman: ' .. formatted_time[1] .. '/' .. formatted_time[2] .. '/' .. formatted_time[3])[BR][/BR]end[BR][/BR]


Zaman Tabanlı Etkinlikler

Questlerde zaman tabanlı etkinlikler planlamak istiyorsanız, örneğin haftanın belirli günlerinde aktif olan bir olay sistemi kurmak istiyorsanız aşağıdaki gibi bir yapı kullanabilirsiniz:

Kod:
[BR][/BR]when 0000.start_game with pc.get_job() == 0 begin[BR][/BR]    local day = get_locale_time()[1] -- Gün[BR][/BR]    if day == 1 then -- Pazartesi[BR][/BR]        notice_all('Bugün özel PvP etkinliği var!')[BR][/BR]    end[BR][/BR]end[BR][/BR]


Gelişmiş Zaman Kontrolleri

Bazı questlerde belirli bir zaman diliminde çalışması gereken komutlar vardır. Örneğin, gece saat 20:00 ile sabah 06:00 arasında özel bir NPC etkinleşebilir. Bu gibi durumlarda şu yapı kullanılabilir:

Kod:
[BR][/BR]local hour = get_locale_time()[4] -- Saat[BR][/BR][BR][/BR]if hour >= 20 or hour < 6 then[BR][/BR]    say('NPC bu saatlerde aktif.') -- Gece boyu aktif[BR][/BR]else[BR][/BR]    say('NPC şu anda pasif.') -- Gündüz kapalı[BR][/BR]end[BR][/BR]


Teknik Açıklamalar

Zaman fonksiyonları quest sisteminin temel bileşenlerinden biridir. Özellikle büyük PvP sunucularında, turnuvaların, özel savaşların ya da bonus zamanlarının kontrolü için kritik öneme sahiptir. Doğru kullanıldığında kullanıcı deneyimini ciddi anlamda artırabilir.

Ayrıca zaman kontrolleri ile otomatik görev tamamlama, ödül verme, item sınırlama gibi işlemler de kolayca sağlanabilir. Bu sayede hem sunucu yönetimi daha verimli hale gelir hem de oyuncular için daha keyifli bir oyun ortamı oluşturulur.

Metin2 özel sunucularında quest geliştirme konusunda daha fazla bilgi almak için Metin2Lobby sitemizi takip edin.


Time Function for Quests in Metin2

In Metin2 private servers, controlling time within quests is highly important. This is especially useful in PvP-oriented servers where timed events, activations, or special tasks change over time. With time functions in quests, we can define actions that trigger at specific hours, on certain days, or after a given duration.

Using Time Functions

There are several built-in time-related functions available in Metin2 quest systems. Some of the most commonly used ones are:

- get_time(): Returns the current system time, usually in Unix timestamp format.
- get_locale_time(): Returns local time in a formatted way, including day, month, year, and hour values.
- Functions like pc.can_wear_item(item_vnum) can be combined with time checks to set temporary item usage limits.

Example Usage:

Kod:
[BR][/BR]when login with pc.is_gm() begin[BR][/BR]    local current_time = get_time()[BR][/BR]    local formatted_time = get_locale_time()[BR][/BR][BR][/BR]    say('Current time: ' .. current_time)[BR][/BR]    say('Local time: ' .. formatted_time[1] .. '/' .. formatted_time[2] .. '/' .. formatted_time[3])[BR][/BR]end[BR][/BR]


Time-Based Events

If you want to schedule time-based events in your quests, such as weekly activities active only on certain days, you can use structures like this:

Kod:
[BR][/BR]when 0000.start_game with pc.get_job() == 0 begin[BR][/BR]    local day = get_locale_time()[1] -- Day[BR][/BR]    if day == 1 then -- Monday[BR][/BR]        notice_all('Special PvP event today!')[BR][/BR]    end[BR][/BR]end[BR][/BR]


Advanced Time Checks

Some quests require commands to run only during specific time intervals. For example, an NPC might become active between 20:00 in the evening and 06:00 in the morning. In such cases, the following structure can be used:

Kod:
[BR][/BR]local hour = get_locale_time()[4] -- Hour[BR][/BR][BR][/BR]if hour >= 20 or hour < 6 then[BR][/BR]    say('NPC is active during these hours.') -- Active all night[BR][/BR]else[BR][/BR]    say('NPC is currently inactive.') -- Inactive during the day[BR][/BR]end[BR][/BR]


Technical Notes

Time functions are one of the core components of the quest system. Especially on large PvP servers, they are critical for managing tournaments, special battles, or bonus times. When used correctly, they significantly enhance user experience.

Moreover, time checks allow for automatic quest completion, reward distribution, and item limitations. This improves server management efficiency and creates a more enjoyable gameplay environment for players.

For more information about quest development in Metin2 private servers, visit Metin2Lobby.
 

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

Benzer konular

Geri
Üst Alt