[Tutorial] How to make a vehicle locked, and unlock it.
#1

Hello. Welcome to my second tutorial.

This time it's how to lock a vehicle for everybody, and unlock it with a /lock command.

This is just a basic code, you may need to script further on it if you want it into your liking.
The lock command will only unlock the vehicle for you.

On top of your script under the defines add this:
pawn Code:
new lockedvehicle[5];
new whatever[MAX_PLAYERS] = 0;
new status[MAX_PLAYERS] = 0;
Then in the Gamemodeinit add this, but make sure you edit it first orelse you will get warnings:

pawn Code:
lockedvehicle[0] = CreateVehicle(VEHICLEID, X, Y, Z, ROTATION, COLOR1, COLOR2, RESPAWNTIME); // defines locked vehicle number 1
    lockedvehicle[1] = CreateVehicle(VEHICLEID, X, Y, Z, ROTATION, COLOR1, COLOR2, RESPAWNTIME); // defines locked vehicle number 2
    lockedvehicle[2] = CreateVehicle(VEHICLEID, X, Y, Z, ROTATION, COLOR1, COLOR2, RESPAWNTIME); // defines locked vehicle number 3
    lockedvehicle[3] = CreateVehicle(VEHICLEID, X, Y, Z, ROTATION, COLOR1, COLOR2, RESPAWNTIME); // defines locked vehicle number 4
    lockedvehicle[4] = CreateVehicle(VEHICLEID, X, Y, Z, ROTATION, COLOR1, COLOR2, RESPAWNTIME); // defines locked vehicle number 5
Add this stock anywhere..
pawn Code:
stock IsALockedVehicle(vehicleid)
{
    for(new i;MAX_VEHICLES>i;i++)
    {
        if(vehicleid == lockedvehicle[i]) return 1;
    }
    return 0;
}
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(ispassenger) return 1;
    if(IsALockedVehicle(vehicleid)) // if is a locked vehicle
    {
        if(whatever[playerid] != 1) // what ever variable you need is not 1
        {
            new Float:x, Float:y, Float:z;
            SendClientMessage(playerid, -1, "You can't enter this vehicle.");
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z+0.5);
        }
    }
    return 1;
}
Now, whenever you try to enter that vehicle it will deny you and say it is locked.
To unlock it, make some sort or command or any other function to unlock it for only that player id with
pawn Code:
whatever[playerid] = 1;
and lock it for that player again with
pawn Code:
whatever[playerid] = 0;
Example on OnPlayerCommandText

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp("/lock", cmdtext, true, 5) == 0)
    {
        if(status[playerid] == 0)
        {
            whatever[playerid] = 1;
            status[playerid] = 1;
            SendClientMessage(playerid, -1, "Unlocked.");
            return 1;
        }
        if(status[playerid] == 1)
        {
            whatever[playerid] = 0;
            status[playerid] = 0;
            SendClientMessage(playerid, -1, "Locked.");
            return 1;
        }
        return 1;
    }
    return 0;
}
The outcome is:

[ame]http://www.youtube.com/watch?v=YSe4l6ORlaM[/ame]
Reply


Messages In This Thread
How to make a vehicle locked, and unlock it. - by Chriham3 - 04.10.2012, 14:42
Re: How to make a vehicle locked, and unlock it. - by ObieHZG - 04.10.2012, 15:32
Re: How to make a vehicle locked, and unlock it. - by xMCx - 04.10.2012, 16:49
Re: How to make a vehicle locked, and unlock it. - by CoDeZ - 04.10.2012, 21:02
Re: How to make a vehicle locked, and unlock it. - by Benzke - 05.10.2012, 03:42
Re: How to make a vehicle locked, and unlock it. - by TuFF12 - 08.11.2015, 17:04

Forum Jump:


Users browsing this thread: 1 Guest(s)