SA-MP Forums Archive
Converting this Small Code from MYSQL into Dini. - 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)
+--- Thread: Converting this Small Code from MYSQL into Dini. (/showthread.php?tid=562976)



Converting this Small Code from MYSQL into Dini. - Goosie - 13.02.2015

Hey, I can't figure out any way to convert this to dini since I don't know anything about mysql.
I'd be happy if any the fellow scripters could help out.

Код:
forward LoadToys(playerid);
public LoadToys(playerid)
{
	//Resetting the data.
	printf("Loading toys for (%s)",PlayerName(playerid));
	for(new i = 1; i < 5; i++)
	{
	    if(i != 5)
	    {
	        ToyInfo[playerid][i][tID] = 0;
	    }
	}
	//Loading the new data
   	new rows, fields;
	cache_get_data(rows, fields);
	if(rows)
	{
	    //print("Toys exist");
	    new fetch[255], indexid;
	    for(new i = 0; i < rows; i++)
	    {
	        //printf("Toy %d loading", i);
	        if(i < 4)
	        {
                cache_get_field_content(i, "indexID", fetch);
                indexid = strval(fetch);
                ToyInfo[playerid][indexid][tID] = indexid;

                cache_get_field_content(i, "bone", fetch);
		        ToyInfo[playerid][indexid][tBone] = strval(fetch);
		        cache_get_field_content(i, "modelid", fetch);
                ToyInfo[playerid][indexid][tModel] = strval(fetch);

                cache_get_field_content(i, "OffSetX", fetch);
				ToyInfo[playerid][indexid][toX] = floatstr(fetch);
				cache_get_field_content(i, "OffSetY", fetch);
    			ToyInfo[playerid][indexid][toY] = floatstr(fetch);
    			cache_get_field_content(i, "OffSetZ", fetch);
    			ToyInfo[playerid][indexid][toZ] = floatstr(fetch);

    			cache_get_field_content(i, "RotX", fetch);
    			ToyInfo[playerid][indexid][trX] = floatstr(fetch);
    			cache_get_field_content(i, "RotY", fetch);
    			ToyInfo[playerid][indexid][trY] = floatstr(fetch);
    			cache_get_field_content(i, "RotZ", fetch);
    			ToyInfo[playerid][indexid][trZ] = floatstr(fetch);

    			cache_get_field_content(i, "ScaleX", fetch);
    			ToyInfo[playerid][indexid][tsX] = floatstr(fetch);
    			cache_get_field_content(i, "ScaleY", fetch);
    			ToyInfo[playerid][indexid][tsY] = floatstr(fetch);
    			cache_get_field_content(i, "ScaleZ", fetch);
    			ToyInfo[playerid][indexid][tsZ] = floatstr(fetch);
    			//printf("Toy %d INDEX loaded", indexid);
				/*if(IsValidClothing(ToyInfo[playerid][indexid][tModel])) //Create the object
				{
				    SetPlayerAttachedObject(playerid, indexid, ToyInfo[playerid][indexid][tModel],ToyInfo[playerid][indexid][tBone],
					ToyInfo[playerid][indexid][toX], ToyInfo[playerid][indexid][toY], ToyInfo[playerid][indexid][toZ],
					ToyInfo[playerid][indexid][trX], ToyInfo[playerid][indexid][trY], ToyInfo[playerid][indexid][trZ],
				 	ToyInfo[playerid][indexid][tsX], ToyInfo[playerid][indexid][tsY], ToyInfo[playerid][indexid][tsZ]);
				}
				*/
	        }
	    }
	}
	return 1;
}
//============================================//
forward SaveToys(playerid);
public SaveToys(playerid)
{
	new query[516];
	for(new i = 1; i < 5; i++)
	{
	    if(i != 5)
	    {
	        if(IsValidClothing(ToyInfo[playerid][i][tModel]))
	        {
		        format(query, sizeof(query), "UPDATE toys SET bone=%d, modelid=%d, OffSetX=%f, OffSetY=%f, OffSetZ=%f, RotX=%f, RotY=%f, RotZ=%f, ScaleX=%f, ScaleY=%f, ScaleZ=%f WHERE PlayerName='%s' AND indexID=%d",
				ToyInfo[playerid][i][tBone],ToyInfo[playerid][i][tModel],
				ToyInfo[playerid][i][toX],ToyInfo[playerid][i][toY],ToyInfo[playerid][i][toZ],
				ToyInfo[playerid][i][trX],ToyInfo[playerid][i][trY],ToyInfo[playerid][i][trZ],
				ToyInfo[playerid][i][tsX],ToyInfo[playerid][i][tsY],ToyInfo[playerid][i][tsZ],
				PlayerName(playerid),i);
				mysql_function_query(handlesql, query, false, "SendQuery", "");
			}
	    }
	}
	return 1;
}



Re: Converting this Small Code from MYSQL into Dini. - Vince - 13.02.2015

Hey, I can't figure out any way to convert a car to a bicycle since I don't know anything about cars. And yet it seems like a ludicrous idea. You need to know one thing: dini is slow and outdated. Do not use it in new projects.


Re: Converting this Small Code from MYSQL into Dini. - GGRoleplay - 13.02.2015

Keep it at MySQL, way faster and more efficient.


Re: Converting this Small Code from MYSQL into Dini. - PowerPC603 - 13.02.2015

Dini should be avoided, it's slow as hell.
Whenever dini reads from a file, it opens the file, loops through the entire file to find the value you need and closes it again.

When you need to read 100 values, dini opens this file 100 times, reads the entire contents 100 times (until the proper value is found) and closes it 100 times.

It overuses your harddrive as well and it may deteriorate faster than normal, because it's reading the same file 100 times instead of 1 time.

Just use MySQL.
Much faster, more reliable as it has built-in error-checking and several protection systems to prevent corrupted data and more flexible.

If you were given the choice to drive a Bentley (MySQL) or a bycicle (dini), which one would you choose?


Re: Converting this Small Code from MYSQL into Dini. - Vince - 13.02.2015

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
If you were given the choice to drive a Bentley (MySQL) or a bycicle (dini), which one would you choose?
I think we already established that he'd rather choose the bycicle because he can't drive.