Author Topic: alive players onplayerrespawn  (Read 849 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
alive players onplayerrespawn
« on: July 06, 2007, 08:21:06 pm »
I never thought OnPlayerRespawn was threaded, and still am in doubt, but after what I did today, I became a little confuzzled...

Code: [Select]
function AlivePlayers(Team: shortint): byte;
var
  i: byte;
begin
  for i := 1 to 32 do if (GetPlayerStat(i,'Active') = true) and (GetPlayerStat(i,'Alive') = true) and ((Team = -1) or (GetPlayerStat(i,'Team') = Team)) then Result := Result + 1;
end;

procedure AfterRespawn(ID: byte);
begin
  Sleep(10);
  ForceWeapon(ID,RespawnWeapon[ID][1],RespawnWeapon[ID][2],0);
  RespawnWeapon[ID][1] := 255;
  RespawnWeapon[ID][2] := 255;
end;

procedure OnPlayerRespawn(ID: byte);
begin
  if AlivePlayers(-1) = 0 then Timer := TimerLimit;
  Command('/say ID = ' + InttoStr(ID) + '; AlivePlayers(-1) = ' + InttoStr(AlivePlayers(-1)));
  ThreadFunc([ID],'AfterRespawn');
end;

Survival mode is enabled...

I'm testing with bots.
I add 4 bravo bots while im alpha.
I kill myself
They die.
Everybody respawns.
The Command procedure is only called four times when it should be called five times, sense there are five players. Errors related to ThreadFunc come up, nothing unexpected due to its instability.
Now I comment out the ThreadFunc line...
Everybody respawns, starting at 2, going up, and then takes care of player 1... Alive players goes up from 1 to 5.

Two problems.. even if I don't use the ThreadFunc line, the number of AlivePlayers should go from 0 to 4 if I am thinking this though correctly, sense it is called  b4 the players actually respawn, when player 2's OnPlayerRespawn is called (the first time it is called),  the number of alive players is 0 but it says it is 1.
Now when I use ThreadFunc, which is required or my script, it gets really messy... Other than error messages coming up many times every time the group of people respawning, theres a problem... When the error comes up for player number 1 (the 5th time OnPlayerRespawn is called), it seems to act as if everything that already happened in OnPlayerRespawn never happened (it doesn't call the procedure Command)

sry if my wording is confusing
« Last Edit: July 08, 2007, 10:50:02 am by DorkeyDear »

Offline chrisgbk

  • Moderator
  • Veteran
  • *****
  • Posts: 1739
Re: alive players onplayerrespawn
« Reply #1 on: July 07, 2007, 04:27:39 pm »
The = true's are required in the usage you are using, because GetPlayerStat returns a Variant, and not a Boolean.

I'll have to get back on the rest; right now enesce.com is down so I can't go look up the reference manual. However, I think that OnRespawn is called AFTER someone respawns, but I need to verify that.