11.09.2018, 19:35
I have a command /lock for locking vehicles and /unlock for unlocking the vehicles. The thing is, you have to be close to your vehicle to lock it or unlock it. I want to remove that in code so players will be able to lock their vehicles from 1000... meters away even from interiors. I tried to remove some lines but then i get bunch of errors.
Here is the code for locking the vehicle:
And this is the code for unlock the vehicle /unlock:
P.S. I don't want to use zcmd!
Here is the code for locking the vehicle:
PHP код:
dcmd_lk(playerid, params[])
{
dcmd_lock(playerid, params);
return 1;
}
dcmd_lock(playerid, params[])
{
#pragma unused params
if (PlayerInfo[playerid][pSpawn] == 1){
new PlayersInVehicle, string[256];
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
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 ++;
//RemovePlayerFromVehicle(i);
//format(string, sizeof(string), "%s Has Ejected You From The Vehicle.", PlayerStats[playerid][pName]);
//SendClientMessage(i, COLOR_ERROR, string);
//GameTextForPlayer(i,"~w~Ejected From Vehicle.",5000,4);
}
}
}
}
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 Float:x, Float:y, Float:z, closest = -1;
new closest = -1;
for(new v = 0; v < CurrentVehicleId; v++)
{
//GetVehiclePos(v, x, y, z);
//if(v != YOUR_VEHICLEID_OR_ARRAY/VARIBLE && IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
if(IsPlayerInRangeOfPoint(playerid, 2.0, CarInfo[v][cLocationX],CarInfo[v][cLocationY],CarInfo[v][cLocationZ]))
{
closest = v;
}
}
if(closest != -1) return closest;
return INVALID_VEHICLE_ID;
}
PHP код:
dcmd_ulk(playerid, params[])
{
dcmd_unlock(playerid, params);
return 1;
}
dcmd_unlock(playerid, params[])
{
#pragma unused params
if (PlayerInfo[playerid][pSpawn] == 1){
new PlayersInVehicle,string[256];
//if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
if(!IsPlayerInAnyVehicle(playerid))
{
new VehicleId = GetClosestVehicle(playerid);
if(VehicleId == INVALID_VEHICLE_ID)
{
SendClientMessage(playerid, COLOR_ERROR, "Your Not Close Enough To Disable Your Vehicles Alarm System.");
return 1;
}
for(new i = 0; i < GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i))
{
if (i != playerid)
{
if(IsPlayerInVehicle(i,VehicleId))
{
PlayersInVehicle ++;
//RemovePlayerFromVehicle(i);
//format(string, sizeof(string), "%s Has Ejected You From The Vehicle.", PlayerStats[playerid][pName]);
//SendClientMessage(i, COLOR_ERROR, string);
//GameTextForPlayer(i,"~w~Ejected From Vehicle.",5000,4);
}
}
}
}
if (PlayersInVehicle > 0)
{
SendClientMessage(playerid, COLOR_ERROR, "You Cannot UnLock A Vehicle While There Is A Player In It.");
return 1;
}
if (CarInfo[VehicleId][cOwned] != -1 && CarInfo[VehicleId][cOwned] != playerid)
{
SendClientMessage(playerid, COLOR_ERROR, "This Is Not Your Vehicle You Cannot UnLock It.");
return 1;
}
if (PlayerInfo[playerid][pCar] == 0)
{
SendClientMessage(playerid, COLOR_ERROR, "You must Own a Vehicle to Disable the Alarm System.");
return 1;
}
if (PlayerInfo[playerid][pCar] != VehicleId)
{
SendClientMessage(playerid, COLOR_ERROR, "You must Own a Vehicle to Disable the Alarm System.");
return 1;
}
if (CarInfo[VehicleId][cLock] == 0)
{
SendClientMessage(playerid, COLOR_ERROR, "The Alarm System is already Disabled 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 Disabled the Alarm System for this Vehicle.");
GameTextForPlayer(playerid,"~w~Alarm Disabled",5000,3);
CarInfo[VehicleId][cOwned] = -1;
CarInfo[VehicleId][cLock] = 0;
PlayerInfo[playerid][pCar] = 0;
format(string, sizeof(string), "No Owner");
strmid(CarInfo[CurrentVehicleId][cOwner], string, 0, strlen(string), 256);
}else
{
SendClientMessage(playerid, COLOR_ERROR, "You Cannot Disabled the Alarm from Inside the Vehicle.");
}
}else{
SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command When You're Dead.");
}
return 1;
}