Not saving right -
RLGaming - 21.09.2012
I have a dynamic business system
but whenever i create a business and do /savebusinesss it saves it etc and adds it into the biz.cfg file, I have ongamemodeinit LoadBusiness(); but it doesnt load them?
Code:
Код:
LoadBusiness() {
if(!fexist("Business/biz.cfg")) return 1;
new
szFileStr[1024],
File: iFileHandle = fopen("Business/biz.cfg", io_read),
iIndex;
while(iIndex < sizeof(BizInfo) && fread(iFileHandle, szFileStr)) {
sscanf(szFileStr, "p<|>iiis[128]s[24]ffffffffiiiiiff",
%d|%d|%d|%s|%s|%f|%f|%f|%f|%f|%f|%f|%f|%d|%d|%d|%d|%d|%f|%f\r\n
BizInfo[iIndex][bOwned],
BizInfo[iIndex][bBInteriorWorld],
BizInfo[iIndex][bDescription],
BizInfo[iIndex][bOwner],
BizInfo[iIndex][bExteriorX],
BizInfo[iIndex][bExteriorY],
BizInfo[iIndex][bExteriorZ],
BizInfo[iIndex][bExteriorR],
BizInfo[iIndex][bInteriorX],
BizInfo[iIndex][bInteriorY],
BizInfo[iIndex][bInteriorZ],
BizInfo[iIndex][bInteriorR],
BizInfo[iIndex][bLock],
BizInfo[iIndex][bValue],
BizInfo[iIndex][bSafeMoney],
BizInfo[iIndex][bPickupID],
BizInfo[iIndex][bExteriorA],
BizInfo[iIndex][bInteriorA]
);
new lockedinfo[20];
if(BizInfo[iIndex][bLock] == 0)
{ lockedinfo = "Open"; }
if(BizInfo[iIndex][bLock] == 1)
{ lockedinfo = "Closed"; }
else { lockedinfo = "Open"; }
new biztype[20];
if(BizInfo[iIndex][b247] == 1)
{ biztype = "24/7 Store"; }
if(BizInfo[iIndex][bGunshop] == 1)
{ biztype = "Gun Store"; }
if(BizInfo[iIndex][bClotheshop] == 1)
{ biztype = "Clothing Store"; }
else { biztype = "Open"; }
if(BizInfo[iIndex][bOwned]) {
if(BizInfo[iIndex][bRentable] == 0) format(szFileStr, sizeof(szFileStr), "Business: %s\n\nOwner: %s\nStatus: %s\n\n{FFFFFF}ID: %d",biztype, BizInfo[iIndex][bOwner],lockedinfo, iIndex);
}
else format(szFileStr, sizeof(szFileStr), "{E8A831}This Business is for sale!\n\n{FFFFFF}Cost: $%d\n{FFFFFF}ID: %d\n\nTo buy this business type /buybiz",BizInfo[iIndex][bValue], iIndex);
BizInfo[iIndex][bPickupID] = CreateDynamicPickup(1239, 23, BizInfo[iIndex][bExteriorX], BizInfo[iIndex][bExteriorY], BizInfo[iIndex][bExteriorZ]);
BizInfo[iIndex][bTextID] = CreateDynamic3DTextLabel(szFileStr, COLOR_GREEN, BizInfo[iIndex][bExteriorX], BizInfo[iIndex][bExteriorY], BizInfo[iIndex][bExteriorZ]+0.5,30.0, .testlos = 1, .streamdistance = 30.0);
++iIndex;
}
return fclose(iFileHandle);
}
Код:
SaveBusiness() {
new
szFileStr[1024],
File: fHandle = fopen("Business/biz.cfg", io_write);
for(new iIndex; iIndex < MAX_BUSINESS; iIndex++) {
format(szFileStr, sizeof(szFileStr), "%d|%d|%d|%s|%s|%f|%f|%f|%f|%f|%f|%f|%f|%d|%d|%d|%d|%d|%f|%f\r\n",
BizInfo[iIndex][bOwned],
BizInfo[iIndex][bBInteriorWorld],
BizInfo[iIndex][bDescription],
BizInfo[iIndex][bOwner],
BizInfo[iIndex][bExteriorX],
BizInfo[iIndex][bExteriorY],
BizInfo[iIndex][bExteriorZ],
BizInfo[iIndex][bExteriorR],
BizInfo[iIndex][bInteriorX],
BizInfo[iIndex][bInteriorY],
BizInfo[iIndex][bInteriorZ],
BizInfo[iIndex][bInteriorR],
BizInfo[iIndex][bLock],
BizInfo[iIndex][b247],
BizInfo[iIndex][bGunshop],
BizInfo[iIndex][bClotheshop],
BizInfo[iIndex][bValue],
BizInfo[iIndex][bSafeMoney],
BizInfo[iIndex][bPickupID],
BizInfo[iIndex][bExteriorA],
BizInfo[iIndex][bInteriorA]
);
fwrite(fHandle, szFileStr);
}
return fclose(fHandle);
}
Im pretty sure its something to do with the %d and %f stuff but im not sure
+rep to anyone who can even help!
thanks alot guys
Re: Not saving right - HuSs3n - 21.09.2012
pawn Код:
sscanf(szFileStr, "p<|>iiis[128]s[24]ffffffffiiiiiff",
BizInfo[iIndex][bOwned],
BizInfo[iIndex][bBInteriorWorld],
BizInfo[iIndex][bDescription],
BizInfo[iIndex][bOwner],
BizInfo[iIndex][bExteriorX],
BizInfo[iIndex][bExteriorY],
BizInfo[iIndex][bExteriorZ],
BizInfo[iIndex][bExteriorR],
BizInfo[iIndex][bInteriorX],
BizInfo[iIndex][bInteriorY],
BizInfo[iIndex][bInteriorZ],
BizInfo[iIndex][bInteriorR],
BizInfo[iIndex][bLock],
BizInfo[iIndex][bValue],
BizInfo[iIndex][bSafeMoney],
BizInfo[iIndex][bPickupID],
BizInfo[iIndex][bExteriorA],
BizInfo[iIndex][bInteriorA]);
this isnt needed in sscanf
pawn Код:
%d|%d|%d|%s|%s|%f|%f|%f|%f|%f|%f|%f|%f|%d|%d|%d|%d|%d|%f|%f\r\n
Re: Not saving right -
RLGaming - 21.09.2012
So which one do i replace it with?
COuld you paste the SaveBusiness and LoadBusiness one please
Re: Not saving right -
trapstar2020 - 21.09.2012
Код:
%d|%d|%d|%s|%s|%f|%f|%f|%f|%f|%f|%f|%f|%d|%d|%d|%d|%d|%d|%d|%f|%f\r\n"
try this
%f is for floating positions
%d is for information
%s is for strings
this is incase you dont know how to use it
Re: Not saving right - HuSs3n - 21.09.2012
pawn Код:
LoadBusiness() {
if(!fexist("Business/biz.cfg")) return 1;
new
szFileStr[1024],
File: iFileHandle = fopen("Business/biz.cfg", io_read),
iIndex;
while(iIndex < sizeof(BizInfo) && fread(iFileHandle, szFileStr)) {
sscanf(szFileStr, "p<|>iiis[128]s[24]ffffffffiiiiiff",
BizInfo[iIndex][bOwned],
BizInfo[iIndex][bBInteriorWorld],
BizInfo[iIndex][bDescription],
BizInfo[iIndex][bOwner],
BizInfo[iIndex][bExteriorX],
BizInfo[iIndex][bExteriorY],
BizInfo[iIndex][bExteriorZ],
BizInfo[iIndex][bExteriorR],
BizInfo[iIndex][bInteriorX],
BizInfo[iIndex][bInteriorY],
BizInfo[iIndex][bInteriorZ],
BizInfo[iIndex][bInteriorR],
BizInfo[iIndex][bLock],
BizInfo[iIndex][bValue],
BizInfo[iIndex][bSafeMoney],
BizInfo[iIndex][bPickupID],
BizInfo[iIndex][bExteriorA],
BizInfo[iIndex][bInteriorA]);
new lockedinfo[20];
if(BizInfo[iIndex][bLock] == 0)
{ lockedinfo = "Open"; }
if(BizInfo[iIndex][bLock] == 1)
{ lockedinfo = "Closed"; }
else { lockedinfo = "Open"; }
new biztype[20];
if(BizInfo[iIndex][b247] == 1)
{ biztype = "24/7 Store"; }
if(BizInfo[iIndex][bGunshop] == 1)
{ biztype = "Gun Store"; }
if(BizInfo[iIndex][bClotheshop] == 1)
{ biztype = "Clothing Store"; }
else { biztype = "Open"; }
if(BizInfo[iIndex][bOwned]) {
if(BizInfo[iIndex][bRentable] == 0) format(szFileStr, sizeof(szFileStr), "Business: %s\n\nOwner: %s\nStatus: %s\n\n{FFFFFF}ID: %d",biztype, BizInfo[iIndex][bOwner],lockedinfo, iIndex);
}
else format(szFileStr, sizeof(szFileStr), "{E8A831}This Business is for sale!\n\n{FFFFFF}Cost: $%d\n{FFFFFF}ID: %d\n\nTo buy this business type /buybiz",BizInfo[iIndex][bValue], iIndex);
BizInfo[iIndex][bPickupID] = CreateDynamicPickup(1239, 23, BizInfo[iIndex][bExteriorX], BizInfo[iIndex][bExteriorY], BizInfo[iIndex][bExteriorZ]);
BizInfo[iIndex][bTextID] = CreateDynamic3DTextLabel(szFileStr, COLOR_GREEN, BizInfo[iIndex][bExteriorX], BizInfo[iIndex][bExteriorY], BizInfo[iIndex][bExteriorZ]+0.5,30.0, .testlos = 1, .streamdistance = 30.0);
++iIndex;
}
return fclose(iFileHandle);
}
Re: Not saving right -
trapstar2020 - 21.09.2012
Код:
#define MAX_BIZ 100000000//changeable
Код:
enum bizInfo
{
bType,
bStatus,
bOwner[32],
Float:bX,
Float:bY,
Float:bZ,
bPickup,
bMoney,
bProducts,
Text3D:bText,
bSold,
bLevel,
bPrice,
bAP
}
new BizInfo[MAX_BIZ][bizInfo];
stock LoadBiz()
{
if(!fexist("biz.cfg")) fcreate("biz.cfg");
new binfo[12][32];
new string[256];
new File:file = fopen("biz.cfg", io_read);
if(file)
{
new idx = 1;
while(idx < MAX_BIZ)
{
fread(file, string);
split(string, binfo, '|');
BizInfo[idx][bType] = strval(binfo[0]);
BizInfo[idx][bStatus] = strval(binfo[1]);
format(BizInfo[idx][bOwner], 32, "%s", binfo[2]);
BizInfo[idx][bX] = floatstr(binfo[3]);
BizInfo[idx][bY] = floatstr(binfo[4]);
BizInfo[idx][bZ] = floatstr(binfo[5]);
BizInfo[idx][bMoney] = strval(binfo[6]);
BizInfo[idx][bProducts] = strval(binfo[7]);
BizInfo[idx][bSold] = strval(binfo[8]);
BizInfo[idx][bLevel] = strval(binfo[9]);
BizInfo[idx][bPrice] = strval(binfo[10]);
BizInfo[idx][bAP] = strval(binfo[11]);
if(BizInfo[idx][bType]) // If Business is owned
{
BizInfo[idx][bPickup] = CreateDynamicPickup(1272, 1, BizInfo[idx][bX], BizInfo[idx][bY], BizInfo[idx][bZ], 0);
if(!strcmp("The State", BizInfo[idx][bOwner])) format(string, sizeof(string), "ID: %d\n%s\nOwner: %s\nStatus: For Sale\nPrice: $%d", idx, RBT(idx), BizInfo[idx][bOwner], BizInfo[idx][bPrice]);
else format(string, sizeof(string), "ID: %d\n%s\nOwner: %s\nStatus: %s", idx, RBT(idx), BizInfo[idx][bOwner], RBS(idx));
BizInfo[idx][bText] = CreateDynamic3DTextLabel(string, COLOR_WHITE, BizInfo[idx][bX], BizInfo[idx][bY], BizInfo[idx][bZ]+0.3, 15);
}
idx++;
}
}
print("Businesses loaded successfully.");
return 1;
}
stock SaveBiz()
{
if(!fexist("biz.cfg")) fcreate("biz.cfg");
new idx = 1, File:file;
new string[256];
while(idx < MAX_BIZ)
{
format(string, sizeof(string), "%d|%d|%s|%f|%f|%f|%d|%d|%d|%d|%d|%d\r\n", BizInfo[idx][bType], BizInfo[idx][bStatus], BizInfo[idx][bOwner], BizInfo[idx][bX], BizInfo[idx][bY], BizInfo[idx][bZ], BizInfo[idx][bMoney], BizInfo[idx][bProducts], BizInfo[idx][bSold], BizInfo[idx][bLevel], BizInfo[idx][bPrice], BizInfo[idx][bAP]);
if(idx == 1)
{
file = fopen("biz.cfg", io_write);
}
else
{
file = fopen("biz.cfg", io_append);
}
fwrite(file, string);
fclose(file);
idx++;
}
print("Businesses saved successfully.");
}
Here is an example...........from zgaming Gamemode
Re: Not saving right -
RLGaming - 21.09.2012
still not working for some reaosn ;/
Re: Not saving right -
Red_Dragon. - 21.09.2012
Do you have Y_INI, i think it is a good saving system, try it
Re: Not saving right -
RLGaming - 21.09.2012
how would i make it into y_ini?
I already have it no idea how to save a business system with the name etc so urm yeah lol
Re: Not saving right -
Red_Dragon. - 21.09.2012
Download YSI system (That includes y_ini and other many things)