How to detect the back of a vehicle
#1

I want to detect the back of a vehicle so I can make a command to put the cargo inside.


This is what I have to detect the job vehicle when entering:
Код:
for(new i; i < sizeof(meatcar); i++)
    {
	    if(vehicleid == meatcar[i])
	    {
	        if(PlayerInfo[playerid][Job] == 1)
	        {
				SendClientMessage(playerid, COLOR_WHITE, "Type /delivermeat to get started.");
			}
			else
			{
			    static
			    Float:x,
			    Float:y,
			    Float:z;

				GetPlayerPos(playerid, x, y, z);
				SetPlayerPos(playerid, x, y, z + 5);
			    SendClientMessage(playerid, COLOR_GREY, "This is a job vehicle and you don't have the job.");

			}
		}
	}
Reply
#2

Solved

Код:
stock IsPlayerInRangeOfVehicle(playerid, vehicleid, Float:Range)
{
    new Float:Pos[3];
	GetVehiclePos(vehicleid, Pos[0], Pos[1], Pos[2]);
	return IsPlayerInRangeOfPoint(playerid, Range, Pos[0], Pos[1], Pos[2]);
}
Reply
#3

That doesn't detect the back of the vehicle, it detects if a player is close (depends on the range you specify) of the center of a vehicle.

You can get the position of the vehicle's back with VEHICLE_MODEL_INFO_SIZE used in GetVehicleModelInfo and some calculations.
Reply
#4

Well, that worked for me xD
Reply
#5

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
Well, that worked for me xD
Spawn a bus, stand by its back. You'll see what I'm talking about.
Reply
#6

What SickAttack is saying is correct. Even though you think it's working, it's not.

Each vehicle will be a different length, and this code is only checking if you are "close" to the point... It's not finding the rear at all. You could go in forwards and it will trigger as well.

There's an include that has extra stats of vehicles, which would likely help out. Can't remember it but I think it may have been Emmets, but again, not sure on it.
Reply
#7

I got a snippet that does it, but you could at least try first.
Reply
#8

"back of a vehicle"

you mean trailer or xD?
Reply
#9

Quote:
Originally Posted by LondonRP
Посмотреть сообщение
"back of a vehicle"

you mean trailer or xD?
You can't be serious, the part where the trunk is xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)