Jump to content
Sign in to follow this  
ShaunUK

Getting the 'clientID' for 'publicVariableClient'

Recommended Posts

publicVariableClient requires the parameter 'clientID'.

Currently the only advice on getting this ID is "You can find out this ID with the owner command (using it on a player's character, for example, will give you that players client ID)."

Surely there is a better more reliable way to find out the clientID? What if I want to find out the clientID on the clientside? Is there no way I can access this ID from the moment the client connects? The variable must be decided and set somewhere that I can access it cleanly; surely it cant be related to a particular object? Crossing my fingers and hoping there is a simple answer to this question. The solution in quotes above just doesn't seem right. I understand that this command is now in use within DayZ so if anyone knows how they do it, I would appreciate it if you could share.

Share this post


Link to post
Share on other sites

As the wiki says, see also owner to get the clientID. Also DayZ isn't ArmA2, what works in DayZ doesn't always work in ArmA2 and the reverse.

Share this post


Link to post
Share on other sites

You have ignored my question really, I was aware of owner, my question was 'is there is a better way?' DayZ mod is an Arma2 mod, hence the scripting they use would work. (Lets not derail the thread with a discussion about DayZ)

Edited by ShaunUK

Share this post


Link to post
Share on other sites

What are you trying to do with the client id? If you are trying to find it, for using it with publicVariableClient then I don't think it makes sense. publicVariableClient sends to a client, and I think that in most first person games all clients are only connected to the server and not to each other, so there is no one but the server to send to, and no need to know the clientId of others on client-only machines.

Share this post


Link to post
Share on other sites

I want the client to send data to the server for processing. So the client sends the data and his ClientId to the server using publicVariableServer. The server reacts to the change in the publicvariable, processes the data and sends back the result to the single client only using publicVariableClient and the ClientId. Please note my question is really, is there any way to get the clientID without using the owner function?

Edited by ShaunUK

Share this post


Link to post
Share on other sites

Then you are probably going to have to request it once.

Server:

"PV_RequestClientId" addPublicVariableEventHandler {
  G_ClientId = owner (_this select 1);
  G_ClientId publicVariableClient "G_ClientId";
};

Client initialization

waitUntil {!isNull player};
//Request ID
PV_RequestClientId = player;
publicVariableServer "PV_RequestClientId";

//Shortly it should arrive in our local G_ClientId

Please note my question is really, is there any way to get the clientID without using the owner function?

Most likely not. (You have onPlayerConnected but that also only works on the server).

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

Thanks for the detailed reply. Is the ID produced by onPlayerConnected the same as the clientID? I was under the impression that it was different. The wiki describes it as "Unique DirectPlay ID."

Share this post


Link to post
Share on other sites

Just assumed that clientId was the same as _id in:

Variables _id and _name are set, in theory _id being the session id number as seen in #userlist.

I have never used onPlayerConnected. To me it's not a good "tool" to use since, I believe that you can only attach one handler to it. Meaning if I use it in my stuff, and I use someone elses stuff which also depends on it I have to tweak stuff to get both working - so I stay far away from it.

Share this post


Link to post
Share on other sites
Thanks for the detailed reply. Is the ID produced by onPlayerConnected the same as the clientID? I was under the impression that it was different. The wiki describes it as "Unique DirectPlay ID."

No, it is different. Or at least it wasn't reliable when I first tested it.

To improve Muzzleflash's suggestion a bit I'd recommend using public setVariable instead. That way you can then access client's ID at any time from any place.

// init.sqf
if (isServer) then
{
  TAG_fnc_requestClientID =
  {
     (_this select 1) setVariable ["TAG_clientID", owner (_this select 1), true];
  };
  "PV_RequestClientId" addPublicVariableEventHandler TAG_fnc_requestClientID;
};
if (!isDedicated) then //Clients
{
  waitUntil {!isNull player};
  PV_RequestClientId = player;
  publicVariableServer "PV_RequestClientId";

  if (isServer) then //Special case for locally hosted game
  {
     ["", player] call TAG_fnc_requestClientID;
  };
};

Share this post


Link to post
Share on other sites
Thanks for the detailed reply. Is the ID produced by onPlayerConnected the same as the clientID? I was under the impression that it was different. The wiki describes it as "Unique DirectPlay ID."

You can iterate over the playableunits array and get the player object already in onPlayerConnected by checking for the name, thus you have the object and can use owner then (and store it in the object variable space or do whatever you want with it)

You just have to check for __SERVER__, a dedicated server (or server) also triggers the OPC event.

Edit: For everything else the best way is to send the object reference with the data. This way you can even fake client peer 2 peer by simply sending the data incl. the object referencte to the server, let the server check where the object belongs to and send the data to the correct client. ACE and Domina are using it for quite some months now (it's event based).

Xeno

Edited by Xeno

Share this post


Link to post
Share on other sites

Thanks Deadfast and Xeno, some really useful responses. I'll test a few combinations of the above ideas, see what works best and post back here.

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  

×