SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 19/05/2017, 04:54 PM   #1
pelican1
Little Clucker
 
Join Date: Jan 2017
Posts: 24
Reputation: 0
Default Optimize my function

Hi!

How can I optimize this function with a loop ?

thanks

HTML Code:
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;
}
pelican1 is offline   Reply With Quote
Old 19/05/2017, 05:00 PM   #2
rolex
Big Clucker
 
rolex's Avatar
 
Join Date: Nov 2008
Posts: 125
Reputation: 15
Default Re: Optimize my function

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?
rolex is offline   Reply With Quote
Old 19/05/2017, 05:00 PM   #3
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,307
Reputation: 1164
Default Re: Optimize my function

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.
Pottus is offline   Reply With Quote
Old 19/05/2017, 05:05 PM   #4
rolex
Big Clucker
 
rolex's Avatar
 
Join Date: Nov 2008
Posts: 125
Reputation: 15
Default Re: Optimize my function

Quote:
Originally Posted by Pottus View Post
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?
rolex is offline   Reply With Quote
Old 19/05/2017, 06:32 PM   #5
CheezIt
Big Clucker
 
CheezIt's Avatar
 
Join Date: Apr 2017
Posts: 185
Reputation: 15
Default Re: Optimize my function

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:
Code:
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.
__________________


I like to share footage of things I find interesting, cool, funny and anything in between!
CheezIt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to optimize this! StreK Scripting Help 6 14/05/2016 01:25 PM
How to optimize this? Magic_Time Scripting Help 1 28/08/2014 09:37 PM
Better way to optimize this? sim_sima Scripting Help 5 15/12/2013 08:20 PM
Optimize. Tomejus Help Archive 0 22/02/2011 03:12 PM


All times are GMT. The time now is 12:58 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.