Problem with lock/unlock system in personal vehicles (RPG)
#1

Hello i'm curently working on a system for my private vehicles and i tried to make when i lock my car if i'm the owner i don't need it to unlock it when i press 'F' to get in it and a normal player can't do that only the owner so i tried something but when it's locked for the first time it's working to get in the car but after i exit the car and it's still locked i can't get it in car anymore only if i unlock it. Here i'll put the Lock and unlock function.

Код:
if (newkeys & KEY_NO)
   {
        if(SwitchKey[playerid] == 1)
        {
			new string[100];
			for(new v=0; v<MAX_PVEHS; v++)
			{
   				if(CheckPlayerDistanceToVehicle(3.0, playerid, personalcar[v][playerid]))
				{
	 				if(CarInfo[OwnedVeh(personalcar[v][playerid])][cLock] == 1)
		  			{
   						GetVehicleParamsEx(personalcar[v][playerid],engine,lights,alarm,doors,bonnet,boot,objective);
	  	    			SetVehicleParamsEx(personalcar[v][playerid],engine,lights,alarm,0,bonnet,boot,objective);
						format(string, sizeof(string), "~h~%s~n~~g~Unlocked",CarInfo[OwnedVeh(personalcar[v][playerid])][cDescription]);
						GameTextForPlayer(playerid, string, 4000, 4);
						PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
						CarInfo[OwnedVeh(personalcar[v][playerid])][cLock] = 0;
						SetVehicleParamsForPlayer(personalcar[v][playerid],playerid,0,0);
						gCarLock[personalcar[v][playerid]] = 0;
						vUpdate(OwnedVeh(personalcar[v][playerid]), cLockx); //
						return 1;
					}
					else if(CarInfo[OwnedVeh(personalcar[v][playerid])][cLock] == 0)
					{
 						GetVehicleParamsEx(personalcar[v][playerid],engine,lights,alarm,doors,bonnet,boot,objective);
	    				SetVehicleParamsEx(personalcar[v][playerid],engine,lights,alarm,1,bonnet,boot,objective);
						format(string, sizeof(string), "~h~%s~n~~r~Locked",CarInfo[OwnedVeh(personalcar[v][playerid])][cDescription]);
						GameTextForPlayer(playerid, string, 4000, 4);
						PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
						SetVehicleParamsForPlayer(personalcar[v][playerid],playerid,0,0);
						CarInfo[OwnedVeh(personalcar[v][playerid])][cLock] = 1;
						gCarLock[personalcar[v][playerid]] = 1;
						vUpdate(OwnedVeh(personalcar[v][playerid]), cLockx); //
     					return 1;
					}
				}
			}
			return 1;
        }
Reply
#2

Show us "Enter and Exit" vehicle...
Reply
#3

i have nothing onplayerentervehicle and onplayerexitvehicle
Reply
#4

So ... how can you get somebody in the car without "unlocking" it ? O.o
Reply
#5

I did some fixes but when i exit the veh it unlocks for all players but is say it's locked.

Код:
	new
    engine ,lights ,alarm ,bonnet ,boot ,objective;
    for(new v=0; v<MAX_PVEHS; v++)
    {
    if(OwnedVeh(personalcar[v][playerid]))
    {
    if(personalcar[v][playerid] != 0 && CarInfo[OwnedVeh(personalcar[v][playerid])][cLock] == 1)
    {
    SetVehicleParamsEx(personalcar[v][playerid],engine,lights,alarm,0,bonnet,boot,objective);//AICI AM RAMAS
    }
    else if(PlayerInfo[playerid][pPcarkey] == 0 && PlayerInfo[playerid][pmotokey] == 0 && PlayerInfo[playerid][phelikey] == 0 && PlayerInfo[playerid][pprcarkey] == 0 && PlayerInfo[playerid][pprcarkey2] == 0 && PlayerInfo[playerid][pPPluscarkey] == 0
	&& PlayerInfo[playerid][pPPluscarkey2] == 0 && PlayerInfo[playerid][pPPluscarkey3] == 0 && PlayerInfo[playerid][pPPluscarkey4] == 0 && PlayerInfo[playerid][pPPluscarkey5] == 0 && PlayerInfo[playerid][pPPluscarkey6] == 0)
    {
    if(personalcar[v][playerid] != 0 && CarInfo[OwnedVeh(personalcar[v][playerid])][cLock] == 1)
    {
    SetVehicleParamsEx(personalcar[v][playerid],engine,lights,alarm,1,bonnet,boot,objective);
    }
    }
    }
    }
Reply
#6

So much wrong with your code...
Quote:

for(new v=0; v<MAX_PVEHS; v++)

use
Quote:

for(new v, vv = GetVehiclePoolSize(); v <= vv; v++)

and then check for valid vehicle

Indentation is not perfect/ good.
Use logic, think how the function should work and how the code can work.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)