I got big problem - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: I got big problem (
/showthread.php?tid=476219)
I got big problem -
dominik523 - 17.11.2013
Hey all! I got a really big problem with saving my businesses. I've created 2 businesses while I was on local host, and here they are in scriptfiles:
Код:
1|0|The State|-2530.523193|1378.588745|7.039062|0|0|0|1|200000|0|0|
2|0|The State|-2523.382324|1377.741455|7.039062|0|0|0|1|200000|0|0|
0|0||0.000000|0.000000|0.000000|0|0|0|0|0|0|0|
0|0||0.000000|0.000000|0.000000|0|0|0|0|0|0|0|
0|0||0.000000|0.000000|0.000000|0|0|0|0|0|0|0|
.
.
.
After I have restarted server 2 times using gmx as rcon command, I got this:
Код:
1|0|The State|-2530.523193|1378.588745|7.039062|0|0|0|1|200000|0|0|
0|0|The State|-2530.523193|1378.588745|7.039062|0|0|0|1|200000|0|0|
2|0|The State|-2523.382324|1377.741455|7.039062|0|0|0|1|200000|0|0|
0|0|The State|-2523.382324|1377.741455|7.039062|0|0|0|1|200000|0|0|
0|0||0.000000|0.000000|0.000000|0|0|0|0|0|0|0|
0|0||0.000000|0.000000|0.000000|0|0|0|0|0|0|0|
Now the same 2 businesses are duplicated. I think my savebiz stock is bugged, so can someone please help me. This is the stock:
pawn Код:
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|%d|%s\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], BizInfo[idx][bTake], BizInfo[idx][bName]);
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.");
}
AW: I got big problem -
Skimmer - 17.11.2013
Change
io_append to
io_write.
Re: I got big problem -
dominik523 - 17.11.2013
that makes sense. I have no idea why do I have new idx = 1, and then checking if idx == 1. Thanks, I will try it
EDIT: should I write it like this
pawn Код:
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|%d|%s\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], BizInfo[idx][bTake], BizInfo[idx][bName]);
file = fopen("biz.cfg", io_write);
fwrite(file, string);
fclose(file);
idx++;
}
print("Businesses saved successfully.");
}
I think that will write each time I save businesses another lines with the same things
Re: I got big problem -
Wizzy951 - 17.11.2013
I had a similar problem with mysql, I was trying to "insert" the e-mail instead of updating the line and it was creating new line. So try to update them instead of saving them.