Loading vehicle loop cause lags
#1

This is the loop that cause the lags.
It cause lags only if there are alot of vehicles in the cars folder so it loads alot vehicles at the start.
For example I had 170 car files and there was no lags.
But now i have 444 and there are alot of lags.


PHP код:
for(new 1<= MAX_VEHICLESv++)
    {
        if(
dini_Exists(CarFile(v)))
        {
               
AddStaticVehicleEx(dini_Int(CarFile(v),"Model"),dini_Float(CarFile(v),"X"),dini_Float(CarFile(v),"Y"),dini_Float(CarFile(v),"Z"),dini_Float(CarFile(v),"A"),dini_Int(CarFile(v),"Color1"),dini_Int(CarFile(v),"Color2"),1000*60*60*24*31*6);
            
SetVehicleVirtualWorld(vdini_Int(CarFile(v),"VirtualWorld"));
               if(!
CanPaintJob(v))
            {
                if(
dini_Int(CarFile(v),"Paintjob") != -1)
                {
                    
dini_Unset(CarFile(v),"Paintjob");
                }
            }
               
ChangeVehiclePaintjob(v,dini_Int(CarFile(v),"Paintjob"));
            
VehicleWindows[v][0] = 0;
            
VehicleWindows[v][1] = 0;
            
VehicleWindows[v][2] = 0;
            
VehicleWindows[v][3] = 0;
            new 
engine,lights,alarm,doors,bonnet,boot,objective;
            
GetVehicleParamsEx(v,engine,lights,alarm,doors,bonnet,boot,objective);
            new 
Float:vehxFloat:vehyFloat:vehzFloat:veha;
            
GetVehiclePos(vvehxvehyvehz);
            
GetVehicleZAngle(v,veha);
            
Siran[v] = false;
            
MicNums[v] = 3;
            
Oil[v] = 70;
            
Fuel[v] = 100;
            
CarInfo[v][vLock] = 1;
            
CarInfo[v][vLtrunk] = 0;
            
CarInfo[v][vLhood] = 0;
            
CarInfo[v][vColor1] = dini_Int(CarFile(v),"Color1");
            
CarInfo[v][vColor2] = dini_Int(CarFile(v),"Color2");
            
ChangeVehicleColor(v,CarInfo[v][vColor1],CarInfo[v][vColor2]);
            
CarInfo[v][Location] = dini_Int(CarFile(v),"Location");
            
CarInfo[v][Insurance] = dini_Int(CarFile(v),"Insurance");
            
CarInfo[v][vSpawnX] = dini_Float(CarFile(v),"X");
            
CarInfo[v][vSpawnY] = dini_Float(CarFile(v),"Y");
             
CarInfo[v][vSpawnZ] = dini_Float(CarFile(v),"Z");
            
CarInfo[v][vSpawnA] = dini_Float(CarFile(v),"A");
            
CarInfo[v][vOSpawnX] = dini_Float(CarFile(v),"X");
            
CarInfo[v][vOSpawnY] = dini_Float(CarFile(v),"Y");
             
CarInfo[v][vOSpawnZ] = dini_Float(CarFile(v),"Z");
            
CarInfo[v][vOSpawnA] = dini_Float(CarFile(v),"A");
            
AddVehicleComponent(v,dini_Int(CarFile(v),"SPOILER"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"HOOD"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"ROOF"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"SIDESKIRT"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"LAMPS"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"NITRO"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"EXHAUST"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"WHEELS"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"STEREO"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"HYDRAULICS"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"FRONT_BUMPER"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"REAR_BUMPER"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"VENT_RIGHT"));
            
AddVehicleComponent(v,dini_Int(CarFile(v),"VENT_LEFT"));
            for(new 
0<= 13;i++)
                
CarInfo[v][Improve][i] = GetVehicleComponentInSlot(v,i);
            
W8[v] = false;
            
vHaveC4[v] = false;
            
SetTimerEx("SpikeTires",500,true,"i",v);
            
//-------------------------------
            
if(IsAPlane(v))
            {
                
CarInfo[v][Manoa] = 5;
            }
            else if(!
IsABike(v) && !IsAVehicleForSell(v) && !IsAPlane(v))
            {
                if(
IsAPoliceCar(v) || IsACoastBoat(v) || IsAChifeCar(v) || IsAGarageCar(v) || IsAPrisonCar(v) || IsAFireCar(v) || IsANewsCar(v) ||
                
IsAMedicCar(v) || IsATrashCar(v) || IsAFisherBoat(v) || IsABicycle(v))
                {
                    
CarInfo[v][Manoa] = 5;
                }
                if(
IsADmvTruck(v) || IsADmvCar(v) || IsADmvTaxi(v) || IsADmvBoat(v))
                {
                    
CarInfo[v][Manoa] = 2;
                }
            }
            else if(
IsABike(v) && !IsAVehicleForSell(v))
            {
                if(
IsAPoliceCar(v) || IsACoastBoat(v) || IsAChifeCar(v) || IsAGarageCar(v) || IsAPrisonCar(v) || IsAFireCar(v) || IsANewsCar(v) ||
                
IsAMedicCar(v) || IsAPizzaBike(v) || IsATrashCar(v) || IsAFisherBoat(v) || IsABicycle(v))
                {
                    
CarInfo[v][Manoa] = 5;
                }
                else if(
IsADmvFastBike(v))
                {
                    
CarInfo[v][Manoa] = 5;
                }
                else if(
IsADmvSlowBike(v))
                {
                    
CarInfo[v][Manoa] = 3;
                }
            }
            else if(
IsAVehicleForSell(v))
            {
                if(
dini_Isset(CarFile(v),"Manoa"))
                {
                    
CarInfo[v][Manoa] = dini_Int(CarFile(v),"Manoa");
                }
                else
                {
                    
CarInfo[v][Manoa] = 1;
                }
            }
            else
            {
                
CarInfo[v][Manoa] = dini_Int(CarFile(v),"Manoa");
            }
            
//-------------------------------
            
if(IsABicycle(v))
            {
                
SetVehicleParamsEx(v,0,0,alarm,0,bonnet,CarInfo[v][vLtrunk],objective);
            }
            else if(
IsAPoliceCar(v)||IsACoastBoat(v)||IsAChifeCar(v)||IsAGarageCar(v)||IsAPrisonCar(v)||IsAFireCar(v)||IsANewsCar(v)||IsAMedicCar(v))
            {
                
SetVehicleParamsEx(v,0,0,alarm,CarInfo[v][vLock],bonnet,CarInfo[v][vLtrunk],objective);
            }
            else if(
IsAPizzaBike(v)||IsATrashCar(v)||IsAFisherBoat(v))
            {
                
SetVehicleParamsEx(v,0,0,alarm,CarInfo[v][vLock],bonnet,CarInfo[v][vLtrunk],objective);
            }
            else if(
IsADmvPlane(v)||IsADmvTruck(v)||IsADmvFastBike(v)||IsADmvCar(v)||IsADmvTaxi(v)||IsADmvBoat(v)||IsADmvSlowBike(v))
            {
                
SetVehicleParamsEx(v,1,1,alarm,0,bonnet,CarInfo[v][vLtrunk],objective);
            }
            else if(
IsAVehicleForSell(v))
            {
                
SetVehicleParamsEx(v,0,0,alarm,0,bonnet,CarInfo[v][vLtrunk],objective);
            }
            else
            {
                
SetVehicleParamsEx(v,0,0,alarm,CarInfo[v][vLock],bonnet,CarInfo[v][vLtrunk],objective);
            }
            if(
CanPaintJob(v))ChangeVehiclePaintjob(v,dini_Int(CarFile(v),"Paintjob"));
            
ChangeVehicleColor(v,dini_Int(CarFile(v),"Color1"),dini_Int(CarFile(v),"Color2"));
            if(
dini_Int(CarFile(v),"Model") == 544)
            {
                if(
IsAFireCar(v)){
                
XLadder[v] = -49.099822;
                
ZLadder[v] = 180.0;
                
Ladder[v] = CreateObject(12950,0,0,0,0,0,0,500);
                
AttachObjectToVehicle(Ladder[v],v,-0.019999,0.000000,1.319999,XLadder[v],0.000000,ZLadder[v]);}
            }
            if(
IsAPoliceCar(v))
            {
                
siran[v] = CreateObject(18646,999,999,999,999,999,999,500);
            }
            if(
dini_Int(CarFile(v),"Model") == 544)
            {
                
siran[v] = CreateObject(18646,999,999,999,999,999,999,500);
            }
            if(
dini_Int(CarFile(v),"Model") == 578)
            {
                if(
IsAGarageCar(v))
                {
                    
AttachObjectToVehicle(CreateObject(983,999,999,999,999,999,999,500), v1.349999, -2.2999980.3500000.0000000.0000000.000000);
                    
AttachObjectToVehicle(CreateObject(983,999,999,999,999,999,999,500), v1.349999, -0.7000000.3500000.0000000.0000000.000000);
                    
AttachObjectToVehicle(CreateObject(983,999,999,999,999,999,999,500), v, -1.349999, -2.2999980.3500000.0000000.0000000.000000);
                    
AttachObjectToVehicle(CreateObject(983,999,999,999,999,999,999,500), v, -1.349999, -0.7000000.3500000.0000000.0000000.000000);
                }
            }
            new 
liceplate[256];
            if(
dini_Isset(CarFile(v),"PlateNumber"))
            {
                
set(liceplate,"%d",dini_Int(CarFile(v),"PlateNumber"));
                
SetVehicleNumberPlate(v,liceplate);
                
CarInfo[v][vPlate] = dini_Int(CarFile(v),"PlateNumber");
            }
            else
            {
                new 
string[512];
                for(new 
01000i++)
                {
                    
LicePlate[v] = 1000000+random(6777777);
                    
set(string,"%d",LicePlate[v]);
                    if(!
dini_Isset("Other/LicePlate.txt",string))
                    {
                        
dini_IntSet("Other/LicePlate.txt",string,v);
                        
dini_IntSet(CarFile(v),"PlateNumber",LicePlate[v]);
                        
set(liceplate,"%d",LicePlate[v]);
                        
SetVehicleNumberPlate(v,liceplate);
                        
CarInfo[v][vPlate] = LicePlate[v];
                        break;
                    }
                }
            }
            
SetVehicleToRespawn(v);
            
SpawnVehicle(v,1);
            
SetVehicleParamsEx(v,0,0,0,CarInfo[v][vLock],0,0,0);
            
FixVehicle(v);
            
SetCarHP(v,1000.0);
        }
    } 
This is an example for car file:
PHP код:
Model=481
VirtualWorld
=20
X
=-1657.288574
Y
=1209.366821
Z
=13.381031
A
=269.263854
Price
=99999999999
Color1
=1
Color2
=1
Lock
=1
Manoa
=2
Location
=0
Insurance
=0
PlateNumber
=3221469 
I currently have 444 cars files to load.
Any idea to reduce the lags caused by loading the cars?
Reply


Messages In This Thread
Loading vehicle loop cause lags - by gahal156 - 06.07.2013, 08:19
Re: Loading vehicle loop cause lags - by Income - 06.07.2013, 08:22
Re: Loading vehicle loop cause lags - by gahal156 - 06.07.2013, 08:23
Re: Loading vehicle loop cause lags - by Income - 06.07.2013, 08:26
Re: Loading vehicle loop cause lags - by gahal156 - 06.07.2013, 08:27
Re: Loading vehicle loop cause lags - by Income - 06.07.2013, 08:29
Re: Loading vehicle loop cause lags - by gahal156 - 06.07.2013, 08:30
Re: Loading vehicle loop cause lags - by Income - 06.07.2013, 08:34
Re: Loading vehicle loop cause lags - by gahal156 - 06.07.2013, 08:47
Re: Loading vehicle loop cause lags - by SwisherSweet - 06.07.2013, 08:50

Forum Jump:


Users browsing this thread: 1 Guest(s)