[C++] Renewal For GM's /set Command

MT2Dev

Cplusplus
Premium Üye
Üye
Mesaj
136
Çözümler
9
Beğeni
207
Puan
744
Ticaret Puanı
0
GİRİŞ & PROBLEM

Merhaba, bugün GM komutlarının en sık kullanılanlarından birini, /set komutunu komple yenileyeceğiz. Hiçbir kontrol ve bilgilendirme içermeyen bu komuta gerekli tüm kontrolleri ekleyip, cinsiyet, karakter ve skill group değişimlerini aktif edip, kullanıcıların büyü hızını ayarlayabileceğiniz yeni bir field ekleyeceğiz.

NEDEN ?

Bunu nasıl olsa GM ekibi kullanacak, gerek yok diye düşünebilirsiniz ama oyun içindeki her yetkilinin oyun fonksiyonlarına hakim olma zorunluluğu yok, dolayısıyla amacımız işlerini mümkün olduğunca kolaylaştırmak ve yanlış bir şeyi tetikleme ihtimallerini ortadan kaldırmak.

ÇÖZÜM

Öncelikle "cmd_gm.cpp" dosyası açılır.

C++:
// UYARI! ; Kodlar "Extended Max Yang" sistemine uyumludur, align bölümünde hard-coded bir kısım mevcut (maalesef) bu yüzden eğer 20.000 üstüne çıkan yeni bir alignment sistemi kullanıyorsanız lütfen o kısmı kendinize göre düzenleyin!



// BULUNUR;

#define MISC    0
#define BINARY  1
#define NUMBER  2

// BU DEFINE KODLARI KOMPLE SILINIR!




// BULUNUR;

const struct set_struct
{
    const char* cmd;
    const char type;
} set_fields[] =
{
    { "gold",        NUMBER    },
    { "race",        BINARY    },
    { "sex",        BINARY    },
    { "exp",        NUMBER    },
    { "max_hp",        NUMBER    },
    { "max_sp",        NUMBER    },
    { "skill",        NUMBER    },
    { "alignment",    NUMBER    },
    { "align",        NUMBER    },
    { "\n",        MISC    }
};




// KOMPLE DEGISTIRILIR;

const struct set_struct
{
    const char* cmd;
    const char type;
}

set_fields[] =
{
    { "gold",        1},
    { "race",        1},
    { "sex",        1},
    { "exp",        1},
    { "max_hp",        1},
    { "max_sp",        1},
    { "skill",        1},
    { "castspeed",    1},
    { "align",        1},
    { "job",        1}, // DevFix 52
    { "\n",            0}
};




// BULUNUR;

ACMD (do_set)




// KOMPLE DEGISTIRILIR;

ACMD (do_set) // DevFix 123 (Full Renewal - MT2Dev)
{
    char arg1[256], arg2[256], arg3[256];
    LPCHARACTER tch = NULL;
    int i, len;
    const char* line;
    line = two_arguments (argument, arg1, sizeof (arg1), arg2, sizeof (arg2));
    one_argument (line, arg3, sizeof (arg3));
    if (!*arg1 || !*arg2 || !*arg3)
    {
        ch->ChatPacket (CHAT_TYPE_INFO, "Usage:  /set <player name> <field> <value>"); // Now it's correct.. - [MT2Dev Note] - 14/04/2024
        ch->ChatPacket (CHAT_TYPE_INFO, "Fields: <gold> <race> <sex> <exp> <max_hp>"); // And some extra info about fields. - [MT2Dev Note] - 22/04/2024
        ch->ChatPacket (CHAT_TYPE_INFO, "        <max_sp> <skill> <castspeed> <align> <job>");
        return;
    }

    tch = CHARACTER_MANAGER::instance().FindPC (arg1);
    if (!tch)
    {
        ch->ChatPacket (CHAT_TYPE_INFO, "<GM> %s not exist!", arg1);
        return;
    }

    len = strlen (arg2);
    for (i = 0; * (set_fields[i].cmd) != '\n'; i++)
    {
        if (!strncmp (arg2, set_fields[i].cmd, len))
        {
            break;
        }
    }

    switch (i)
    {
        case 0:   // Gold
        {
            long long int gold = 0;
            str_to_number (gold, arg3);
            gold = MINMAX (-GOLD_MAX, gold, GOLD_MAX);
            DBManager::instance().SendMoneyLog (MONEY_LOG_MISC, 3, gold);
            tch->PointChange (POINT_GOLD, gold, true);
            long long int after_gold = tch->GetGold();
            if (after_gold < 0)
            {
                tch->PointChange (POINT_GOLD, -after_gold, true);
                after_gold = 0;
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're yang has been change with minimum value!");
            }
            else if (after_gold > GOLD_MAX)
            {
                long long int difference = after_gold - GOLD_MAX;
                tch->PointChange (POINT_GOLD, -difference, true);
                after_gold = GOLD_MAX;
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're yang has been change with maximum value!");
            }
            else
            {
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're yang has been change successfully!");
            }
        } // Also useless log removed by me. - [MT2Dev Note] - 19/04/2024
        break;

        case 1:   // Race
        {
            // DevFix 52
            unsigned char amount = 0;  // DevFix 122
            str_to_number (amount, arg3);
            amount = MINMAX (0, amount, JOB_MAX_NUM);
            ESex mySex = GET_SEX (tch);
            DWORD dwRace;

            switch (amount)
            {
                case JOB_WARRIOR:
                    dwRace = (mySex == SEX_MALE) ? MAIN_RACE_WARRIOR_M : MAIN_RACE_WARRIOR_W;
                    break;

                case JOB_ASSASSIN:
                    dwRace = (mySex == SEX_MALE) ? MAIN_RACE_ASSASSIN_M : MAIN_RACE_ASSASSIN_W;
                    break;

                case JOB_SURA:
                    dwRace = (mySex == SEX_MALE) ? MAIN_RACE_SURA_M : MAIN_RACE_SURA_W;
                    break;

                case JOB_SHAMAN:
                    dwRace = (mySex == SEX_MALE) ? MAIN_RACE_SHAMAN_M : MAIN_RACE_SHAMAN_W;
                    break;
            }

            if (dwRace != tch->GetRaceNum())
            {
                tch->SetRace (dwRace);
                tch->ClearSkill();
                tch->SetSkillGroup (0);
                tch->SetPolymorph (101);
                tch->SetPolymorph (0);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're race has been change successfully!");
            }
        }
        break;

        case 2:   // Sex
        {
            // DevFix 52
            unsigned char amount = 0;  // DevFix 122
            str_to_number (amount, arg3);
            amount = MINMAX (SEX_MALE, amount, SEX_FEMALE);
            if (amount != GET_SEX (tch))
            {
                tch->ChangeSex();
                tch->SetPolymorph (101);
                tch->SetPolymorph (0);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're sex has been change successfully!");
            }
        }
        break;

        case 3:   // Exp
        {
            int amount = 0;
            str_to_number (amount, arg3);
            amount = MINMAX (-2050000000, amount, 2050000000); // It's hard-coded(i hate it for sure but we don't need to worry about this for now {because of the int limitations and 1-99 limit}) from exp_table_common.. - [MT2Dev Note] - 21/04/2024
            int before_exp = tch->GetExp();
            if (before_exp + amount >= 0)
            {
                tch->PointChange (POINT_EXP, amount, true);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're EXP has been change successfully!");
            }
            else
            {
                ch->ChatPacket (CHAT_TYPE_INFO, "<GM Control> Players minimum EXP cannot be under 0!");
            }
        }
        break;

        case 4:   // Max HP
        {
            int amount = 0;
            str_to_number (amount, arg3);
            amount = MINMAX (-10000000, amount, 10000000); // 10M is enough for the Max HP i guess, so it's hard-coded(and i hate it x2 -_-) .. - [MT2Dev Note] - 21/04/2024
            int before_hp = tch->GetMaxHP();
            if (before_hp + amount >= 1000)
            {
                tch->PointChange (POINT_MAX_HP, amount, true);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're Max HP has been change successfully!");
            }
            else
            {
                ch->ChatPacket (CHAT_TYPE_INFO, "<GM Control> Players Max HP cannot be under 1000!");
            }
        }
        break;

        case 5:   // Max SP
        {
            int amount = 0;
            str_to_number (amount, arg3);
            amount = MINMAX (-10000000, amount, 10000000); // 10M is enough for the Max SP i guess, so it's hard-coded(and i hate it x3 -_-) .. - [MT2Dev Note] - 21/04/2024
            int before_sp = tch->GetMaxSP();
            if (before_sp + amount >= 600)
            {
                tch->PointChange (POINT_MAX_SP, amount, true);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're Max SP has been change successfully!");
            }
            else
            {
                ch->ChatPacket (CHAT_TYPE_INFO, "<GM Control> Players Max SP cannot be under 600!");
            }
        }
        break;

        case 6:   // Active Skill Point
        {
            short int amount = 0;  // DevFix 122
            str_to_number (amount, arg3);
            amount = MINMAX (-180, amount, 180); // For possible 9 Skill (Yohara Extension) system, it's hard-coded with 180(and i hate it x4 -_-) .. - [MT2Dev Note] - 21/04/2024
            short int before_skillpoint = tch->GetPoint (POINT_SKILL);
            if (before_skillpoint + amount >= 0)
            {
                tch->PointChange (POINT_SKILL, amount, true);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're Skill Points has been change successfully!");
            }
            else
            {
                ch->ChatPacket (CHAT_TYPE_INFO, "<GM Control> Players skill points cannot be under 0!");
            }
        }
        break;

        case 7:   // Casting Speed
        {
            short int amount = 0;
            str_to_number (amount, arg3);
            amount = MINMAX (-30000, amount, 30000); // It's also hard-coded but this one not give us any trouble in the future.. - [MT2Dev Note] - 22/04/2024
            short int before_castspeed = tch->GetPoint (POINT_CASTING_SPEED);
            if (before_castspeed + amount >= 0)
            {
                tch->PointChange (POINT_CASTING_SPEED, amount, true);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're Casting Speed has been change successfully!");
            }
            else
            {
                ch->ChatPacket (CHAT_TYPE_INFO, "<GM Control> Players Casting Speed cannot be under 0!");
            }
        }
        break;

        case 8:   // Align
        {
            int amount = 0;
            str_to_number (amount, arg3);
            amount = MINMAX (-200000, amount, 200000); // I hate hard-code, did i tell u before ? *_* Change this if you have different system.. - [MT2Dev Note] - 23/04/2024
            tch->UpdateAlignment (amount - ch->GetRealAlignment());
            int after_align = tch->GetRealAlignment();
            if (after_align < -200000)   // If players final align < -20.000 (MAX value for original codes) - [MT2Dev Note] - 21/04/2024
            {
                tch->UpdateAlignment (-200000);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're alignment has been change with minimum value!");
            }
            else if (after_align > 200000)   // If players final align > 20.000 (MAX value for original codes) - [MT2Dev Note] - 21/04/2024
            {
                tch->UpdateAlignment (200000);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're alignment has been change with maximum value!");
            }
            else
            {
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're alignment has been change successfully!");
            }
        }
        break;

        case 9:   // Job
        {
            unsigned char amount = 0;  // DevFix 122
            str_to_number (amount, arg3);
            amount = MINMAX (0, amount, 2);
            if (amount != tch->GetSkillGroup())
            {
                tch->ClearSkill();
                tch->SetSkillGroup (amount);
                tch->ChatPacket (CHAT_TYPE_INFO, "<GM> You're skill group has been change successfully!");
            }
        }
        break;
    }

    if (set_fields[i].type == 1)
    {
        int amount = 0;
        str_to_number (amount, arg3);
        ch->ChatPacket (CHAT_TYPE_INFO, "<GM> %s's %s set to [%d]", tch->GetName(), set_fields[i].cmd, amount);
    }
}
 
Paylaşım için teşekkürler
ufak olsa bir video ilav edersen guzel bir konu olur kral
 
Son düzenleme:
Son günlerde mükemmel paylaşımlar yapılıyor bu da onlardan biri. Eline, emeğine sağlık.
 
Muhteşem, eline sağlık. Oyun komutlarında yenilenmesi gereken epey bir şey var. item purge, item full set gibi
 
Bir sonraki konu da full_set için olabilir, bu ara GM kodlarıyla epey vakit geçiriyorum. :D Rica ederim.
Full_set'e P3NG3R el atmıştı. Ortalamalı silah, taş vs ayarlama var. tek sorunu item_full_set komutunun doğru çalışıp, normal full_set komutunun ortalamalı silahın ortalamasını verememesi.
 
Full_set'e P3NG3R el atmıştı. Ortalamalı silah, taş vs ayarlama var. tek sorunu item_full_set komutunun doğru çalışıp, normal full_set komutunun ortalamalı silahın ortalamasını verememesi.

İnceledim ama yöntem pek mantıklı gelmedi açıkçası, bir de ben el atayım farklı seçenek olsun. :LOL:
 
Geri
Üst