Vehicle help
#1

I am creating a vehicle system, I have done everything until i somehow am stumped on this dealership thing.

I am trying to create a dealership where the cars are parked outside and you walk up to them, when you try to enter a textdraw opens asking the player to type 1 to buy and 2 to close the textdraw. when the player buys a vehicle any vehicle in the lot, the player always ends up buying the first car in the lot. I am using loops and i am having a difficult time getting the player to buy the correct car.

Here's is my script when the player tries to buy the car:
Код:
public OnPlayerText(playerid, text[])
{

    for(new idx=1; idx<MAX_CAR; idx++)
	{
	    new vehicleid;
		vehicleid = GetPlayerVehicleID(playerid);
  		    if(PlayerInfo[playerid][BuyCarMenu] == 1 && CarInfo[idx][cStatus] == 2)
  		    {
    			if(text[0] == '1') // Buy Car
				{
				    PutPlayerInVehicle(playerid, CarInfo[idx][cVID], 0);
				    new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
			    	SendClientMessage(playerid, COLOR_RED, "Enjoy your new vehicle");
			    	TextDrawHideForPlayer(playerid, BuyCar);
                    CarInfo[idx][cStatus] = 1;
		    		CarInfo[idx][cDealership] = 0;
    				GetPlayerName(playerid, name, sizeof(name));
		    		format(CarInfo[idx][cOwner], 32, "%s", name);
		    		format(string, sizeof(string), "License Plate Expired");
		    		Update3DTextLabelText(CarInfo[idx][Text3D:cText], COLOR_RED, "License Plate Expired");
	 			   	Attach3DTextLabelToVehicle(CarInfo[idx][Text3D:cText], CarInfo[idx][cVID], 0.0, 0.0, 2.0);
    				return 0;
				}
				if(text[0] == '2') // Close
				{
			    	TextDrawHideForPlayer(playerid, BuyCar);
			    	PlayerInfo[playerid][BuyCarMenu] = 0;
			    	return 0;
				}
		}
	
	}
}
If you need any other codes scriptlets to look at please let me know

Thank You
Reply
#2

If I were you, then I'd check the closest vehicle of a player:
pawn Код:
new
    vehicleid = GetClosestVehicle(playerid);

if (vehicleid != INVALID_VEHICLE_ID)
{
    // "vehicleid" stores the closest vehicle's ID.
}
pawn Код:
stock GetClosestVehicle(playerid)
{
    new
        vehicleid;
   
    if ((vehicleid = GetPlayerVehicleID(playerid))) return vehicleid;

    new
        Float: px,
        Float: py,
        Float: pz,
        Float: distance = 999.0,
        Float: tmp;
   
    vehicleid = INVALID_VEHICLE_ID;
    GetPlayerPos(playerid, px, py, pz);
    for (new v = 1; v != MAX_VEHICLES; ++v)
    {
        if ((tmp = GetVehicleDistanceFromPoint(v, px, py, pz)) < distance)
        {
            distance = tmp;
            vehicleid = v;
        }
    }
    return vehicleid;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)