SA-MP Forums Archive
How to optimize this! - 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: How to optimize this! (/showthread.php?tid=607053)



How to optimize this! - StreK - 13.05.2016

'm doing a furniture system , and I want to display a list of furniture that has a home but the array is too large to be displayed.

Код:
#define MAX_FURNITURE (1000) // max objects
#define MAX_HOUSE_FURNITURE (20) // max objects per house
this is the command I'm doing to display objects that have a home.

PHP код:
CMD:furniture(playeridparams[])
{
    static
        
houseid = -1;
    if ((
houseid House_Inside(playerid)) != -&& House_IsOwner(playeridhouseid))
    {
        new 
count;
        
        static
            
muebles[MAX_HOUSE_FURNITURE];
           for(new 
0,MAX_FURNITURE;<= j;i++)
        {
            if (
count MAX_HOUSE_FURNITURE && FurnitureData[i][furnitureExists] && FurnitureData[i][furnitureHouse] == houseid)
            {
                
ListedFurniture[playerid][count++] = i;
                
muebles[i] = FurnitureData[i][furnitureModel];
            }
        }
        if (
count) {
            
ShowModelSelectionMenu(playerid"Muebles"MODEL_SELECTION_MUEBLESmueblessizeof(muebles), -16.00.0, -55.00.91);
         }
         else 
SendErrorMessage(playerid"esta casa no tiene muebles.");
    }
    else 
SendErrorMessage(playerid"no estбs en el interior de tu casa.");
    return 
1;

the problem is that the array is too big, and I do not see how to optimize to show correctly the list.
pd: sorry for my bad English :P


Re: How to optimize this! - Micko123 - 14.05.2016

Код:
CMD:furniture(playerid, params[])
{
	static houseid = -1;
    if((houseid = House_Inside(playerid)) != -1 && House_IsOwner(playerid, houseid))
    {
        new count;
        static muebles[MAX_HOUSE_FURNITURE];
        for(new i = 0,j = MAX_FURNITURE;i <= j;i++)
        {
            if(count < MAX_HOUSE_FURNITURE && FurnitureData[i][furnitureExists] && FurnitureData[i][furnitureHouse] == houseid)
            {
                ListedFurniture[playerid][count++] = i;
                muebles[i] = FurnitureData[i][furnitureModel];
            }
        }
        if(count)
		{
            ShowModelSelectionMenu(playerid, "Muebles", MODEL_SELECTION_MUEBLES, muebles, sizeof(muebles), -16.0, 0.0, -55.0, 0.9, 1);
  		}
        else SendErrorMessage(playerid, "esta casa no tiene muebles.");
    }
    else SendErrorMessage(playerid, "no estбs en el interior de tu casa.");
    return 1;
}
Maybe it will work maybe not. If not send me errors or warns that you get


Re: How to optimize this! - BiosMarcel - 14.05.2016

Quote:
Originally Posted by Micko123
Посмотреть сообщение
Код:
CMD:furniture(playerid, params[])
{
	static houseid = -1;
    if((houseid = House_Inside(playerid)) != -1 && House_IsOwner(playerid, houseid))
    {
        new count;
        static muebles[MAX_HOUSE_FURNITURE];
        for(new i = 0,j = MAX_FURNITURE;i <= j;i++)
        {
            if(count < MAX_HOUSE_FURNITURE && FurnitureData[i][furnitureExists] && FurnitureData[i][furnitureHouse] == houseid)
            {
                ListedFurniture[playerid][count++] = i;
                muebles[i] = FurnitureData[i][furnitureModel];
            }
        }
        if(count)
		{
            ShowModelSelectionMenu(playerid, "Muebles", MODEL_SELECTION_MUEBLES, muebles, sizeof(muebles), -16.0, 0.0, -55.0, 0.9, 1);
  		}
        else SendErrorMessage(playerid, "esta casa no tiene muebles.");
    }
    else SendErrorMessage(playerid, "no estбs en el interior de tu casa.");
    return 1;
}
Maybe it will work maybe not. If not send me errors or warns that you get
They only thing that u did was removing white space, that is not optimizing it is retarded and if u do that at least format the rest properly ... that is dirty scripting


Re: How to optimize this! - Micko123 - 14.05.2016

I am dirty :3
And there is problem when posting codes on this forum. Everything moves left or right..


Re: How to optimize this! - BiosMarcel - 14.05.2016

Quote:
Originally Posted by Micko123
Посмотреть сообщение
I am dirty :3
And there is problem when posting codes on this forum. Everything moves left or right..
No, not if you do it properly


Re: How to optimize this! - F1N4L - 14.05.2016

Код:
CMD:furniture(playerid, params[])
{
	static houseid = -1, muebles[MAX_HOUSE_FURNITURE];
	new count;
    if((houseid = House_Inside(playerid)) != -1 && House_IsOwner(playerid, houseid))
    {
        for(new i = 0,j = MAX_FURNITURE;i <= j;i++)
        {
            if(count < MAX_HOUSE_FURNITURE && FurnitureData[i][furnitureExists] && FurnitureData[i][furnitureHouse] == houseid) 
				ListedFurniture[playerid][count++] = i,
                muebles[i] = FurnitureData[i][furnitureModel];
        }
        if(count) ShowModelSelectionMenu(playerid, "Muebles", MODEL_SELECTION_MUEBLES, muebles, sizeof(muebles), -16.0, 0.0, -55.0, 0.9, 1);
        else SendErrorMessage(playerid, "esta casa no tiene muebles.");
    }
    else SendErrorMessage(playerid, "no estбs en el interior de tu casa.");
    return 1;
}



Re: How to optimize this! - BiosMarcel - 14.05.2016

Quote:
Originally Posted by F1N4L
Посмотреть сообщение
Код:
CMD:furniture(playerid, params[])
{
	static houseid = -1, muebles[MAX_HOUSE_FURNITURE];
	new count;
    if((houseid = House_Inside(playerid)) != -1 && House_IsOwner(playerid, houseid))
    {
        for(new i = 0,j = MAX_FURNITURE;i <= j;i++)
        {
            if(count < MAX_HOUSE_FURNITURE && FurnitureData[i][furnitureExists] && FurnitureData[i][furnitureHouse] == houseid) 
				ListedFurniture[playerid][count++] = i,
                muebles[i] = FurnitureData[i][furnitureModel];
        }
        if(count) ShowModelSelectionMenu(playerid, "Muebles", MODEL_SELECTION_MUEBLES, muebles, sizeof(muebles), -16.0, 0.0, -55.0, 0.9, 1);
        else SendErrorMessage(playerid, "esta casa no tiene muebles.");
    }
    else SendErrorMessage(playerid, "no estбs en el interior de tu casa.");
    return 1;
}
You even made it worse with putting the "new count;" out of the first if block ^^ and still this isnt optimizing it is just dirty coding ffs
The lifetime of a variable should be as small as possible