SA-MP Forums Archive
post a better/faster code please.... - 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: post a better/faster code please.... (/showthread.php?tid=248978)



post a better/faster code please.... - THE_KNOWN - 16.04.2011

Код:
stock LoadOvehs()
{
    new
       query[128],
       field[13][128],
       c1,
       c2;
    mysql_query("SELECT * FROM `orgvehs`");
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
    for(new i=mysql_retrieve_row();i<mysql_num_rows();i++)
      {
            mysql_fetch_row_format(query, "|");
            explode(query, field, "|");
            new mdl,vidid,Float:x,Float:y,Float:z,Float:r;
            mdl=strval(field[1]);
            x=strval(field[2]);
            y=strval(field[3]);
            z=strval(field[4]);
            r=strval(field[5]);
            c1=strval(field[6]);
            c2=strval(field[7]);
            vidid=CreateVehicle(mdl,x,y,z+0.2,r,c1,c2,1800);
            vorg[vidid]=strval(field[0]);
            new d[128];
			format(d,128,"vehicle %d created. org - %d",vidid,vorg[vidid]);
			printf("%s",d);
      }
    }
    mysql_free_result();
    return 1;
}
this is my version but after it loads abt 100 cars off mysql it stops loading and breaks the public. so im requesting a better way of doing this and also i heard of ppl using sscanf which i would like to try


Re: post a better/faster code please.... - THE_KNOWN - 17.04.2011

bump no one loads cars from mysql here?


Re: post a better/faster code please.... - Calgon - 17.04.2011

I gave you an example a while ago, refer to that, I'm not going to write it up all again.


Re: post a better/faster code please.... - THE_KNOWN - 17.04.2011

uh yeah you gave me one with while and i DID try that. but the flaw i noticed was it was skipping records like:

1
2
3

and it would load

1
3

skipping 2.... so help please

EDIT:the code i posted is the same code you gave me and the only thing is changed is the while to for bcoz of the pob it caused


Re: post a better/faster code please.... - Donya - 17.04.2011

try using
pawn Код:
SELECT * FROM `orgvehs` ORDER BY `id` ASC
to stop skipping maybe?


Re: post a better/faster code please.... - THE_KNOWN - 17.04.2011

no it doesnt matter like that. it just loads alternative records.


Re: post a better/faster code please.... - [L3th4l] - 17.04.2011

Please post your entire table structure. I mean, what's in the first field? Second? I can tell much about that stock, but i need the whole code to make a better stock.


Re: post a better/faster code please.... - THE_KNOWN - 17.04.2011

heres the structure



the ID field specifies the org of the vehicle. i use that data when i get the id of the car created so i can assign it to the org. the rest are obvious

EDIT: i added a count of how many vehicles load off mysql and noticed that only the first 14 load out of 88


Re: post a better/faster code please.... - [L3th4l] - 17.04.2011

Here you go:
pawn Код:
stock LoadOvehs()
{
    new
        iStr[90],
        v_Model,
        v_Color[2],
        v_ID,
        Float:v_Spawn[4];

    mysql_query("SELECT * FROM `orgvehs`");
    mysql_store_result();
   
    if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(iStr))
        {
            sscanf(iStr, "p<|>iiffffii", v_ID, v_Model, v_Spawn[0], v_Spawn[1], v_Spawn[2], v_Spawn[3], v_Color[0], v_Color[1]);
           
            new
                iVehicle = CreateVehicle(v_Model, v_Spawn[0], v_Spawn[1], v_Spawn[2], v_Spawn[3], v_Color[0], v_Color[1], 1800);

            vorg[iVehicle] = v_ID;
           
            ++ v_ID;
        }
    }
    printf("%i orgveh vehicles loaded!", v_ID);
    mysql_free_result();
    return 1;
}