y_ini - How to load created map
#1

Hi guys.

I'm making a InGame Object Creator and here is my code to save created objects:


Код:
new INI:ini_doeMap = INI_Open(mapName);
for(new i = 0; i < doe_Index + 1; i++)
{
new stringName[30], stringParams[256];
format(stringName, sizeof(stringName), "doe_Object[%i]", i);
format(stringParams, sizeof(stringParams), "CreateObject(%i, %f, %f, %f, %f, %f, %f);", DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
INI_WriteString(ini_doeMap, stringName, stringParams);
}
INI_Close(ini_doeMap);
It works great, but I have no idea how to load the objects back to the game from file (I'm not much experienced about y_ini)

Saved file with the objects:
Код:
doe_Object[1] = CreateObject(3035, -2003.729370, 433.925506, 35.015625, 0, 0, 0);
doe_Object[2] = CreateObject(3035, -1998.181884, 438.433471, 35.637966, 0, 0, 0);
doe_Object[3] = CreateObject(3034, -2005.000488, 444.294250, 35.015625, 0, 0, 0);
doe_Object[4] = CreateObject(3036, -1997.110839, 444.868347, 35.015625, 0, 0, 0);
doe_Object[5] = CreateObject(3034, -2005.863647, 449.276489, 35.015625, 0, 0, 0);
doe_Object[6] = CreateObject(3034, -2005.863647, 449.276489, 35.015625, 0, 0, 0);
doe_Object[7] = CreateObject(3034, -2005.863647, 449.276489, 35.015625, 0, 0, 0);
doe_Object[8] = CreateObject(3034, -2000.441772, 454.467773, 35.015625, 0, 0, 0);
Can somebody help please?
Thank you.
Reply
#2

Show 'mapName', use standard file system and why you starts from 1 ?
new i = 1;
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Show 'mapName', use standard file system and why you starts from 1 ?
new i = 1;
It's just a string with name of file. Yea, I could, but it would be easy .
Reply
#4

save
pawn Код:
new stringParams[150];
new File:ini_doeMap = fopen(mapName, io_write);
for(new i = 1; i < doe_Index + 1; i++)
{
    format(stringParams, sizeof(stringParams), "CreateObject(%i,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f);\r\n", DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
    fwrite(ini_doeMap, stringParams);
}
fclose(ini_doeMap);
load
pawn Код:
new string[128],i = 1;
new File:ini_doeMap = fopen(mapName, io_read);
while(i < sizeof(DOE) && fread(ini_doeMap, string))
{
    sscanf(string,"'('p<,>ifffffp<)>f",DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
    doe_Object[i] = CreateObject(DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
    i++;
}
fclose(ini_doeMap);
Reply
#5

Quote:
Originally Posted by Jefff
Посмотреть сообщение
save
pawn Код:
new stringParams[150];
new File:ini_doeMap = fopen(mapName, io_write);
for(new i = 1; i < doe_Index + 1; i++)
{
    format(stringParams, sizeof(stringParams), "CreateObject(%i,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f);\r\n", DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
    fwrite(ini_doeMap, stringParams);
}
fclose(ini_doeMap);
load
pawn Код:
new string[128],i = 1;
new File:ini_doeMap = fopen(mapName, io_read);
while(i < sizeof(DOE) && fread(ini_doeMap, string))
{
    sscanf(string,"'('p<,>ifffffp<)>f",DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
    doe_Object[i] = CreateObject(DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
    i++;
}
fclose(ini_doeMap);
It works, but when I restart a server the objects aren't loading.

Output in file is normal.


Here my code:
Код:
		new string[256],i = 0;
		if(!fexist(mapName)) return SendClientMessage(playerid, c_red, "Tento soubor neexistuje!");
		new File:ini_doeMap = fopen(mapName, io_read);
		while(i < sizeof(DOE) && fread(ini_doeMap, string))
		{
			sscanf(string,"'('p<,>iffffffp<)>f", DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
			doe_Object[doe_Index] = CreateObject(DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
			SendClientMessage(playerid, c_ltgreen, string);
			new stringg[256];
			SendFormatMsg(playerid, c_red, stringg, "doe_Object[%i/%i] = %f, %f, %f, %f, %f, %f", doe_Index, i, DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
			i++;
			doe_Index++;
		}
		fclose(ini_doeMap);
When I print the variables (Red = string, Green = stringg):
Reply
#6

Remove one 'f' before p<)>
Reply
#7

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Remove one 'f' before p<)>
Still the same problem.
Reply
#8

Should load fine and missing in SendFormatMsg %d for model
Reply
#9

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Should load fine and missing in SendFormatMsg %d for model
But It doesn't.

It looks that problem is in these lines.

Код:
sscanf(string,"'('p<,>ifffffp<)>f", DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
doe_Object[doe_Index] = CreateObject(DOE[i][DOE_ModelID], DOE[i][DOE_X], DOE[i][DOE_Y], DOE[i][DOE_Z], DOE[i][DOE_rX], DOE[i][DOE_rY], DOE[i][DOE_rZ]);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)