Author Topic: Problems with avoiding GetPlayerStat(ID,'team') <- Solved  (Read 1387 times)

0 Members and 1 Guest are viewing this topic.

Offline Mighty

  • Camper
  • ***
  • Posts: 276
Problems with avoiding GetPlayerStat(ID,'team') <- Solved
« on: February 26, 2011, 03:47:33 pm »
As topic subject says, im trying to avoid GetPlayerStat as much as i can, so i got PTeam array[1..32] of byte to store players team. Obvious. The problems start when i want to put spec-on-join in the script.

Atm i use code below:

Code: [Select]
procedure OnJoinTeam(ID, Team: byte);
begin
PTeam[ID] := Team;
end;

procedure OnJoinGame(ID, Team: byte);
begin
PTeam[ID] := Team;
Command('/setteam5 1');
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);
begin
PTeam[ID] := 0;
end;

And now, if a player joins game and wants to join specs, everything's ok. but if he chose another team on joining, then PTeam will store his choice instead of his real team (which would be spec ofc).
If i swap OnJoinGame commands, the problem remains.

Any way how could i fix that without AppOnIdle?
« Last Edit: February 27, 2011, 04:34:38 am by Mighty »
xFire: macmil        e-mail: macekmil@gmail.com
My scripts: Accuracy Script       Flashbang       Punishments GUID
            CatchMe Gamemod       AntiFake
            CW System             AntiFakeGUID

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Problems with avoiding GetPlayerStat(ID,'team')
« Reply #1 on: February 26, 2011, 04:38:56 pm »
if it's like that then just do PTeam[ID] := 5
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 Mighty

  • Camper
  • ***
  • Posts: 276
Re: Problems with avoiding GetPlayerStat(ID,'team')
« Reply #2 on: February 27, 2011, 04:34:15 am »
Above didn't work, still PTeam[ID] was "1" in the end.

Ok, now i came up with something else which solved the problem. Here's the code if anyone ever had same problems.
Code: [Select]
procedure OnJoinTeam(ID, Team: byte);
begin
  if not(Joined = ID) then
    PTeam[ID] := Team
  else
    Joined := 0;
end;

procedure OnJoinGame(ID, Team: byte);
begin
  Command('/setteam5 1');
  PTeam[ID] := 5;
  Joined := ID;
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);
begin
  PTeam[ID] := 0;
end;
xFire: macmil        e-mail: macekmil@gmail.com
My scripts: Accuracy Script       Flashbang       Punishments GUID
            CatchMe Gamemod       AntiFake
            CW System             AntiFakeGUID

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Problems with avoiding GetPlayerStat(ID,'team') <- Solved
« Reply #3 on: February 27, 2011, 05:09:56 am »
oh wait, i just noticed. you do setteam in OnJoinGame. I'm quite surprised that it works, i mean, i think that menu choice should override it. In OnJoinGame you should just mark that player just joined, and do all the stuff in OnJoinTeam
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 Polifen

  • Soldier
  • **
  • Posts: 127
Re: Problems with avoiding GetPlayerStat(ID,'team') <- Solved
« Reply #4 on: February 27, 2011, 06:24:59 am »
I'd suggest using array of boolean instead of joined : byte. That's quite simple, if 2 people join game, both wait 10 seconds before chosing team it will move only the one who joined team first.

Offline Mighty

  • Camper
  • ***
  • Posts: 276
Re: Problems with avoiding GetPlayerStat(ID,'team') <- Solved
« Reply #5 on: February 27, 2011, 06:32:42 pm »
I guess OnJoinGame is called when A player actually chose team. Otherways it would be impossible to call it. Am I right?

Also it is possible to connect with a server, but if u dont pick you team fast it might turn out that somebody else joined during your team picking and the servers full aready. The game would just freeze. then, only thing i could do is quit to lobby.

I was thinking about booleans also, was a choice between a little faster process and less variables. Or there's no difference?

All im writing here are just my thoughts, i might be wrong, im not a genius :)
xFire: macmil        e-mail: macekmil@gmail.com
My scripts: Accuracy Script       Flashbang       Punishments GUID
            CatchMe Gamemod       AntiFake
            CW System             AntiFakeGUID

Offline Polifen

  • Soldier
  • **
  • Posts: 127
Re: Problems with avoiding GetPlayerStat(ID,'team') <- Solved
« Reply #6 on: February 28, 2011, 12:58:42 am »
Also it is possible to connect with a server, but if u dont pick you team fast it might turn out that somebody else joined during your team picking and the servers full aready. The game would just freeze. then, only thing i could do is quit to lobby.

I was thinking about booleans also, was a choice between a little faster process and less variables. Or there's no difference?

First, the bug you wrote about is not related to team picking, it happens when 2 people join in very short time, so the first who joined isn't yet loaded. And what I told is like:
- ABC joins game and don't choose team
- BCD joins game and choose team
- ABC chooses team later
What will happen? BCD will be moved to spec, but ABC will not ( but his PTeam[ID] will be 5, that's damn bad i think ).That's why using array of boolean is way safer than using one variable for 32 players.