Raised This Month: $ Target: $400
 0% 

get_players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GhostMan
Senior Member
Join Date: Jun 2012
Old 07-14-2012 , 13:58   get_players
Reply With Quote #1

v1
PHP Code:
new players[32], numtid
get_players
(playersnum"a")

for( new 
0numi++ )
{
    switch(
cs_get_user_team(tid))
    {
        case 
CS_TEAM_T:
        {
            
set_user_health(tid100)
        }
        
        case 
CS_TEAM_CT:
        {
            
set_user_health(tid100)
        }
    }

v2

PHP Code:
new players[32], numtid
get_players
(playersnum"a")

for( new 
0numi++ )
{
    
tid players[i]
    
set_user_health(tid100)

Lets say i want to set 100 health for both teams, so witch one is better or it has no matter?

Last edited by GhostMan; 07-14-2012 at 13:58.
GhostMan is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 07-14-2012 , 14:18   Re: get_players
Reply With Quote #2

Obviously the second one. You don't need to check anything if you execute the same code for all cases.
__________________
<VeCo> is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-14-2012 , 14:33   Re: get_players
Reply With Quote #3

PHP Code:
new players[32], numtid
get_players
(playersnum"a")

for( new 
0numi++ )
{
    
tid players[i]
    
set_user_health(tid100)

->
PHP Code:
new players[32], num
get_players
(playersnum"a")

for( --
numnum >= 0num-- )
{
    
set_user_health(players[num], 100)

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 07-14-2012 at 14:33.
ConnorMcLeod is offline
GhostMan
Senior Member
Join Date: Jun 2012
Old 07-14-2012 , 15:01   Re: get_players
Reply With Quote #4

Connor, all "for" cicles must be started like that

v1
PHP Code:
new g_max_clients get_maxplayers()

new 
players[32], numtid
get_players
(playersnum"a")

for( new 
0num <= g_max_clientsi++ )
{
    
tid players[i]
    
set_user_health(tid100)

in case of avoiding late warnings?

At the moment when i use for cicle so i do it like that

v2
PHP Code:
new players[32], numtid
get_players
(playersnum"a")

for( new 
0numi++ )
{
    
tid players[i]
    
set_user_health(tid100)

You want to say v1 is more secure?

Last edited by GhostMan; 07-14-2012 at 15:03.
GhostMan is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-14-2012 , 17:46   Re: get_players
Reply With Quote #5

Connor already posted the most efficient one, why do you keep trying to use different version?

Quote:
Originally Posted by ConnorMcLeod View Post
PHP Code:
new players[32], num
get_players
(playersnum"a")

for( --
numnum >= 0num-- )
{
    
set_user_health(players[num], 100)

__________________
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
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-14-2012 , 18:37   Re: get_players
Reply With Quote #6

Quote:
Originally Posted by GhostMan View Post
Connor, all "for" cicles must be started like that
No they don't. A for loop requires syntax like this....

counter; condition; increment

you DO NOT need to define the counter in the header. The condition doesn't have to be related to the counter, and the increment is just a way of manipulating the data after the iteration. It is used most commonly as you have discribed, but it can be done in many different ways. It is pretty much a glorified while loop, with a counter.
Use connor's code. it relieves a native call, 3 variables, and is actually more easy to understand. This is because instead of filling an array, then starting from zero at that array and working to the end. it fills the array, takes the count of that array, and works from the top down. Also, you don't need to add your tid = players[i] because you're only calling players once. This is just redundant in this manner. You should only use that statement when you're going to be indexing an array more than once in your loop.

EDIT: but to answer your question....v2 would be the best way OF THOSE SELECTIONS. This is because num will ALWAYS be <= maxPlayers, because its the number if ids indexed into the players array.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-14-2012 at 18:39.
Liverwiz is offline
GhostMan
Senior Member
Join Date: Jun 2012
Old 07-14-2012 , 19:07   Re: get_players
Reply With Quote #7

YamiKaitou - just trying to find out that's the different between "this" or "that" code.

Last edited by GhostMan; 07-14-2012 at 19:07.
GhostMan is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 07-15-2012 , 06:36   Re: get_players
Reply With Quote #8

Quote:
Originally Posted by GhostMan View Post
YamiKaitou - just trying to find out that's the different between "this" or "that" code.
Connor's code doesn't use additional "i" variable, it uses directly the "num" variable from the native.
__________________
<VeCo> 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 15:06.


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