saving system -
Dare Devil..... - 26.07.2012
Houses dont save
pawn Код:
public SaveHouses()
{
new idx;
new File: file2;
while (idx < sizeof(HouseInfo))
{
new coordsstring[512];
format(coordsstring, sizeof(coordsstring), "%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%f|%f|%f|%f|%f|%f|%f|%f|%d|%d|%d|%d\r\n",
HouseInfo[idx][hOwned],
HouseInfo[idx][hPrice],
HouseInfo[idx][hOwner],
HouseInfo[idx][hLevel],
HouseInfo[idx][hLocked],
HouseInfo[idx][hRentable],
HouseInfo[idx][hRentPrice],
HouseInfo[idx][hGun1],
HouseInfo[idx][hGun2],
HouseInfo[idx][hGun3],
HouseInfo[idx][hMoney],
HouseInfo[idx][hEntranceX],
HouseInfo[idx][hEntranceY],
HouseInfo[idx][hEntranceZ],
HouseInfo[idx][hEntranceA],
HouseInfo[idx][hExitX],
HouseInfo[idx][hExitY],
HouseInfo[idx][hExitZ],
HouseInfo[idx][hExitA],
HouseInfo[idx][hInt],
HouseInfo[idx][hWorld],
HouseInfo[idx][hInsideInt],
HouseInfo[idx][hInsideWorld]);
if(idx == 0)
{
file2 = fopen("Houses.cfg", io_write);
}
else
{
file2 = fopen("Houses.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}
This is saving system.
pawn Код:
YCMD:buyhouse(playerid, params[])
{
if(gPlayerLoggedIn[playerid] == 0) return 1;
new id = IsPlayerNearHouseEnt(playerid);
new rentid = PlayerInfo[playerid][RentingID];
if(id == -1 || id == 0) return SendClientMessage(playerid, COLOR_GREY, "You are not near a house.");
if(HouseInfo[id][hOwned] != 0 || HouseInfo[id][hPrice] == 0) return SendClientMessage(playerid, COLOR_GREY, "This house is not for sale.");
if(rentid != 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are currently renting a house.");
if(PlayerInfo[playerid][HouseID] != 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You already own a house.");
if(PlayerInfo[playerid][Money] < HouseInfo[id][hPrice]) return SendClientMessage(playerid, COLOR_LIGHTRED, "Sorry, you can not afford this house.");
PlayerInfo[playerid][HouseID] = id;
PlayerInfo[playerid][Money] -= HouseInfo[id][hPrice];
GivePlayerMoney(playerid, -HouseInfo[id][hPrice]);
HouseInfo[id][hLocked] = 0;
HouseInfo[id][hOwned] = 1;
HouseInfo[id][hRentable] = 0;
strmid(HouseInfo[id][hOwner], PlayerName(playerid), 0, strlen(PlayerName(playerid)), 255);
SendClientMessage(playerid, COLOR_YELLOW, "Congratulations on your new home! Use /househelp to get help, or /ask!");
return 1;
}
Housing dont save.
Re: saving system -
Devilxz97 - 26.07.2012
do u have enum hInfo ?
Re: saving system -
Dare Devil..... - 26.07.2012
Yes thats like this
pawn Код:
// -------------------------------------------------------------------------- //
enum hInfo {
hOwned,
hPrice,
hOwner[128],
hLevel,
hLocked,
hRentable,
hRentPrice,
hGun1,
hGun2,
hGun3,
hMoney,
Float:hEntranceX,
Float:hEntranceY,
Float:hEntranceZ,
Float:hEntranceA,
Float:hExitX,
Float:hExitY,
Float:hExitZ,
Float:hExitA,
hInt,
hWorld,
hInsideInt,
hInsideWorld,
hInsideIcon,
hOutsideIcon
}
new HouseInfo[200][hInfo];
public LoadHouses()
{
new arrCoords[23][64];
new strFromFile2[256];
new File: file = fopen("Houses.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(HouseInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, '|');
HouseInfo[idx][hOwned] = strval(arrCoords[0]);
HouseInfo[idx][hPrice] = strval(arrCoords[1]);
strmid(HouseInfo[idx][hOwner], arrCoords[2], 0, strlen(arrCoords[2]), 255);
HouseInfo[idx][hLevel] = strval(arrCoords[3]);
HouseInfo[idx][hLocked] = strval(arrCoords[4]);
HouseInfo[idx][hRentable] = strval(arrCoords[5]);
HouseInfo[idx][hRentPrice] = strval(arrCoords[6]);
HouseInfo[idx][hGun1] = strval(arrCoords[7]);
HouseInfo[idx][hGun2] = strval(arrCoords[8]);
HouseInfo[idx][hGun3] = strval(arrCoords[9]);
HouseInfo[idx][hMoney] = strval(arrCoords[10]);
HouseInfo[idx][hEntranceX] = floatstr(arrCoords[11]);
HouseInfo[idx][hEntranceY] = floatstr(arrCoords[12]);
HouseInfo[idx][hEntranceZ] = floatstr(arrCoords[13]);
HouseInfo[idx][hEntranceA] = floatstr(arrCoords[14]);
HouseInfo[idx][hExitX] = floatstr(arrCoords[15]);
HouseInfo[idx][hExitY] = floatstr(arrCoords[16]);
HouseInfo[idx][hExitZ] = floatstr(arrCoords[17]);
HouseInfo[idx][hExitA] = floatstr(arrCoords[18]);
HouseInfo[idx][hInt] = strval(arrCoords[19]);
HouseInfo[idx][hWorld] = strval(arrCoords[20]);
HouseInfo[idx][hInsideInt] = strval(arrCoords[21]);
HouseInfo[idx][hInsideWorld] = strval(arrCoords[22]);
if(HouseInfo[idx][hOutsideIcon]) DestroyDynamicPickup(HouseInfo[idx][hOutsideIcon]);
if(HouseInfo[idx][hInsideIcon]) DestroyDynamicPickup(HouseInfo[idx][hInsideIcon]);
HouseInfo[idx][hOutsideIcon] = CreateDynamicPickup(1273, 1, HouseInfo[idx][hEntranceX], HouseInfo[idx][hEntranceY], HouseInfo[idx][hEntranceZ], HouseInfo[idx][hWorld]);
HouseInfo[idx][hInsideIcon] = CreateDynamicPickup(1273, 1, HouseInfo[idx][hExitX], HouseInfo[idx][hExitY], HouseInfo[idx][hExitZ], HouseInfo[idx][hInsideWorld]);
idx++;
}
fclose(file);
}
return 1;
}
public SaveHouses()
{
new idx;
new File: file2;
while (idx < sizeof(HouseInfo))
{
new coordsstring[512];
format(coordsstring, sizeof(coordsstring), "%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%f|%f|%f|%f|%f|%f|%f|%f|%d|%d|%d|%d\r\n",
HouseInfo[idx][hOwned],
HouseInfo[idx][hPrice],
HouseInfo[idx][hOwner],
HouseInfo[idx][hLevel],
HouseInfo[idx][hLocked],
HouseInfo[idx][hRentable],
HouseInfo[idx][hRentPrice],
HouseInfo[idx][hGun1],
HouseInfo[idx][hGun2],
HouseInfo[idx][hGun3],
HouseInfo[idx][hMoney],
HouseInfo[idx][hEntranceX],
HouseInfo[idx][hEntranceY],
HouseInfo[idx][hEntranceZ],
HouseInfo[idx][hEntranceA],
HouseInfo[idx][hExitX],
HouseInfo[idx][hExitY],
HouseInfo[idx][hExitZ],
HouseInfo[idx][hExitA],
HouseInfo[idx][hInt],
HouseInfo[idx][hWorld],
HouseInfo[idx][hInsideInt],
HouseInfo[idx][hInsideWorld]);
if(idx == 0)
{
file2 = fopen("Houses.cfg", io_write);
}
else
{
file2 = fopen("Houses.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}
Re: saving system -
Dare Devil..... - 26.07.2012
Any oone?
Re: saving system -
Dare Devil..... - 26.07.2012
still unsolve any one?
Re: saving system -
Ranama - 26.07.2012
sorry I'm using mysql, so don't know about this saving system but what i think about the code is that it's someting wrong with the save function, where you save the data to the file, i don't see any errors in the non saving part.
Re: saving system -
Jeffry - 26.07.2012
Your code works fine for me.
Forgot to call
SaveHouses() where you want to save them?
Re: saving system -
Dare Devil..... - 26.07.2012
Any thing needs to be cahnged because after server restart nomm house.remain on its place.
Re: saving system -
Dare Devil..... - 27.07.2012
Help me any one I will rep + for this please I need help.