Checking if a player is near ANY vehicle. -
vIBIENNYx - 21.09.2012
So far I have this:
pawn Code:
command(vinteract, playerid, params[])
{
if(loggedin[playerid] == 0) return SendClientMessage(playerid, 0x66666666, "You must be logged in perform commands");
if(GetPlayerVehicleID(playerid) > 0)
{
if(GetPlayerVehicleSeat(playerid) == 0 || GetPlayerVehicleSeat(playerid) == 1)
{
ShowPlayerDialog(playerid, VEHINTERACTIONIN, DIALOG_STYLE_LIST, "Vehicle Interaction - Front Seat.", "> Engine (On/off)\n> Lights (On/Off)\n> Glovebox(Open/Close)\n> Bonnet(Open/Close)\n> Trunk(Open/Close)\n> Windows (Up/Down)", "Close", "");
}
else
{
ShowPlayerDialog(playerid, VEHINTERACTIONBACK, DIALOG_STYLE_LIST, "Vehicle Interaction - Back Seat.", "> Windows (Up/Down)", "Close", "");
}
}
else
{
/*if(IsPlayerInRangeOfAVehicle(playerid))
{
//ShowPlayerDialog(playerid, VEHINTERACTIONOUT, DIALOG_STYLE_LIST, "", dialog, "Close", "");
}
else
{
SendClientMessage(playerid, 0x66666666, "You must be near a vehicle");
}
*/
}
return 1;
}
I need to know how I can check if a player is within range of ANY vehicle in the server, and pick the closest one to him, any ideas how I can do this?
Re: Checking if a player is near ANY vehicle. -
C00K13M0N$73R - 21.09.2012
GetVehiclePos
IsPlayerInRangeOfPoint
Re: Checking if a player is near ANY vehicle. -
vIBIENNYx - 21.09.2012
Good point, I guess I could use a for loop, but what would be the best way to hold the floats and still gather the closest vehicle?
Re: Checking if a player is near ANY vehicle. -
Danyal - 21.09.2012
pawn Code:
forward GetClosestVehicle(carid);
public GetClosestVehicle(carid)
{
new x,Float:dis,Float:dis2,car;
car = 0;
dis = 99999.99;
for ( x = 0; x < MAX_VEHICLES; x++ )
{
if(x != carid)
{
dis2 = GetDistanceBetweenVehicles(x,carid);
if(dis2 < dis && dis2 < 8.0)
{
dis = dis2;
car = x;
}
}
}
return car;
}
i dont under your english becoz i am not good at english but i think you want that function...
Re: Checking if a player is near ANY vehicle. -
vIBIENNYx - 21.09.2012
Quote:
Originally Posted by Danyal
pawn Code:
forward GetClosestVehicle(carid); public GetClosestVehicle(carid) { new x,Float:dis,Float:dis2,car; car = 0; dis = 99999.99; for ( x = 0; x < MAX_VEHICLES; x++ ) { if(x != carid) { dis2 = GetDistanceBetweenVehicles(x,carid); if(dis2 < dis && dis2 < 8.0) { dis = dis2; car = x; } } } return car; }
i dont under your english becoz i am not good at english but i think you want that function...
|
Close, but it's from a standing player to a vehicle.
Re: Checking if a player is near ANY vehicle. -
milanosie - 21.09.2012
Untested, modify it to your liking to return 0 if dis > 10
pawn Code:
public GetClosestVehicleFromPlayer(playerid)
{
new Float:dis = 99999999.0;
new veh = -1;
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for(new i = 1; i < MAX_VEHICLES; i++)
{
new Float:distance = GetVehicleDistanceFromPoint(i, x, y, z);
if(distance < dis)
{
dis = distance;
veh = i;
}
}
return veh;
}
Re: Checking if a player is near ANY vehicle. -
vIBIENNYx - 21.09.2012
Quote:
Originally Posted by milanosie
Untested, modify it to your liking to return 0 if dis > 10
pawn Code:
public GetClosestVehicleFromPlayer(playerid) { new Float:dis = 99999999.0; new veh = -1; new Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z); for(new i = 1; i < MAX_VEHICLES; i++) { new Float:distance = GetVehicleDistanceFromPoint(i, x, y, z); if(distance < dis) { dis = distance; veh = i; } } return veh; }
|
Thank you, I'll edit it now :3