SA-MP Forums Archive
Is this function optimized? - 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: Is this function optimized? (/showthread.php?tid=533099)



Is this function optimized? - Magic_Time - 22.08.2014

Hi, I want to know if there's a way to optimize this function:

PHP код:
stock AdminRank(playerid)
{
    new 
rank[40];
    switch(
PlayerInfo[playerid][pAdmin])
    {
        case 
0: rank = "Nothing";
        case 
1: rank = "{FFFF28}[Temp admin]";
        case 
2: rank = "{660066}[Junior Admin]";
        case 
3: rank = "{FF8000}[Senior Admin]";
        case 
4: rank = "{2F5E35}[Head Admin]";
        case 
5: rank = "{00FFFF}[Global Admin]";
        case 
6: rank = "{80FF00}[Community Manager]";
        case 
7: rank = "{80FF00}[Server Owner]";
    }
    return 
rank;
} 
Thanks for replying.


Re: Is this function optimized? - Battlezone - 22.08.2014

new rank[29]; would be enough, and i clearly see that its optimized


Re: Is this function optimized? - DobbysGamertag - 22.08.2014

Quote:
Originally Posted by Vince
Посмотреть сообщение
an array might be more effective.
pawn Код:
static const gAdminRanks[][] = {
    "None", // 0
    "Moderator", // 1
    "Junior", // 2
    "Senior" // 3
};

format(msg, sizeof(msg), "Player %d's admin level is: %s", targetid, gAdminRanks[PlayerInfo[targetid][pAdmin]]);
Dis.


Re: Is this function optimized? - Ihateyou - 22.08.2014

is this optimized?:

printf("%d",1+1);


Re: Is this function optimized? - HazardouS - 22.08.2014

Quote:
Originally Posted by Ihateyou
Посмотреть сообщение
is this optimized?:

printf("%d",1+1);
Make the calculations and store the result in another variable, then print that variable.


Re: Is this function optimized? - zT KiNgKoNg - 22.08.2014

Quote:
Originally Posted by DobbysGamertag
Посмотреть сообщение
Dis.
I wouldn't say that is any way, you don't see me using that function to retrieve dynamic faction ranks. So if it works it works at the end of the day, and if it doesn't exceed the required string length (the return string) then yeah its optimized enough for its purpose. (FYI: i know this is the internet but considering using real words).

Quote:
Originally Posted by Ihateyou
Посмотреть сообщение
is this optimized?:

printf("%d",1+1);
I don't know if you're asking a serious question but by the looks of it you're not (Make you're own thread if you're going to troll, look forward to getting banned if they feel like doing it.)


Re: Is this function optimized? - Ihateyou - 08.09.2014

Quote:
Originally Posted by zT KiNgKoNg
Посмотреть сообщение
I wouldn't say that is any way, you don't see me using that function to retrieve dynamic faction ranks. So if it works it works at the end of the day, and if it doesn't exceed the required string length (the return string) then yeah its optimized enough for its purpose. (FYI: i know this is the internet but considering using real words).




I don't know if you're asking a serious question but by the looks of it you're not (Make you're own thread if you're going to troll, look forward to getting banned if they feel like doing it.)
just making fun of retards creating threads like this .. learn 2 sarcasm