Добро пожаловать на Pro Pawn - Портал о PAWN-скриптинге.
Показано с 1 по 1 из 1
  1. #1
    Аватар для Igoreshka
    Пользователь

    Статус
    Оффлайн
    Регистрация
    24.03.2015
    Сообщений
    32
    Репутация:
    0 ±

    class в pawn(инвентарь)

    Решил сделать основное взаимодействия с инвентарем. Много чего написал, и получилось 83 разные функции, там много не нужных сравнений которые можно облегчить. В общем писал чист для своего понимая. Теперь к самой сути.

    Разные типы инвентаря
    • Рюкзак
    • Руки
    • Аксессуары
    • Домашний инвентарь
    • Личного транспорта инвентарь
    • Фракционного транспорта инвентарь
    • Домашнего транспорта инвентарь
    • Отельный инвентарь
    • Бизнес инвентарь
    • Трейлер инвентарь
    • Drop(на земле) предметы
    • Фракционный инвентарь

    Возможности изменения
    • Размера инвентаря для определенного типа
    • Максимальное число предметов для определенного типа

    В общем много чего. Смысл в том, что я хочу сделать подобие классов только с использованием ссылок.
    То есть есть разные перечисления(enum), где хранятся разные типы данных.
    Но, например, есть такие действия для всех типов одинаковые. Перемещение в инвентаре, удаления, добавления. Смысл либо создавать для каждого тип отдельную функцию. Либо создать функцию с использованием ссылки и действиями внутри.
    Большинство функций будут в OnPlayerTextDrawClick, чтобы туда лишь добавить типы переменных как параметры функции.

    Думаю объяснил нормально. Теперь вопрос, как лучше всего сделать подобное действия.


    Пример того, что примерно должно быть. Хотя мне все равно не нравится все это.
    PHP код:
    for(new iMAX_HAND_ITEMi++)
            {
                static const 
    text_int[] = "Hand_ID_%i";
                new 
    string_invsizeof(text_int) + ];
                
    f(string_invtext_inti);
                new 
    invid GetPVarInt(playeridstring_inv);
                if(
    playertextid == INV_hand[invid])
                {
                    switch(
    GetPVarInt(playerid"ShowInv_handorac"))
                    {
                        case 
    1:
                        {
                            switch(
    GetPVarInt(playerid"InvOrHand"))
                            {
                            case 
    0:
                                {
                                    switch(
    Player[playerid][pHand][i])
                                    {
                                    case 
    0:
                                        {
                                            switch(
    GetPVarInt(playerid"Item_Player"))
                                            {
                                                case 
    1PlayerClickMenuInHand(playeridiinvidPlayer[playerid][pInv][GetPVarInt(playerid"SelectSlot_inv")], Player[playerid][pInvAmount][GetPVarInt(playerid"SelectSlot_inv")]);
                                                case 
    2:
                                                {
                                                    new 
    veh_info Player[GetPVarInt(playerid"Id_Car_Inv")][pCarkeyID][GetPVarInt(playerid"Id_Car_Inv_")];
                                                    
    PlayerClickMenuInHand(playeridiinvidVehicleInfo[veh_info][vTrunk][GetPVarInt(playerid"SelectSlot_inv")], VehicleInfo[veh_info][vTrunkAmmount][GetPVarInt(playerid"SelectSlot_inv")]);
                                                }
                                                case 
    3PlayerClickMenuInHand(playeridiinvidHouseInfo[Player[playerid][pPhousekey]][hInv][GetPVarInt(playerid"SelectSlot_inv")], HouseInfo[Player[playerid][pPhousekey]][hInv_k][GetPVarInt(playerid"SelectSlot_inv")]);
                                                case 
    4PlayerClickMenuInHand(playeridiinvidTrailerInfo[Player[playerid][pTrailer]][t_inv][GetPVarInt(playerid"SelectSlot_inv")], TrailerInfo[Player[playerid][pTrailer]][t_inv_ammount][GetPVarInt(playerid"SelectSlot_inv")]);
                                            }
                                        }
                                    default:
                                        {
                                            switch(
    GetPVarInt(playerid"Item_Player"))
                                            {
                                                case 
    1PlayerClickMenuInHandIs(playeridiinvidPlayer[playerid][pInv][GetPVarInt(playerid"SelectSlot_inv")], Player[playerid][pInvAmount][GetPVarInt(playerid"SelectSlot_inv")]);
                                                case 
    2PlayerClickMenuInHandIs(playeridiinvidVehicleInfo[Player[GetPVarInt(playerid"Id_Car_Inv")][pCarkeyID][GetPVarInt(playerid"Id_Car_Inv_")]][vTrunk][GetPVarInt(playerid"SelectSlot_inv")], VehicleInfo[Player[GetPVarInt(playerid"Id_Car_Inv")][pCarkeyID][GetPVarInt(playerid"Id_Car_Inv_")]][vTrunkAmmount][GetPVarInt(playerid"SelectSlot_inv")]);
                                                case 
    3PlayerClickMenuInHandIs(playeridiinvidHouseInfo[Player[playerid][pPhousekey]][hInv][GetPVarInt(playerid"SelectSlot_inv")], HouseInfo[Player[playerid][pPhousekey]][hInv_k][GetPVarInt(playerid"SelectSlot_inv")]);
                                                case 
    4PlayerClickMenuInHandIs(playeridiinvidTrailerInfo[Player[playerid][pTrailer]][t_inv][GetPVarInt(playerid"SelectSlot_inv")], TrailerInfo[Player[playerid][pTrailer]][t_inv_ammount][GetPVarInt(playerid"SelectSlot_inv")]);
                                            }
                                        }
                                    }
                                }
                            default:
                                {
                                    if(
    Player[playerid][pHand][i] == && GetPVarInt(playerid"SelectSlot") == 0) return PlayerPlaySound(playerid312030.00.00.0);
                                    else if(
    == GetPVarInt(playerid"SelectSlot_inv") )
                                    {
                                        
    PlayerTextDrawBoxColor(playeridINV_hand[invid-1], -227);
                                        
    PlayerTextDrawShow(playeridINV_hand[invid-1]);
                                        
    ResetInvPVar(playerid);
                                        
    PlayerPlaySound(playerid312030.00.00.0);
                                        
    HideInformation(playerid);
                                        return 
    1;
                                    }
                                    else 
    PlayerPlaySound(playerid178030.00.00.0);
                                    switch(
    GetPVarInt(playerid"SelectSlot"))
                                    {
                                    case 
    0:
                                        {
                                            
    PlayerTextDrawBoxColor(playeridINV_hand[invid-1], -842150576);
                                            
    PlayerTextDrawShow(playeridINV_hand[invid-1]);
                                            
    SetPVarInt(playerid"SelectSlot"invid);
                                            
    SetPVarInt(playerid"SelectSlot_inv"i);
                                            
    LoadInformation(playeridPlayer[playerid][pHand][i]);
                                            
    SetPVarInt(playerid"InvOrHand"1);
                                        }
                                    default:
                                        {
                                            switch(
    Player[playerid][pHand][i])
                                            {
                                            case 
    0:
                                                {
                                                    new 
    inv_id_last GetPVarInt(playerid"SelectSlot"), inv_id_inv GetPVarInt(playerid"SelectSlot_inv");
                                                    
    Player[playerid][pHand_][i] = Player[playerid][pHand_][inv_id_inv];
                                                    
    Player[playerid][pHandAmount][i] = Player[playerid][pHandAmount][inv_id_inv];
                                                    
    Player[playerid][pHand][i] = Player[playerid][pHand][inv_id_inv];
                                                    new 
    iteams GetPVarInt(playerid"Item_Player");
                                                    
    SetPVarInt(playerid"Item_Player"0);
                                                    
    INV_UPDATE_TEXTDRAW(playeridiinvid);
                                                    
    Player[playerid][pHandAmount][inv_id_inv] = 0;
                                                    
    Player[playerid][pHand][inv_id_inv] = 0;
                                                    
    Player[playerid][pHand_][inv_id_inv] = false;
                                                    
    INV_UPDATE_TEXTDRAW(playeridinv_id_invinv_id_last);
                                                    
    SetPVarInt(playerid"Item_Player"iteams);
                                                    
    ResetInvPVar(playerid);
                                                    
    HideInformation(playerid);
                                                }
                                            default:
                                                {
                                                    if(
    Player[playerid][pHand][i] == Player[playerid][pHand][GetPVarInt(playerid"SelectSlot_inv")])
                                                    {
                                                        switch(
    ItemsInfo[Player[playerid][pHand][GetPVarInt(playerid"SelectSlot_inv")]][ItemType])
                                                        {
                                                            case 
    1341013141723:
                                                            {
                                                                new 
    inv_id_last GetPVarInt(playerid"SelectSlot");
                                                                
    PlayerTextDrawBoxColor(playeridINV_inv[inv_id_last-1], -227);
                                                                
    PlayerTextDrawShow(playeridINV_inv[inv_id_last-1]);
                                                                
    ResetInvPVar(playerid);
                                                                
    PlayerPlaySound(playerid312030.00.00.0);
                                                                
    HideInformation(playerid);
                                                                return 
    1;
                                                            }
                                                        }
                                                        new 
    inv_id_last GetPVarInt(playerid"SelectSlot"), inv_id_inv GetPVarInt(playerid"SelectSlot_inv");
                                                        
    Player[playerid][pHandAmount][i] += Player[playerid][pHandAmount][inv_id_inv];
                                                        
    Player[playerid][pHandAmount][inv_id_inv] = 0;
                                                        
    Player[playerid][pHand][inv_id_inv] = 0;
                                                        
    INV_UPDATE_TEXTDRAW(playeridiinvid);
                                                        new 
    iteams GetPVarInt(playerid"Item_Player");
                                                        
    SetPVarInt(playerid"Item_Player"0);
                                                        
    INV_UPDATE_TEXTDRAW(playeridinv_id_invinv_id_last);
                                                        
    SetPVarInt(playerid"Item_Player"iteams);
                                                        
    ResetInvPVar(playerid);
                                                        
    HideInformation(playerid);
                                                    }
                                                    else
                                                    {
                                                        new 
    inv_id_last GetPVarInt(playerid"SelectSlot");
                                                        
    PlayerTextDrawBoxColor(playeridINV_hand[inv_id_last-1], -227);
                                                        
    PlayerTextDrawShow(playeridINV_hand[inv_id_last-1]);
                                                        
    ResetInvPVar(playerid);
                                                        
    PlayerPlaySound(playerid312030.00.00.0);
                                                        
    HideInformation(playerid);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        case 
    2:
                        {
                            switch(
    GetPVarInt(playerid"InvOrHand"))
                            {
                            case 
    0:
                                {
                                    switch(
    Player[playerid][pAccessories][i])
                                    {
                                    case 
    0:
                                        {
                                            switch(
    GetPVarInt(playerid"Item_Player"))
                                            {
                                                case 
    1PlayerClickMenuAccessories(playeridiinvidPlayer[playerid][pInv][GetPVarInt(playerid"SelectSlot_inv")], Player[playerid][pInvAmount][GetPVarInt(playerid"SelectSlot_inv")]);
                                                case 
    2PlayerClickMenuAccessories(playeridiinvidVehicleInfo[Player[GetPVarInt(playerid"Id_Car_Inv")][pCarkeyID][GetPVarInt(playerid"Id_Car_Inv_")]][vTrunk][GetPVarInt(playerid"SelectSlot_inv")], VehicleInfo[Player[GetPVarInt(playerid"Id_Car_Inv")][pCarkeyID][GetPVarInt(playerid"Id_Car_Inv_")]][vTrunkAmmount][GetPVarInt(playerid"SelectSlot_inv")]);
                                                case 
    3PlayerClickMenuAccessories(playeridiinvidHouseInfo[Player[playerid][pPhousekey]][hInv][GetPVarInt(playerid"SelectSlot_inv")], HouseInfo[Player[playerid][pPhousekey]][hInv_k][GetPVarInt(playerid"SelectSlot_inv")]);
                                                case 
    4PlayerClickMenuAccessories(playeridiinvidTrailerInfo[Player[playerid][pTrailer]][t_inv][GetPVarInt(playerid"SelectSlot_inv")], TrailerInfo[Player[playerid][pTrailer]][t_inv_ammount][GetPVarInt(playerid"SelectSlot_inv")]);
                                            }
                                        }
                                    default: return 
    PlayerPlaySound(playerid312030.00.00.0);
                                    }
                                }
                            default:
                                {
                                    if(
    Player[playerid][pAccessories][i] == && GetPVarInt(playerid"SelectSlot") == 0) return PlayerPlaySound(playerid312030.00.00.0);
                                    else if(
    == GetPVarInt(playerid"SelectSlot_inv") )
                                    {
                                        
    PlayerTextDrawBoxColor(playeridINV_hand[invid-1], -227);
                                        
    PlayerTextDrawShow(playeridINV_hand[invid-1]);
                                        
    ResetInvPVar(playerid);
                                        
    PlayerPlaySound(playerid312030.00.00.0);
                                        
    HideInformation(playerid);
                                        return 
    1;
                                    }
                                    else 
    PlayerPlaySound(playerid178030.00.00.0);
                                    switch(
    GetPVarInt(playerid"SelectSlot"))
                                    {
                                    case 
    0:
                                        {
                                            
    PlayerTextDrawBoxColor(playeridINV_hand[invid-1], -842150576);
                                            
    PlayerTextDrawShow(playeridINV_hand[invid-1]);
                                            
    SetPVarInt(playerid"SelectSlot"invid);
                                            
    SetPVarInt(playerid"SelectSlot_inv"i);
                                            
    LoadInformation(playeridPlayer[playerid][pAccessories][i]);
                                            
    SetPVarInt(playerid"InvOrHand"1);
                                        }
                                    default:
                                        {
                                            switch(
    Player[playerid][pAccessories][i])
                                            {
                                            case 
    0:
                                                {
                                                    new 
    inv_id_last GetPVarInt(playerid"SelectSlot"), inv_id_inv GetPVarInt(playerid"SelectSlot_inv");
                                                    
    Player[playerid][pAccessories][i] = Player[playerid][pAccessories][inv_id_inv];
                                                    new 
    iteams GetPVarInt(playerid"Item_Player");
                                                    
    SetPVarInt(playerid"Item_Player", -1);
                                                    
    INV_UPDATE_TEXTDRAW(playeridiinvid);
                                                    
    TranferAccessories(playeridinv_id_invi);
                                                    
    Player[playerid][pAccessories][inv_id_inv] = 0;
                                                    
    INV_UPDATE_TEXTDRAW(playeridinv_id_invinv_id_last);
                                                    
    SetPVarInt(playerid"Item_Player"iteams);
                                                    
    ResetInvPVar(playerid);
                                                    
    HideInformation(playerid);
                                                }
                                            default: return 
    PlayerPlaySound(playerid312030.00.00.0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } 
    PHP код:
    stock PlayerClickMenuInHand(playeridiinvid, &inv, &invk)
    {
        switch(
    ItemsInfo[inv][ItemType])
        {
            case 
    1:
            {
                static const 
    dialog_text[] = "{FFFFFF}Вы действительно хотите изменить "LIGHTBLUE"#%i{FFFFFF} внешность на "LIGHTBLUE"#%i{FFFFFF}\nЕсли нет, то одежда будет перемещен в руки(возможно для выбрасывания)";
                new 
    string_dialog[sizeof(dialog_text) + 2*3-1];
                
    format(string_dialogsizeof(string_dialog), dialog_textGetPlayerSkin(playerid), inv);
                
    Dialog_Show(playeridDIALOG_CHANGESKINDIALOG_STYLE_MSGBOX""vGotov"Изменить одежду"string_dialog"Да""Нет");
                return 
    1;
            }
            case 
    2:
            {
                for(new 
    id_handid_hand MAX_HAND_ITEMid_hand++)
                {
                    if(
    Player[playerid][pHand][id_hand] == 0) continue;
                    if(
    Slot_ID_Gun[Player[playerid][pHand][id_hand]-MAX_ITEM_SKIN] == Slot_ID_Gun[inv-MAX_ITEM_SKIN])
                    {
                        
    SendClientMessageError(playeridCOLOR_RED"[ОШИБКА]{FFFFFF} У вас уже есть в руках оружие данного типа!");
                        return 
    1;
                    }
                }
                static const 
    text_dialog[] = "{FFFFFF} Введите какое количество %s вы хотите переложить в руку\n\n"vPod"Примичание{FFFFFF}: ничего не вводите если хотите переложить все сразу.\nВы имеете %i количества %s.";
                new 
    string_dialogsizeof(text_dialog) + ( - 32)*+ ( - 12 ) + ];
                
    f(string_dialogtext_dialogItemsInfo[inv][ItemName], invkItemsInfo[inv][ItemName]);
                
    Dialog_Show(playeridDIALOG_INV_PUTDIALOG_STYLE_INPUT"{FFFFFF}Инвентарь"string_dialog"Положить""Назад");
                
    SetPVarInt(playerid"INV_invid_"invid);
                
    SetPVarInt(playerid"INV_i_"i);
                return 
    1;
            }
            case 
    3: return PlayerPlaySound(playerid312030.00.00.0);
            case 
    4: return SendClientMessageError(playeridCOLOR_RED"[ОШИБКА]{ffffff} Данный объект является аксессуаром, его нужно перекладывать в соответствующий раздел.");
            case 
    5..9:
            {
                new 
    Float:Health_men;
                
    GetPlayerHealth(playeridHealth_men);
                if(
    Health_men >= 100.0)
                {
                    
    SendClientMessageError(playeridCOLOR_RED"[ОШИБКА]{ffffff} У вас максимальное кол-во здоровья.");
                    new 
    inv_id_last GetPVarInt(playerid"SelectSlot");
                    
    PlayerTextDrawBoxColor(playeridINV_inv[inv_id_last-1], -227);
                    
    PlayerTextDrawShow(playeridINV_inv[inv_id_last-1]);
                    
    ResetInvPVar(playerid);
                    
    PlayerPlaySound(playerid312030.00.00.0);
                    
    HideInformation(playerid);
                    return 
    1;
                }
            }
            case 
    14:
            {
                if(!
    IsACop(playerid))return SendClientMessageError(playeridCOLOR_REDUnAdminMes);
            }
            case 
    23:
            {
                if(
    IsAHand(playeridinv) != -1)
                {
                    
    SendClientMessageError(playeridCOLOR_RED"[ОШИБКА]{ffffff} У вас уже имеется бронежилет.");
                    new 
    inv_id_last GetPVarInt(playerid"SelectSlot");
                    
    PlayerTextDrawBoxColor(playeridINV_inv[inv_id_last-1], -227);
                    
    PlayerTextDrawShow(playeridINV_inv[inv_id_last-1]);
                    
    ResetInvPVar(playerid);
                    
    PlayerPlaySound(playerid312030.00.00.0);
                    
    HideInformation(playerid);
                    return 
    1;
                }
                else
                {
                    new 
                        
    inv_id_last GetPVarInt(playerid"SelectSlot"),
                        
    inv_id_inv GetPVarInt(playerid"SelectSlot_inv");
                    
    Player[playerid][pHandAmount][i] = inv;
                    
    Player[playerid][pHand][i] = invk;
                    
    inv 
                    
    invk 0;
                    if(
    Player[playerid][pHandAmount][i] > ItemsInfo[Player[playerid][pHand][i]][ItemMax]) Player[playerid][pHandAmount][i] = ItemsInfo[Player[playerid][pHand][i]][ItemMax];
                    
    SetPlayerArmour(playerid,Player[playerid][pHandAmount][i]);
                    new 
    iteams GetPVarInt(playerid"Item_Player");
                    
    SetPVarInt(playerid"Item_Player"0);
                    
    INV_UPDATE_TEXTDRAW(playeridiinvid);
                    
    SetPVarInt(playerid"Item_Player"1);
                    
    INV_UPDATE_TEXTDRAW(playeridinv_id_invinv_id_last);
                    
    SetPVarInt(playerid"Item_Player"iteams);
                    
    PlayerTextDrawBoxColor(playeridINV_inv[inv_id_last-1], -227);
                    
    PlayerTextDrawShow(playeridINV_inv[inv_id_last-1]);
                    
    ResetInvPVar(playerid);
                    
    HideInformation(playerid);
                    return 
    1;
                }
            }
            
        }
        if(
    invk == 1)
        {
            new 
    inv_id_last GetPVarInt(playerid"SelectSlot"), inv_id_inv GetPVarInt(playerid"SelectSlot_inv");
            if(
    IsAHand(playeridinv) != -1)
            {
                static const 
    text_int[] = "Hand_ID_%i";
                new 
    string_invsizeof(text_int) + ];
                
    IsAHand(playeridinv);
                
    f(string_invtext_inti);
                
    invid GetPVarInt(playeridstring_inv);
                
    Player[playerid][pHandAmount][i] += invk;
            }
            else
            {
                
    Player[playerid][pHandAmount][i] = inv;
                
    Player[playerid][pHand][i] = invk;
            }
            new 
    iteams GetPVarInt(playerid"Item_Player");
            
    SetPVarInt(playerid"Item_Player"0);
            
    INV_UPDATE_TEXTDRAW(playeridiinvid);
            
    SetPVarInt(playerid"Item_Player"iteams);
            
    invk 
            
    inv 0;
            
    INV_UPDATE_TEXTDRAW(playeridinv_id_invinv_id_last);
            
    ResetInvPVar(playerid);
            
    HideInformation(playerid);
            
    SetPlayerHand(playeridi);
        }
        else
        {
            static const 
    text_dialog[] = "{FFFFFF} Введите какое количество %s вы хотите переложить в руку\n\n"vPod"Примичание{FFFFFF}: ничего не вводите если хотите переложить все сразу.\nВы имеете %i количества %s.";
            new 
    string_dialogsizeof(text_dialog) + ( - 32)*+ ( - 12 ) + ];
            
    f(string_dialogtext_dialogItemsInfo[inv][ItemName], invkItemsInfo[inv][ItemName]);
            
    Dialog_Show(playeridDIALOG_INV_PUTDIALOG_STYLE_INPUT"{FFFFFF}Инвентарь"string_dialog"Положить""Назад");
            
    SetPVarInt(playerid"INV_invid_"invid);
            
    SetPVarInt(playerid"INV_i_"i);
            return 
    1;
        }
        return 
    1;

    Последний раз редактировалось Igoreshka; 22.10.2019 в 16:10.

 

 

Информация о теме

Пользователи, просматривающие эту тему

Эту тему просматривают: 1 (пользователей: 0 , гостей: 1)

Ваши права

  • Вы не можете создавать новые темы
  • Вы не можете отвечать в темах
  • Вы не можете прикреплять вложения
  • Вы не можете редактировать свои сообщения
  •