Need help with fixing a little problem on my /buy CMD
#1

Код:
else if(strcmp("/buy", cmd, true) == 0)
	{
		new cmdcount = strcount(cmdtext, ' ');

		new busid;
		new locationid = GetLocationID(playerid);
		if(locationid != INVALID_LOCATION_ID) busid = LocationInfo[locationid][lBusinessId];
		else busid = PlayerExtraInfo[playerid][pxInBusiness];
		//printf("busid: %d, locationid: %d", busid,locationid);
	 	if(busid == 0) return SendClientMessage(playerid, COLOR_GREY, " You need to be near a business.");

		if(cmdcount < 2)
		{
			//generate product list
			for(new i = 0; i < MAX_PRODUCTS; i++)
			{
				if(ProductInfo[busid][i][prSQLId] != INVALID_SQL_ID)
				{
					if(ProductInfo[busid][i][prFlags] & BUYABLE_PRODUCT)
					{
						format(string, sizeof(string),"%s, $%.2f", BaseProductInfo[ProductInfo[busid][i][prSQLId]][bpName],
						 	FloatMoney(ProductInfo[busid][i][prBuyPrice]));
						SendClientMessage(playerid, COLOR_GREY, string);
					}
				}
			}
			format(string, sizeof(string), "Warning: [%i]%s just typed /buy - be sure he is not abusing this command.",playerid,PlayerInfo[playerid][pName]);
		  SendAdminMessage(ADMIN_RED, string);
			SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /buy [name/id] [amount=1]");
			return 1;
		}

		/*if(PlayerExtraInfo[playerid][pxInBusiness] == 0)
		{
		  if (!IsPlayerNearBusiness(playerid, BUSINESS_TYPE_FUEL, 10))
		  {
		 		SendClientMessage(playerid, COLOR_GREY, "  You must be inside the business.");
		 		return 1;
			}
		}
		*/
		if(BusinessInfo[busid][bType] & BUSINESS_TYPE_DRUGS)
		{
			//need to be a drug dealer
			if(PlayerInfo[playerid][pJobId] != JOB_DRUGDEALER)
			{
				SendClientMessage(playerid, COLOR_GRAD2, "You need to be a Drug Dealer to use this store.");
				return 1;
			}
		}
		tmp = strtok(cmdtext, idx);
		new prodid = GetProductID(busid, tmp);
		//printf("productid: %d ", prodid);
		if(prodid == INVALID_PRODUCT_ID)
		{
			format(string, sizeof(string),"  Product %s doesn't exist.", tmp);
			SendClientMessage(playerid, COLOR_GREY, string);
			return 1;
		}
		new prodcount = 1;
		new prodtmp;
		new ProdSQLId = ProductInfo[busid][prodid][prSQLId];
		//new currentfuel;
		if(cmdcount == 3)
		{
			tmp = strtok(cmdtext, idx);
		 	if (strcmp("Fuel",BaseProductInfo[ProdSQLId][bpName],true) == 0)
		 	{
			 	prodtmp = strval(tmp);
			}
		 	else
		 	{
		 		prodcount = strval(tmp);
			}
		}
				if (strcmp("Fuel",BaseProductInfo[ProdSQLId][bpName],true) == 0)
		{


			if(prodtmp < 1 || prodtmp > 100) return SendClientMessage(playerid,COLOR_GREY, " Amount must be less than 100 and more than 0 (percent)");
			new modelid = VehicleInfo[GetPlayerVehicleID(playerid)][vModel]-MIN_VEHICLEMODELID;
			if (IsPlayerDriver(playerid)) prodcount = prodtmp * VehicleCostInfo[modelid][vcMaxFuel] / 100;
			else prodcount = prodtmp * 25/*fuel can*/ / 100;
			//printf("prodcount = %d",prodcount);
//			if (IsPlayerDriver(playerid)) currentfuel = VehicleInfo[GetPlayerVehicleID(playerid)][vFuel];
		}
		else
		{
			if(prodcount < 1) prodcount = 1;
		}

		//printf("prodtmp = %d | prodcount = %d",prodtmp,prodcount);

		if(!(ProductInfo[busid][prodid][prFlags] & BUYABLE_PRODUCT))
		{
			format(string, sizeof(string),"  You can't buy %s from here.", BaseProductInfo[ProdSQLId][bpName]);
			SendClientMessage(playerid, COLOR_GREY, string);
			return 1;
		}

		if(ProductInfo[busid][prodid][prFlags] & AUTOGET_PRODUCT) //auto fulls up shop no need for trucker
		{
			new resultamt;
			new used = AddToValue(ProductInfo[busid][prodid][prNumAvailable], BaseProductInfo[ProdSQLId][bpAvailable], resultamt, BaseProductInfo[ProdSQLId][bpMaxAllowed]);
			ProductInfo[busid][prodid][prNumAvailable] = resultamt;
			BaseProductInfo[ProdSQLId][bpAvailable] -= used;
			ProductInfo[busid][prodid][prBuyPrice] = BaseProductInfo[ProdSQLId][bpCurrentPrice];
			ProductInfo[busid][prodid][prSellPrice] = 0;
		}

		if(ProductInfo[busid][prodid][prNumAvailable] == 0)
		{
			format(string, sizeof(string),"  Sorry, we are currently sold out of %s.", BaseProductInfo[ProdSQLId][bpName]);
			SendClientMessage(playerid, COLOR_GREY, string);
			return 1;
		}

		if (strcmp("Fuel",BaseProductInfo[ProdSQLId][bpName],true) == 0)
		{
			if(ProductInfo[busid][prodid][prNumAvailable] < prodcount)
			{
				format(string, sizeof(string),"  Sorry, we only have %d percent %s available.", ProductInfo[busid][prodid][prNumAvailable]*100/BaseProductInfo[ProdSQLId][bpMaxFactory], BaseProductInfo[ProdSQLId][bpName]);
				SendClientMessage(playerid, COLOR_GREY, string);
				return 1;
			}
		}
		else
		{
			if(ProductInfo[busid][prodid][prNumAvailable] < prodcount)
			{
				format(string, sizeof(string),"  Sorry, we only have %d %s available.", ProductInfo[busid][prodid][prNumAvailable], BaseProductInfo[ProdSQLId][bpName]);
				SendClientMessage(playerid, COLOR_GREY, string);
				return 1;
			}
		}


		new totalprice = ProductInfo[busid][prodid][prBuyPrice]*prodcount;
		if(PlayerInfo[playerid][pCash] < totalprice)
		{
			format(string, sizeof(string),"  You don't have enough money for this purchase, you need $%.2f.", FloatMoney(totalprice));
			SendClientMessage(playerid, COLOR_GREY, string);
			return 1;
		}
		

		new ProductType = BaseProductInfo[ProdSQLId][bpTypeId];
		if(ProductType == PROD_FUEL)
		{
			new playerstate = GetPlayerState(playerid);
			if(playerstate == PLAYER_STATE_DRIVER)
			{
				new vehicleid = GetPlayerVehicleID(playerid);
				new vcmodelid = VehicleInfo[vehicleid][vModel]-MIN_VEHICLEMODELID;
				if(VehicleInfo[vehicleid][vFuel] >= VehicleCostInfo[vcmodelid][vcMaxFuel])
				{
					SendClientMessage(playerid, COLOR_GREY, "  Sorry, but you can't full up your vehicle any more.");
					return 1;
				}
				new fuel = VehicleInfo[vehicleid][vFuel] * 100 / VehicleCostInfo[vcmodelid][vcMaxFuel];
				if (prodtmp <= fuel) return SendClientMessage(playerid, COLOR_GREY, " You can't fill your vehicle with less than your current fuel");
				if (prodcount <= 0) return SendClientMessage(playerid,COLOR_GREY," Go fill your car with fuel first!");
			}
			//add fuel
			IsPlayerBuying[playerid] = 1;
			GameTextForPlayer(playerid,"~w~~n~~n~~n~~n~~n~~n~~n~~n~~n~Collecting Fuel, please wait",2000,3);
			StartTPWaitEvent(playerid,REFUELWAIT,busid,prodid,prodcount,1);
		}
		else
		{
      IsPlayerBuying[playerid] = 1;
			StartTPWaitEvent(playerid,1,busid,prodid,prodcount,0);
      if (PlayerToPoint(playerid, 50.0, -2165.8521,643.1754,1057.5938) || PlayerToPoint(playerid, 50.0, 234.4259,1072.0295,1084.1925) || PlayerToPoint(playerid, 50.0, 140.4808,1372.1063,1084.2736))
	    {
	    if (PlayerInfo[playerid][pFaction] == GetFactionIdFromName(playerid, "MAFIA1") || PlayerInfo[playerid][pFaction] == GetFactionIdFromName(playerid, "MAFIA3") || PlayerInfo[playerid][pFaction] == GetFactionIdFromName(playerid, "MAFIA2"))
			{
			IsPlayerBuying[playerid] = 1;
			StartTPWaitEvent(playerid,1,busid,prodid,prodcount,0);
			}
      else
			{
      SendClientMessage(playerid, COLOR_RED, "You are not allowed to buy from here");
      IsPlayerBuying[playerid] = -1;
			}
		}
		}
		return 1;
	}
If someone is not allowed to buy from the correctly place, its writing to him "You are not allowed", And gives him the item till all his items are full.

How to fix that it will not give him anything?


Thanks
Reply
#2

Anyone?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)