Vehicle Central Lock
#1

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:
PHP код:
dcmd_lk(playeridparams[])
{
    
dcmd_lock(playeridparams);
    return 
1;
}
dcmd_lock(playeridparams[])
{
    
#pragma unused params
    
if (PlayerInfo[playerid][pSpawn] == 1){
    new 
PlayersInVehiclestring[256];
    if(
GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
    if(!
IsPlayerInAnyVehicle(playerid))
    {
            new 
VehicleId GetClosestVehicle(playerid);
            if(
VehicleId == INVALID_VEHICLE_ID)
            {
            
SendClientMessage(playeridCOLOR_ERROR"Your Not Close Enough To Activate Your Vehicles Alarm System.");
            return 
1;
            }
            for(new 
0GetMaxPlayers(); i++)
            {
                if(
IsPlayerConnected(i))
            {
                    if (
!= 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(playeridCOLOR_ERROR"You Cannot Lock A Vehicle While There Is A Player In It.");
            return 
1;
            }
            if (
CarInfo[VehicleId][cOwned] != -&& CarInfo[VehicleId][cOwned] != playerid)
            {
            
SendClientMessage(playeridCOLOR_ERROR"You Must Own a Vehicle to Set the Alarm System.");
            return 
1;
            }
            if (
PlayerInfo[playerid][pCar] == 0)
            {
            
SendClientMessage(playeridCOLOR_ERROR"You Must Own a Vehicle to Set the Alarm System.");
            return 
1;
            }
            if (
PlayerInfo[playerid][pCar] != VehicleId)
            {
            
SendClientMessage(playeridCOLOR_ERROR"You Must Own a Vehicle to Set the Alarm System.");
            return 
1;
            }
            if (
CarInfo[VehicleId][cLock] == 1)
            {
            
SendClientMessage(playeridCOLOR_ERROR"The Alarm is Already Activated on this Vehicle.");
            return 
1;
            }
            new 
Float:XFloat:YFloat:Z;
            
PlayerPlaySound(playerid1147XYZ);
            
SendClientMessage(playeridCOLOR_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(stringsizeof(string), "%s",PlayerInfo[playerid][pName]);
            
strmid(CarInfo[CurrentVehicleId][cOwner], string0strlen(string), 256);
    }else
    {
    
SendClientMessage(playeridCOLOR_ERROR"You Cannot Activate the Alarm from Inside the Vehicle.");
    }
    }else{
    
SendClientMessage(playeridCOLOR_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 
0CurrentVehicleIdv++)
    {
        
//GetVehiclePos(v, x, y, z);
        //if(v != YOUR_VEHICLEID_OR_ARRAY/VARIBLE && IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
        
if(IsPlayerInRangeOfPoint(playerid2.0CarInfo[v][cLocationX],CarInfo[v][cLocationY],CarInfo[v][cLocationZ]))
        {
        
closest v;
        }
    }
    if(
closest != -1) return closest;
    return 
INVALID_VEHICLE_ID;

And this is the code for unlock the vehicle /unlock:

PHP код:
dcmd_ulk(playeridparams[])
{
    
dcmd_unlock(playeridparams);
    return 
1;
}
dcmd_unlock(playeridparams[])
{
    
#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(playeridCOLOR_ERROR"Your Not Close Enough To Disable Your Vehicles Alarm System.");
            return 
1;
            }
            for(new 
0GetMaxPlayers(); i++)
            {
                if(
IsPlayerConnected(i))
                {
                    if (
!= 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(playeridCOLOR_ERROR"You Cannot UnLock A Vehicle While There Is A Player In It.");
            return 
1;
            }
            if (
CarInfo[VehicleId][cOwned] != -&& CarInfo[VehicleId][cOwned] != playerid)
            {
            
SendClientMessage(playeridCOLOR_ERROR"This Is Not Your Vehicle You Cannot UnLock It.");
            return 
1;
            }
            if (
PlayerInfo[playerid][pCar] == 0)
            {
            
SendClientMessage(playeridCOLOR_ERROR"You must Own a Vehicle to Disable the Alarm System.");
            return 
1;
            }
            if (
PlayerInfo[playerid][pCar] != VehicleId)
            {
            
SendClientMessage(playeridCOLOR_ERROR"You must Own a Vehicle to Disable the Alarm System.");
            return 
1;
            }
            if (
CarInfo[VehicleId][cLock] == 0)
            {
            
SendClientMessage(playeridCOLOR_ERROR"The Alarm System is already Disabled on this Vehicle.");
            return 
1;
            }
            new 
Float:XFloat:YFloat:Z;
            
PlayerPlaySound(playerid1147XYZ);
            
SendClientMessage(playeridCOLOR_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(stringsizeof(string), "No Owner");
            
strmid(CarInfo[CurrentVehicleId][cOwner], string0strlen(string), 256);
    }else
    {
    
SendClientMessage(playeridCOLOR_ERROR"You Cannot Disabled the Alarm from Inside the Vehicle.");
    }
    }else{
    
SendClientMessage(playeridCOLOR_ERROR"You Cannot Use This Command When You're Dead.");
    }
    return 
1;

P.S. I don't want to use zcmd!
Reply


Messages In This Thread
Vehicle Central Lock - by DarknesS1988 - 11.09.2018, 19:35
Re: Vehicle Central Lock - by solstice_ - 11.09.2018, 19:38
Re: Vehicle Central Lock - by DarknesS1988 - 11.09.2018, 20:05
Re: Vehicle Central Lock - by solstice_ - 11.09.2018, 20:08
Re: Vehicle Central Lock - by Undef1ned - 11.09.2018, 20:30
Re: Vehicle Central Lock - by solstice_ - 11.09.2018, 21:29
Re: Vehicle Central Lock - by Undef1ned - 11.09.2018, 21:40
Re: Vehicle Central Lock - by solstice_ - 11.09.2018, 21:46

Forum Jump:


Users browsing this thread: 1 Guest(s)