Raised This Month: $ Target: $400
 0% 

Solved 1 = player, more than 2 = players.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xTr3m3r
Member
Join Date: Feb 2010
Old 02-15-2017 , 13:15   1 = player, more than 2 = players.
Reply With Quote #1

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");
        }
    } 

Last edited by xTr3m3r; 02-15-2017 at 15:09.
xTr3m3r is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 02-15-2017 , 13:26   Re: 1 = player, more than 2 = players.
Reply With Quote #2

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" ""); 
__________________

Last edited by ddhoward; 02-15-2017 at 13:26.
ddhoward is offline
Old 02-15-2017, 13:26
Black Rose
This message has been deleted by Black Rose. Reason: Sloooooow
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-15-2017 , 13:47   Re: 1 = player, more than 2 = players.
Reply With Quote #3

if(iNum > 0)

No need to check if players number are greater than 0 the condition of the loop do it 4 you...
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-15-2017 at 13:47.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 02-15-2017 , 13:53   Re: 1 = player, more than 2 = players.
Reply With Quote #4

Quote:
Originally Posted by Natsheh View Post
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.
__________________
ddhoward is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-15-2017 , 13:56   Re: 1 = player, more than 2 = players.
Reply With Quote #5

Quote:
Originally Posted by ddhoward View Post
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
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-15-2017 at 13:59.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
xTr3m3r
Member
Join Date: Feb 2010
Old 02-15-2017 , 15:03   Re: 1 = player, more than 2 = players.
Reply With Quote #6

Thanks, @ddhoward!
I guess I was in a hurry

@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); 
        }
    }


Last edited by xTr3m3r; 02-15-2017 at 15:08.
xTr3m3r is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-15-2017 , 16:30   Re: 1 = player, more than 2 = players.
Reply With Quote #7

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!"
         }

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-15-2017 at 16:32.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
xTr3m3r
Member
Join Date: Feb 2010
Old 02-15-2017 , 17:05   Re: 1 = player, more than 2 = players.
Reply With Quote #8

I could but im a newbieeeeee

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

Last edited by xTr3m3r; 02-15-2017 at 17:05.
xTr3m3r is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-15-2017 , 17:29   Re: 1 = player, more than 2 = players.
Reply With Quote #9

Quote:
Originally Posted by xTr3m3r View Post
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
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 02-16-2017 , 13:30   Re: 1 = player, more than 2 = players.
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
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).
__________________

Last edited by PRoSToTeM@; 02-16-2017 at 13:54.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Reply


Thread Tools
Display Modes

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


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