Harvest question
#1

I have a question, i set maximum capacity of grams a player can carry.

So if he has already more than defined grams, he can't harvest anymore.

So i did this:

pawn Код:
if(Player[playerid][MarijuanaGrams] > MARIJUANA_MAX_CAPACITY) return SCM(playerid, COLOR_RED,"* You have reached max ammount of marijuana grams you can carry. Sell some at local DPS (/findps) first.");
My question is:

Imagine i have already 30 grams of marijuana in my inventory, and i can carry a max of 50 grams (defined in marijuana_max capacity), how i can harvest the 20 grams left and remain the rest to the plant?

This is the code which adds harvested grams to inventory and removes from the plant:

pawn Код:
Player[playerid][MarijuanaGrams] += PlantData[plantid][plantDrugs];
Lemme do an example:

I have 30 grams of marijuana, plant has 50. Limit is 50 which i can carry, i wanna harvest only 20 (30 + 20 = 50 (max capacity) and leave the remaining 30 grams (50 - 30 harvested) in the plant. How?
Reply
#2

PHP код:
if(Player[playerid][MarijuanaGrams] >= MARIJUANA_MAX_CAPACITY) return SCM(playeridCOLOR_RED,"* You have reached max ammount of marijuana grams you can carry. Sell some at local DPS (/findps) first.");
if(
PlantData[plantid][plantDrugs] >= 1)
{
    
PlantData[plantid][plantDrugs] --;
    
Player[playerid][MarijuanaGrams] ++;

Reply
#3

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

Код:
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;
}
Reply
#4

Thank you both.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)