new File:file = fopen("DroppedGuns.ini", io_read);
if(file)
{
new buffer[256], FileCoords[8][20];
for(new g = 0; g < MAX_OBJ; g++)
{
fread(file, buffer);
split(buffer, FileCoords, ',');
dGunData[g][ObjPos][0] = floatstr(FileCoords[0]);
dGunData[g][ObjPos][1] = floatstr(FileCoords[1]);
dGunData[g][ObjPos][2] = floatstr(FileCoords[2]);
dGunData[g][ObjData][0] = strval(FileCoords[3]);
dGunData[g][ObjData][1] = strval(FileCoords[4]);
dGunData[g][ObjInt] = strval(FileCoords[5]);
dGunData[g][ObjWorld] = strval(FileCoords[6]);
dGunData[g][ObjType] = strval(FileCoords[6]);
if(dGunData[g][ObjData][0] > 0 && dGunData[g][ObjData][1] != 0 && dGunData[g][ObjPos][0] != 0)
{
switch(dGunData[g][ObjType])
{
case 1:
{
dGunData[g][ObjID] = CreateDynamicObject(GunobjectIds[dGunData[g][ObjData][0]], dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-1, 93.7, 120.0, 120.0, dGunData[g][ObjWorld], dGunData[g][ObjInt], -1, 200.0, 0.0);
dGunData[g][ObjText] = CreateDynamic3DTextLabel("{339900}Item\n(/pickupitem)",0xFFFFFFFF, dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-1, 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, dGunData[g][ObjWorld], dGunData[g][ObjInt], -1, 90);
printf("* %s loaded: %f,%f,%f,", GunNames[dGunData[g][ObjData][0]], dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-1);
}
case 2:
{
dGunData[g][ObjID] = CreateDynamicObject(1578, dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-1, 93.7, 120.0, 120.0, dGunData[g][ObjWorld], dGunData[g][ObjInt], -1, 200.0, 0.0);
dGunData[g][ObjText] = CreateDynamic3DTextLabel("{339900}Item\n(/pickupitem)",0xFFFFFFFF, dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-1, 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, dGunData[g][ObjWorld], dGunData[g][ObjInt], -1, 90);
}
}
}
}
}
while(fread(file, buffer) && g < MAX_OBJ)
Oh boy ... That's some stuff I haven't seen in a long, long time. Sscanf does a much better job at splitting strings.
I'm guessing now, but I don't think using fread within a for-loop is a good idea. I have no idea what happens if you force it to read a line, even if there are no more lines left. Declare "g" outside of the loop and then restructure it into a while-loop. And obviously don't forget to increment within the loop. PHP код:
|
new File: file = fopen("DroppedGuns.ini", io_read);
if (!file) return print("Warning: Could not open file \"DroppedGuns.ini\".");
new buffer[256], count = -1;
// read the whole file
while (fread(file, buffer))
{
if (++count >= sizeof dGunData) break; // making sure it won't go out of bounds
sscanf(buffer, "p<,>fffiiiii", dGunData[count][ObjPos][0], dGunData[count][ObjPos][1], dGunData[count][ObjPos][2], dGunData[count][ObjData][0], dGunData[count][ObjData][1], dGunData[count][ObjInt], dGunData[count][ObjWorld], dGunData[count][ObjType]);
if (dGunData[g][ObjData][0] > 0 && dGunData[g][ObjData][1] != 0 && dGunData[g][ObjPos][0] != 0)
{
switch (dGunData[g][ObjType])
{
case 1:
{
dGunData[g][ObjID] = CreateDynamicObject(GunobjectIds[dGunData[g][ObjData][0]], dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2] - 1, 93.7, 120.0, 120.0, dGunData[g][ObjWorld], dGunData[g][ObjInt], -1, 200.0, 0.0);
dGunData[g][ObjText] = CreateDynamic3DTextLabel("{339900}Item\n(/pickupitem)", 0xFFFFFFFF, dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2] - 1, 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, dGunData[g][ObjWorld], dGunData[g][ObjInt], -1, 90);
printf("* %s loaded: %f,%f,%f,", GunNames[dGunData[g][ObjData][0]], dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2] - 1);
}
case 2:
{
dGunData[g][ObjID] = CreateDynamicObject(1578, dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2] - 1, 93.7, 120.0, 120.0, dGunData[g][ObjWorld], dGunData[g][ObjInt], -1, 200.0, 0.0);
dGunData[g][ObjText] = CreateDynamic3DTextLabel("{339900}Item\n(/pickupitem)", 0xFFFFFFFF, dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2] - 1, 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, dGunData[g][ObjWorld], dGunData[g][ObjInt], -1, 90);
}
}
}
}