25.04.2010, 16:02
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 =)
Originally Posted by ♣ Joker ♠
Search - GetClosestVehicle - first result ...
|
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;
}
new closest_vehicle = GetClosestVehicle(playerid);
//with distance
new closest_vehicle, Float:distance;
closest_vehicle = GetClosestVehicle(playerid, distance);
Originally Posted by Seif_
Quote:
Quote:
|
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; }