SA-MP Forums Archive
Making this code faster - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Making this code faster (/showthread.php?tid=132350)



Making this code faster - jonrb - 07.03.2010

Hi guys,
Is there any way this loop can be made more efficient?
It's only called in OnFilterScriptInit, but it takes 23 seconds to complete.
There are roughly 680 cars. MAX_CARS is 700.
pawn Код:
cars=0;
new vehid;
new ownedcars,freecars;
new str[128];
new str1[5];
new idx;
new Float:info[4],model;
for(new id;id<MAX_CARS;id++)
{
    format(str,128,"");
    format(str1,5,"%i",id);
    idx=0;
    model=0;
    if(!dini_Isset(CARLIST,str1)) continue;
    str = dini_SGet(CARLIST,str1);
    model = strval(Sstrtok(str,idx));
    info[0] = floatstr(Sstrtok(str,idx));
    info[1] = floatstr(Sstrtok(str,idx));
    info[2] = floatstr(Sstrtok(str,idx));
    info[3] = floatstr(Sstrtok(str,idx));
    vehid = CreateVehicle(model,info[0],info[1],info[2],info[3],-1,-1,360000);
    Vcolour1[vehid] = -1;
    Vcolour2[vehid] = -1;
    SetColour(vehid);
    if(dini_Isset(MODFILE,valtostr(vehid))) LoadMods(vehid,dini_SGet(MODFILE,valtostr(vehid)));
    if(!dini_Isset("carsys/carowners.txt",str1))
    {
        carowner[id] = "No Owner";
        freecars++;
    }
    else
    {
        str = dini_SGet("carsys/carowners.txt",str1);
        format(carowner[id],MAX_PLAYER_NAME,str);
        ownedcars++;
    }
    if(model==509 || model==481 || model==510) EngineOn[vehid] = 1;
    cars++;
    }
Any custom functions are already very efficient. It's just this bit I want to fix up!

P.S. I don't want answers like "Get a streamer". There's no challenge in that!


Re: Making this code faster - ¤Adas¤ - 07.03.2010

OMFG, 23 seconds? This can not be true... I can't help you, I don't know DINI...