Raised This Month: $ Target: $400
 0% 

Loop Players HUD Message


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ichiban
Member
Join Date: Dec 2008
Old 01-06-2011 , 06:00   Loop Players HUD Message
Reply With Quote #1

Hi,

I am unsure of how to loop players in my HUD message

PHP Code:
/*
    Example Output:
    Players:
    Name
    Name
    Name
    Name
*/

public show_players(id)
{
    new 
szPlayers[200]
    new 
maxplayers get_maxplayers()
    
szPlayers[200] = "Players:^n"
    
    
for (new 1<= maxplayersi++)
    {
        new 
szName[32]
        
get_user_name(iszName31)
        
        
//szPlayers += ("%s^n", szName)
    
}
    
    
set_hudmessage(25500, -1.00.01)
    
show_hudmessage(idszPlayers)

ichiban is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-06-2011 , 06:28   Re: Loop Players HUD Message
Reply With Quote #2

You do realize that get_maxplayers returns the settings value and not the amount of connected players currently at the server, search for proper method. Strings don't have operators, so you could use some kind of native for example format to build the string. You are setting the string's value totally wrong, read some pawn tutorial for arrays and their indexes and please don't create variables inside loops. Why would you create such function as public?

Last edited by SnoW; 01-06-2011 at 06:32.
SnoW is offline
Send a message via MSN to SnoW
Elusive138
Senior Member
Join Date: Dec 2010
Old 01-06-2011 , 07:42   Re: Loop Players HUD Message
Reply With Quote #3

Quote:
Originally Posted by SnoW View Post
You do realize that get_maxplayers returns the settings value and not the amount of connected players currently at the server, search for proper method. Strings don't have operators, so you could use some kind of native for example format to build the string. You are setting the string's value totally wrong, read some pawn tutorial for arrays and their indexes and please don't create variables inside loops. Why would you create such function as public?
To clarify:

Use get_players instead.
To set/modify strings (in this case) use format and/or formatex.
Put the new szName[32] outside (above) the loop.

See http://www.amxmodx.org/funcwiki.php for more information on these, and please read http://wiki.alliedmods.net/Optimizin...d_X_Scripting).

Last edited by Elusive138; 01-06-2011 at 08:26. Reason: Fixing link
Elusive138 is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-06-2011 , 08:11   Re: Loop Players HUD Message
Reply With Quote #4

Quote:
Originally Posted by Elusive138 View Post
To clarify:

Use get_players instead.
To set/modify strings (in this case) use format and/or formatex.
Put the new szName[32] outside (above) the loop.

See http://www.amxmodx.org/funcwiki.php for more information on these, and please read http://wiki.alliedmods.net/Optimizin...od_X_Scripting).
Clarifing with ( in this case ) you probably meant after the first time setting the value as after the initialization.

Your link doesn't work.
http://wiki.alliedmods.net/Optimizin...d_X_Scripting)
SnoW is offline
Send a message via MSN to SnoW
vato loco [GE-S]
Veteran Member
Join Date: Oct 2006
Location: Germany
Old 01-06-2011 , 08:21   Re: Loop Players HUD Message
Reply With Quote #5

take look on my Show Admins Online
plugin it does what you try to do
you only need to remove the admin stuff

__________________
vato loco [GE-S] is offline
ichiban
Member
Join Date: Dec 2008
Old 01-06-2011 , 08:34   Re: Loop Players HUD Message
Reply With Quote #6

Thanks everyone.

Here is my final code that works. If there are any optimizations, please correct.

PHP Code:
public show_players(id)
{
    new 
szName[32]
    new 
szPlayers[201], iLen
    iLen 
+= copy(szPlayers[iLen], (201 iLen), "Players^n")
    
    for(new 
1<= get_maxplayers(); i++)
    {
        if (
is_user_connected(i))
        {
            
get_user_name(iszName31)            
            
iLen += formatex(szPlayers[iLen], (201 iLen), "%s^n"szName)
        }
    }
    
    
set_hudmessage(25500, -1.00.01)
    
show_hudmessage(idszPlayers)

ichiban is offline
Old 01-06-2011, 08:37
lucas_7_94
This message has been deleted by lucas_7_94.
vato loco [GE-S]
Veteran Member
Join Date: Oct 2006
Location: Germany
Old 01-06-2011 , 08:44   Re: Loop Players HUD Message
Reply With Quote #7

PHP Code:
new g_iMaxPlayers
new g_SyncMsgPlayer

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_SyncMsgPlayer CreateHudSyncObj()
    
g_iMaxPlayers get_maxplayers()
}

public 
show_players(id)
{
    new 
szName[32], szPlayers[512], iLeni
    iLen 
+= formatex(szPlayers[iLen], 511-iLen"Players:")
    
    for(
1<= g_iMaxPlayers i++)
    {
        if (
is_user_connected(i))
        {
            
get_user_name(iszName31)            
            
iLen += formatex(szPlayers[iLen], 511-iLen"^n%s"szName)
        }
    }
    
set_hudmessage(255000.020.2__4.0__4)
    
ShowSyncHudMsg(idg_SyncMsgPlayer"%s"szPlayers)


Last edited by vato loco [GE-S]; 01-06-2011 at 08:57.
vato loco [GE-S] is offline
Old 01-06-2011, 08:45
Elusive138
This message has been deleted by Elusive138.
ichiban
Member
Join Date: Dec 2008
Old 01-06-2011 , 11:01   Re: Loop Players HUD Message
Reply With Quote #8

What's the advantage of using g_iMaxPlayers instead of using get_maxplayers() in the loop?
ichiban is offline
Elusive138
Senior Member
Join Date: Dec 2010
Old 01-06-2011 , 11:10   Re: Loop Players HUD Message
Reply With Quote #9

Quote:
Originally Posted by ichiban View Post
What's the advantage of using g_iMaxPlayers instead of using get_maxplayers() in the loop?
Read the optimisations link I gave you... Here's the specific section, but I recommend you read the whole thing.

http://wiki.alliedmods.net/Optimizin...op_Comparisons
Elusive138 is offline
Reply



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 02:09.


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