Help with Selfmade House- and Businesssystem
#1

Hey,

I have a problem with a selfmade House- and Businessystem, I think it don't really saves the way it should...

Код:
function LoadBusiness()
{
    new File: PropertyFile;
    new key[256], Data[256], val[256];
	for(new i = 0; i < sizeof(Business); i++)
	{
	    Business[i][bUsed] = 0;
	    Business[i][bOwned] = 0;
	    strmid(Business[i][bOwner], "Keiner", 0, strlen("Keiner"), 255);
	    strmid(Business[i][bTitle], "Keiner", 0, strlen("Keiner"), 255);
	    Business[i][bEnterX] = 0.0;
	    Business[i][bEnterY] = 0.0;
	    Business[i][bEnterZ] = 0.0;
	    Business[i][bExitX] = 0.0;
	    Business[i][bExitY] = 0.0;
	    Business[i][bExitZ] = 0.0;
	    Business[i][bKasse] = 0;
	    Business[i][bInt] = 0;
		FormateString(filestring, "/objektsysteme/business/%d.ini", i);
		if(fexist(filestring))
		{
			PropertyFile = fopen(filestring, io_read);
			while(fread(PropertyFile, Data, sizeof(Data)))
			{
				key = ini_GetKey( Data );
				if(strcmp(key, "Used", true) == 0)		{ val = ini_GetValue(Data); Business[i][bUsed] = strval(val); }
				if(strcmp(key, "Price", true) == 0)		{ val = ini_GetValue(Data); Business[i][bPrice] = strval(val); }
				if(strcmp(key, "Owned", true) == 0)		{ val = ini_GetValue(Data); Business[i][bOwned] = strval(val); }
				if(strcmp(key, "Owner", true) == 0)		{ val = ini_GetValue(Data); strmid(Business[i][bOwner], val, 0, strlen(val) - 1, 255); }
				if(strcmp(key, "Title", true) == 0)		{ val = ini_GetValue(Data); strmid(Business[i][bTitle], val, 0, strlen(val) - 1, 255); }
				if(strcmp(key, "EnterX", true) == 0)	{ val = ini_GetValue(Data); Business[i][bEnterX] = floatstr(val); }
				if(strcmp(key, "EnterY", true) == 0)	{ val = ini_GetValue(Data); Business[i][bEnterY] = floatstr(val); }
				if(strcmp(key, "EnterZ", true) == 0)	{ val = ini_GetValue(Data); Business[i][bEnterZ] = floatstr(val); }
				if(strcmp(key, "ExitX", true) == 0)		{ val = ini_GetValue(Data); Business[i][bExitX] = floatstr(val); }
				if(strcmp(key, "ExitY", true) == 0)		{ val = ini_GetValue(Data); Business[i][bExitY] = floatstr(val); }
				if(strcmp(key, "ExitZ", true) == 0)		{ val = ini_GetValue(Data); Business[i][bExitZ] = floatstr(val); }
				if(strcmp(key, "Int", true) == 0)		{ val = ini_GetValue(Data); Business[i][bInt] = strval(val); }
				if(strcmp(key, "Kasse", true) == 0)		{ val = ini_GetValue(Data); Business[i][bKasse] = strval(val); }
				fclose(PropertyFile);
			}
		}
		else
		{
		    FormateString(ErrorReport, "SystemError: Kann Business %d nicht laden", i);
		    SendClientMessageToAll(COLOR_YELLOW, ErrorReport);
		    print(ErrorReport);
		}
	}
	return true;
}

function SaveBusiness()
{
    new File: PropertyFile;
    new var[256];
	for(new i = 0; i < sizeof(Business); i++)
	{
		FormateString(filestring, "/objektsysteme/business/%d.ini", i);
		PropertyFile = fopen(filestring, io_write);
		if(PropertyFile)
		{
			format(var, 128, "Used=%d\n", Business[i][bUsed]);					fwrite(PropertyFile, var);
			format(var, 128, "Price=%d\n", Business[i][bPrice]);				fwrite(PropertyFile, var);
			format(var, 128, "Owned=%d\n", Business[i][bOwned]);				fwrite(PropertyFile, var);
			format(var, 128, "Owner=%s\n", Business[i][bOwner]);				fwrite(PropertyFile, var);
			format(var, 128, "Title=%d\n", Business[i][bTitle]);				fwrite(PropertyFile, var);
			format(var, 128, "EnterX=%.1f\n", Business[i][bEnterX]);			fwrite(PropertyFile, var);
			format(var, 128, "EnterY=%.1f\n", Business[i][bEnterY]);			fwrite(PropertyFile, var);
			format(var, 128, "EnterZ=%.1f\n", Business[i][bEnterZ]);			fwrite(PropertyFile, var);
			format(var, 128, "ExitX=%..f\n", Business[i][bExitX]);				fwrite(PropertyFile, var);
			format(var, 128, "ExitY=%.1f\n", Business[i][bExitY]);				fwrite(PropertyFile, var);
			format(var, 128, "ExitZ=%.1f\n", Business[i][bExitZ]);				fwrite(PropertyFile, var);
			format(var, 128, "Int=%d\n", Business[i][bInt]);					fwrite(PropertyFile, var);
			format(var, 128, "Kasse=%d\n", Business[i][bKasse]);				fwrite(PropertyFile, var);
			fclose(PropertyFile);
		}
		else
		{
		    FormateString(ErrorReport, "SystemError: Kann Business %d nicht speichern", i);
		    SendClientMessageToAll(COLOR_YELLOW, ErrorReport);
		    print(ErrorReport);
		}
	}
	return true;
}
It never says "Could not save" or "Could not load", but seems link it could not load :S 'cause the businessfiles are right:

Код:
Used=0
Price=0
Owned=0
Owner=Keiner
Title=Keinen
EnterX=0.0
EnterY=0.0
EnterZ=0.0
ExitX=0
ExitY=0.0
ExitZ=0.0
Int=0
Kasse=0
It crashes if I use /rcon gmx, but thats not so bad, I can live with that, but those bugs should go out

Would be nice to help

Tion
Reply
#2

Please help, I really can_t find the bug ;(

Tion
Reply
#3

I found the bug, I closed the file while reading out of it *i am an idiot*

#closerequest
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)