AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ Solved ] How to get num of terrorists ? (https://forums.alliedmods.net/showthread.php?t=76372)

xPaw 08-23-2008 11:32

[ Solved ] How to get num of terrorists ?
 
:o

Arkshine 08-23-2008 11:40

Re: How to get num of terrorists ?
 
It should work. How did you test to get this conslusion ?

xPaw 08-23-2008 11:56

Re: How to get num of terrorists ?
 
with looping task in init, every 30 secs

Brad 08-23-2008 19:51

Re: How to get num of terrorists ?
 
Don't use that method anyway, though it seems the most common sense way to do it.

Before I give you updated code, I have to question why the hell you'd be looping this. That's a bad idea and needless to boot. Do you want to know the current T count at any given moment?

This code will give you the T count:
Code:

new players[32], playerCnt, playerIdx, terroristCnt;
get_players(players, playerCnt);

for (playerIdx = 0; playerIdx < playerCnt; playerIdx++)
{
  if (get_user_team(players[playerIdx]) == 2)
  {
      terroristCnt++;
  }
}

You'll need to confirm if terrorists are team 1 or 2 as I can't recall at the moment.

Arkshine 08-23-2008 19:56

Re: How to get num of terrorists ?
 
Quote:

== 2)
1 = terro / 2 = ct ^^

danielkza 08-23-2008 20:28

Re: How to get num of terrorists ?
 
Quote:

Originally Posted by Brad (Post 674455)
Don't use that method anyway, though it seems the most common sense way to do it.

Before I give you updated code, I have to question why the hell you'd be looping this. That's a bad idea and needless to boot. Do you want to know the current T count at any given moment?

This code will give you the T count:
Code:

new players[32], playerCnt, playerIdx, terroristCnt;
get_players(players, playerCnt);

for (playerIdx = 0; playerIdx < playerCnt; playerIdx++)
{
  if (get_user_team(players[playerIdx]) == 2)
  {
      terroristCnt++;
  }
}

You'll need to confirm if terrorists are team 1 or 2 as I can't recall at the moment.

You don't need to use both,get_players and a loop. Just use one of them.
PHP Code:

new iTRCount 0
new iMaxPlayers get_maxplayers()
for(new 
i=1;<= iMaxPlayers;i++)
{
    if(
is_user_connected(i) && get_user_team(i) == 1)
        
iTRCount++



Brad 08-23-2008 21:23

Re: How to get num of terrorists ?
 
Have you done any tests to see which is better? I haven't, so was just wondering.

danielkza 08-23-2008 22:00

Re: How to get num of terrorists ?
 
Quote:

Originally Posted by Brad (Post 674509)
Have you done any tests to see which is better? I haven't, so was just wondering.

This has been discussed a lot, and in the end the common sense is just use what seems better to you,or which needs less code. Obviously, get_players + a loop is not in any way better. It has the disadvantages of both methods. Also, the funcwiki says:
Quote:

Originally Posted by FuncWiki
Note: "e" flag can return incorrect results (for cstrike/czero at least).


"We don't really support get_players() with flags anymore. It was a bad idea and if it was our choice, it would have never been added to the original AMX Mod." - BAILOPAN

So, I would stick with the MaxPlayers' loop method.

Iwon 08-24-2008 06:29

Re: How to get num of terrorists ?
 
PHP Code:

new players[32], playerCntplayerIdxterroristCnt;
get_players(playersplayerCnt);

for (
playerIdx 0playerIdx playerCntplayerIdx++)
{
   if (
get_user_team(players[playerIdx]) == 2)
   {
      
terroristCnt++;
   }


That is better.

Arkshine 08-24-2008 07:07

Re: How to get num of terrorists ?
 
No, I don't think. The less you use natives, the better it is.

I don't see the point to use get_players() without flags, if the purpose is just to loop through all players. So, the danielkza's way is more appropriate. ( considering that "e" flag can return incorrect results )


All times are GMT -4. The time now is 03:10.

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