Jump to content
Sign in to follow this  
snkman

Player in multiplayer ( server )

Recommended Posts

Hey Guy's,

just wondering after a lot of testing in some of my scripts the command "player" works in some scripts but in others it doesnt.

For example:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_soldier1 move getPos player

( Didn't work )

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

If (isPlayer _unit) then {Unit = _unit};

_soldier1 move getPos Unit;

Works

but

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (_soldier1 knowsAbout player > 0.1) then {Hint "Working"}

Works without making the player to a Global variable???

Someone plz can explain me why?

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_soldier1 move getPos player

( Didn't work )

Where do you execute this code ?

If you run it on the server it doesn't work. player is allways local on the players computer. If you give the player entity a variable name then it will work everywhere (something like "_soldier1 move getPos ALPHA_1")

Xeno

Share this post


Link to post
Share on other sites

The player is a client. There is no client on the server (unless it is a local server which is both client and server).

On my computer the, player is me. On your computer, the player is you. On a dedi-server, the player is null.

--Ben

Share this post


Link to post
Share on other sites

if (player is pissed) then {player say "zomg!"}:

The condition is local but what about the statement?

Does it broadcast or does it remain local? huh.gif .

Share this post


Link to post
Share on other sites
The player is a client. There is no client on the server (unless it is a local server which is both client and server).

On my computer the, player is me. On your computer, the player is you. On a dedi-server, the player is null.

--Ben

Yes i know this but it's just confusing me, becouse in many script im using player and it works.

Just in some scripts where i for example order a unit to move to my position i have to use a Global Variable instead of player...

Well but does it mean every scripts which are using the player command do only run on the player machine?

So if someone join a dedicated server and there are script which use player, then they only will work for the one who is a player or does player never work on a dedi?

Share this post


Link to post
Share on other sites

So if someone join a dedicated server and there are script which use player, then they only will work for the one who is a player or does player never work on a dedi?

Like benreeper wrote, the player object doesn't exist on a server, it is just null.

Player is allways different on each client and if you use player in a script you have to execute it on a client and not on the server.

Add "if (local player) then..." or "!isServer" to ensure that it is only running on the client.

Xeno

Share this post


Link to post
Share on other sites
if (player is pissed) then {player say "zomg!"}:

The condition is local but what about the statement?

Does it broadcast or does it remain local? huh.gif .

Afair the say command doesn't get broadcasted over the network.

There are other examples, setDamage, if you execute it on a client gets broadcasted over the network, setFuel on the other hand doesn't get broadcasted.

Xeno

Share this post


Link to post
Share on other sites

If you are using sqf scripts you will have to make sure that all private variables are saved in private array, e.g: private ["_unit"]; etc.

For the rest it's as other's say. "player" can not be used in Multiplayer unless the script runs on client machines, and you want to do something with the player on that machine.

Here some snippet to keep track of all players in Multiplayer:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">SNK_players = [];

SNK_trig = createTrigger ["EmptyDetector",getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition")];

SNK_trig setTriggerType "NONE";

SNK_trig setTriggerActivation ["ANY", "PRESENT", true];

SNK_trig setTriggerArea [30000, 30000, 0, false ];

SNK_trig setTriggerStatements ["this", "", ""];

private ["_ar"];

while {true} do

{

_ar = [];

{ if (isPlayer _x) then { _ar = _ar + [_x] } } forEach (list SNK_trig);

SNK_players = [] + _ar;

sleep 5;

};Now you can simply pick players from SNK_players array, and do whatever you need with them.

You can also choose not to use _ar, and simply replace _ar = _ar + [_x] with: if (!(_x in SNK_players)) then { SNK_players = SNK_players + [_x] }

problem is that at some point there will be a few objNull's in SNK_players, due to players dying, leaving, etc. So you would need to keep that in mind or you would need a SNK_players cleaning function smile_o.gif

Share this post


Link to post
Share on other sites
On a dedi-server, the player is null.

--Ben

On a dedi the 'player' is '--SERVER--' (the minus signs are actually underscores, but the forum software doesn't like them...), it's Id is 2... it's a special kind of 'client'/player that 'we' do not have full control over like a 'normal' player client...

Share this post


Link to post
Share on other sites
On a dedi-server, the player is null.

--Ben

On a dedi the 'player' is '--SERVER--' (the minus signs are actually underscores, but the forum software doesn't like them...), it's Id is 2... it's a special kind of 'client'/player that 'we' do not have full control over like a 'normal' player client...

Actually the name is --SERVER-- (underscores), (which you can find when you have an onPlayerConnected and output the _name and _id). Still, the object "player" is objNull on a server afaik.

Share this post


Link to post
Share on other sites

Actually the name is --SERVER-- (underscores), (which you can find when you have an onPlayerConnected and output the _name and _id). Still, the object "player" is objNull on a server afaik.

Correct, player is a null object on the server.

Xeno

Share this post


Link to post
Share on other sites

Wow that many feedback. smile_o.gif

Well first thanks for all the nice help and thx fur the example sickboy.

Well as far as i undersand player can not be used on a Dedi but if scripts are initialized on the client then i can use player on a Dedi.

So only thing i have to note is that scripts with "player" are running on the client side and scripts which are on the Dedi need a global player array or a global variable insted of the "player"

I hope i finally got it... whistle.gif

Well just another question about this topic:

I have a Eventhandler "Engine" which is Global

so now if i initialize the Eventhandler with all units and players then in the script which was called by the Eventhandler "Engine"

i can use player becouse it's global and it was initialized with all players too. right?

Share this post


Link to post
Share on other sites
On a dedi-server, the player is null.

--Ben

On a dedi the 'player' is '--SERVER--' (the minus signs are actually underscores, but the forum software doesn't like them...), it's Id is 2... it's a special kind of 'client'/player that 'we' do not have full control over like a 'normal' player client...

Actually the name is --SERVER-- (underscores), (which you can find when you have an onPlayerConnected and output the _name and _id). Still, the object "player" is objNull on a server afaik.

@Sickboy/@_Xeno_...

... actually that's exactly what I wrote... 'underscores' - time for 'glasses' ? smile_o.gif

Yes, it is objnull, now... at one point in 1.02 it was a bit more accessible and actually wasn't objnull all the time and wasn't just accessible through the 'onPlayerConnected'...

Share this post


Link to post
Share on other sites

My dear Synide smile_o.gif

I wasn't pointing at the underscores. I was pointing at:

Quote[/b] ]On a dedi-server, the player is null.

--Ben

Quote[/b] ]On a dedi the 'player' is '--SERVER--'...
There Ben notes that player is null (objNull), while you note that it's actually '--SERVER--' (underscores).

Maybe it's just a matter of the way of writing, but I meant to say that indeed the name is --SERVER-- (underscores), but the object player, is a null object (objNull).

Quote[/b] ]I have a Eventhandler "Engine" which is Global

so now if i initialize the Eventhandler with all units and players then in the script which was called by the Eventhandler "Engine"

i can use player becouse it's global and it was initialized with all players too. right?

If that eventhandler runs a script on a client (player) machine, then indeed, you can do something with that specific player on that computer, but only with that player.

Another computer can do something with 'his player'

That the eventhandler is global, means that when the engine eventhandler gets triggered, it gets triggered on all machines (incl server).

Whereas a local eventhandler would only trigger where the unit (which triggered it) is local.

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  

×