When I try /lock vehicle works fine but when i try /lock in near of other owned vehicles by others, it returns vehicle id -1(means no vehicle near)
PHP код:
CMD:lock(playerid,params[]){
new id,engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(DynamicVehicle[id][dvehicle_vehicle], engine, lights, alarm, doors, bonnet, boot, objective);
id = GetPlayerOwnVehicleID(playerid);
if(VehicleInfo[DynamicVehicle[id][dvehicle_vehicle]][vehicle_door]){
VehicleInfo[DynamicVehicle[id][dvehicle_vehicle]][vehicle_door] = 0;
GameTextForPlayer(playerid, "~g~UNLOCKED", 2000, 5);
}else{
VehicleInfo[DynamicVehicle[id][dvehicle_vehicle]][vehicle_door] = 1;
GameTextForPlayer(playerid, "~r~LOCKED", 2000, 5);
}
SetVehicleParamsEx(DynamicVehicle[id][dvehicle_vehicle], engine, lights, alarm, VehicleInfo[DynamicVehicle[id][dvehicle_vehicle]][vehicle_door], bonnet, boot, objective);
return 1;
}
PHP код:
GetPlayerOwnVehicleID(playerid, Float: range = 2.0)
{
new id = -1, Float: dist = range, Float: tempdist;
for(new i; i < MAX_PLAYER_VEHICLE; i++)
{
if(DynamicVehicle[i][dvehicle_owner]==PlayerInfo[playerid][pID]){
tempdist = GetPlayerDistanceFromPoint(playerid, DynamicVehicle[i][dvehicle_pos][0], DynamicVehicle[i][dvehicle_pos][1],DynamicVehicle[i][dvehicle_pos][2]);
if(tempdist > range) continue;
if(tempdist <= dist)
{
dist = tempdist;
id = i;
}
}
}
return id;
}