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;
}
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;
}
hello i have /lock command to lock vehicle.
pawn Код:
i want to make it with out range of vehicle. code of closestvehicle pawn Код:
|
stock GetClosestCar(playerid, exception = INVALID_VEHICLE_ID) { new Float: Distance, target = -1, Float: vPos[3]; if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid, vPos[0], vPos[1], vPos[2]); else GetVehiclePos(GetPlayerVehicleID(playerid), vPos[0], vPos[1], vPos[2]); for(new v; v < MAX_VEHICLES; v++) if(GetVehicleModel(v) >= 400) { if(v != exception && (target < 0 || Distance > GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]))) { target = v; Distance = GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]); } } return target; }
native IsValidVehicle(vehicleid);//under includes on top of script THIS IS IMPORTANT
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 = PlayerInfo[playerid][pCar];
if(!IsValidVehicle(VehicleId))return SendClientMessage(playerid, COLOR_ERROR, "You dont own any vehicle");
for (new i = 0; i < GetMaxPlayers(); i++)
{
if (IsPlayerConnected(i))
{
if (i != playerid)
{
if (IsPlayerInVehicle(i,VehicleId))
{
PlayersInVehicle ++;
}
}
}
}
if (CarInfo[VehicleId][cLock] == 1)
{
SendClientMessage(playerid, COLOR_ERROR, "The Alarm is Already Activated on this Vehicle.");
return 1;
}
PlayerPlaySound(playerid, 1147, 0.0, 0.0, 0.0);
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;
}