Loading objects from a .cfg file.
#1

Evening, I finally got the gamemode working.

Now I have an another problem..
Previously I loaded maps like this:

Код:
stock LoadObjects()
{
	new dinfo[15][128];
	new string[256];
	new File:file = fopen("objects22.cfg", io_read);
	if(file)
	{
	    new idx = 1;
		while(idx < MAX_OBJ)
		{
		    fread(file, string);
		    split(string, dinfo, '|');
			ObjInfo[idx][oModel] = strval(dinfo[0]);
			ObjInfo[idx][oX] = floatstr(dinfo[1]);
			ObjInfo[idx][oY] = floatstr(dinfo[2]);
			ObjInfo[idx][oZ] = floatstr(dinfo[3]);
			ObjInfo[idx][oRX] = floatstr(dinfo[4]);
			ObjInfo[idx][oRY] = floatstr(dinfo[5]);
			ObjInfo[idx][oRZ] = floatstr(dinfo[6]);
			if(ObjInfo[idx][oModel]) // If gate exists
			{
				ObjInfo[idx][obj] = CreateDynamicObject(ObjInfo[idx][oModel], ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], ObjInfo[idx][oRX], ObjInfo[idx][oRY], ObjInfo[idx][oRZ]);
                format(string, sizeof(string), "Object ID: %d (Model ID: %d)", idx, ObjInfo[idx][oModel]);
				ObjInfo[idx][oText] = CreateDynamic3DTextLabel(string, COLOR_GREY, ObjInfo[idx][oX], ObjInfo[idx][oY], ObjInfo[idx][oZ], 10);
			}
			idx++;
	    }
	}
	print("Objects loaded successfully.");
	return 1;
}
the .cfg it was reading from:

Код:
0|0.000000|0.000000|0.000000|0.000000|0.000000|0.000000
0|0.000000|0.000000|0.000000|0.000000|0.000000|0.000000
0|0.000000|0.000000|0.000000|0.000000|0.000000|0.000000
0|0.000000|0.000000|0.000000|0.000000|0.000000|0.000000
0|0.000000|0.000000|0.000000|0.000000|0.000000|0.000000
0|0.000000|0.000000|0.000000|0.000000|0.000000|0.000000
0|0.000000|0.000000|0.000000|0.000000|0.000000|0.000000
I was obviously using | to split data.
Now.. I want to use multiple splits.
And read them like this:

Код:
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
	CreateDynamicObject(0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000);
Is this even possible?
Reply
#2

Sscanf should be able to do that quite easily, I reckon.
Код:
"p<,>'CreateDynamicObject('dffffff');'"
Something like that.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Sscanf should be able to do that quite easily, I reckon.
Код:
"p<,>'CreateDynamicObject('dffffff');'"
Something like that.
I think that wouldn't work on the last value.

I haven't tested this but it should work.
Код:
"P<(),>{s[20]}iffffff"
[20] depends on the lengthiest string sscanf should ignore (CreateDynamicObject( in this case)
Reply
#4

Thanks!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)