Jump to content
Sign in to follow this  
[kh]jman

server target a player object?

Recommended Posts

Quick question.

How do I target a player's object if I'm the server?

What I have so far:

if(isServer) then {
	onPlayerConnected "[_id, _name, _uid] execVM ""playerconnected.sqf""";
};

        _pid = (_this select 0);  // get player's id
	_pname =  (_this select 1);  // get player's name
	_puid  =  (_this select 2);  // get player's uid

so I have the player's id, name and uid but how do I target the player's object, say to get the player's score?

Share this post


Link to post
Share on other sites

tmp_fnc_findPlayer = {
  private ["_player"];
  _player = objNull;
  {
    if (getPlayerUID _x == _this) exitWith {
         _player = _x;
    };
  } forEach allUnits; // could also try playableUnits instead of allUnits.
  _player; // return _player
};

Call with:

_player = _puid call tmp_fnc_findPlayer;
if !(isNull _player) then {
  // do stuff with _player.
};

Edited by Sickboy

Share this post


Link to post
Share on other sites

Thanks Sickboy that worked.

One other issue I have now is that I'm targeting the player's side chat but it's not outputting to the player's screen...

_player = objNull;
	{
	if (getPlayerUID _x == _puid) exitWith {
		   _player = _x;
	  };
	} forEach playableUnits; 

	if !(isNull _player) then {
	_player sideChat "Hello world";
	};		

Share this post


Link to post
Share on other sites
Jman;1791647']

One other issue I have now is that I'm targeting the player's side chat but it's not outputting to the player's screen...

onPlayerConnected/Disconnected triggers only on the server, not on clients.

(and it can't be stacked, means you can use OPC/OPD only once)

Xeno

Share this post


Link to post
Share on other sites

Argh yes of course, so would there be any other way to do it?

What if I set a publicvariable in the 'playerconnected.sqf' containing the player I want the server to target and then create an eventlistener on the players to call on the player who's id equaled the publicvariable?

Edited by [KH]Jman

Share this post


Link to post
Share on other sites

You can try another approach (at least that's what I do in Domina):

- store the UID when the player connects in a hash (if the UID doesn't exist in the hash yet)

- once the player has connected send a request from the player/client machine (with client data) to the server to retrieve all necessary data from the server

(client waits for a specific time, no answer from the server/timeout, use default values)

- when the player disconnects save all player data in the hash (some hash data is updated during the mission on the fly)

Quite easy to handle.

I'm using it to store teamkills, side of the player (if the player switches sides in the TvT version the other players are notified about it),

name of the player (other players are notified if a player changes his name) and so on, and so on...

The late client/server data exchange has the advantage that I can also store the var name of the player

(beside things like player side which are not available on connect).

Xeno

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  

×