Home   Help Search Login Register  

Author Topic: How can I find the players names in MP?  (Read 2611 times)

0 Members and 1 Guest are viewing this topic.

Offline Nixer6

  • Members
  • *
How can I find the players names in MP?
« on: 15 Oct 2007, 20:09:48 »
Topic says it all.

How do I find the "real name" of players in an MP game.  :scratch:

I know the game keeps track of them, for scoring and such. There must be a way to access the names...but how???

I've searched here and the Biki...........
Why do I have to be a Rocket Scientist to make a good mission?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: How can I find the players names in MP?
« Reply #1 on: 15 Oct 2007, 21:09:46 »
OnPlayerConnected

Code: [Select]
// init.sqf
if (isServer) then
{
   listofplayers = [];
   OnPlayerConnected "listofplayers = listofplayers + [_name]";
   OnPlayerDisconnected "listofplayers = listofplayers - [_name]";
};

global array listofplayers would contain the list of players already connected to the servers.

Offline Nixer6

  • Members
  • *
Re: How can I find the players names in MP?
« Reply #2 on: 16 Oct 2007, 07:50:33 »
OnPlayerConnected  :clap:


Thank you sir. :yes:      But............. 

Now how would I find the name of a specific in game playable unit. :dunno:

ie;

The name of the player whom is the leader of group "Alpha"  or the name of the player who just killed me.   :weeping:


I am now also looking for a reference containg a list of all the global arrays and variables the game generates and/or uses????

Why do I have to be a Rocket Scientist to make a good mission?

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How can I find the players names in MP?
« Reply #3 on: 16 Oct 2007, 12:41:17 »
To find out who currently leads a specific group:
Code: (init for each member of "Alpha" group) [Select]
alphaGroup = group this;

Code: (Within a script) [Select]
_alphaLeader = name (leader alphaGroup);

To discover the name of the player that killed you, you need to use a KILLED handler on yourself. See addEventHandler in the COMREF for details. e.g.

Code: (init.sqf) [Select]
player addEventHandler ["KILLED",
    {
        _killed = _this select 0;
        _killer = _this select 1;
        _killer sideChat (format ["Ha, ha! I sent %1 to heaven!", name _killed]);
    }
];

As far as I can tell, ArmA doesn't use any global variables except this (within object init) and thisList (within trigger code). It does have commands which return of copy of internal data, such as player and vehicles (which contains vehicles and objects, but not people; Oh, for a players or people list!). For a full list of commands, peruse the COMREF.

Remember that if you use the player list as suggested by Mandoble, that the list will only be visible on the server, not on any of the client machines. Just thought that might catch you out.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Nixer6

  • Members
  • *
Re: How can I find the players names in MP?
« Reply #4 on: 16 Oct 2007, 15:23:48 »
Thanks Spooner.

I peruse the Comref here and on the Biki more than I read the news, less depressing.  :shhh:
As I have absolutely ZERO computer programming background (and the math skills of a high school drop out), this scripting is like something between Voodoo and Quantum Physics to me. I just refuse to give up

Remember that if you use the player list as suggested by Mandoble, that the list will only be visible on the server, not on any of the client machines. Just thought that might catch you out.

Ahhh..........more local/global stuff. But the information from the list can be read by clients, as in the "scoreboard", n'est pas?


Thanks all for your patience.
Why do I have to be a Rocket Scientist to make a good mission?

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How can I find the players names in MP?
« Reply #5 on: 16 Oct 2007, 15:53:50 »
No, in Mandoble's example, listofplayers exists only on the server. The clients cannot see it at all (except in SP, when the server is the same machine as the client). It would be considerably more difficult to ensure that the array was updated on all machines.

I have a system in SPON_Core that overcomes this and maintains global lists of player names and objects, but that part of the script pack is still a little ropey, so I wouldn't assume that it works in all circumstances (I need to work on it some more - sorry!). Since I have a mechanism for this already in my script, I won't write a specific, relatively complex, version for you, though someone else might take pity on you ;P
« Last Edit: 16 Oct 2007, 16:06:34 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline [KH]Alien

  • Members
  • *
Re: How can I find the players names in MP?
« Reply #6 on: 18 Oct 2007, 00:36:28 »
there's also name player


eg

script.sqs

_myname = name player
hint format["Your name is %1", _myname]

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How can I find the players names in MP?
« Reply #7 on: 18 Oct 2007, 01:41:11 »
No, name player just tells you the name of the player on the client machine. It doesn't allow you to know who all the other players are (unless those other machines communicate that information to you).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Nixer6

  • Members
  • *
Re: How can I find the players names in MP?
« Reply #8 on: 18 Oct 2007, 15:02:01 »
unless those other machines communicate that information to you)

I take it thats a hint then.  :dunno:

Soooooooooo.....................

Mando's example:

Code: [Select]
// init.sqf
if (isServer) then
{
   listofplayers = [];
   OnPlayerConnected "listofplayers = listofplayers + [_name]";
   OnPlayerDisconnected "listofplayers = listofplayers - [_name]";
};

What about this?
publicVariable

Code: [Select]
// init.sqf
if (isServer) then
{
   listofplayers = [];
   publicVariable "listofplayers";
   OnPlayerConnected "listofplayers = listofplayers + [_name]";
   OnPlayerDisconnected "listofplayers = listofplayers - [_name]";
};

Would listofplayers then be able to be accessed on all client machines???
« Last Edit: 18 Oct 2007, 15:08:20 by Nixer6 »
Why do I have to be a Rocket Scientist to make a good mission?

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How can I find the players names in MP?
« Reply #9 on: 18 Oct 2007, 18:40:03 »
You have the right idea, but sadly you can't broadcast the array type directly via publicVariable. I think, from your code, you are also assuming that publicVariable makes a variable global across all machines, when what it actually does is copy its current contents across all machines once. If you want to keep it updated, then you have to publicVariable it every time it is altered (but obviously not in this case, since you can't publicVariable an array, as I said).

My solution to your problem involves some relatively advanced methods (Well, if you aren't used to MP scripting), so I am not sure I can explain it fully, but:
Code: (init.sqf) [Select]
// List of players should be initalised on all machines.
listofplayers = [];

// The server requests the connecting player name be added to the list, or the disconnecting player name be removed from the list:
if (isServer) then
{
   OnPlayerConnected "global_command = format [""listofplayers = listofplayers + [""""%1""""]"", _name]; publicVariable ""global_command"";";
   OnPlayerDisconnected "global_command = format [""listofplayers = listofplayers - [""""%1""""]"", _name]; publicVariable ""global_command"";";
};

// global_command is used to perform remote command execution.
global_command = "";

// Monitor global_command for new commands and then execute them.
[] spawn
{
    while {true} do
    {
        waitUntil {global_command != ""};
        call compile global_command;
        global_command = "";
    };
};

In the script above, I've used a general method for executing code on remote machines, which isn't specific to the list of players. You might find other uses for it in MP games. Note that though I've given it a quick check for syntax errors, I haven't tested it in a proper MP game.

** EDIT **
As usual with MP scripting, I overlooked something. Both Mandoble's and my version will record a "player" called __server__ which isn't a real player. You can just ignore that player in the list or prevent the player name being added if it is __server__ (or __SERVER__, I can't remember which).

The other issue is that my version isn't JIP-compatible since only the server and those players in the game from the start will have the correct list (Mandoble's is fine for JIP since it only works on the server anyway). JIP players will not have any names of people who joined the game before them, so If you need JIP players to have the correct list, then I'll have to do things differently...oops! MP scripting is never straightforward :blink:
« Last Edit: 18 Oct 2007, 21:05:24 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Nixer6

  • Members
  • *
Re: How can I find the players names in MP?
« Reply #10 on: 18 Oct 2007, 23:35:50 »
Thank you Spooner. That is something I can work with. I will do some experimenting and report back.
Why do I have to be a Rocket Scientist to make a good mission?

Offline sbsmac

  • Members
  • *
  • I'm a llama!
Re: How can I find the players names in MP?
« Reply #11 on: 28 Oct 2007, 11:38:53 »
Alternatively, assuming you are not using huge numbers of AI and a smallish map...

Code: [Select]
   _men = nearestObjects [position player,["Man"],1000]; 
   {
       if (isplayer _x) then {
        player sidechat name _x ;
        } ;
   } foreach _men ;
« Last Edit: 28 Oct 2007, 12:17:04 by bedges »