OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Gadjuka on 06 Jun 2003, 11:14:52

Title: Player array
Post by: Gadjuka on 06 Jun 2003, 11:14:52
Hi!

I wonder how you do to get an array of all the (human) players in a MP game.
Title: Re:Player array
Post by: CrashDome on 06 Jun 2003, 15:11:16
unpossible!

thats right..i said it..... UNpossible....


really it IS possible but you need alot of scripting knowledge. Fortunately, someone has done that for you. The Chain of Command released a set of scripts and functions called COC Network Services. It has a function in there for you that just may work for ya. I do believe it is hosted on this site.
Title: Re:Player array
Post by: Mujahedeen on 06 Jun 2003, 20:51:32
Hi!

You might be able to use this:
...although it only counts all players...

-----
playersNumber side
Operand types:
    side: Side
Compatibility:
    Version 1.8 required.
Type of returned value:
    Number
Description:
    Return count of players playing on given side.
-----

Cheers...
Title: Re:Player array
Post by: Gadjuka on 17 Jun 2003, 05:13:35
I've noticed that players always has the skill 1...
To find out which units are players, set all units to a skill less than 1. Then check which units have their skill set to 1 - these are the players!
q.e.d  8)
Title: Re:Player array
Post by: DrStrangelove on 17 Jun 2003, 20:57:41
Wow, now that's a good trick!  :D
Title: Re:Player array
Post by: MI_Fred on 17 Jun 2003, 21:35:07
How about this in your init.sqs:
Code: [Select]
allplayers = []
allplayers = allplayers + [player]

;D

Init.sqs is ran on all machines, and player is picked up from each. I quarantee not that it works, nor the order is nothing but random. It might also work only in-mission, I experimented with enabling/disabling maps, pads, watches and compass' for certain units only. It was only possible after enabling all from description.ext and from the mission executing the script with [player] exec "equipment.sqs". That got a hold of em all and it works.
Title: Re:Player array
Post by: PheliCan on 18 Jun 2003, 00:35:51
Well...
Init.sqs is started on all computers. But they are still runned locally and therefor, you vill get a global array on your local computer containing the name of your player. What you have to do is to broadcast the playername with "publicVariable", but them you'll risk overwriting each other...
This method is much better, even if it might not look very well. ::)
Title: Re:Player array
Post by: Chris Death on 20 Jun 2003, 17:08:25
Another way:

This might take some pre-work to be done, but it's also a
solution:

As you all know, there's a little difference on the names,
once a unit get's player controlled (except you're using
setidentity command).

Now there are guys called: Bobby Bruining, Mike Hirasaki,
etc. hanging around, if they are AI controlled.

If a player takes control over an AI, the name will change to
the player's name: [BF] ChrisDeath, etc..

Only thing you need to do is:

Put all your playable soldiers into an array (let's say: player_array)

check for the AI name like:

?(name unit1 != "Bobby Bruining"): player_array = player_array - [unit1]


The only thing i'm not sure about is:

If you disable unit1, and select unit2 in the player selection menu, will Bobby Bruining then be unit2, or do the names
remain to their affilatetd units.

Sorry, but i can't check this right now as i'm at work.

If this is the case, then there would still be a work around
by creating a second array: names_array

Into this names array you would have to put all your AI names.

names_array = ["Bobby Bruining","Mike Hirasaki",etc..]

Then you would have to check:

?(name unit1 in names_array): player_array = player_array - [unit1]

But don't take my sample commands here too serious, as i just
showed ya where the kitchen is, and not how to cook.

You might need to make a loop for checking all those names
through the arrays.


~S~ CD
Title: Re:Player array
Post by: toadlife on 21 Jun 2003, 10:59:47
Start with a trigger (I'll call it "allunits") that covers the map to gather all units...
then place a gamelogic and name it "server"....

then use these lines to weed out the AI dudes and return an array of players...

Code: [Select]
_everyone = list allunits
_players = []
{if ((!local _x) || (player == _x)) then {_players = _players + [_x]}} foreach _everyone
_players = _players - [server]
hint format ["%1",_players]

This of course, will only work on the server.

Title: Re:Player array
Post by: Dinger on 22 Jun 2003, 15:58:50
aren't AI units local to the group leader's client?

Anyway, check out CoC_NS.  v. 1.1 is simple to use (just place an object on the map; or copy scripts and run an init).  Run the script, and all players appear in an array (I think it's CoC_PeerList)
Title: Re:Player array
Post by: toadlife on 23 Jun 2003, 00:25:28
aren't AI units local to the group leader's client?

Ewww you're right. We'll my little script is flawed then.