Need help with a command!(+rep)
#1

Hello. Basically, I'm having trouble with the command which players should use to sell their char to another player.

It does seem to work except a thing. It won't set the buyer's car slot to the car's id, so they can't use the car..

I'm using a heavily modified LA:RP gamemode, both the command for selling and accepting the car here:

Код:
if(strcmp(cmd, "/sellcarto", true) == 0) // 
	{
	    if(IsPlayerConnected(playerid))
		{
  			{
				if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3])
				{
				    GetPlayerName(playerid, sendername, sizeof(sendername));
				    new ownvehkey;
	                if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { ownvehkey = PlayerInfo[playerid][pPcarkey]; }
	                else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { ownvehkey = PlayerInfo[playerid][pPcarkey2]; }
	                else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3]) { ownvehkey = PlayerInfo[playerid][pPcarkey3]; }
        			else { return 1; }
				    if(strcmp(sendername, CarInfo[ownvehkey][cOwner], true) == 0)
				    {
						tmp = strtok(cmdtext, idx);
						if(!strlen(tmp))
						{
						    SendClientMessage(playerid, COLOR_WHITE, "HINT: /sellcarto [playerid/PartOfName] [price]");
						    return 1;
						}
						giveplayerid = ReturnUser(tmp);
						if(IsPlayerConnected(giveplayerid))
						{
							if(giveplayerid != INVALID_PLAYER_ID)
							{
							    if(ProxDetectorS(8.0, playerid, giveplayerid))
       							{
							    	if(PlayerInfo[giveplayerid][pPcarkey] == -1)
							    	{
							            tmp = strtok(cmdtext, idx);
							            if(!strlen(tmp))
							            {
							                SendClientMessage(playerid, COLOR_WHITE, "HINT: /sellcarto [playerid/PartOfName] [price]");
							                return 1;
							            }
							            new price;
							            price = strval(tmp);
							            if(price < 1 || price > 15000000)
							            {
							                SendClientMessage(playerid, COLOR_GREY, "  Price not lower then 1 and not higher then 15,000,000 $. ");
							                return 1;
							            }
							            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
							       		format(string, sizeof(string), "* You offerd %s to buy your car for $%d .", giveplayer, price);
					        			SendClientMessage(playerid, COLOR_WHITE, string);
					        			format(string, sizeof(string), "* Car Owner %s offered you to buy his/her car for $%d (type /accept car) to buy.", playername, price);
					        			SendClientMessage(giveplayerid, COLOR_WHITE, string);
					        			OwnableCarOffer[giveplayerid] = playerid;
					        			OwnableCarID[giveplayerid] = ownvehkey;
					        			OwnableCarPrice[giveplayerid] = price;
	        							format(string, sizeof(string), "AdmWarning: %s offered %s to buy his car for %d (/sellcarto)",sendername, giveplayer, price);
										SendAdminMessage(COLOR_LIGHTRED, string);
					        			return 1;
							        }
							        else if(PlayerInfo[giveplayerid][pPcarkey2] == -1)
							        {
							            tmp = strtok(cmdtext, idx);
							            if(!strlen(tmp))
							            {
							                SendClientMessage(playerid, COLOR_WHITE, "HINT: /sellcarto [playerid/PartOfName] [price]");
							                return 1;
							            }
							            new price;
							            price = strval(tmp);
							            if(price < 1 || price > 15000000)
							            {
							                SendClientMessage(playerid, COLOR_GREY, "  Price not lower then 1 and not higher then 15,000,000 $. ");
							                return 1;
							            }
							            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
							       		format(string, sizeof(string), "* You offerd %s to buy your car for $%d .", giveplayer, price);
					        			SendClientMessage(playerid, COLOR_WHITE, string);
					        			format(string, sizeof(string), "* Car Owner %s offered you to buy his/her car for $%d (type /accept ownablecar) to buy.", playername, price);
					        			SendClientMessage(giveplayerid, COLOR_WHITE, string);
					        			OwnableCarOffer[giveplayerid] = playerid;
					        			OwnableCarID[giveplayerid] = ownvehkey;
					        			OwnableCarPrice[giveplayerid] = price;
					        			return 1;
							        }
							        else if(PlayerInfo[giveplayerid][pPcarkey3] == -1)
							        {
							            tmp = strtok(cmdtext, idx);
							            if(!strlen(tmp))
							            {
							                SendClientMessage(playerid, COLOR_WHITE, "HINT: /v sellto [playerid/PartOfName] [price]");
							                return 1;
							            }
							            new price;
							            price = strval(tmp);
							            if(price < 1 || price > 15000000)
							            {
							                SendClientMessage(playerid, COLOR_GREY, "  Price not lower then 1 and not higher then 15,000,000 $. ");
							                return 1;
							            }
							            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
							       		format(string, sizeof(string), "* You offerd %s to buy your car for $%d .", giveplayer, price);
					        			SendClientMessage(playerid, COLOR_WHITE, string);
					        			format(string, sizeof(string), "* Car Owner %s offered you to buy his/her car for $%d (type /accept ownablecar) to buy.", playername, price);
					        			SendClientMessage(giveplayerid, COLOR_WHITE, string);
					        			OwnableCarOffer[giveplayerid] = playerid;
					        			OwnableCarID[giveplayerid] = ownvehkey;
					        			OwnableCarPrice[giveplayerid] = price;
					        			return 1;
							        }
							        else
							        {
							            SendClientMessage(playerid, COLOR_GREY, "   Player has 3 cars already ! ");
							            return 1;
							        }
							    }
							    else
							    {
							        SendClientMessage(playerid, COLOR_GREY, "   Player is not near you ! ");
							        return 1;
							    }
							}
						}
				    }
				    else
				    {
				        SendClientMessage(playerid, COLOR_GREY, "  This is not your car");
				        return 1;
				    }
				}
				else
				{
				    SendClientMessage(playerid, COLOR_GREY, "  You have to sit at your own car to sell it");
				    return 1;
				}
			}
		}
		return 1;
	}
And the receiving part..(Yes, it's quite long, please excuse it:P)


Код:
			else if(strcmp(x_job,"car",true) == 0)
			{
			    if(OwnableCarOffer[playerid] < 999)
			    {
			        if(OwnableCarID[playerid] == 0) { return 1; }
			        if(OwnableCarPrice[playerid] == 0 || OwnableCarPrice[playerid] > 15000001) { return 1; }

			        if(OwnableCarID[playerid] == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey]) { }
			        else if(OwnableCarID[playerid] == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey2]) { }
			        else if(OwnableCarID[playerid] == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey3]) { }
			        else { SendClientMessage(playerid, COLOR_GREY, "  Offer is no longer available"); return 1; }

			        if(GetPlayerMoney(playerid) >= OwnableCarPrice[playerid])
			        {
						if(IsPlayerConnected(OwnableCarOffer[playerid]))
						{
						    GetPlayerName(OwnableCarOffer[playerid], giveplayer, sizeof(giveplayer));
						    GetPlayerName(playerid, sendername, sizeof(sendername));
						    if(PlayerInfo[playerid][pPcarkey] == -1)
							{
								if(GetPlayerVehicleID(OwnableCarOffer[playerid]) == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey])
								{
									PlayerInfo[playerid][pPcarkey] = OwnableCarID[playerid];
						    		PlayerInfo[OwnableCarOffer[playerid]][pPcarkey] = -1;
								}
								else if(GetPlayerVehicleID(OwnableCarOffer[playerid]) == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey2])
								{
									PlayerInfo[playerid][pPcarkey] = OwnableCarID[playerid];
						    		PlayerInfo[OwnableCarOffer[playerid]][pPcarkey2] = -1;
								}
								else if(GetPlayerVehicleID(OwnableCarOffer[playerid]) == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey3])
								{
									PlayerInfo[playerid][pPcarkey] = OwnableCarID[playerid];
						    		PlayerInfo[OwnableCarOffer[playerid]][pPcarkey3] = -1;
								}
								else
								{
								    SendClientMessage(playerid, COLOR_GREY, "  Vehicle seller needs to be in his car !");
									return 1;
								}
								format(string, sizeof(string), "* You bought a car for $%d from %s.",OwnableCarPrice[playerid],giveplayer);
								SendClientMessage(playerid, COLOR_WHITE, string);
								format(string, sizeof(string), "AdmWarning: %s accepted the car from %s for %d (/accept car).",sendername,giveplayer,OwnableCarPrice[playerid]);
     							SendAdminMessage(COLOR_LIGHTRED, string);
								format(string, sizeof(string), "* %s has bought your car for $%d.",sendername,OwnableCarPrice[playerid]);
								SendClientMessage(OwnableCarOffer[playerid], COLOR_WHITE, string);
						    	RemovePlayerFromVehicle(OwnableCarOffer[playerid]);
						    	SafeGivePlayerMoney(playerid, - OwnableCarPrice[playerid]);
						    	SafeGivePlayerMoney(OwnableCarOffer[playerid], OwnableCarPrice[playerid]);
						    	strmid(CarInfo[OwnableCarID[playerid]][cOwner], sendername, 0, strlen(sendername), 999);
							}
						    else if(PlayerInfo[playerid][pPcarkey2] == -1)
							{
							    if(GetPlayerVehicleID(OwnableCarOffer[playerid]) == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey])
								{
									PlayerInfo[playerid][pPcarkey2] = OwnableCarID[playerid];
						    		PlayerInfo[OwnableCarOffer[playerid]][pPcarkey] = -1;
								}
								else if(GetPlayerVehicleID(OwnableCarOffer[playerid]) == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey2])
								{
									PlayerInfo[playerid][pPcarkey2] = OwnableCarID[playerid];
						    		PlayerInfo[OwnableCarOffer[playerid]][pPcarkey2] = -1;
								}
								else if(GetPlayerVehicleID(OwnableCarOffer[playerid]) == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey3])
								{
									PlayerInfo[playerid][pPcarkey2] = OwnableCarID[playerid];
						    		PlayerInfo[OwnableCarOffer[playerid]][pPcarkey3] = -1;
								}
								else
								{
								    SendClientMessage(playerid, COLOR_GREY, "  Vehicle seller needs to be at his car !");
									return 1;
								}
								format(string, sizeof(string), "* You bought a car for $%d from %s.",OwnableCarPrice[playerid],giveplayer);
								SendClientMessage(playerid, COLOR_WHITE, string);
								format(string, sizeof(string), "AdmWarning: %s had bought a car from %s for %d.",sendername, giveplayer, OwnableCarPrice[playerid]);
								format(string, sizeof(string), "* %s has bought your car for $%d.",sendername,OwnableCarPrice[playerid]);
								SendClientMessage(OwnableCarOffer[playerid], COLOR_WHITE, string);
						    	RemovePlayerFromVehicle(OwnableCarOffer[playerid]);
						    	SafeGivePlayerMoney(playerid, - OwnableCarPrice[playerid]);
						    	SafeGivePlayerMoney(OwnableCarOffer[playerid], OwnableCarPrice[playerid]);
						    	strmid(CarInfo[OwnableCarID[playerid]][cOwner], sendername, 0, strlen(sendername), 999);
							}
						    else if(PlayerInfo[playerid][pPcarkey3] == -1)
							{
							    if(GetPlayerVehicleID(OwnableCarOffer[playerid]) == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey])
								{
									PlayerInfo[playerid][pPcarkey3] = OwnableCarID[playerid];
						    		PlayerInfo[OwnableCarOffer[playerid]][pPcarkey] = -1;
								}
								else if(GetPlayerVehicleID(OwnableCarOffer[playerid]) == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey2])
								{
									PlayerInfo[playerid][pPcarkey3] = OwnableCarID[playerid];
						    		PlayerInfo[OwnableCarOffer[playerid]][pPcarkey2] = -1;
								}
								else if(GetPlayerVehicleID(OwnableCarOffer[playerid]) == PlayerInfo[OwnableCarOffer[playerid]][pPcarkey3])
								{
									PlayerInfo[playerid][pPcarkey3] = OwnableCarID[playerid];
						    		PlayerInfo[OwnableCarOffer[playerid]][pPcarkey3] = -1;
								}
								else
								{
								    SendClientMessage(playerid, COLOR_GREY, "  Vehicle seller needs to be at his car !");
									return 1;
								}
								format(string, sizeof(string), "* You bought a car for $%d from %s.",OwnableCarPrice[playerid],giveplayer);
								SendClientMessage(playerid, COLOR_WHITE, string);
								format(string, sizeof(string), "AdmWarning: %s had bought a car from %s for %d.",playername, giveplayer, OwnableCarPrice[playerid]);
								format(string, sizeof(string), "* %s has bought your car for $%d.",sendername,OwnableCarPrice[playerid]);
								SendClientMessage(OwnableCarOffer[playerid], COLOR_WHITE, string);
						    	RemovePlayerFromVehicle(OwnableCarOffer[playerid]);
						    	SafeGivePlayerMoney(playerid, - OwnableCarPrice[playerid]);
						    	SafeGivePlayerMoney(OwnableCarOffer[playerid], OwnableCarPrice[playerid]);
						    	strmid(CarInfo[OwnableCarID[playerid]][cOwner], sendername, 0, strlen(sendername), 999);
							}
						    else
						    {
						        SendClientMessage(playerid, COLOR_GREY, "  You already have 3 cars ! ");
						        return 1;
							}
						    DateProp(playerid);
							DateProp(OwnableCarOffer[playerid]);
							OnPropUpdate();
							OnPlayerUpdate(playerid);
							OnPlayerUpdate(OwnableCarOffer[playerid]);
						    OwnableCarOffer[playerid] = 999;
							OwnableCarID[playerid] = 0;
							OwnableCarPrice[playerid] = 0;
							GameTextForPlayer(playerid, "~w~Congratulations~n~Don't forget to /park it!", 5000, 3);
							SendClientMessage(playerid, COLOR_GRAD2, "Congratulations on your new purchase!");
							SendClientMessage(playerid, COLOR_GRAD2, "Type /carhelp to view the vehicle manual!");
							CarKeys(playerid);
							return 1;
						}
						else
						{
						    SendClientMessage(playerid, COLOR_GREY, "   Car seller is Offline !");
			        		return 1;
						}
			        }
			    }
			    else
			    {
			        SendClientMessage(playerid, COLOR_GREY, "   No-one offerd you any Ownable Car !");
			        return 1;
			    }
			}
Note: I receive no warnings or errors with the given code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)