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
#2

https://sampwiki.blast.hk/wiki/GetPlayerVehicleID
Reply
#3

Quote:
Originally Posted by willbedie
Посмотреть сообщение
I don't need nitro in static vehicle. I just want to edit the code. Read my post again please or explain more, what to do with given link?
Reply
#4

Who said you need intro? Try replacing GetClosestVehicle with GetPlayerVehicleID.
Reply
#5

Just remove "IsPlayerInRangeOfPoint" from "GetClosestVehicle", so you can lock / unlock the vehicle from a long distance.
Reply
#6

Quote:
Originally Posted by Undef1ned
Посмотреть сообщение
Just remove "IsPlayerInRangeOfPoint" from "GetClosestVehicle", so you can lock / unlock the vehicle from a long distance.
Why do that which might bug things, when he can do it in a totally different function?
Reply
#7

Yes I know. It can be done in a better way but its code is shit. "IsPlayerInRangeOfPoint", only executes the function if it is in that position. "GetPlayerVehicleID" Only detects if the player is inside a vehicle, and what he is asking is to be allowed to block / unlock from where the player is.

Edit: For your code to be well executed and optimized it would have to be done from 0. Basically your code does not work.
Reply
#8

Just noticed you're using "pragma unused params"

Why are you definding that? Do you even know what that does? In a way it hides the warnings you get from the compiler so even if there's warnings that might bug your gamemode that is going to hide it. Stop using that!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)