Need help with /lock for character owned cars
#1

Okay, firstly thank you for reading. I have came across a big problem, me and a friend are working on a server and I found out that you cannot lock your vehicle. Basically when you do /v lock a message pops up saying that your vehicle is now "LOCKED" but anyone can still enter.

Here is the code I am using.

Код:
	        else if(strcmp(x_nr,"lock",true) == 0)
	        {
                new keycar = PlayerInfo[playerid][pPcarkey];
                if(keycar != 9999)
                {
                    new Float:X,Float:Y,Float:Z;
                    GetVehiclePos(keycar,X,Y,Z);
					if(IsPlayerInRangeOfPoint(playerid, 25,X,Y,Z))
					{
	                    new locked[128];
	                    locked = strtok(cmdtext, idx);
	                    if(CarInfo[keycar][cLock] == 1)
	                    {
							format(string, sizeof(string), "~w~Vehicle~n~~g~Unlocked");
							GameTextForPlayer(playerid, string, 4000, 3);
							CarInfo[keycar][cLock] = 0;
							OnPropUpdate(4,keycar);
							return 1;
						}
						else if(CarInfo[keycar][cLock] == 0)
						{
							format(string, sizeof(string), "~w~Vehicle~n~~r~Locked");
							GameTextForPlayer(playerid, string, 4000, 3);
							CarInfo[keycar][cLock] = 1;
							OnPropUpdate(4,keycar);
							return 1;
						}
					}
					else
					{
					    SendClientMessage(playerid, COLOR_GREY,"* You must be Near or in Your car to lock it!");
					    return 1;
					}
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "* You don't have a vehicle at slot 1");
                    return 1;
                }
	        }
	        else if(strcmp(x_nr,"lock2",true) == 0)
	        {
                new keycar = PlayerInfo[playerid][pPcarkey2];
                if(keycar != 9999)
                {
                    new Float:X,Float:Y,Float:Z;
                    GetVehiclePos(keycar,X,Y,Z);
					if(IsPlayerInRangeOfPoint(playerid, 25,X,Y,Z))
					{
	                    new locked[128];
	                    locked = strtok(cmdtext, idx);
	                    if(CarInfo[keycar][cLock] == 1)
	                    {
							format(string, sizeof(string), "~w~Vehicle~n~~g~Unlocked");
							GameTextForPlayer(playerid, string, 4000, 3);
							CarInfo[keycar][cLock] = 0;
							OnPropUpdate(4,keycar);
							return 1;
						}
						else if(CarInfo[keycar][cLock] == 0)
						{
							format(string, sizeof(string), "~w~Vehicle~n~~r~Locked");
							GameTextForPlayer(playerid, string, 4000, 3);
							CarInfo[keycar][cLock] = 1;
							OnPropUpdate(4,keycar);
							return 1;
						}
					}
					else
					{
					    SendClientMessage(playerid, COLOR_GREY,"* You must be Near or in Your car to lock it!");
					    return 1;
					}
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "  You don't have a vehicle at slot 2");
                    return 1;
                }
	        }
Also if anyone could help me with this I would be greatful.
Reply
#2

You locked it through your own functions/variables. You need to set the car to locked with the SAMP function (which I forgot it.)

Or, use OnPlayerEnterVehicle.

When the player enters the vehicle & if it's locked, slap them or something,
Reply
#3

Not exactly sure what you mean by "SAMP function" but I think you mean a proper SAMP method?

I'm kind of new to SAMP scripting so I wouldn't exactly know where to start
Reply
#4

There's a SAMP Method/Function that you can call which'll lock that vehicle, yes.

my /v lock uses this:
https://sampwiki.blast.hk/wiki/SetVehicleParamsForPlayer
Reply
#5

I'll work from the wiki base, I might be asking for too much but could you PM me your /v lock command just so I know what I'm dealing with? If no that's fine I just wanna have a look
Reply
#6

pawn Код:
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),playerid,0,1);
next create a variable called LastCar[MAX_PLAYERS]; then within that command LastCar[playerid] = GetPlayerVehicleID(playerid);

next in OnPlayerEnterVehicle
if(LastCar[playerid] == vehicleid)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playe rid),playerid,0,0);
}
Reply
#7

pawn Код:
else if(!strcmp(x_vehicle, "lock",true))
            {
                if(ProxDetectorV(10, playerid, PlayerInfo[playerid][pCarKey]))
                {
                    if(VehicleInfo[PlayerInfo[playerid][pCarKey]][vLock])
                    {
                        VehicleInfo[PlayerInfo[playerid][pCarKey]][vLock] = 0;
                        UnLockCar(PlayerInfo[playerid][pCarKey]);
                        new str[256];
                        SetVehicleParamsForPlayer(PlayerInfo[playerid][pCarKey],playerid,0,0);
                        format(str, sizeof(str), "~b~%s ~n~~g~Unlocked", VehicleNames[GetVehicleModel(PlayerInfo[playerid][pCarKey])-400]);
                        GameTextForPlayer(playerid, str, 2000, 4);
                    }
                    else
                    {
                        VehicleInfo[PlayerInfo[playerid][pCarKey]][vLock] = 1;
                        PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                        LockCar(PlayerInfo[playerid][pCarKey]);
                        new str[256];
                        SetVehicleParamsForPlayer(PlayerInfo[playerid][pCarKey],playerid,0,1);
                        format(str, sizeof(str), "~b~%s ~n~~r~Locked", VehicleNames[GetVehicleModel(PlayerInfo[playerid][pCarKey])-400]);
                        GameTextForPlayer(playerid, str, 2000, 4);
                    }
Reply
#8

This is quite confusing I don't understand, I went onto the Wiki and I am really lost right now. @Kamzaf I tried following your steps but failed miserably.
Reply
#9

for now just add
Код:
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),playerid,0,1);
to lock your vehicle and

Код:
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),playerid,0,0);
to unlock.
Reply
#10

Quote:

else if(strcmp(x_nr,"lock",true) == 0)
{
new keycar = PlayerInfo[playerid][pPcarkey];
if(keycar != 9999)
{
new Float:X,Float:Y,Float:Z;
GetVehiclePos(keycar,X,Y,Z);
if(IsPlayerInRangeOfPoint(playerid, 25,X,Y,Z))
{
new locked[128];
locked = strtok(cmdtext, idx);
if(CarInfo[keycar][cLock] == 1)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playe rid),playerid,0,0);
format(string, sizeof(string), "~w~Vehicle~n~~g~Unlocked");
GameTextForPlayer(playerid, string, 4000, 3);
CarInfo[keycar][cLock] = 0;
OnPropUpdate(4,keycar);
return 1;
}
else if(CarInfo[keycar][cLock] == 0)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playe rid),playerid,0,1);
LastCar[playerid] = GetPlayerVehicleID(playerid);
format(string, sizeof(string), "~w~Vehicle~n~~r~Locked");
GameTextForPlayer(playerid, string, 4000, 3);
CarInfo[keycar][cLock] = 1;
OnPropUpdate(4,keycar);
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY,"* You must be Near or in Your car to lock it!");
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "* You don't have a vehicle at slot 1");
return 1;
}
}

This is what the code looks like but it doesn't do anything
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)