Time freeze using CMDS [vehicle]
#6

Opening, writing and closing files 2000 times. You set idx to the value "carsonserver" is so what's the point of checking all the time instead of just opening the file once.

Plus you never check for invalid file handles and that can crash the server and declaring a string 2000 times as well (keep it outside of the loop).

PHP код:
public OnCarUpdate()
{
    new 
coordsstring[256], Filefile2 fopen("masini.cfg"io_write);
    
    if (!
file2) return 0;
    
    for (new 
idx carsonserveridx != sizeof (CarInfo); ++idx)
    {
        
format(coordsstringsizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
        
CarInfo[idx][cModel],
        
CarInfo[idx][cLocationx],
        
CarInfo[idx][cLocationy],
        
CarInfo[idx][cLocationz],
        
CarInfo[idx][cAngle],
        
CarInfo[idx][cColorOne],
        
CarInfo[idx][cColorTwo],
        
CarInfo[idx][cOwner],
        
CarInfo[idx][cDescription],
        
CarInfo[idx][cValue],
        
CarInfo[idx][cOwned],
        
CarInfo[idx][mod1],
        
CarInfo[idx][mod2],
        
CarInfo[idx][mod3],
        
CarInfo[idx][mod4],
        
CarInfo[idx][mod5],
        
CarInfo[idx][mod6],
        
CarInfo[idx][mod7],
        
CarInfo[idx][mod8],
        
CarInfo[idx][mod9],
        
CarInfo[idx][mod10],
        
CarInfo[idx][mod11],
        
CarInfo[idx][mod12],
        
CarInfo[idx][mod13],
        
CarInfo[idx][mod14],
        
CarInfo[idx][mod15],
        
CarInfo[idx][mod16],
        
CarInfo[idx][mod17],
        
CarInfo[idx][paintjob]);

        
fwrite(file2coordsstring);
    }
    
fclose(file2);
    return 
1;

Reply


Messages In This Thread
Time freeze using CMDS [vehicle] - by PepsiCola23 - 19.05.2015, 15:36
Re: Time freeze using CMDS [vehicle] - by azzerking - 19.05.2015, 18:23
Re: Time freeze using CMDS [vehicle] - by PepsiCola23 - 19.05.2015, 18:35
Re: Time freeze using CMDS [vehicle] - by azzerking - 19.05.2015, 18:39
Re: Time freeze using CMDS [vehicle] - by PepsiCola23 - 19.05.2015, 19:02
Re: Time freeze using CMDS [vehicle] - by Konstantinos - 19.05.2015, 19:11
Re: Time freeze using CMDS [vehicle] - by azzerking - 19.05.2015, 19:11
Re: Time freeze using CMDS [vehicle] - by PepsiCola23 - 19.05.2015, 19:43

Forum Jump:


Users browsing this thread: 1 Guest(s)