Load help
#1

I need help with this it won't load it when the server start, maybe you guys are able to help me, thanks in advance!


PHP код:
new File:file fopen("DroppedGuns.ini"io_read);
    if(
file)
    {
        new 
buffer[256], FileCoords[8][20];
        for(new 
0MAX_OBJg++)
        {
            
fread(filebuffer);
            
split(bufferFileCoords',');
            
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] > && dGunData[g][ObjData][1] != && 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]-193.7120.0120.0dGunData[g][ObjWorld], dGunData[g][ObjInt], -1200.00.0);
                        
dGunData[g][ObjText] = CreateDynamic3DTextLabel("{339900}Item\n(/pickupitem)",0xFFFFFFFFdGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-110.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0dGunData[g][ObjWorld], dGunData[g][ObjInt], -190);
                        
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(1578dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-193.7120.0120.0dGunData[g][ObjWorld], dGunData[g][ObjInt], -1200.00.0);
                        
dGunData[g][ObjText] = CreateDynamic3DTextLabel("{339900}Item\n(/pickupitem)",0xFFFFFFFFdGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-110.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0dGunData[g][ObjWorld], dGunData[g][ObjInt], -190);
                    }
                }
            }
        }
    } 
Reply
#2

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 код:
while(fread(filebuffer) && MAX_OBJ
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
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 код:
while(fread(filebuffer) && MAX_OBJ
Still same problem.
Reply
#4

This should work unless it cannot open the file for some reason (permissions etc.).
PHP код:
new Filefile 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(filebuffer))
{
    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] > && dGunData[g][ObjData][1] != && 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] - 193.7120.0120.0dGunData[g][ObjWorld], dGunData[g][ObjInt], -1200.00.0);
                
dGunData[g][ObjText] = CreateDynamic3DTextLabel("{339900}Item\n(/pickupitem)"0xFFFFFFFFdGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2] - 110.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0dGunData[g][ObjWorld], dGunData[g][ObjInt], -190);
                
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(1578dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2] - 193.7120.0120.0dGunData[g][ObjWorld], dGunData[g][ObjInt], -1200.00.0);
                
dGunData[g][ObjText] = CreateDynamic3DTextLabel("{339900}Item\n(/pickupitem)"0xFFFFFFFFdGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2] - 110.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0dGunData[g][ObjWorld], dGunData[g][ObjInt], -190);
            }
        }
    }

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)