stock crashing my server - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: stock crashing my server (
/showthread.php?tid=180841)
stock crashing my server -
Whizion - 03.10.2010
This is my stock:
pawn Код:
stock GiveCellNumber(playerid)
{
new number;
new string[128];
new Infinity = 0;
if(IsPlayerConnectedAndLoggedIn(playerid))
{
while(Infinity != 1)
{
number = random(899999) + 100000;
format(string, sizeof(string), "XRPG/Numbers/%s.ini",number);
if(!fexist(string)) // Check's if it's taken.
{
new File:hFile;
hFile = fopen(string, io_append);
fwrite(hFile, PlayerName[playerid]);
PlayerInfo[playerid][pMyNumber] = number;
fclose(hFile);
return 1; // Stops the loop. (i think :X).
}
}
}
return 1;
}
It's supose to give you an unique cell phone number, but when ever i use it, my server crashes. (it turnes off).
Please help, thank you.
Re: stock crashing my server -
bigcomfycouch - 03.10.2010
pawn Код:
stock GiveCellNumber(playerid)
{
new
number,
File:hFile,
string[128];
if (IsPlayerConnectedAndLoggedIn(playerid))
{
while (true)
{
number = random(899999) + 100000;
format(string, sizeof(string), "XRPG/Numbers/%s.ini", number);
if (!fexist(string))
{
hFile = fopen(string, io_readwrite);
PlayerInfo[playerid][pMyNumber] = number;
fwrite(hFile, PlayerName[playerid]);
fclose(hFile);
break;
}
}
}
return 1;
}
You were trying to append a string to a nonexistent file.
Re: stock crashing my server -
Whizion - 03.10.2010
Uhm, it's not working.
First i get this warning on the line with while (true):
warning 206: redundant test: constant expression is non-zero
And second, the filename isn't the number it's some strange letter instead.
Please help, thanks.
Re: stock crashing my server -
Conroy - 03.10.2010
pawn Код:
stock GiveCellNumber(playerid)
{
new
foundnumber,
number,
File:hFile,
string[128];
if (IsPlayerConnectedAndLoggedIn(playerid))
{
while (!foundnumber)
{
number = random(899999) + 100000;
format(string, sizeof(string), "XRPG/Numbers/%s.ini", number);
if (!fexist(string))
{
foundnumber = 1;
hFile = fopen(string, io_readwrite);
PlayerInfo[playerid][pMyNumber] = number;
fwrite(hFile, PlayerName[playerid]);
fclose(hFile);
}
}
}
return 1;
}
Re: stock crashing my server -
bigcomfycouch - 03.10.2010
I was formatting the string incorrectly.
pawn Код:
stock GiveCellNumber(playerid)
{
new
number,
File:hFile,
string[128];
if (IsPlayerConnectedAndLoggedIn(playerid))
{
for ( ; ; )
{
number = random(899999) + 100000;
format(string, sizeof(string), "XRPG/Numbers/%i.ini", number);
if (!fexist(string))
{
hFile = fopen(string, io_readwrite);
PlayerInfo[playerid][pMyNumber] = number;
fwrite(hFile, PlayerName[playerid]);
fclose(hFile);
break;
}
}
}
return 1;
}