enum pInfo
{
pCarKey,
};
new PlayerInfo[MAX_PLAYERS][pInfo];enum CarSystem
{
CarDescription[128],
CarOwner[MAX_PLAYER_NAME],
Float:CarX,
Float:CarY,
Float:CarZ,
Float:CarAngle,
CarOwned,
CarPrice,
CarLocked,
CarID,
CarModel,
CarCol1,
CarCol2,
};
new Cars[100][CarSystem];
forward LoadCars();
forward SaveCars();
public SaveCars()
{
new idx;
new File: file2;
while (idx < sizeof(Cars))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%s|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d\n",
Cars[idx][CarDescription],
Cars[idx][CarOwner],
Cars[idx][CarX],
Cars[idx][CarY],
Cars[idx][CarZ],
Cars[idx][CarAngle],
Cars[idx][CarOwned],
Cars[idx][CarPrice],
Cars[idx][CarLocked],
Cars[idx][CarID],
Cars[idx][CarModel],
Cars[idx][CarCol1],
Cars[idx][CarCol2]);
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[22][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][CarDescription], arrCoords[0], 0, strlen(arrCoords[0]), 255);
strmid(Cars[idx][CarOwner], arrCoords[1], 0, strlen(arrCoords[1]), 255);
Cars[idx][CarX] = floatstr(arrCoords[2]);
Cars[idx][CarY] = floatstr(arrCoords[3]);
Cars[idx][CarZ] = floatstr(arrCoords[4]);
Cars[idx][CarAngle] = floatstr(arrCoords[5]);
Cars[idx][CarOwned] = strval(arrCoords[6]);
Cars[idx][CarPrice] = strval(arrCoords[7]);
Cars[idx][CarLocked] = strval(arrCoords[8]);
Cars[idx][CarID] = strval(arrCoords[9]);
Cars[idx][CarModel] = strval(arrCoords[10]);
Cars[idx][CarCol1] = strval(arrCoords[12]);
Cars[idx][CarCol2] = strval(arrCoords[13]);
if(Cars[idx][CarPrice] == 0)
{
if(Cars[idx][CarOwned] == 0)
{
Cars[idx][CarID] = CreateVehicle(Cars[idx][CarModel],Cars[idx][CarX],Cars[idx][CarY],Cars[idx][CarZ],Cars[idx][CarAngle],Cars[idx][CarCol1],Cars[idx][CarCol2],0);
}
else if(Cars[idx][CarOwned] == 1)
{
Cars[idx][CarID] = CreateVehicle(Cars[idx][CarModel],Cars[idx][CarX],Cars[idx][CarY],Cars[idx][CarZ],Cars[idx][CarAngle],Cars[idx][CarCol1],Cars[idx][CarCol2],0);
}
}
idx++;
}
fclose(file);
}
return 1;
}
LoadCars(); < Init SaveCars(); < Exit
if(strcmp(cmd, "/buy", true) == 0)
{
if(IsPlayerConnected(playerid))
{
new Float:oldposx, Float:oldposy, Float:oldposz;
new playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerPos(playerid, oldposx, oldposy, oldposz);
for(new h = 0; h < sizeof(Cars); h++)
{
if(IsPlayerInVehicle(playerid,Cars[h][CarID]))
{
if(Cars[h][CarPrice] == 0)
{
SendClientMessage(playerid, c_r, "[ ! ] A price isn't set for this car, it's probably not meant to be bought.");
return 1;
}
if(PlayerInfo[playerid][pCarKey] != 255 && strcmp(playername, Cars[PlayerInfo[playerid][pCarKey]][CarOwner], true) == 0)
{
SendClientMessage(playerid, c_r, "[ ! ] You can only own one car, you must sell the old one before buying this one!");
return 1;
}
if(GetPlayerRcash(playerid) > Cars[h][CarPrice])
{
PlayerInfo[playerid][pCarKey] = h;
Cars[h][CarOwned] = 1;
strmid(Cars[h][CarOwner], playername, 0, strlen(playername), 255);
GivePlayerRcash(playerid,-Cars[h][CarPrice]);
SendClientMessage(playerid, COLOR_WHITE, "[ ! ] You have successfully purchased this car!");
PlayerActionMessage(playerid,15.0,"[ ! ] hands a package full of money to the estate agent, who then give returns with a key.");
ChangeStreamPickupModel(Houses[h][PickupID],1239);
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]][CarOwner], true) == 0)
{
new house = PlayerInfo[playerid][pCarKey];
if(IsPlayerInVehicle(playerid,Cars[house][CarID]))
{
Cars[house][CarLocked] = 0;
Cars[house][CarOwned] = 0;
strmid(Cars[house][CarOwner], "None", 0, strlen("None"), 255);
GivePlayerRcash(playerid,Cars[house][CarPrice]);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
format(string, sizeof(string), "[ ! ] You have sold your car for %d rcash.", Cars[house][CarPrice]);
SendClientMessage(playerid, COLOR_GREEN, string);
PlayerInfo[playerid][pCarKey] = 255;
OnPlayerDataSave(playerid);
SaveCars();
return 1;
}
else
{
SendClientMessage(playerid,c_r,"[ ! ] You must be inside you're car to sell it!");
}
}
else
{
SendClientMessage(playerid,c_r,"[ ! ] You don't even own a car!");
}
}
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
for(new h = 0; h < sizeof(Cars); h++)
{
if(newstate == 2)
{
if (Cars[h][CarOwner] == 1)
{
new xxx[128];
format(xxx,sizeof(xxx),"[ ! ] ID : %d ' %s ' Bought by : %s",Cars[h][CarID],Cars[h][CarDescription],Cars[h][CarOwner]);
SendClientMessage(playerid,COLOR_GREY,xxx);
}
else if(Cars[h][CarOwner] == 0)
{
if(GetPlayerAdminz(playerid) >= 1){
}
new fffx[128];
format(fffx,sizeof(fffx),"[ ! ] ID : %d ' %s ' Price : %d",Cars[h][CarID],Cars[h][CarDescription],Cars[h][CarPrice]);
SendClientMessage(playerid,COLOR_GREY,fffx);
}
else
{
new ex[128];
format(ex,sizeof(ex),"[ ! ] ID : %d ' %s ' Bought by : %s",Cars[h][CarID],Cars[h][CarDescription],Cars[h][CarOwner]);
SendClientMessage(playerid,COLOR_GREY,ex);
}
}
}
return 1;
}
Turismo|None|0|0|0|0|0|0|0|1|0
|None|0|0|0|0|0|0|0|2|0
|None|0|0|0|0|0|0|0|3|0
|None|0|0|0|0|0|0|0|4|0
|None|0|0|0|0|0|0|0|5|0
|None|0|0|0|0|0|0|0|6|0
|None|0|0|0|0|0|0|0|7|0
|None|0|0|0|0|0|0|0|8|0
|None|0|0|0|0|0|0|0|9|0
|None|0|0|0|0|0|0|0|10|0
|None|0|0|0|0|0|0|0|11|0
|None|0|0|0|0|0|0|0|12|0
|None|0|0|0|0|0|0|0|13|0
|None|0|0|0|0|0|0|0|14|0
|None|0|0|0|0|0|0|0|15|0
|None|0|0|0|0|0|0|0|16|0
|None|0|0|0|0|0|0|0|17|0
|None|0|0|0|0|0|0|0|18|0
|None|0|0|0|0|0|0|0|19|0
|None|0|0|0|0|0|0|0|20|0
|None|0|0|0|0|0|0|0|21|0
|None|0|0|0|0|0|0|0|22|0
|None|0|0|0|0|0|0|0|23|0
|None|0|0|0|0|0|0|0|24|0
|None|0|0|0|0|0|0|0|25|0
|None|0|0|0|0|0|0|0|26|0
|None|0|0|0|0|0|0|0|27|0
|None|0|0|0|0|0|0|0|28|0
|None|0|0|0|0|0|0|0|29|0
|None|0|0|0|0|0|0|0|30|0
|None|0|0|0|0|0|0|0|31|0
|None|0|0|0|0|0|0|0|32|0
|None|0|0|0|0|0|0|0|33|0
|None|0|0|0|0|0|0|0|34|0
|None|0|0|0|0|0|0|0|35|0
|None|0|0|0|0|0|0|0|36|0
|None|0|0|0|0|0|0|0|37|0
|None|0|0|0|0|0|0|0|38|0
|None|0|0|0|0|0|0|0|39|0
|None|0|0|0|0|0|0|0|40|0
|None|0|0|0|0|0|0|0|41|0
|None|0|0|0|0|0|0|0|42|0
|None|0|0|0|0|0|0|0|43|0
|None|0|0|0|0|0|0|0|44|0
|None|0|0|0|0|0|0|0|45|0
|None|0|0|0|0|0|0|0|46|0
|None|0|0|0|0|0|0|0|47|0
|None|0|0|0|0|0|0|0|48|0
|None|0|0|0|0|0|0|0|49|0
|None|0|0|0|0|0|0|0|50|0
|None|0|0|0|0|0|0|0|51|0
|None|0|0|0|0|0|0|0|52|0
|None|0|0|0|0|0|0|0|53|0
|None|0|0|0|0|0|0|0|54|0
|None|0|0|0|0|0|0|0|55|0
|None|0|0|0|0|0|0|0|56|0
|None|0|0|0|0|0|0|0|57|0
|None|0|0|0|0|0|0|0|58|0
|None|0|0|0|0|0|0|0|59|0
|None|0|0|0|0|0|0|0|60|0
|None|0|0|0|0|0|0|0|61|0
|None|0|0|0|0|0|0|0|62|0
|None|0|0|0|0|0|0|0|63|0
|None|0|0|0|0|0|0|0|64|0
|None|0|0|0|0|0|0|0|65|0
|None|0|0|0|0|0|0|0|66|0
|None|0|0|0|0|0|0|0|67|0
|None|0|0|0|0|0|0|0|68|0
|None|0|0|0|0|0|0|0|69|0
|None|0|0|0|0|0|0|0|70|0
|None|0|0|0|0|0|0|0|71|0
|None|0|0|0|0|0|0|0|72|0
|None|0|0|0|0|0|0|0|73|0
|None|0|0|0|0|0|0|0|74|0
|None|0|0|0|0|0|0|0|75|0
|None|0|0|0|0|0|0|0|76|0
|None|0|0|0|0|0|0|0|77|0
|None|0|0|0|0|0|0|0|78|0
|None|0|0|0|0|0|0|0|79|0
|None|0|0|0|0|0|0|0|80|0
|None|0|0|0|0|0|0|0|81|0
|None|0|0|0|0|0|0|0|82|0
|None|0|0|0|0|0|0|0|83|0
|None|0|0|0|0|0|0|0|84|0
|None|0|0|0|0|0|0|0|85|0
|None|0|0|0|0|0|0|0|86|0
|None|0|0|0|0|0|0|0|87|0
|None|0|0|0|0|0|0|0|88|0
|None|0|0|0|0|0|0|0|89|0
|None|0|0|0|0|0|0|0|90|0
|None|0|0|0|0|0|0|0|91|0
|None|0|0|0|0|0|0|0|92|0
|None|0|0|0|0|0|0|0|93|0
|None|0|0|0|0|0|0|0|94|0
|None|0|0|0|0|0|0|0|95|0
|None|0|0|0|0|0|0|0|96|0
|None|0|0|0|0|0|0|0|97|0
|None|0|0|0|0|0|0|0|98|0
|None|0|0|0|0|0|0|0|99|0
|None|0|0|0|0|0|0|0|100|0
while (idx < sizeof(Cars)) { fread(file, strFromFile2);
while (fread(file, strFromFile2) && idx < sizeof(Cars)) {
public LoadCars()
{
new arrCoords[9][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][CarDescription], arrCoords[0], 0, strlen(arrCoords[0]), 255);
Cars[idx][CarModel] = strval(arrCoords[1]);
Cars[idx][CarX] = floatstr(arrCoords[2]);
Cars[idx][CarY] = floatstr(arrCoords[3]);
Cars[idx][CarZ] = floatstr(arrCoords[4]);
Cars[idx][CarAngle] = floatstr(arrCoords[5]);
Cars[idx][CarCol1] = strval(arrCoords[6]);
Cars[idx][CarCol2] = strval(arrCoords[7]);
Cars[idx][CarOwned] = strval(arrCoords[8]);
strmid(Cars[idx][CarOwner], arrCoords[9], 0, strlen(arrCoords[9]), 255);
CreateVehicle(Cars[idx][CarModel],Cars[idx][CarX],Cars[idx][CarY],Cars[idx][CarZ],Cars[idx][CarAngle],Cars[idx][CarCol1],Cars[idx][CarCol2], -1);
idx++;
}
fclose(file);
}
return 1;
}
public SaveCars()
{
new idx;
new File: file2;
while (idx < sizeof(Cars))
{
new coordsstring[512];
format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f|%d|%d|%d|%d\n",
Cars[idx][CarDescription],
Cars[idx][CarModel],
Cars[idx][CarX],
Cars[idx][CarY],
Cars[idx][CarZ],
Cars[idx][CarAngle],
Cars[idx][CarCol1],
Cars[idx][CarCol2],
Cars[idx][CarOwned],
Cars[idx][CarOwner]);
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;
}
strmid(Cars[idx][CarOwner], arrCoords[9], 0, strlen(arrCoords[9]), 255);
Originally Posted by coole210
Okay i've changed the LoadCars and SaveCars to this :
pawn Код:
pawn Код:
|
Originally Posted by coole210
Nobody has an answer to this problem?
NOTE: I will give exact errors when im on my computer ( on laptop right now, no script here ) |
strmid(Cars[idx][CarOwner], arrCoords[9], 0, strlen(arrCoords[9]), 255);
new arrCoords[10][64] wiil solve this problem. AND Your code is FULL of error 1:2:Код://format error format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f|%d|%d|%d|%d\n",
3:Код://in LoadCars //told you BEFORE! while (idx < sizeof(Cars)) { fread(file, strFromFile2);
Код://in SaveCars //You need a global variable to store how much vec you load in fact. while (idx < sizeof(Cars))