Raised This Month: $51 Target: $400
 12% 

Simple question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 04-20-2014 , 08:07   Simple question
Reply With Quote #1

this was answered, please read my second post
Well here it goes
I used to use a script like this to go trough all players
Code:
	new iPlayers[32]
	new iNum
	new player
	get_players( iPlayers, iNum )

	for( new i = 0; i < iNum; i++ )
	{
		player = iPlayers[i]
		if(is_user_connected(player))
		{
		}
	}
All I want to know is, why is this better than
Code:
for(new i=0;i<33;i++)
{
if(is_user_connected(i))
{
blabla
}
}
What's the difference except the maxplayers hardcode?

Last edited by aron9forever; 04-20-2014 at 12:06. Reason: update
aron9forever is offline
Ef_Deas
Member
Join Date: Aug 2012
Location: Rio de Janeiro
Old 04-20-2014 , 08:35   Re: Simple question
Reply With Quote #2

I use
PHP Code:
MaxPlayers get_maxplayers(); // in plugin_init or something

// Player indexes starts with 1. Zero is the server.
// And ends with MaxPlayers, because it's not always 32. You may have 22 slots for example.
for(new idUser 1idUser <= MaxPlayersidUser++)
   if( 
is_user_connected(idUser) )
      
//... 
Ef_Deas is offline
Send a message via Skype™ to Ef_Deas
Ef_Deas
Member
Join Date: Aug 2012
Location: Rio de Janeiro
Old 04-20-2014 , 08:56   Re: Simple question
Reply With Quote #3

The difference is that with get_players you can specify which players you want to get, like only dead or alive and not bots etc. Read the documentation. And, I guess, you don't need is_user_connected
Ef_Deas is offline
Send a message via Skype™ to Ef_Deas
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-20-2014 , 10:02   Re: Simple question
Reply With Quote #4

get_players = 1 native
for loop = up to 32 natives

Search, there are many topics about this question. Also, when you use get_players, you don't need to use is_user_connected as it will only return the connected users
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Ef_Deas
Member
Join Date: Aug 2012
Location: Rio de Janeiro
Old 04-20-2014 , 13:16   Re: Simple question
Reply With Quote #5

Quote:
Originally Posted by YamiKaitou View Post
get_players = 1 native
for loop = up to 32 natives
True. Never thought about it. Thanks )
Ef_Deas is offline
Send a message via Skype™ to Ef_Deas
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:05.


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