Jump to content
Sign in to follow this  
KaRRiLLioN

Counting players server-side possible?

Recommended Posts

I'm trying to count human players using a server-side script, but since dedicated servers don't seem to "see" whether a unit is a player or not, I'm kinda stumped.

I've also tried this:

?(Name _unit != "Error: No Vehicle") : Players = Players + 1

But with the : in the quotes, it gives me an error for some reason.

I then tried this:

if (name _unit != "Error: No Vehicle") then {PlayerCount=PlayerCount+1};

but then it counted all units, even AI units.

Is there an easy way to count the number of players in a list using Foreach?  I'm not sure how to qualify whether the unit is a player or not.

I suppose the only other option is to have one client do the count, but that gets messy with lag.

*EDIT*

OK nevermind about the Foreach part, I just figured it out:

PlayerCount = "_x == Player" count (WestList + EastList)

But I guess I'll still have to do it client side.

Share this post


Link to post
Share on other sites

Since 1.85, there is the command

_number = playersNumber side

that should return the number of human players on a side.

Share this post


Link to post
Share on other sites

Karrillion,

why don't you let a script run on server side,

and check for: !local

all units, not local on the server should be client players.

:remember - AI is local on the server.

Now you just have to get sure, wether it's a dedicated

server, or a non-dedicated server.

You could try to check for a local player then.

If a player is local on the server, it's a non-ded

if none's local, then it's dedicated.

not sure if it will work, but i think it's worth a try

~S~ CD

Share this post


Link to post
Share on other sites

OK, I think the following works, and it can determine if you are playing in SP or MP.

I set 2 triggers on the map, one set to activate if West present, one to activate it East present. The triggers covered all of Nogova. In OnActivation, I put WestList = thislist (in the one activated by WEST) and EastList = thislist (in the one activated by EAST) I did this so that I can check during a MP game how many Players exist, in case some leave. This determines how many AI get created, etc.

Also, I set the triggers to activate with a delay of 3 seconds.

In Init.sqs I put:

WestList = []

EastList = []

In script that I exec'd from the init.sqs I have this:

;;wait until the triggers activate

@(Count WestList > 0) AND (Count EastList > 0)

_array = WestList + EastList

;;count all local players on the server. If local, then it is SP

?(Local Server) : PlayerCount = "_x == Player" count (_array)

?(PlayerCount > 0) : Dedicated = FALSE

;;if Dedicated TRUE, then it's a MP game

?(PlayerCount <= 0) : Dedicated = TRUE

;;count all units that are not local objects to the server if dedicated is true.

?(Local Server) AND (Dedicated): PlayerCount = "!Local _x" count (_array); PublicVariable "PlayerCount"

Share this post


Link to post
Share on other sites

Seems you got it Karrillion,

ok, it's 4 am here now, and i can't keep my eyes open anymore. But out of my thiny 2eyes, and what they do

show me, i think it'll work.

~S~ CD

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (DV Chris Death @ Nov. 18 2002,03:54)</td></tr><tr><td id="QUOTE">why don't you let a script run on server side,

and check for: !local

all units, not local on the server should be client players.

:remember - AI is local on the server.<span id='postcolor'>

This is not always true. If player is leader, all AI members of his group are local on player's computer.

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">This is not always true. If player is leader, all AI members of his group are local on player's computer.<span id='postcolor'>

wow.gif don't you think this was a bit late now? biggrin.gif

Ah - my grey cells start workin again, and i begin to

remember.

Vehicle, in use by client = local on clients machine

Group of leader = local on groupleaders machine

OK, Karrillion i think this info doesn't cause any troubles to

your script, because you're scanning for local or not local players anyway.

~S~ CD

Share this post


Link to post
Share on other sites

Interesting point. At the beginning of the mission, players don't start in a vehicle and they don't control any units, however later, they most certainly will.

Animal sent me a script that he uses which might work for my purposes.

At least now I know why a script that I had made before didn't work at all. I had tested it on my PC and it worked perfectly, but on a dedicated it worked like crud, mainly because I had no idea about the way players were not local to a server, unless you were hosting the mission (non-dedicated), and then 1 player would be local to it.

This also makes more sense now about some AI creation scripts I had made once. When I tested it on my PC, I created a squad using an Action on the action menu. The squad would join a pre-existing squad and then it would become its own independent squad. It worked perfectly in testing on my PC, but once it got on a dedicated server, the AI would just sit there motionless, and even shooting them wouldn't get a reaction. It was like the server wasn't accepting control of them or something since when they were made with an action by a player, they were made non-locally to the server.

I dunno , but I suppose that's the reason it didn't work. That was in 1.46 BTW, haven't tried it that same way in 1.85.

OK, back to the drawing board. =)

Share this post


Link to post
Share on other sites

i don't want to create a new thread for this.

but isn't it possible to determine players at all on dedicated server?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;;[wio1] exec prepareofficer1.sqs

_leadr1 = _this select 0

;;Player is kicked here

?(_leadr1==player): exit

?!(local Server): exit

?(_leadr1!=player): [_leadr1] join grpNull

?(_leadr1!=player): unassignVehicle (vehicle _leadr1)

exit

mad_o.gif

[ edit]

Allright!

I found it out, I added an Gun120 to the players, and in the script:

?!(_leadr1 hasWeapon "Gun120"): do AI specific stuff

Share this post


Link to post
Share on other sites

Or you can plop the CoC NS utility on the map and read CoC_ClientList array tounge_o.giftounge_o.gif

could not resist

Share this post


Link to post
Share on other sites
Or you can plop the CoC NS utility on the map and read CoC_ClientList array  tounge_o.gif  tounge_o.gif

could not resist

or, I can throw the OFP cd's out of the window wink_o.gif

Share this post


Link to post
Share on other sites

<trys to understand all this, but fails misserably and blows up>

Share this post


Link to post
Share on other sites
Or you can plop the CoC NS utility on the map and read CoC_ClientList array tounge_o.giftounge_o.gif

could not resist

or, I can throw the OFP cd's out of the window wink_o.gif

Or I can drink water.

crazy_o.gif What are you talking about...?

Share this post


Link to post
Share on other sites
Or you can plop the CoC NS utility on the map and read CoC_ClientList array  tounge_o.gif  tounge_o.gif

could not resist

or, I can throw the OFP cd's out of the window  wink_o.gif

Or I can drink water.

crazy_o.gif  What are you talking about...?

I'm talking about that I will try your mod some day, and build an mission for it, but this I'm trying todo is quite simple, and meanwhile very teaching as well, and timeconsuming.

But hey, what would I do instead biggrin_o.gif

What I meant by throwing the CD's is that If I grow tired of it I can allways throw the cd's away.

Best not to upset the mods for me being OT, must stop.

*meh hides*

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  

×