Jump to content

Cycling through players checking if they're alive


Recommended Posts

Good afternoon,

 

I'd like to cycle through the players (not just bots!) from a team to check if they are in a AABB area; I'd like to count them when they're alive (so not dead nor waiting for a Medic)

 

First check can be ETUtil.IsTeamDead, but that's ofc not enough

I know how to cycle through bots with BotTable, and there seemed to be a function in the Bot library that could help but it is marked as deprecated (IsWaitingForMedic), and probably just work for bots?

 

So I'm looking for the elements to build a loop to go through the players, and just for a particular team check if their position is inside the AABB while being able to walk... Basically just counting them

I can then just sort a % with Server.Team[ team ].NumPlayers and say tell if the area is 'safe' for the other team to like secure an objective :P

 

Could someone please point me to the right direction? I haven't found an example in the scripts (perhaps I'm just bad at searching ^^')

 

Thanks

Link to comment
Share on other sites

  • Moderators

Cycle through all players may be slow, so I would recommend to create a trigger region. Then define some table in your script to store all players who are in the region. Add a player to the table in OnEnter and remove him from the table in OnExit. Then build a loop to go through players in that table and count only those who have Util.GetEntHealth(ent)>0.

 

Link to comment
Share on other sites

That were the first thought I had, I'll have to protect that table writing with a mutual exclusion because I will do that check not only on Enter/Exit events but through a thread that will be running while the objective is taken...

 

But if that's faster than cycling through players then I'll go this way

 

Will I have to be careful with disconnections? Like in the role management in the OB internal GM scripts, or do they trigger the Exit event?

Edited by Mateos
Link to comment
Share on other sites

  • Moderators

Function OnExit can be called after a player switched team or disconnected. There are too many maps with this "team switch bug". I fixed it in the fueldump map today.

GameMonkey scripts have simple cooperative multitasking. Threads can be switched only at sleep or yield. That's why no locks or mutexes are needed.

 

Link to comment
Share on other sites

Yup, I've seen your commit earlier, I'll simplify my waypoints accordingly (especially that setting a null will affect tableCount accordingly)

 

So that means the next OnExit is called after the previous one is over if no sleep/yield, that will also simplify the thingy!

 

Thank you very much!

Edited by Mateos
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...