Locking Vehicles
#1

Hey there, so I'm wanting to lock a particular Vehicle: LSPD Cruiser to a particular group.
Meaning that civilians can't hijack LSPD Cruiser Vehicles and only members apart of that group can use them.
If anyone can help me do that it'd be greatly appreciated!

(Vortex Roleplay 1 Gamemode Script)

LSPD Group Variable:
pawn Код:
if(Groups[Player[playerid][Group]][CommandTypes] == 1)
Reply
#2

Here you go man.

Код:
stock IsACopCar(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 523,427,528,596,598,597,599,601,497,430: return 1;
    }
    return 0;
}


public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(IsACopCar(vehicleid) && !ispassenger)
	{
             if(Groups[Player[playerid][Group]][CommandTypes] == 1)
	    {
                        SendClientMessage(playerid, -1, "You are not a cop!");
			ClearAnimations(playerid);
		}
	}
}
This isn't actually "locking" them, but disabling them for use. If you wanted to lock them and only allow cops to unlock it that's a pretty simple function just use GetVehicleParamsEx and SetVehicleParamsEx but players will be able to drive the vehicle if it's unlocked.
Reply
#3

Quote:
Originally Posted by Divergent
Посмотреть сообщение
Here you go man.

Код:
stock IsACopCar(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 523,427,528,596,598,597,599,601,497,430: return 1;
    }
    return 0;
}


public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(IsACopCar(vehicleid) && !ispassenger)
	{
             if(Groups[Player[playerid][Group]][CommandTypes] == 1)
	    {
                        SendClientMessage(playerid, -1, "You are not a cop!");
			ClearAnimations(playerid);
		}
	}
}
This isn't actually "locking" them, but disabling them for use. If you wanted to lock them and only allow cops to unlock it that's a pretty simple function just use GetVehicleParamsEx and SetVehicleParamsEx but players will be able to drive the vehicle if it's unlocked.
Firstly, thankyou very much for helping me here. I appreciate it a lot.
Next I have a couple questions as I'm very new to pawno scripting.

1. Where do I put the stock IsACopCar(vehicleid) etc..?
2. How do I add the OnPlayerEnterVehicle... etc to my current one which is this:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if (GetPlayerSurfingVehicleID(playerid) == vehicleid)
    {
        ClearAnimations(playerid);
    }

    new model = GetVehicleModel(vehicleid);
    if(model == 596)
    {
        Player[playerid][GotInCopCar]++;
        ResetPlayerWeapons(playerid);
        GivePlayerSavedWeapons(playerid);
    }
    return 1;
}
Reply
#4

The stock is a function, meaning you can put it anywhere you want in the script (just not inside of another function or brackets or anything and make sure it's after the #includes).


To add the code to what you already have you can just add it to the bottom.

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if (GetPlayerSurfingVehicleID(playerid) == vehicleid)
    {
        ClearAnimations(playerid);
    }

    new model = GetVehicleModel(vehicleid);
    if(model == 596)
    {
        Player[playerid][GotInCopCar]++;
        ResetPlayerWeapons(playerid);
        GivePlayerSavedWeapons(playerid);
    }

	if(IsACopCar(vehicleid) && !ispassenger)
	{
 		if(Groups[Player[playerid][Group]][CommandTypes] == 1)
	    {
			SendClientMessage(playerid, -1, "You are not a cop!");
			ClearAnimations(playerid);
		}
	}
    return 1;
}
Reply
#5

Quote:
Originally Posted by Divergent
Посмотреть сообщение
The stock is a function, meaning you can put it anywhere you want in the script (just not inside of another function or brackets or anything and make sure it's after the #includes).


To add the code to what you already have you can just add it to the bottom.

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if (GetPlayerSurfingVehicleID(playerid) == vehicleid)
    {
        ClearAnimations(playerid);
    }

    new model = GetVehicleModel(vehicleid);
    if(model == 596)
    {
        Player[playerid][GotInCopCar]++;
        ResetPlayerWeapons(playerid);
        GivePlayerSavedWeapons(playerid);
    }

	if(IsACopCar(vehicleid) && !ispassenger)
	{
 		if(Groups[Player[playerid][Group]][CommandTypes] == 1)
	    {
			SendClientMessage(playerid, -1, "You are not a cop!");
			ClearAnimations(playerid);
		}
	}
    return 1;
}
This made it back the front, cops can't enter the lspd cruisers but civilians can? :/
Reply
#6

My bad, simple fix though.


Код:
if(Groups[Player[playerid][Group]][CommandTypes] != 1)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)