new string[128];
for(new c = 0; c < sizeof(Cars); c++)
{
if(vehicleid == Cars[c][cCarID] && (Cars[c][cOwner] == 1))
{
format(string,sizeof(string),"[ ! ] ID : %d ' %s ' Bought by : %s",Cars[c][cCarID],Cars[c][cDescription],Cars[c][cOwner]);
SendClientMessage(playerid,COLOR_GREY,string);
}
return 1;
}
new string[128]; for(new c = 0; c < sizeof(Cars); c++) { printf("loop:%d_%d_%d_%d_",c,vehicleid,Cars[c][cCarID],Cars[c][cCarOwner]); if(vehicleid == Cars[c][cCarID] && (Cars[c][cOwner] == 1)) { format(string,sizeof(string),"[ ! ] ID : %d ' %s ' Bought by : %s",Cars[c][cCarID],Cars[c][cDescription],Cars[c][cOwner]); SendClientMessage(playerid,COLOR_GREY,string); break; } return 1; }
Originally Posted by coole210
That still doesn't send the message when the player enters the car :S
|
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
forward LoadCars();
forward SaveCars(); // FORWARDS
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 )
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