Jump to content
Sign in to follow this  
davidoss

count players

Recommended Posts

Hi.

 

There wil be script executed server side and  i want to create dependency in the script  to waituntil  are  more than one player connected.

 

How to write that?

Share this post


Link to post
Share on other sites


if ((count allPlayers) > 0) then {//code};

Share this post


Link to post
Share on other sites

Hmm ok thanks but how i can integrate this?

 

init.sqf

if (isServer) then {

//run on dedicated server or player host


	while {true} do {
		trueplayers = 0;
		trueplayers = count allPlayers;
		sleep 100;
	};

[] execVM "script.sqf";
};

script.sqf

waitUntil {trueplayers >= 2};
code...

???

 

or simply in the script

waitUntil {(count allPlayers) >= 2};

Share this post


Link to post
Share on other sites

Put the while loop stuff inside the script.sqf, and only put

 if(isServer) then{execVM "scripts.sqf"};

into your init.

 

Then you do something along those lines:

while{true} do // you probably want to use spawn
{
    if ((count allPlayers) > 0) then
    {
    //code
    };
};

Of course, waitUntil is also possible instead of an If-condition.

Share this post


Link to post
Share on other sites

Of course, waitUntil is also possible instead of an If-condition.

... especially because waitUntil "only" runs (roughly) on each frame, but while runs as quickly as possible which is a bit of an overkill for this purpose, if you ask me.

Share this post


Link to post
Share on other sites

... especially because waitUntil "only" runs (roughly) on each frame, but while runs as quickly as possible which is a bit of an overkill for this purpose, if you ask me.

 

Nitpicking? :)

 

When it comes down to it, there's all sorts of BIS code running, bulging at the seams with whiles and wait-untils, that I don't think it matters.

 

What about a while + a sleep?

 

while {TRUE} do {

      if (!((count allPlayers) isEqualTo 0)) exitWith {};

     sleep 1;

};

 

Oh right, I heard while loops were spawned by Satan himself, to clog the Universe's scheduler and terminate the Great Script  :D 

  • Like 1

Share this post


Link to post
Share on other sites

Nitpicking? :)

 

I'm kindOf a freak when it comes to code performance, so yes, this is my nitpick of the day. :D

 

You're right, who knows what code already runs and whiles and waits until ... just because ArmA is running. Still, good coding behaviour will sooner or later pay off when all the little things people do out of lazyness or because "it doesn't matter" start to stack up and in a sum will actually matter.

 

A simple example I witnessed was a life mod with dozens of addAction statements which partly had very complex conditions. One or two complex conditions won't actually matter. But with a bunch of them, you could see a massive drop in frames compared to playing without all these actions. And a lot of these actions had conditions containing "playerSide == west" which you could easily avoid if you only added the action in the first place, IF the player has the respective side.

  • Like 2

Share this post


Link to post
Share on other sites

Still, good coding behaviour will sooner or later pay off when all the little things people do out of lazyness or because "it doesn't matter" start to stack up and in a sum will actually matter.

You can see this effect today if you add a lot of mods to your game

Share this post


Link to post
Share on other sites

You can see this effect today if you add a lot of mods to your game

 

Funniest to me is when players complain about 'heavily scripted etc', meanwhile trying to find updates for the 25 mods they use.

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×