- Автор темы
- #1
Inv:
#define MAX_ITEMS 20 #define MAX_NEAR_PLAYERS 10 #define MAX_CARRY_WEIGHT 10000 // 100 кг #define MAX_MEDKITS 3 #define MAX_REPAIRKITS 3 #define MAX_ACCESSORY_SLOTS 7
#include <a_samp> #include <a_mysql>
new MySQL:db;
enum INVENTORY_SLOT { item_id, item_name[32], item_weight, item_type, item_value };
new PlayerInventory[MAX_PLAYERS][MAX_ITEMS][INVENTORY_SLOT]; new PlayerAccessories[MAX_PLAYERS][MAX_ACCESSORY_SLOTS][INVENTORY_SLOT]; new SelectedSlot[MAX_PLAYERS] = {-1, ...}; new SelectedAccessory[MAX_PLAYERS] = {-1, ...}; new NearPlayers[MAX_PLAYERS][MAX_NEAR_PLAYERS]; new NearPlayerCount[MAX_PLAYERS]; new InventoryTransferSlot[MAX_PLAYERS]; new Text:SkinModelDraw[MAX_PLAYERS]; new Text:InventorySlots[MAX_ITEMS]; new Text:AccessorySlots[MAX_ACCESSORY_SLOTS]; new Text:ActionButtons[6]; new Text:WeightDisplay[MAX_PLAYERS]; new Text:SkinDisplay[MAX_PLAYERS];
new PlayerCurrentSkin[MAX_PLAYERS]; new Text:CloseInventoryButton[MAX_PLAYERS];
enum { BUTTON_USE, BUTTON_DROP, BUTTON_GIVE, BUTTON_CLOSE, BUTTON_REMOVE_ACC, BUTTON_EQUIP_ACC };
stock SavePlayerAccessories(playerid) { new query[512]; for (new i = 0; i < MAX_ACCESSORY_SLOTS; i++) { format(query, sizeof(query), "REPLACE INTO player_accessories (player_id, slot, item_id, name, weight, type, value) VALUES (%d, %d, %d, '%e', %d, %d, %d)", playerid, i, PlayerAccessories[playerid][i][item_id], PlayerAccessories[playerid][i][item_name], PlayerAccessories[playerid][i][item_weight], PlayerAccessories[playerid][i][item_type], PlayerAccessories[playerid][i][item_value] ); mysql_tquery(db, query, "", ""); } }
stock LoadPlayerAccessories(playerid) { new query[128]; format(query, sizeof(query), "SELECT * FROM player_accessories WHERE player_id = %d", playerid); mysql_tquery(db, query, "OnAccessoriesLoaded", "i", playerid); }
public OnAccessoriesLoaded(playerid) { new rows, fields; cache_get_data(rows, fields, db); if (!rows) return;
new slot;
for (new i = 0; i < rows; i++)
{
cache_get_field_content(i, "slot", slot);
PlayerAccessories[playerid][slot][item_id] = cache_get_field_content_int(i, "item_id");
cache_get_field_content(i, "name", PlayerAccessories[playerid][slot][item_name], db, 32);
PlayerAccessories[playerid][slot][item_weight] = cache_get_field_content_int(i, "weight");
PlayerAccessories[playerid][slot][item_type] = cache_get_field_content_int(i, "type");
PlayerAccessories[playerid][slot][item_value] = cache_get_field_content_int(i, "value");
}
ShowAccessorySlots(playerid);
}
stock SavePlayerSkin(playerid) { new query[128]; format(query, sizeof(query), "UPDATE player_skins SET skin_id = %d WHERE player_id = %d", PlayerCurrentSkin[playerid], playerid); mysql_tquery(db, query, "", ""); }
stock LoadPlayerSkin(playerid) { new query[128]; format(query, sizeof(query), "SELECT skin_id FROM player_skins WHERE player_id = %d", playerid); mysql_tquery(db, query, "OnSkinLoaded", "i", playerid); }
public OnSkinLoaded(playerid) { new rows, fields; cache_get_data(rows, fields, db); if (rows) { PlayerCurrentSkin[playerid] = cache_get_field_content_int(0, "skin_id"); SetPlayerSkin(playerid, PlayerCurrentSkin[playerid]); } }
stock GetCurrentCarryWeight(playerid) { new total = 0; for (new i = 0; i < MAX_ITEMS; i++) { total += PlayerInventory[playerid][i][item_weight]; } return total; }
stock GetItemCount(playerid, const itemName[]) { new count = 0; for (new i = 0; i < MAX_ITEMS; i++) { if (strcmp(PlayerInventory[playerid][i][item_name], itemName, true) == 0) { count++; } } return count; }
stock CanPickupItem(playerid, const itemName[], weight) { if ((GetCurrentCarryWeight(playerid) + weight) > MAX_CARRY_WEIGHT) { SendClientMessage(playerid, 0xFF0000FF, "Вы не можете взять предмет. Превышен лимит веса!"); return 0; }
if (strcmp(itemName, "Аптечка", true) == 0 && GetItemCount(playerid, "Аптечка") >= MAX_MEDKITS)
{
SendClientMessage(playerid, 0xFF0000FF, "У вас уже максимальное количество аптечек!");
return 0;
}
if (strcmp(itemName, "Ремкомплект", true) == 0 && GetItemCount(playerid, "Ремкомплект") >= MAX_REPAIRKITS)
{
SendClientMessage(playerid, 0xFF0000FF, "У вас уже максимальное количество ремкомплектов!");
return 0;
}
return 1;
}
stock ShowAccessorySlots(playerid) { // Отобразить аксессуары на экране игрока }
И да код сделал гпт. Проверьте код работает он или нет