Okay i still couldn't figure out the problem but when i tried to put this in OnPlayerState i enter Car ID 1 and it says Turismo Bought by me (ID 0) and it says ID 0 infernus Price : 100 ( ID 1 )
So I'm posting my car system (very similar to my house system) if you see the problem please tell me
pawn Код:
enum CarSystem
{
cDescription[128],
cOwner[MAX_PLAYER_NAME],
Float:cX,
Float:cY,
Float:cZ,
Float:cAngle,
cOwned,
cPrice,
cLocked,
cCarID,
cModel,
cCol1,
cCol2,
};
new Cars[2][CarSystem]; // ENUM
pawn Код:
forward LoadCars();
forward SaveCars(); // FORWARDS
pawn Код:
public SaveCars()
{
new idx;
new File: file2;
while (idx < sizeof(Cars))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%s|%s|%d|%f|%f|%f|%f|%d|%d|%d|%d|%d|%d\n",
Cars[idx][cDescription],
Cars[idx][cOwner],
Cars[idx][cModel],
Cars[idx][cX],
Cars[idx][cY],
Cars[idx][cZ],
Cars[idx][cAngle],
Cars[idx][cOwned],
Cars[idx][cPrice],
Cars[idx][cLocked],
Cars[idx][cCarID],
Cars[idx][cCol1],
Cars[idx][cCol2]);
if(idx == 0)
{
file2 = fopen("Cars/cars.cfg", io_write);
}
else
{
file2 = fopen("Cars/cars.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}
public LoadCars()
{
new arrCoords[13][64];
new strFromFile2[256];
new File: file = fopen("Cars/cars.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(Cars))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, '|');
strmid(Cars[idx][cDescription], arrCoords[0], 0, strlen(arrCoords[0]), 255);
strmid(Cars[idx][cOwner], arrCoords[1], 0, strlen(arrCoords[1]), 255);
Cars[idx][cModel] = strval(arrCoords[2]);
Cars[idx][cX] = floatstr(arrCoords[3]);
Cars[idx][cY] = floatstr(arrCoords[4]);
Cars[idx][cZ] = floatstr(arrCoords[5]);
Cars[idx][cAngle] = floatstr(arrCoords[6]);
Cars[idx][cOwned] = strval(arrCoords[7]);
Cars[idx][cPrice] = strval(arrCoords[8]);
Cars[idx][cLocked] = strval(arrCoords[9]);
Cars[idx][cCarID] = strval(arrCoords[10]);
Cars[idx][cCol1] = strval(arrCoords[11]);
Cars[idx][cCol2] = strval(arrCoords[12]);
CreateVehicle(Cars[idx][cModel],Cars[idx][cX],Cars[idx][cY],Cars[idx][cZ],Cars[idx][cAngle],Cars[idx][cCol1],Cars[idx][cCol2],1000);
idx++;
}
fclose(file);
}
return 1;
} // LOAD CARS SAVE CARS ( ALSO PUT IN ONGAMEMODEINIT AND EXIT )
pawn Код:
if(strcmp(cmd, "/buy", true) == 0)
{
if(IsPlayerConnected(playerid))
{
new playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
new c;
while (c < sizeof(Cars))
{
if(IsPlayerInAnyVehicle(playerid))
{
if(Cars[c][cOwned] == 1)
{
SendClientMessage(playerid,c_r,"[ ! ] This car is bought !");
return 1;
}
if(Cars[c][cPrice] == 0)
{
SendClientMessage(playerid, c_r, "[ ! ] A price isn't set for this car, it is not meant to be bought!");
return 1;
}
if(PlayerInfo[playerid][pCarKey] != 255 && strcmp(playername, Cars[c][cOwner], true) == 0)
{
SendClientMessage(playerid, c_r, "[ ! ] You can only own one car, sell your original car first before buying this one!");
return 1;
}
if(GetPlayerRcash(playerid) >= Cars[c][cPrice])
{
PlayerInfo[playerid][pCarKey] = c;
Cars[c][cOwned] = 1;
strmid(Cars[c][cOwner], playername, 0, strlen(playername), 255);
GivePlayerRcash(playerid,-Cars[c][cPrice]);
SendClientMessage(playerid, COLOR_GREEN, "[ ! ] You have successfully purchased this car!");
SaveCars();
OnPlayerDataSave(playerid);
return 1;
}
else
{
SendClientMessage(playerid, c_r, "[ ! ] You don't have enough rcash!");
return 1;
}
}
}
}
return 1;
}
if(strcmp(cmd, "/sell", true) == 0)
{
if(IsPlayerConnected(playerid))
{
new playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
if(PlayerInfo[playerid][pCarKey] != 255 && strcmp(playername, Cars[PlayerInfo[playerid][pCarKey]][cOwner], true) == 0)
{
new car = PlayerInfo[playerid][pCarKey];
if(IsPlayerInAnyVehicle(playerid))
{
if(Cars[car][cOwned] == 0)
{
SendClientMessage(playerid,c_r,"[ ! ] This car is not owned by you !");
return 1;
}
Cars[car][cOwned] = 0;
strmid(Cars[car][cOwner], "None", 0, strlen("None"), 255);
GivePlayerRcash(playerid,Cars[car][cPrice]);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
format(string, sizeof(string), "[ ! ] You have sold your Car for %i rcash!",Cars[car][cPrice]);
SendClientMessage(playerid, COLOR_GREEN, string);
PlayerInfo[playerid][pCarKey] = 255;
OnPlayerDataSave(playerid);
SaveCars();
return 1;
}
else
{
SendClientMessage(playerid,c_r,"[ ! ] You must be inside your car to sell it!");
}
}
else
{
SendClientMessage(playerid,c_r,"[ ! ] You don't even own a car!");
}
}
return 1;
} // BUY AND SELL
So what's the problem?