Closest Car and car id
#1

Hello. I got a small problem to find the command that works that gives the the closest car and its id can some one please post a link or the code here =)
Reply
#2

Search - GetClosestVehicle - first result ...
Reply
#3

Quote:
Originally Posted by ♣ Joker ♠
Search - GetClosestVehicle - first result ...

ive tried that one and it didnt work for me ''/ or is it jsut that i dont understand how it shall work ''/
Reply
#4

I think he wanted a GetClosestVehicle not IsVehicleInRangeOfPoint

so here a GetClosestVehicle function with distance parameter
pawn Код:
stock GetClosestVehicle(playerid, &Float:dis = (Float:0x7F800000))
{
  dis = (Float:0x7F800000);
  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;
}
and the usage
pawn Код:
new closest_vehicle = GetClosestVehicle(playerid);
pawn Код:
//with distance
new closest_vehicle, Float:distance;
closest_vehicle = GetClosestVehicle(playerid, distance);
Reply
#5

and how does i get the id of it?
Reply
#6

Quote:
Originally Posted by Seif_
Quote:
Originally Posted by | Friped |
and how does i get the id of it?
Quote:
Originally Posted by ♣ Joker ♠
and the usage
pawn Код:
new closest_vehicle = GetClosestVehicle(playerid);
pawn Код:
//with distance
new closest_vehicle, Float:distance;
closest_vehicle = GetClosestVehicle(playerid, distance);
i dont get it O.o
Reply
#7

I just say i dont get one of them to work for me :S




code can some one see whats wrong and help me out. HE shall be out side car.

Код:
dcmd_vlock(playerid,params[])
{
	new Float:x, Float:y, Float:z;
  for(new v; v < MAX_VEHICLES; v++)
  {
  GetVehiclePos(v, x, y, z);
  	if(IsPlayerInRange(playerid,10.0,10.0,x,y,z)) return SendClientMessage(playerid, Yellow, "FAIL: You're not close a vehicle.");
	new file[128];
	format(file,sizeof(file),"cars/%d.cfg",v);
  	if(udb_hash(dini_Get(file,"OWNER")) != udb_hash(PlayerName(playerid))) return SendClientMessage(playerid, Yellow, "FAIL: You're not the owner of the vehicle.");
	else
	{
  new text[128];
	format(text,sizeof(text),"*%s picks up his keys and locks the vehicle",PlayerName(playerid));
	dini_IntSet(file,"LOCK",1);
	GetPlayerPos(playerid, x, y, z);
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	SetVehicleParamsForPlayer(v,i,0,1);
  iVehicle[GetPlayerVehicleID(playerid)][0] = 1;
	if(IsPlayerInRange(i,10.0,10.0,x,y,z))
	{
	SendClientMessage(i, Purple, text);
	}
  }
	}
	}
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)