Anyone can park car ? Why ? Plz help
#1

Hello here is my /park code But anyone can park house car !!! I want this Only Owner can Park-
Here are the Functions -
For your Help i this is a Additional Code which Verify the Car Owner else it throw player out of the car-
Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
	// Setup local variables
	new vid, Name[24], Msg[128], engine, lights, alarm, doors, bonnet, boot, objective;

	// Check if the player became the driver of a vehicle
	if (newstate == PLAYER_STATE_DRIVER)
	{
		// Get the ID of the player's vehicle
		vid = GetPlayerVehicleID(playerid);
		// Get the player's name
		GetPlayerName(playerid, Name, sizeof(Name));

		// Check if the vehicle is owned
		if (AVehicleData[vid][Owned] == true)
		{
			// Check if the vehicle is owned by somebody else (strcmp will not be 0)
			if (strcmp(AVehicleData[vid][Owner], Name, false) != 0)
			{
				// Force the player out of the vehicle
				RemovePlayerFromVehicle(playerid);
				// Turn off the lights and engine
				GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
				SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
				// Let the player know he cannot use somebody else's vehicle
				format(Msg, 128, "{FF0000}You cannot use this vehicle, it's owned by \"{FFFF00}%s{FF0000}\"", AVehicleData[vid][Owner]);
				SendClientMessage(playerid, 0xFFFFFFFF, Msg);
			}
		}
	}

	return 1;
}

and finally my /park code -
Код:
COMMAND:park(playerid, params[])
{
	// Setup local variables
	new Float:x, Float:y, Float:z, Float:rot, vid, HouseID, Msg[128];
	new engine,lights,alarm,doors,bonnet,boot,objective;

	// If a player hasn't logged in properly, he cannot use this command
	if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;

	// Check if the player is inside a vehicle (he must be the driver)
	if (GetPlayerVehicleSeat(playerid) == 0)
	{
		// Get the vehicle-id
		vid = GetPlayerVehicleID(playerid);
		// Get the HouseID to which this vehicle belongs
		HouseID = AVehicleData[vid][BelongsToHouse];

		// Check if this vehicle belongs to a house (if not, the vehicle cannot be parked, as it's not a house-vehicle)
		if (HouseID != 0)
		{
			// Check if the vehicle is in range of the house-entrance (you cannot park a vehicle further away from your house than 150m)
			if (IsPlayerInRangeOfPoint(playerid, ParkRange, AHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ]))
			{
				// Get the player's position and angle
				GetVehiclePos(vid, x, y, z);
				GetVehicleZAngle(vid, rot);
				// Save those values for the vehicle
				AVehicleData[vid][SpawnX] = x;
				AVehicleData[vid][SpawnY] = y;
				AVehicleData[vid][SpawnZ] = z;
				AVehicleData[vid][SpawnRot] = rot;

				// Loop through all carslots of this house to find the vehicle-id
				for (new CarSlot; CarSlot < 10; CarSlot++)
				{
					// Check if this carslot holds the same vehicle-id
				    if (AHouseData[HouseID][VehicleIDs][CarSlot] == vid)
				    {
	                    House_ReplaceVehicle(HouseID, CarSlot); // Re-create the vehicle at the same spot the player wants to park his vehicle
	                    PutPlayerInVehicle(playerid, AHouseData[HouseID][VehicleIDs][CarSlot], 0);
						// Turn on the engine and lights
						GetVehicleParamsEx(AHouseData[HouseID][VehicleIDs][CarSlot], engine, lights, alarm, doors, bonnet, boot, objective);
						SetVehicleParamsEx(AHouseData[HouseID][VehicleIDs][CarSlot], 1, 1, alarm, doors, bonnet, boot, objective);
	                    break; // Stop the for-loop
					}
				}

				// Let the player know he parked his vehicle
				SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You've parked your vehicle");

				// Save the housefile
				HouseFile_Save(HouseID);
			}
			else
			{
			    format(Msg, 128, "{FF0000}You need to be within {FFFF00}%im{FF0000} of your house to park this vehicle", ParkRange);
			    SendClientMessage(playerid, 0xFFFFFFFF, Msg);
			}
		}
		else
		    SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot park a vehicle that's not owned by you");
	}
	else
	    SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You must be driving a vehicle you own to park it");

	// Let the server know that this was a valid command
	return 1;
}
Please Help-

Rep++ if you help me.
Reply
#2

Do you even check if the vehicle belongs to the player?
Otherwise everyone can park it.
Reply
#3

No,Just it Verifys the Name of Owner / Player.
See in the First Code....Make it pls
Reply
#4

Define the vehicleid to be GetPlayerVehicleID(playerid).
Then use an if to check if it's the player's vehicle, with the player variable you store the custom vehicle info in.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)