Help with function
#1

There is something in this function, it crash function not whole gamemode or server, but prevents loading rest functions...
I just can't figure out what can be problem! No compile errors or nothing. There is file in right place. Text " Has been loaded." will never comes to server log...

Please help with this.

Код:
public LoadFuelStaions ()
{
	printf("[FUELSTATIONS]: Starting to load...");
    new SplitDiv[5][10];
    new filestring[125];
    new fueltext[55];
    new File: file = fopen(FUEL_STATIONS_FILE, io_read);
        for(new stid = 0; stid < MAX_FUELSTATIONS; stid++)
        {
            fread(file, filestring);
            split(filestring, SplitDiv, ',');
            stfuelcoords[stid][stX] = floatstr(SplitDiv[0]);
           	stfuelcoords[stid][stY] = floatstr(SplitDiv[1]);
            stfuelcoords[stid][stZ] = floatstr(SplitDiv[2]);
            stfuelcoords[stid][fuelcost] = strval(SplitDiv[3]);
            strmid(stfuelcoords[stid][ownerfuel], SplitDiv[4], 0, strlen(SplitDiv[4]), 255);
            format(fueltext, sizeof(fueltext), "%iЂ/l || %s", stfuelcoords[stid][fuelcost], stfuelcoords[stid][ownerfuel]);
   			CreateDynamicMapIcon(stfuelcoords[stid][stX], stfuelcoords[stid][stY], stfuelcoords[stid][stZ], 51, 0, -1, -1, -1);
   			stfuelcoords[stid][fuellabel] = CreateDynamic3DTextLabel(fueltext, COLOR_3D_TEXT_NORMAL, stfuelcoords[stid][stX], stfuelcoords[stid][stY], stfuelcoords[stid][stZ], DRAW_DISRANCE_3DTEXT, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, TEST_LOS, -1, -1, -1);
		}
		fclose(file);
		printf("[FUELSTATIONS]: Has been loaded.");
}
Reply
#2

You should check whether the file was opened correctly or not before reading from/writing to it.

pawn Код:
public LoadFuelStaions ()
{
    printf("[FUELSTATIONS]: Starting to load...");
    new SplitDiv[5][10];
    new filestring[125];
    new fueltext[55];
    new File: file = fopen(FUEL_STATIONS_FILE, io_read);
    if(file)
    {
        for(new stid = 0; stid < MAX_FUELSTATIONS; stid++)
        {
            fread(file, filestring);
            split(filestring, SplitDiv, ',');
            stfuelcoords[stid][stX] = floatstr(SplitDiv[0]);
            stfuelcoords[stid][stY] = floatstr(SplitDiv[1]);
            stfuelcoords[stid][stZ] = floatstr(SplitDiv[2]);
            stfuelcoords[stid][fuelcost] = strval(SplitDiv[3]);
            strmid(stfuelcoords[stid][ownerfuel], SplitDiv[4], 0, strlen(SplitDiv[4]), 255);
            format(fueltext, sizeof(fueltext), "%i€/l || %s", stfuelcoords[stid][fuelcost], stfuelcoords[stid][ownerfuel]);
            CreateDynamicMapIcon(stfuelcoords[stid][stX], stfuelcoords[stid][stY], stfuelcoords[stid][stZ], 51, 0, -1, -1, -1);
            stfuelcoords[stid][fuellabel] = CreateDynamic3DTextLabel(fueltext, COLOR_3D_TEXT_NORMAL, stfuelcoords[stid][stX], stfuelcoords[stid][stY], stfuelcoords[stid][stZ], DRAW_DISRANCE_3DTEXT, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, TEST_LOS, -1, -1, -1);
        }
        fclose(file);
    }
    printf("[FUELSTATIONS]: Has been loaded.");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)