View Single Post
Old 13/06/2019, 03:38 PM   #10
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 27
Default Re: Price or item does not update

Quote:
Originally Posted by Blake95 View Post
Doesn't work!

Maybe bad code...

Code:
if(PlayerCache_GetFree(playerid)!= -1)
	            {
	            	PlayerInfo[playerid][ItemCache][index_id] = x;
	            	SetPVarInt(playerid, "PriceCount", GetPVarInt(playerid, "PriceCount") + ReturnItemPrice(x));
					
					if(PlayerInfo[playerid][ItemCache][x])
					{
					    if(GetPVarInt(playerid, "PriceCount") - ReturnItemPrice(PlayerInfo[playerid][ItemCache][index_id]) > 0)//here
					    {
					    	SetPVarInt(playerid, "PriceCount", GetPVarInt(playerid, "PriceCount") - ReturnItemPrice(PlayerInfo[playerid][ItemCache][index_id]));//Also you might want to to + instead of - here
						}
						else
						{
						    SetPVarInt(playerid, "PriceCount", 0);
						}
						PlayerInfo[playerid][ItemCache][index_id] = -1;
					}
				}
				new price[24];
				format(price, 24, "~g~$%s", MoneyFormat(GetPVarInt(playerid, "PriceCount")));
				PlayerTextDrawSetString(playerid, Store_Cart[playerid], price);
	        }
Did you read my reply?

Quote:
Originally Posted by Plastikmensch View Post
Might be bad math. If I understand your code correctly, you check if PriceCount - ItemPrice is greater than 0.
Code:
if(PlayerInfo[playerid][ItemCache][x])
{
   if(GetPVarInt(playerid, "PriceCount") - ReturnItemPrice(PlayerInfo[playerid][ItemCache][index_id]) > 0)//here
   {
      SetPVarInt(playerid, "PriceCount", GetPVarInt(playerid, "PriceCount") - ReturnItemPrice(PlayerInfo[playerid][ItemCache][index_id]));//Also you might want to to + instead of - here
   }
   else
   {
      SetPVarInt(playerid, "PriceCount", 0);
   }
   PlayerInfo[playerid][ItemCache][index_id] = -1;
}
But if you select the first item, PriceCount - ItemPrice will be 0 which will execute the else and set PriceCount to 0.
Assuming the PriceCount is the total price of all items, you might want to add and not subtract from it.

The ReturnItemPrice function is fine except you might don't want to return 1 if itemid is not inside switch.
Also the code in my reply wasn't fixed code. I quoted your code to show you where the problems are, hence the "//here" and "//You might want to do + instead of - here"

Also I don't quite understand, what you are trying to do.
You add ItemPrice to PriceCount, check if PriceCount - ItemPrice is greater than 0 which it will never be on the first item, so you have unreachable code, where you are subtracting from PriceCount again (which would be 0 again) and in the else, which gets executed, you set PriceCount to 0 and then show PriceCount to the player with a textdraw?
Plastikmensch is offline   Reply With Quote