OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: Nixer6 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...........
-
OnPlayerConnected (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=n#onPlayerConnected)
// 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.
-
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????
-
To find out who currently leads a specific group:
alphaGroup = group this;
_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 (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=a#addEventHandler)in the COMREF for details. e.g.
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. (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=a)
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.
-
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.
-
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 (http://www.ofpec.com/forum/index.php?topic=30274.0) 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
-
there's also name player
eg
script.sqs
_myname = name player
hint format["Your name is %1", _myname]
-
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).
-
unless those other machines communicate that information to you)
I take it thats a hint then. :dunno:
Soooooooooo.....................
Mando's example:
// init.sqf
if (isServer) then
{
listofplayers = [];
OnPlayerConnected "listofplayers = listofplayers + [_name]";
OnPlayerDisconnected "listofplayers = listofplayers - [_name]";
};
What about this?
publicVariable (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=p#publicVariable)
// 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???
-
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:
// 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:
-
Thank you Spooner. That is something I can work with. I will do some experimenting and report back.
-
Alternatively, assuming you are not using huge numbers of AI and a smallish map...
_men = nearestObjects [position player,["Man"],1000];
{
if (isplayer _x) then {
player sidechat name _x ;
} ;
} foreach _men ;