03.02.2015, 13:19
hello i have /lock command to lock vehicle.
problem is that its get closest vehicle and if 2 vehicles are at same position or distance it do not lock vehicle...
i want to make it with out range of vehicle.
code of closestvehicle
pawn Код:
COMMAND:lk(playerid, params[])
{
return cmd_lock(playerid, params);
}
COMMAND:lock(playerid, params[])
{
if (PlayerInfo[playerid][pSpawn] == 1)
{
new PlayersInVehicle, string[256];
if (!IsPlayerInAnyVehicle(playerid))
{
new VehicleId = GetClosestVehicle(playerid);
if (VehicleId == INVALID_VEHICLE_ID)
{
SendClientMessage(playerid, COLOR_ERROR, "Your Not Close Enough To Activate Your Vehicles Alarm System.");
return 1;
}
for (new i = 0; i < GetMaxPlayers(); i++)
{
if (IsPlayerConnected(i))
{
if (i != playerid)
{
if (IsPlayerInVehicle(i,VehicleId))
{
PlayersInVehicle ++;
}
}
}
}
if (PlayersInVehicle > 0)
{
SendClientMessage(playerid, COLOR_ERROR, "You Cannot Lock A Vehicle While There Is A Player In It.");
return 1;
}
if (CarInfo[VehicleId][cOwned] != -1 && CarInfo[VehicleId][cOwned] != playerid)
{
SendClientMessage(playerid, COLOR_ERROR, "You Must Own a Vehicle to Set the Alarm System.");
return 1;
}
if (PlayerInfo[playerid][pCar] == 0)
{
SendClientMessage(playerid, COLOR_ERROR, "You Must Own a Vehicle to Set the Alarm System.");
return 1;
}
if (PlayerInfo[playerid][pCar] != VehicleId)
{
SendClientMessage(playerid, COLOR_ERROR, "You Must Own a Vehicle to Set the Alarm System.");
return 1;
}
if (CarInfo[VehicleId][cLock] == 1)
{
SendClientMessage(playerid, COLOR_ERROR, "The Alarm is Already Activated on this Vehicle.");
return 1;
}
new Float:X, Float:Y, Float:Z;
PlayerPlaySound(playerid, 1147, X, Y, Z);
SendClientMessage(playerid, COLOR_SERVER_HELP_MSG, "You have Activated the Alarm System for this Vehicle.");
GameTextForPlayer(playerid,"~w~Alarm Activated",5000,3);
CarInfo[VehicleId][cOwned] = playerid;
CarInfo[VehicleId][cLock] = 1;
PlayerInfo[playerid][pCar] = VehicleId;
format(string, sizeof(string), "%s",PlayerInfo[playerid][pName]);
strmid(CarInfo[CurrentVehicleId][cOwner], string, 0, strlen(string), 256);
}
else
{
SendClientMessage(playerid, COLOR_ERROR, "You Cannot Activate the Alarm from Inside the Vehicle.");
}
}else{
SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command When You're Dead.");
}
return 1;
}
i want to make it with out range of vehicle.
code of closestvehicle
pawn Код:
stock GetClosestVehicle(playerid)
{
new closest = -1;
for (new v = 0; v < CurrentVehicleId; v++)
{
if (IsPlayerInRangeOfPoint(playerid, 5.0, CarInfo[v][cLocationX],CarInfo[v][cLocationY],CarInfo[v][cLocationZ]))
{
closest = v;
}
}
if (closest != -1) return closest;
return INVALID_VEHICLE_ID;
}