Check For Owner -
HondaCBR - 25.11.2011
When you buy a car a file is created YOURNAME.ini
this function checks if you are in your vehicle
pawn Код:
if(IsPlayerInVehicle(playerid, Vehicle090[playerid]))
And also inside the file YOURNAME.ini there is a line Owner=YOURNAME
Why is this not working?
pawn Код:
if(IsPlayerInVehicle(playerid, (Vehicle090[playerid],VehicleInfo[playerid][Owner])))
To check if you are the owner when you enter?
Re: Check For Owner -
Rob_Maate - 25.11.2011
Well that's easy.
IsPlayerInVehicle() requires you to give it two parameters.
1. playerid: The player you are actually checking against
2. vehicleid: The vehicle you are checking if the player is in
In YOUR code, you have not provided a vehicle ID, you have produced whatever
pawn Код:
(Vehicle090[playerid],VehicleInfo[playerid][Owner])
equals in pawno land.
You have made a terrible mistake in your code: VehicleInfo[playerid][owner] will not work.
You need to use VehicleInfo[<your vehicle id variable here>][Owner]
Also what is the point of Vehicle090[playerid]? What does it store?
Re: Check For Owner -
HondaCBR - 25.11.2011
Vehicle090 doesnt store anything, its just new Vehicle090[MAX_PLAYERS];
can you edit that code for me so it works?
Re: Check For Owner -
Rob_Maate - 25.11.2011
Well firstly, I need to know what variable stores the Vehicle's ID
can you post the surrounding code?
Re: Check For Owner -
HondaCBR - 25.11.2011
pawn Код:
enum cInfo
{
cModel,
Float:cLocX,
Float:cLocY,
Float:cLocZ,
Float:cAngle,
cColor1,
cColor2,
cOwner[MAX_PLAYER_NAME],
cDescription[128],
cValue,
cKomis,
cOwned,
cLock,
Float:cLocMainX,
Float:cLocMainY,
Float:cLocMainZ,
Float:cMainAngle,
cTune1,
cTune2,
cTune3,
cTune4,
cTune5,
cTune6,
cTune7,
cTune8,
cTune9,
cTune10,
cTune11,
cTune12,
cTune13,
cTune14,
cTune15,
cTune16,
cTune17,
};
new CarInfo[242][cInfo];
Re: Check For Owner -
Rob_Maate - 26.11.2011
This would work in both OnPlayerUpdate and OnPlayerStateChange
pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new CurrentDriver[64];
new CurrentVehicle;
GetPlayerName(playerid, CurrentDriver, sizeof(CurrentDriver);
CurrentVehicle = GetPlayerVehicleID(playerid);
if(strfind(CarInfo[CurrentVehicle][cOwner], CurrentDriver, true) != -1)
{
//This is where you place code affecting the owner of this vehicle
}
else
{
//This is where you place code affecting a player who entered the vehicle, but is NOT the owner
}
}
Untested - Sorry if I made any small errors
Re: Check For Owner -
HondaCBR - 26.11.2011
thx, could you also change it so the else bit only works for cars that have a file with playername in Cars folder? So it doesnt remove player from every vehicle.
Re: Check For Owner -
Rob_Maate - 26.11.2011
kk try this matey
I noticed you had cOwned as a variable as CarInfo. Provided that's set whenever a player purchases a car, this will work.
pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new CurrentDriver[64];
new CurrentVehicle;
GetPlayerName(playerid, CurrentDriver, sizeof(CurrentDriver);
CurrentVehicle = GetPlayerVehicleID(playerid);
if(CarInfo[CurrentVehicle][cOwned] == 1)
{
if(strfind(CarInfo[CurrentVehicle][cOwner], CurrentDriver, true) != -1)
{
//This is where you place code affecting the owner of this vehicle
return 1;
}
else
{
//This is where you place code affecting a player who entered the vehicle, but is NOT the owner
return 1;
}
}
else
{
//This will occur when a player enters a non-owned car.
return 1;
}
}
Re: Check For Owner -
HondaCBR - 26.11.2011
Right, I tested the code but whenever you enter as owner, notowner or enter other vehicle it goes through the last else, saying Other Car
pawn Код:
new CurrentDriver[64];
new CurrentVehicle;
GetPlayerName(playerid, CurrentDriver, sizeof(CurrentDriver));
CurrentVehicle = GetPlayerVehicleID(playerid);
if(VehicleInfo[CurrentVehicle][Owned] == 1)
{
if(strfind(VehicleInfo[CurrentVehicle][Owner], CurrentDriver, true) != -1)
{
SendClientMessage(playerid, COLOR_ORANGE, "Yours");
//This is where you place code affecting the owner of this vehicle
return 1;
}
else
{
SendClientMessage(playerid, COLOR_ORANGE, "Not yours.");
//This is where you place code affecting a player who entered the vehicle, but is NOT the owner
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_ORANGE, "Other Car.");
//This will occur when a player enters a non-owned car.
// return 1;
}
Just to let you know, I gave you wrong lines before it should be this, but I changed the code for this but it doesnt work. (Other Car Message whatever happens)
pawn Код:
enum car_info
{
Owner,
Owned
}
new VehicleInfo[MAX_PLAYERS][car_info];
And the file looks like this:
And inside the file
And also this is what I use to save/load the cars:
pawn Код:
new file[256], name[MAX_PLAYER_NAME];
GetPlayerName(OwnerID[vehicleid], name, sizeof(name));
format(file,sizeof(file),"Cars/%s.ini",name);
if(dini_Exists(file))