Jump to content
Sign in to follow this  
UltimateBawb

Quick MP vs. SP Question

Recommended Posts

If I use objects like "player" to give someone something, will that mess up in multiplayer and treat everyone in player? If so how would I discriminate between players?

Share this post


Link to post
Share on other sites

Pretty much. Player is different on every client and it's a null object on a dedicated server.

Two playable units named p1 and p2

on p1's computer, player is equal to p1

on p2's computer, player is equal to p2.

Share this post


Link to post
Share on other sites

So how would I make the player object local? I read the wiki's and they seemed to show how to check if something if local, not set it to local.

Share this post


Link to post
Share on other sites

The player object is local - always - it's just that every computer has its own player object. If have this line:

player addWeapon "M16a4";

Then it will only happen on the machines (computers) that run that line of code. Let's take an example where it does not run for all. Actions are local. So say you create an action on a vehicle "Add Weapon". And that scripts runs the above line. Then only the player that uses the action will get the weapon. If you "add the action on another player's machine too" then he also has the action and he too can go over and a weapon.

What the others are really saying it that if you put the, say the above line, into the file init.sqf then that file will be run by all machines. So whenever a player's Arma is done loading the mission then init.sqf will run. Then everybody will get a the weapon since every machine runs that line.

So how would I make the player object local? I read the wiki's and they seemed to show how to check if something if local, not set it to local.

You cannot. Maybe with some trickery you can change where the AI is local, but you can't change where player is local.

Share this post


Link to post
Share on other sites

You don't make anything local either the object is or is not.

If (local player) then {
  // do stuff local to that client.
  Player setDammage 1;
}

If (isServer) then {
   // do stuff like spawn ai on the server
};

Share this post


Link to post
Share on other sites

Would be easier to help you if you explained what you're trying to do :).

If you can't use "player" then use the objects name.

Some examples

unit123 addWeapon "M16a4";

if (player == unit123) then {
 player addWeapon "M16a4";
};

//or

if (local unit123) then {
 unit123 addWeapon "M16a4";
};

Many possibilities:)

Edited by cuel

Share this post


Link to post
Share on other sites

Ok, thanks a lot guys. :)

Just to be safe, though, whenever I use the "player" object, it only runs on the computer that activated that script, correct?

Share this post


Link to post
Share on other sites

I reread your posts and I think your misunderstanding comes from the missunderstanding that player is an object.

Its not really, its a command that returns the object localy where it is run.

So if I put player when the game compliles that code it will instead replace the word player with the local object where the command is run.

It allows us to create dynamic scripts that run locally but will work for everyone.

So if I want to give everyone a map I can code it using player and then run it locally one each client and the game will put the correct object name there.

That way I don't have to hardcode everything.

Edited by Riouken

Share this post


Link to post
Share on other sites
Ok, thanks a lot guys. :)

Just to be safe, though, whenever I use the "player" object, it only runs on the computer that activated that script, correct?

That depends only on how you ran the script.

If you use the player command inside a script, read what Riouken wrote.

If you run it by using addAction, it only runs on the client who performed the action.

If you used a trigger with

0 = [] execVM "script.sqf"

then it would run for everyone where the condition was met.

Edited by cuel

Share this post


Link to post
Share on other sites

And most importantly:

http://community.bistudio.com/wiki/player

Before you use the player object (usually to avoid JIP issues) all you need is to run:

waitUntil {!isNull player};

Anything else you see in other scripts is equivalent and/or redundant. Of course JIP players may need more than just the player to point at the actual JIP player unit, but that's script/mission-specific.

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  

×