AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved 1 = player, more than 2 = players. (https://forums.alliedmods.net/showthread.php?t=293945)

xTr3m3r 02-15-2017 13:15

1 = player, more than 2 = players.
 
Hi. (its me again)

Im trying to make something very simple but yet hard for me (I guess)
Whenever I use this code to respawn a player it says player but whenever I respawn 2 or more I want it to say playerS but it seems like that Iam mistaken somewhere.. Can somebody tell me what am I doing wrong here?
PHP Code:

    if(iNum 0)
        { 
            for(new 
0iNumi++)
            {
                new 
id iPlayers[i];
                
fm_respawnplayer(id);
            }
            
            
client_print(idprint_chat"%s You have just revived %d player%s"gszPrefixiNumiNum " " "s");
        }
    } 


ddhoward 02-15-2017 13:26

Re: 1 = player, more than 2 = players.
 
The first option is used if the expression is true, the second if false. You've switched them around.

Also, you can probably just get rid of the space between the quotes.

PHP Code:

client_print(idprint_chat"%s You have just revived %d player%s"gszPrefixiNumiNum "s" ""); 


Natsheh 02-15-2017 13:47

Re: 1 = player, more than 2 = players.
 
if(iNum > 0)

No need to check if players number are greater than 0 the condition of the loop do it 4 you...

ddhoward 02-15-2017 13:53

Re: 1 = player, more than 2 = players.
 
Quote:

Originally Posted by Natsheh (Post 2495648)
if(iNum > 0)

No need to check if players number are greater than 0 the condition of the loop do it 4 you...

No it doesn't. The loop doesn't affect whether or not the message prints.

Natsheh 02-15-2017 13:56

Re: 1 = player, more than 2 = players.
 
Quote:

Originally Posted by ddhoward (Post 2495649)
No it doesn't. The loop doesn't affect whether or not the message prints.

Im not talking about the printing btw it just need to change the id to 0 since the id is defined in the loop which will be undefined there

Yes it dose ,checking if(inum > 0) is useless when it has the same condition of the loop if the loop condition isnt true it wont start the loop

xTr3m3r 02-15-2017 15:03

Re: 1 = player, more than 2 = players.
 
Thanks, @ddhoward!
I guess I was in a hurry :D

@Natsheh
I check If iNum is 0 because:

PHP Code:

RespawnAll(id)
{
    if (
get_user_flags(id) & PLUGIN_ADMIN_LEVEL2)
    {
        new 
iPlayers[32], iNum;
        
get_playersiPlayersiNum"b" );
        
        if(
iNum 0)
        { 
            for(new 
0iNumi++)
            {
                new 
id iPlayers[i];
                
fm_respawnplayer(id);
            }
            
            
client_print(idprint_chat"%s You have just revived %d player%s"PrefixiNumiNum "s" ""); 
        }
        else 
        {
            
client_print(idprint_chat"%s All players are alive now!"Prefix); 
        }
    }



Natsheh 02-15-2017 16:30

Re: 1 = player, more than 2 = players.
 
you could....

PHP Code:

RespawnAll(id)
{
         if(
get_user_flags(id) & PLUGIN_ADMIN_LEVEL2)
         {
                  new 
iPlayers[32], iNum;
                  
get_playersiPlayersiNum"bh");
        
                  for(new 
iiNumi++)
                  {
                           
fm_respawnplayer(iPlayers[i]);
                  }
        
                  
client_print(idprint_chat"%s %s"PrefixiNum ? ("You have just revived %d player%s"iNumiNum "s" ""):"All players are alive!"
         }



xTr3m3r 02-15-2017 17:05

Re: 1 = player, more than 2 = players.
 
I could but im a newbieeeeee

P.S. get_players( iPlayers, iNum, "bh");
what does b and h mean btw?

Natsheh 02-15-2017 17:29

Re: 1 = player, more than 2 = players.
 
Quote:

Originally Posted by xTr3m3r (Post 2495726)
I could but im a newbieeeeee

P.S. get_players( iPlayers, iNum, "bh");
what does b and h mean btw?

B = get dead players only
H = Skip HLTV

PRoSToTeM@ 02-16-2017 13:30

Re: 1 = player, more than 2 = players.
 
Quote:

Originally Posted by Natsheh (Post 2495713)
you could....

PHP Code:

RespawnAll(id)
{
         if(
get_user_flags(id) & PLUGIN_ADMIN_LEVEL2)
         {
                  new 
iPlayers[32], iNum;
                  
get_playersiPlayersiNum"bh");
        
                  for(new 
iiNumi++)
                  {
                           
fm_respawnplayer(iPlayers[i]);
                  }
        
                  
client_print(idprint_chat"%s %s"PrefixiNum ? ("You have just revived %d player%s"iNumiNum "s" ""):"All players are alive!"
         }



His code looks better than yours.
In your code there are some problems:
1. It will alloc 'i' on stack and reset it even if iNum is 0, so there is no reason to move this condition in another place. Your code will check this condition two times too (in loop and in print). If you don't like repeating print_chat and Prefix you can create a separate PrintToChat(player, format, ...) function/macro that would include print_chat arg and Prefix.
2. Better explicitly reset 'i' than implicitly.
3. We should exclude not only HLTV, but all spectators and UNA. We should include only dead CT and dead TR. There is no flag for this, so we can't do it via get_players directly.
So:
PHP Code:

new iPlayers[32], iNum;
get_players(iPlayersiNum"bh");

new 
excludedCount 0;
for(new 
0iNumi++)
{
         new 
CsTeams:team cs_get_user_team(iPlayers[i]);
         if (
team == CS_TEAM_SPECTATOR || team == CS_TEAM_UNASSIGNED) {
                  
excludedCount++;
                  continue;
         }

         
fm_respawnplayer(iPlayers[i]);
}
iNum -= excludedCount

HLTV flag is not necessary now, but it excludes HLTV right away (some optimization, but this is function not frequently called, so optimizations make no sense here).


All times are GMT -4. The time now is 21:02.

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