PDA

Просмотр полной версии : [Вопрос] class в pawn(инвентарь)



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

Разные типы инвентаря

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

Возможности изменения

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

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

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

https://i.ibb.co/5FCgh3y/image.png (https://ibb.co/k1zs2Tf)
Пример того, что примерно должно быть. Хотя мне все равно не нравится все это.

for(new i; i < MAX_HAND_ITEM; i++)
{
static const text_int[] = "Hand_ID_%i";
new string_inv[ sizeof(text_int) + 1 ];
f(string_inv, text_int, i);
new invid = GetPVarInt(playerid, string_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 1: PlayerClickMenuInHand(playerid, i, invid, Player[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(playerid, i, invid, VehicleInfo[veh_info][vTrunk][GetPVarInt(playerid, "SelectSlot_inv")], VehicleInfo[veh_info][vTrunkAmmount][GetPVarInt(playerid, "SelectSlot_inv")]);
}
case 3: PlayerClickMenuInHand(playerid, i, invid, HouseInfo[Player[playerid][pPhousekey]][hInv][GetPVarInt(playerid, "SelectSlot_inv")], HouseInfo[Player[playerid][pPhousekey]][hInv_k][GetPVarInt(playerid, "SelectSlot_inv")]);
case 4: PlayerClickMenuInHand(playerid, i, invid, TrailerInfo[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 1: PlayerClickMenuInHandIs(playerid, i, invid, Player[playerid][pInv][GetPVarInt(playerid, "SelectSlot_inv")], Player[playerid][pInvAmount][GetPVarInt(playerid, "SelectSlot_inv")]);
case 2: PlayerClickMenuInHandIs(playerid, i, invid, VehicleInfo[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 3: PlayerClickMenuInHandIs(playerid, i, invid, HouseInfo[Player[playerid][pPhousekey]][hInv][GetPVarInt(playerid, "SelectSlot_inv")], HouseInfo[Player[playerid][pPhousekey]][hInv_k][GetPVarInt(playerid, "SelectSlot_inv")]);
case 4: PlayerClickMenuInHandIs(playerid, i, invid, TrailerInfo[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] == 0 && GetPVarInt(playerid, "SelectSlot") == 0) return PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.0);
else if(i == GetPVarInt(playerid, "SelectSlot_inv") )
{
PlayerTextDrawBoxColor(playerid, INV_hand[invid-1], -227);
PlayerTextDrawShow(playerid, INV_hand[invid-1]);
ResetInvPVar(playerid);
PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.0);
HideInformation(playerid);
return 1;
}
else PlayerPlaySound(playerid, 17803, 0.0, 0.0, 0.0);
switch(GetPVarInt(playerid, "SelectSlot"))
{
case 0:
{
PlayerTextDrawBoxColor(playerid, INV_hand[invid-1], -842150576);
PlayerTextDrawShow(playerid, INV_hand[invid-1]);
SetPVarInt(playerid, "SelectSlot", invid);
SetPVarInt(playerid, "SelectSlot_inv", i);
LoadInformation(playerid, Player[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(playerid, i, invid);
Player[playerid][pHandAmount][inv_id_inv] = 0;
Player[playerid][pHand][inv_id_inv] = 0;
Player[playerid][pHand_][inv_id_inv] = false;
INV_UPDATE_TEXTDRAW(playerid, inv_id_inv, inv_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 1, 3, 4, 10, 13, 14, 17, 23:
{
new inv_id_last = GetPVarInt(playerid, "SelectSlot");
PlayerTextDrawBoxColor(playerid, INV_inv[inv_id_last-1], -227);
PlayerTextDrawShow(playerid, INV_inv[inv_id_last-1]);
ResetInvPVar(playerid);
PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.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(playerid, i, invid);
new iteams = GetPVarInt(playerid, "Item_Player");
SetPVarInt(playerid, "Item_Player", 0);
INV_UPDATE_TEXTDRAW(playerid, inv_id_inv, inv_id_last);
SetPVarInt(playerid, "Item_Player", iteams);
ResetInvPVar(playerid);
HideInformation(playerid);
}
else
{
new inv_id_last = GetPVarInt(playerid, "SelectSlot");
PlayerTextDrawBoxColor(playerid, INV_hand[inv_id_last-1], -227);
PlayerTextDrawShow(playerid, INV_hand[inv_id_last-1]);
ResetInvPVar(playerid);
PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.0);
HideInformation(playerid);
}
}
}
}
}
}
}
}
case 2:
{
switch(GetPVarInt(playerid, "InvOrHand"))
{
case 0:
{
switch(Player[playerid][pAccessories][i])
{
case 0:
{
switch(GetPVarInt(playerid, "Item_Player"))
{
case 1: PlayerClickMenuAccessories(playerid, i, invid, Player[playerid][pInv][GetPVarInt(playerid, "SelectSlot_inv")], Player[playerid][pInvAmount][GetPVarInt(playerid, "SelectSlot_inv")]);
case 2: PlayerClickMenuAccessories(playerid, i, invid, VehicleInfo[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 3: PlayerClickMenuAccessories(playerid, i, invid, HouseInfo[Player[playerid][pPhousekey]][hInv][GetPVarInt(playerid, "SelectSlot_inv")], HouseInfo[Player[playerid][pPhousekey]][hInv_k][GetPVarInt(playerid, "SelectSlot_inv")]);
case 4: PlayerClickMenuAccessories(playerid, i, invid, TrailerInfo[Player[playerid][pTrailer]][t_inv][GetPVarInt(playerid, "SelectSlot_inv")], TrailerInfo[Player[playerid][pTrailer]][t_inv_ammount][GetPVarInt(playerid, "SelectSlot_inv")]);
}
}
default: return PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.0);
}
}
default:
{
if(Player[playerid][pAccessories][i] == 0 && GetPVarInt(playerid, "SelectSlot") == 0) return PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.0);
else if(i == GetPVarInt(playerid, "SelectSlot_inv") )
{
PlayerTextDrawBoxColor(playerid, INV_hand[invid-1], -227);
PlayerTextDrawShow(playerid, INV_hand[invid-1]);
ResetInvPVar(playerid);
PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.0);
HideInformation(playerid);
return 1;
}
else PlayerPlaySound(playerid, 17803, 0.0, 0.0, 0.0);
switch(GetPVarInt(playerid, "SelectSlot"))
{
case 0:
{
PlayerTextDrawBoxColor(playerid, INV_hand[invid-1], -842150576);
PlayerTextDrawShow(playerid, INV_hand[invid-1]);
SetPVarInt(playerid, "SelectSlot", invid);
SetPVarInt(playerid, "SelectSlot_inv", i);
LoadInformation(playerid, Player[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(playerid, i, invid);
TranferAccessories(playerid, inv_id_inv, i);
Player[playerid][pAccessories][inv_id_inv] = 0;
INV_UPDATE_TEXTDRAW(playerid, inv_id_inv, inv_id_last);
SetPVarInt(playerid, "Item_Player", iteams);
ResetInvPVar(playerid);
HideInformation(playerid);
}
default: return PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.0);
}
}
}
}
}
}
}
}
}

stock PlayerClickMenuInHand(playerid, i, invid, &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-2 + 1];
format(string_dialog, sizeof(string_dialog), dialog_text, GetPlayerSkin(playerid), inv);
Dialog_Show(playerid, DIALOG_CHANGESKIN, DIALOG_STYLE_MSGBOX, ""vGotov"Изменить одежду", string_dialog, "Да", "Нет");
return 1;
}
case 2:
{
for(new id_hand; id_hand < MAX_HAND_ITEM; id_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(playerid, COLOR_RED, "[ОШИБКА]{FFFFFF} У вас уже есть в руках оружие данного типа!");
return 1;
}
}
static const text_dialog[] = "{FFFFFF} Введите какое количество %s вы хотите переложить в руку\n\n"vPod"Примичание{FFFFFF}: ничего не вводите если хотите переложить все сразу.\nВы имеете %i количества %s.";
new string_dialog[ sizeof(text_dialog) + ( - 2 + 32)*2 + ( - 2 + 12 ) + 1 ];
f(string_dialog, text_dialog, ItemsInfo[inv][ItemName], invk, ItemsInfo[inv][ItemName]);
Dialog_Show(playerid, DIALOG_INV_PUT, DIALOG_STYLE_INPUT, "{FFFFFF}Инвентарь", string_dialog, "Положить", "Назад");
SetPVarInt(playerid, "INV_invid_", invid);
SetPVarInt(playerid, "INV_i_", i);
return 1;
}
case 3: return PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.0);
case 4: return SendClientMessageError(playerid, COLOR_RED, "[ОШИБКА]{ffffff} Данный объект является аксессуаром, его нужно перекладывать в соответствующий раздел.");
case 5..9:
{
new Float:Health_men;
GetPlayerHealth(playerid, Health_men);
if(Health_men >= 100.0)
{
SendClientMessageError(playerid, COLOR_RED, "[ОШИБКА]{ffffff} У вас максимальное кол-во здоровья.");
new inv_id_last = GetPVarInt(playerid, "SelectSlot");
PlayerTextDrawBoxColor(playerid, INV_inv[inv_id_last-1], -227);
PlayerTextDrawShow(playerid, INV_inv[inv_id_last-1]);
ResetInvPVar(playerid);
PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.0);
HideInformation(playerid);
return 1;
}
}
case 14:
{
if(!IsACop(playerid))return SendClientMessageError(playerid, COLOR_RED, UnAdminMes);
}
case 23:
{
if(IsAHand(playerid, inv) != -1)
{
SendClientMessageError(playerid, COLOR_RED, "[ОШИБКА]{ffffff} У вас уже имеется бронежилет.");
new inv_id_last = GetPVarInt(playerid, "SelectSlot");
PlayerTextDrawBoxColor(playerid, INV_inv[inv_id_last-1], -227);
PlayerTextDrawShow(playerid, INV_inv[inv_id_last-1]);
ResetInvPVar(playerid);
PlayerPlaySound(playerid, 31203, 0.0, 0.0, 0.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(playerid, i, invid);
SetPVarInt(playerid, "Item_Player", 1);
INV_UPDATE_TEXTDRAW(playerid, inv_id_inv, inv_id_last);
SetPVarInt(playerid, "Item_Player", iteams);
PlayerTextDrawBoxColor(playerid, INV_inv[inv_id_last-1], -227);
PlayerTextDrawShow(playerid, INV_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(playerid, inv) != -1)
{
static const text_int[] = "Hand_ID_%i";
new string_inv[ sizeof(text_int) + 1 ];
i = IsAHand(playerid, inv);
f(string_inv, text_int, i);
invid = GetPVarInt(playerid, string_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(playerid, i, invid);
SetPVarInt(playerid, "Item_Player", iteams);
invk =
inv = 0;
INV_UPDATE_TEXTDRAW(playerid, inv_id_inv, inv_id_last);
ResetInvPVar(playerid);
HideInformation(playerid);
SetPlayerHand(playerid, i);
}
else
{
static const text_dialog[] = "{FFFFFF} Введите какое количество %s вы хотите переложить в руку\n\n"vPod"Примичание{FFFFFF}: ничего не вводите если хотите переложить все сразу.\nВы имеете %i количества %s.";
new string_dialog[ sizeof(text_dialog) + ( - 2 + 32)*2 + ( - 2 + 12 ) + 1 ];
f(string_dialog, text_dialog, ItemsInfo[inv][ItemName], invk, ItemsInfo[inv][ItemName]);
Dialog_Show(playerid, DIALOG_INV_PUT, DIALOG_STYLE_INPUT, "{FFFFFF}Инвентарь", string_dialog, "Положить", "Назад");
SetPVarInt(playerid, "INV_invid_", invid);
SetPVarInt(playerid, "INV_i_", i);
return 1;
}
return 1;
}