SA-MP Forums Archive
Optimize my function - 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: Optimize my function (/showthread.php?tid=634458)



Optimize my function - pelican1 - 19.05.2017

Hi!

How can I optimize this function with a loop ?

thanks

Код HTML:
Function(playerid)
{
	if(PlayerInfo[playerid][house1] == 40)
	{
		PlayerInfo[playerid][house1] = 0;
	}
	else if(PlayerInfo[playerid][house2] == 40){
		PlayerInfo[playerid][house2] = 0;
	}
	else if(PlayerInfo[playerid][house3] == 40){
		PlayerInfo[playerid][house3] = 0;
	}
	else if(PlayerInfo[playerid][house4] == 40){
		PlayerInfo[playerid][house4] = 0;
	}
	else if(PlayerInfo[playerid][house5] == 40){
		PlayerInfo[playerid][house5] = 0;
	}
	else if(PlayerInfo[playerid][house6] == 40){
		PlayerInfo[playerid][house6] = 0;
	}
	else if(PlayerInfo[playerid][house7] == 40){
		PlayerInfo[playerid][house7] = 0;
	}
	else if(PlayerInfo[playerid][house8] == 40){
		PlayerInfo[playerid][house8] = 0;
	}
	return 1;
}



Re: Optimize my function - rolex - 19.05.2017

in you enum PlayerInfo[playerid][house1] you have the one var for each house? as: house1, house2, house3? or house = all house ids?

can you post here the PlayerInfo enum?


Re: Optimize my function - Pottus - 19.05.2017

You fucked yourself up with your data structures so everywhere in your code will need to be updated now to fix this. What you should have is something like this.

new PlayerInfo[playerid][MAX_PLAYER_HOUSES][HouseENUM]

It would be best though to separate your house system from your player interface then you could just save a list of references for each house a player owns which will reduce resources requires. I would just using mysql/sqlite and just save the primary integer keys.


Re: Optimize my function - rolex - 19.05.2017

Quote:
Originally Posted by Pottus
Посмотреть сообщение
You fucked yourself up with your data structures so everywhere in your code will need to be updated now to fix this. What you should have is something like this.

new PlayerInfo[playerid][MAX_PLAYER_HOUSES][HouseENUM]
yeah, i don't know what is that function purposes...

[house1] == 40?


Re: Optimize my function - CheezIt - 19.05.2017

If "house1, house2, house3, etc." is a factor or a enumerator and the first factor starts at index 0 (modify the loop's initial and final value if it does not start at index 0), you can do:
pawn Код:
for(new i = 0; i < 8; i ++)
{
    if(PlayerInfo[playerid][nameOfEnumerator:i] == 40)
    {
        PlayerInfo[playerid][nameOfEnumerator:i] = 0;
    }
}
Please note that you must change "nameOfEnumerator" to the correspondent name of your enumerator.