Vehicle ownership
#1

Hello, so i'm making a vehicleowner ship and i'm almost done, but now I have to do car permissions like if a player is not the vehicle owner he can't enter the car.

So i've messed with it around at "OnPlayerEnterVehicle" and I can't get it to work. does any of you guys have an idea of how I can make it working like car permissions /givekeys etc... i'm not asking for the code just an idea of how to get it to work.

EDIT: I've made this code so far but it doesn't work, I can't even access my own vehicle or any vehicle at the server.

New variables
PHP код:
new VehicleOwner[MAX_VEHICLES] = {INVALID_PLAYER_ID, ...};
new 
VehicleOwner1[MAX_VEHICLES] = {INVALID_PLAYER_ID, ...};
new 
VehicleOwner2[MAX_VEHICLES] = {INVALID_PLAYER_ID, ...}; 
OnPlayerEnterVehicle:
PHP код:
    for(new xMAX_VEHICLESx++)
    {
        if(
VehicleOwner[x] != playerid || VehicleOwner1[x] != playerid || VehicleOwner2[x] != playerid )
         {
            new 
tName[MAX_PLAYER_NAME], string[128], pID;
            
GetPlayerName(pIDtNameMAX_PLAYER_NAME);
            
format(stringsizeof(string), "This vehicle is owned by %s, you can't access it without hes permission"tName);
            
SendClientMessage(playeridREDstring);
            
ClearAnimations(playerid);
            break;
        }
    } 
Reply
#2

You're supposed to be comparing the name of the vehicle owner to the player's name, not their player ID. And next time, use strcmp to compare two strings together.

Код:
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
for(new x; x < MAX_VEHICLES; x++)
{
	if( strcmp(Name, VehicleOwner[x], true) != 0)
 	{
        new tName[MAX_PLAYER_NAME], string[128], pID;
        GetPlayerName(pID, tName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "This vehicle is owned by %s, you can't access it without hes permission", tName);
        SendClientMessage(playerid, RED, string);
        ClearAnimations(playerid);
        break;
    }
}
Reply
#3

Why are you looping through all vehicles when instead you could check the vehicle the player is currently entering from OnPlayerEnterVehicle?

Код:
if(VehicleOwner[x] != playerid || VehicleOwner1[x] != playerid || VehicleOwner2[x] != playerid )
That would mean they need to be set as VehicleOwner, VehicleOwner1 and VehicleOwner2 for it to pass.

Код:
if(VehicleOwner[x] != playerid && VehicleOwner1[x] != playerid && VehicleOwner2[x] != playerid )
Now if they're at least set as VehicleOwner, that would work I believe.

Replace

Код:
for(new x; x < MAX_VEHICLES; x++) 
    { 
        if(VehicleOwner[x] != playerid || VehicleOwner1[x] != playerid || VehicleOwner2[x] != playerid ) 
         { 
            new tName[MAX_PLAYER_NAME], string[128], pID; 
            GetPlayerName(pID, tName, MAX_PLAYER_NAME); 
            format(string, sizeof(string), "This vehicle is owned by %s, you can't access it without hes permission", tName); 
            SendClientMessage(playerid, RED, string); 
            ClearAnimations(playerid); 
            break; 
        } 
    }
with

Код:
if(VehicleOwner[vehicleid] != playerid && VehicleOwner1[vehicleid] != playerid && VehicleOwner2[vehicleid] != playerid )
{
    new tName[MAX_PLAYER_NAME], string[128], pID;
    GetPlayerName(pID, tName, MAX_PLAYER_NAME);
    format(string, sizeof(string), "This vehicle is owned by %s, you can't access it without hes permission", tName);
    SendClientMessage(playerid, RED, string);
    ClearAnimations(playerid);
    break;
}
Does that work?
Reply
#4

I'll try both of your codes now thanks.
Reply
#5

DarkClone your code did work, but still when I try to enter a spawned or a random vehicle that I didn't bought or towed it will not let me enter.
Reply
#6

You shouldn't base the owner off the player's name, but rather use their database ID, so you don't have to change the owner's name etc etc everytime a player name changes. Just a tip.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)