PDA

View Full Version : Problem with lock/unlock system in personal vehicles (RPG)


sheNdjze
08/12/2016, 09:14 PM
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;
}

TheRohlikar
09/12/2016, 11:56 AM
Show us "Enter and Exit" vehicle...

sheNdjze
09/12/2016, 07:32 PM
i have nothing onplayerentervehicle and onplayerexitvehicle

TheRohlikar
09/12/2016, 09:33 PM
So ... how can you get somebody in the car without "unlocking" it ? O.o

sheNdjze
11/12/2016, 11:14 AM
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);
}
}
}
}

Logic_
11/12/2016, 11:41 AM
So much wrong with your code...
for(new v=0; v<MAX_PVEHS; v++)
use
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.