SA-MP Forums Archive
Vehicle ownership - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Vehicle ownership (/showthread.php?tid=599957)



Vehicle ownership - rambalili2 - 01.02.2016

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;
        }
    } 



Re: Vehicle ownership - FunnyBear - 01.02.2016

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;
    }
}



Re: Vehicle ownership - DarkClone - 01.02.2016

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?


Re: Vehicle ownership - rambalili2 - 01.02.2016

I'll try both of your codes now thanks.


Re: Vehicle ownership - rambalili2 - 01.02.2016

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.


Re: Vehicle ownership - IzadorO - 01.02.2016

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.