Closest Car and car id - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Closest Car and car id (
/showthread.php?tid=144055)
Closest Car and car id -
friped93 - 25.04.2010
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 =)
Re: Closest Car and car id -
Nero_3D - 25.04.2010
Search - GetClosestVehicle - first result ...
Re: Closest Car and car id -
friped93 - 25.04.2010
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 ''/
Re: Closest Car and car id -
Nero_3D - 25.04.2010
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);
Re: Closest Car and car id -
friped93 - 25.04.2010
and how does i get the id of it?
Re: Closest Car and car id -
friped93 - 25.04.2010
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
Re: Closest Car and car id -
friped93 - 25.04.2010
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;
}