SA-MP Forums Archive
How to detect the back of a vehicle - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to detect the back of a vehicle (/showthread.php?tid=615983)



How to detect the back of a vehicle - AndreiWow - 29.08.2016

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.");

			}
		}
	}



Re: How to detect the back of a vehicle - AndreiWow - 29.08.2016

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]);
}



Re: How to detect the back of a vehicle - SickAttack - 29.08.2016

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.


Re: How to detect the back of a vehicle - AndreiWow - 30.08.2016

Well, that worked for me xD


Re: How to detect the back of a vehicle - SickAttack - 30.08.2016

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.


Re: How to detect the back of a vehicle - Sew_Sumi - 30.08.2016

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.


Re: How to detect the back of a vehicle - SickAttack - 30.08.2016

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


Re: How to detect the back of a vehicle - LondonRP - 30.08.2016

"back of a vehicle"

you mean trailer or xD?


Re: How to detect the back of a vehicle - SickAttack - 30.08.2016

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