Author Topic: GetPlayerStat(id, 'active') and spectators  (Read 1147 times)

0 Members and 1 Guest are viewing this topic.

Offline Szaman

  • Soldier
  • **
  • Posts: 145
GetPlayerStat(id, 'active') and spectators
« on: April 23, 2014, 04:05:47 pm »
Hi,

I would like ask you for help with some small script :)

Code: [Select]
OnJoinTeam:
     for i := 1 to 32 do
     begin
          if ((GetPlayerStat(i, 'human') = true) and (GetPlayerStat(i, 'active') = true) then
          begin
               if (GetPlayerStat(i, 'hwid') = hwid) then count := count + 1;
          end;
     end;
This code doesn't counts players that are in the spectators team.

If I rewrite it to:

Code: [Select]
OnJoinTeam:
     for i := 1 to 32 do
     begin
          if ((GetPlayerStat(i, 'human') = true) and (GetPlayerStat(i, 'active') = true) or (GetPlayerStat(i, 'team') = 5) then
          begin
               if (GetPlayerStat(i, 'hwid') = hwid) then count := count + 1;
          end;
     end;
Then it will work, but... If I leave the game and then rejoin (with other ID) I will be counted twice (probably my "old me" is also counted because of the second condition).

How to get all human, live players from all teams, also spectators?

Best regards,
Szaman.

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: GetPlayerStat(id, 'active') and spectators
« Reply #1 on: April 23, 2014, 04:18:50 pm »
The first one should work for that, i don't see a reason for it to fail. Maybe except that "= true", remove them. I've seen a scripts that didn't work because they had such things.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline Szaman

  • Soldier
  • **
  • Posts: 145
Re: GetPlayerStat(id, 'active') and spectators
« Reply #2 on: April 23, 2014, 04:24:12 pm »
But the first one works fine for players who join to the normal "playable" team (dm, alpha, etc.). It only not works for the spectators.
As it's said in dev wiki (for GetPlayerStat):
Quote
Active    Is in-game?    Boolean
So it means that the player is "in game" (playing).

Offline Szaman

  • Soldier
  • **
  • Posts: 145
Re: GetPlayerStat(id, 'active') and spectators
« Reply #3 on: April 23, 2014, 04:28:44 pm »
WTF...

It now works fine also for spectators... o_O

I have no idea why it was failing before... ;/
Sorry for making the mess.
« Last Edit: April 23, 2014, 04:30:50 pm by Szaman »

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: GetPlayerStat(id, 'active') and spectators
« Reply #4 on: April 23, 2014, 04:51:41 pm »
"Active" means that this slot is occupied by an actual player/bot. You can use it to count the players and also make sure that other GetPlayerStat() variables aren't "trash" values.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline Szaman

  • Soldier
  • **
  • Posts: 145
Re: GetPlayerStat(id, 'active') and spectators
« Reply #5 on: April 23, 2014, 04:59:40 pm »
Yeah... I thought so. But there was some strange behaviour of the script engine that made me think that it works differently. And then it work normally again.

Magic :D

Thanks for help, btw :)