Server crashing for no reason...
#1

The SaveInventory is causing the server to crash...
I tried to /savestats and the server crashed because savestats saves inventory

SaveInventory Code
Код:
stock SaveInventory(playerid)
{
	gItemList="";
	new filename[48];
	GetPlayerName(playerid,filename,24);
	format(filename,48,"Inventory/%s.inv",filename);
	new File:file=fopen(filename,io_write);
	for(new item;item<MAX_ITEMS;item++)
	{
		if(!strlen(_GetItemNamePVar(playerid,item))||!_GetItemAmountPVar(playerid,item))continue;
		format(gItemList,sizeof(gItemList),"%s%s\n%d\n",gItemList,_GetItemNamePVar(playerid,item),_GetItemAmountPVar(playerid,item));
	}
	fwrite(file,gItemList);
	fclose(file);
	GetPlayerName(playerid,filename,24);
	printf("[INV] %s[%d]'s inventory saved.",filename,playerid);
}
Reply
#2

Got some logs now.
Код:
[14:23:03] [debug] Server crashed while executing zm.amx
[14:23:03] [debug] AMX backtrace:
[14:23:03] [debug] #0 native fwrite () from samp7775_6043
[14:23:03] [debug] #1 0008fe68 in SaveInventory (playerid=2) at C:\Users\xc0de\Desktop\tst\gamemodes\zm1.pwn:9180
[14:23:03] [debug] #2 0007f758 in public SaveStats (playerid=2) at C:\Users\xc0de\Desktop\tst\gamemodes\zm1.pwn:7532
[14:23:03] [debug] #3 0003a84c in ?? (... <2 arguments>) at C:\Users\xc0de\Desktop\tst\gamemodes\zm1.pwn:1664
[14:23:03] [debug] #4 000188e0 in public ppb_OnPlayerDisconnect (playerid=2, reason=0) at C:\Users\xc0de\Desktop\tst\pawno\include\YSI\y_hooks/impl.inc:661
[14:23:03] [debug] #5 00012208 in public SSCANF_OnPlayerDisconnect (playerid=2, reason=0) at C:\Users\xc0de\Desktop\tst\pawno\include\progressbarv2.inc:397
[14:23:03] [debug] #6 00003aec in public Itter_OnPlayerDisconnect (playerid=2, reason=0) at C:\Users\xc0de\Desktop\tst\pawno\include\sscanf2.inc:197
[14:23:03] [debug] #7 00002b98 in public Audio_OnPlayerDisconnect (playerid=2, reason=0) at C:\Users\xc0de\Desktop\tst\pawno\include\YSI\y_iterate.inc:909
[14:23:03] [debug] #8 native CallLocalFunction () from samp7775_6043
[14:23:03] [debug] #9 00001060 in public OnPla
Reply
#3

fwrite
Код:
stock SaveInventory(playerid)
{
	gItemList="";
	new filename[48];
	GetPlayerName(playerid,filename,24);
	format(filename,48,"Inventory/%s.inv",filename);
	new File:file=fopen(filename,io_write);
	for(new item;item<MAX_ITEMS;item++)
	{
		if(!strlen(_GetItemNamePVar(playerid,item))||!_GetItemAmountPVar(playerid,item))continue;
		format(gItemList,sizeof(gItemList),"%s%s\n%d\n",gItemList,_GetItemNamePVar(playerid,item),_GetItemAmountPVar(playerid,item));
	}
	fwrite(file,gItemList);
	fclose(file);
	GetPlayerName(playerid,filename,24);
	printf("[INV] %s[%d]'s inventory saved.",filename,playerid);
}
Reply
#4

always do a check for valid file handling.
Reply
#5

fixed by doing this
[code]stock SaveInventory(playerid)
{
gItemList="";
new filename[48];
GetPlayerName(playerid,filename,24);
format(filename,48,"Inventory/%s.inv",filename);
new File:handle1=fopen(filename,io_write);
for(new item;item<MAX_ITEMS;item++)
{
if(!strlen(_GetItemNamePVar(playerid,item))||!_Get ItemAmountPVar(playerid,item))continue;
format(gItemList,sizeof(gItemList),"%s%s\n%d\n",gI temList,_GetItemNamePVar(playerid,item),_GetItemAm ountPVar(playerid,item));
}
if(handle1)
{
fwrite(handle1,gItemList);
fclose(handle1);
GetPlayerName(playerid,filename,24);
printf("[INV] %s[%d]'s inventory saved.",filename,playerid);
}
else
print("Failed to open file \"file.txt\".");
}/code]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)