Checking if a player is close to car. - 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: Checking if a player is close to car. (
/showthread.php?tid=291536)
Checking if a player is close to car. -
Supercop - 20.10.2011
Okay so, I know how to check if a player is in a certain radius to a certain location, but how can I make that a command is only availeble when the player is at a certain car?
With "certain car" it has to be at one car model, so any car model of the SFPD cruiser.
Thanks,
Re: Checking if a player is close to car. -
Stigg - 20.10.2011
Try using:
pawn Код:
stock GetClosestVehicle(playerid, Float:dis)
{
new Float:X, Float:Y, Float:Z;
if(GetPlayerPos(playerid, X, Y, Z))
{
new vehicleid = INVALID_VEHICLE_ID;
for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
{
if(GetVehiclePos(v, VX, VY, VZ))
{
VX -= X, VY -= Y, VZ -= Z;
temp = VX * VX + VY * VY + VZ * VZ;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 0.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}
Adjust to suit your needs.
Re: Checking if a player is close to car. -
Supercop - 20.10.2011
Thanks.
What do I add in the actually command?
Re: Checking if a player is close to car. -
Supercop - 20.10.2011
By that, GetClosestVehicle I got already in my script.
pawn Код:
stock GetClosestVehicle(playerid)
{
if(IsPlayerConnected(playerid) && IsVehicleConnected(0))
{
new closestvehicle=0;
new Float:closestdist=GetDistanceToVehicle(playerid,0);
for(new vehicleid=0; vehicleid<MAX_VEHICLES; vehicleid++)
{
new Float:dist = GetDistanceToVehicle(playerid,vehicleid);
if ((dist < closestdist))
{
closestdist = dist;
closestvehicle = vehicleid;
}
}
return closestvehicle;
}
return -1;
}
Re: Checking if a player is close to car. -
Supercop - 20.10.2011
Third page bump
Re: Checking if a player is close to car. -
=WoR=Varth - 20.10.2011
https://sampwiki.blast.hk/wiki/GetVehicleModel
Re: Checking if a player is close to car. -
Supercop - 21.10.2011
I need to check if the player is CLOSE TO a vehicle, not if he's inside of it.