Raised This Month: $32 Target: $400
 8% 

What is better way of printing this?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
6Yukimuro9
Junior Member
Join Date: May 2019
Location: Serbia, Belgrade
Old 06-02-2019 , 04:49   What is better way of printing this?
Reply With Quote #1

Hello, I'm creating VIP plugin from scratch and its like 90% done by now so I' m doing optimisation...

I'm wondering what is better way of doing this:

Code:
public print_online_vips(id)
{
	new vips[100], vips2[100], iPlayers[32], iPlayersNum, i;
	
	get_players(iPlayers, iPlayersNum, "c");
	for(i = 0; i < iPlayersNum; ++i)
	{
		if(get_user_flags(iPlayers[i]) & VIP_LEVEL)
		{
			new name[MAX_NAME_LENGTH];
			get_user_name(iPlayers[i], name, sizeof(name));
			
			
			if(strlen(vips) < 100)
				format(vips, sizeof(vips), "%s%s%s", vips, name, !vips[0] ? "" : ", ");
			else
				format(vips2, sizeof(vips2), "%s, %s", vips2, name);
		}
	}
	
	if(!vips[0])
		client_print_color(id, id, "^4[VIP]^1 %L", id, "NO_VIP_ONLINE");
		
	else
		client_print_color(id, id, "^4VIP Online:^3 %s^4%s", vips, vips2[0] ? "," : ".");
		
	if(vips2[0])
		client_print_color(id, id, "^3 %s^4.", vips2);
		
	return PLUGIN_HANDLED;
}
6Yukimuro9 is offline
SHIELD755
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
Old 06-02-2019 , 06:40   Re: What is better way of printing this?
Reply With Quote #2

Use cromchat
__________________
SED LYF !!!
SHIELD755 is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 06-02-2019 , 06:42   Re: What is better way of printing this?
Reply With Quote #3

Quote:
Originally Posted by SHIELD755 View Post
Use cromchat
Beat me to it...
redivcram is offline
6Yukimuro9
Junior Member
Join Date: May 2019
Location: Serbia, Belgrade
Old 06-02-2019 , 08:29   Re: What is better way of printing this?
Reply With Quote #4

Quote:
Originally Posted by SHIELD755 View Post
Use cromchat
Why would I do that?

This doesn't have any bugs and its better & faster
6Yukimuro9 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-02-2019 , 08:54   Re: What is better way of printing this?
Reply With Quote #5

Your code is limited to only 2 arrays of vips. With 32 VIPs online, it won't print all of them.

PHP Code:
public print_online_vips(id)
{
    static const 
iMax 4
    
new szVips[160], iPlayers[MAX_PLAYERS], iPnumiCountAll
    get_players
(iPlayersiPnum"ch")

    
szVips "^4VIPs Online: ^3"

    
for(new iiCountiPlayeriPnumi++)
    {
        
iPlayer iPlayers[i]

        if(
get_user_flags(iPlayer) & VIP_LEVEL)
        {
            
iCountAll++

            if(
iCount++ < iMax)
            {
                
add(szVipscharsmax(szVips), fmt("%n"iPlayer))

                if(
iPnum 1)
                {
                    
add(szVipscharsmax(szVips), "^4, ^3")
                }
            }
            else
            {
                
iCount 0
                client_print_color
(ididszVips)
                
szVips[0] = EOS
            
}
        }
    }

    if(
iCountAll)
    {
        
client_print_color(ididszVips)
    }
    else
    {
        
client_print_color(idid"^4%l""NO_VIP_ONLINE")
    }

    return 
PLUGIN_HANDLED

iMax is the maximum number of players that will get printed on each line.
__________________

Last edited by OciXCrom; 06-02-2019 at 11:17.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-02-2019 , 09:45   Re: What is better way of printing this?
Reply With Quote #6

Quote:
Originally Posted by OciXCrom View Post
Your code is limited to only 2 arrays of vips. With 32 VIPs online, it won't print all of them.

PHP Code:
public print_online_vips(id)
{
    static const 
iMax 4
    
new szVips[160], iPlayers[MAX_PLAYERS], iPnumiCountiCountAlli
    get_players
(iPlayersiPnum"ch")

    @
new_string:
    
szVips "^4VIPs Online: ^3"

    
for(new iPlayeriPnumi++)
    {
        
iPlayer iPlayers[i]

        if(
get_user_flags(iPlayer) & VIP_LEVEL)
        {
            
iCountAll++

            if(
iCount++ < iMax)
            {
                
add(szVipscharsmax(szVips), fmt("%n"iPlayer))

                if(
iPnum 1)
                {
                    
add(szVipscharsmax(szVips), "^4, ^3")
                }
            }
            else
            {
                
iCount 0
                client_print_color
(ididszVips)
                goto @
new_string
            
}
        }
    }

    if(
iCountAll)
    {
        
client_print_color(ididszVips)
    }
    else
    {
        
client_print_color(idid"^4%l""NO_VIP_ONLINE")
    }

    return 
PLUGIN_HANDLED

iMax is the maximum number of players that will get printed on each line.
goto and jumping backwards
__________________
HamletEagle is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-02-2019 , 11:17   Re: What is better way of printing this?
Reply With Quote #7

I guess we can skip that part. I edited the code.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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

Forum Jump


All times are GMT -4. The time now is 16:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode