Raised This Month: $ Target: $400
 0% 

loop through all players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-12-2013 , 13:18   Re: loop through all players
Reply With Quote #1

Not maybe, it is 100% sure, get_players make checks internally, when the second way has to check if each player is connected, so maxclient * is_user_connected natives calls for nothing.


Anyway, if it is just to print a message, you can send 1 message to everyone :

client_print(0, print_chat, "Your message with some patterns like %s", szName)


Or you can make your own if it is justified :

PHP Code:
print_message(id, const msg[]) 
{
    
message_begin(id MSG_ONE MSG_ALLgmsgSayText_id)
    
write_byte(id)
    
write_string(msg)
    
message_end()
}

print_message_format(id, const fmt[], any:...) 
{
    new 
msg[192]
    
vformat(msgcharsmax(msg), fmt3)
    
message_begin(id MSG_ONE MSG_ALLgmsgSayText_id)
    
write_byte(id)
    
write_string(msg)
    
message_end()


Anyway, do never use code #1, never.
And about code #2, in your example, 'player' variable is not required because you use it only once, so you can directly use players[i] instead. 'player' is usefull for optimization to prevent multiple use of players[i] (called re-indexing if you read wiki about optimizations).
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 02-12-2013 at 13:21.
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-13-2013 , 21:15   Re: loop through all players
Reply With Quote #2

Quote:
Originally Posted by ConnorMcLeod View Post
Or you can make your own if it is justified :
@hypheni, What are you doing that you "think" you need to do it this way?
__________________

Last edited by fysiks; 02-13-2013 at 21:15.
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-14-2013 , 00:28   Re: loop through all players
Reply With Quote #3

If you don't plain to add color, use client_print native
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 11:11.


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