11.09.2018, 01:02
If the current amount of the player's inventory plus the amount in the plant exceeds the maximum, subtract the current amount the player has from the maximum (50 - 30).
This is the amount that fits in the inventory without exceeding the limit.
Simply add it to the inventory and subtract it from the plant.
50 (limit) - 30 (inventory) = 20 free inventory space
50 (plant) - 20 (free inventory space) = 30 left in the plant
30 (inventory) + 20 (collected) = 50 in inventory
This is the amount that fits in the inventory without exceeding the limit.
Simply add it to the inventory and subtract it from the plant.
50 (limit) - 30 (inventory) = 20 free inventory space
50 (plant) - 20 (free inventory space) = 30 left in the plant
30 (inventory) + 20 (collected) = 50 in inventory
Код:
new transfer = MAX_INVENTORY_SPACE - Player[playerid][MarijuanaGrams]; // Calculate difference if(transfer < PlantData[plantid][plantDrugs]) // If less than the plant's capacity can be transfered, only transfer what fits into the inventory (which is the difference between the limit and current amount (the transfer variable)) { PlantData[plantid][plantDrugs] -= transfer; Player[playerid][MarijuanaGrams] += transfer; } else // Otherwise transfer all of it. { Player[playerid][MarijuanaGrams] += PlantData[plantid][plantDrugs]; PlantData[plantid][plantDrugs] = 0; }