04.10.2012, 14:42
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:
Then in the Gamemodeinit add this, but make sure you edit it first orelse you will get warnings:
Add this stock anywhere..
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
and lock it for that player again with
Example on OnPlayerCommandText
The outcome is:
[ame]http://www.youtube.com/watch?v=YSe4l6ORlaM[/ame]
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;
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
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;
}
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;
pawn Code:
whatever[playerid] = 0;
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;
}
[ame]http://www.youtube.com/watch?v=YSe4l6ORlaM[/ame]