Jump to content
jcae2798

Covert player code to MP

Recommended Posts

Hey guys, looking for some help.  Tried to do my homework, but not getting far.

 

I’m trying to take an existing SP mission of mine and make it MP compatible.  I have some decent SP coding experience, but still noobish toward MP coding.

 

I have many scripts that ask for current Player Position, or compare Player Position against AI units.  I need to be able to do this for MP Players.  Some examples below.  Not sure how to convert this.  Thanks in advance.

 

Examples:

_spawnPos = [getPos player, 700,1000,1,0,0,0] call BIS_fnc_findSafePos;

Waituntil {sleep 15; {getposatl player distance getposatl _x > 2500} forEach units _group1};

 

If (((getPosATL player) select 2) > 5) exitwith {_Count = 1};

 

If (surfaceIsWater getPos player) then {[] spawn {call JCPlayerAMB_FNC_BoatPatrol};

 

_remove = (allunits - _ignore);

{If (player distance _x >= 500 && SIDE _X == EAST || SIDE _X == INDEPENDENT) then {Deletevehicle _X}} foreach _remove;

Share this post


Link to post
Share on other sites

If you're running the code on the client (player) machine, then <player> script command can still be used.

 

If you run on the server, then you need to know what client you are referring to.

 

Respawn stuff can normally be handled on client machine.  I'd probably then remoteExec over to the server to handle your boat patrol stuff (assuming it's an enemy patrol spawned when player respawns).

 

It's hard to tell what you're doing though from a few isolated lines of code.

 

Read up on locality:

 

http://killzonekid.com/arma-scripting-tutorials-locality/

https://community.bistudio.com/wiki/Locality_in_Multiplayer

 

When you have a fair idea, then plan what you need to do and on what PC.  Chances are you will have to rewrite a lot of stuff.  Don't be afraid to experiment!

  • Like 1

Share this post


Link to post
Share on other sites

Thanks.  This will help.  

 

 

To further clarify, these are mostly dynamic spawn scripts that were spawning units around the player and then waiting for the AI units to die or despawn if player gets away from that zone.   I would assume this happens at server level otherwise each player can spawn there own? And if their together it spawn twice?

 

 

Based on reading some of the locality, confused if AI is spawned locally to that player, will others see them as well?  Does all it really mean is that this players PC is hosting the AI GROUP?

 

thanks again

Share this post


Link to post
Share on other sites

Ok, if you're running spawn scripts around the players, I would keep the script that handles it on the server (as it is guaranteed to be connected to the mission all of the time).

 

So you could have say a loop on the server that picks a player to spawn stuff around.

 

At this point, you could:

1 - do all of the calculation and spawning on the server (so the AI units are owned by the server)

2 - You could calculate where to spawn on the server and spawn them on the server, then palm them off onto the client to handle the load.

3 - You could calculate where to spawn on the server and spawn them on the client.

4 - you could tell a client to do all of the calculation and spawning themselves.

 

There's pros and cons to each approach (you will have to experiment to see what works for you best).  Units are MP synched so exist on each connected machine.

 

  • Like 1

Share this post


Link to post
Share on other sites

So with some learning and further testing, i think the following solution will work.

 

i created a function with the below code.  Then i will replace "PLAYER" in all my scripts with "W_player" variable which the function will list a random player.  If anyone sees any issues with this, let me know!  Thanks again for the suggestions and direction.

 

/*
	Author: JCae2798 AKA GigaS

	Description:
	Returns random player
	call findPlayer;

	Returns:
	W_player = Random PLAYER
*/

if (!isServer) exitWith {};

W_player = nil;

waitUntil {(count (playableUnits)) > 0};

_units = [];
{
 if (isPlayer _x && ALIVE _x) then {
   _units pushBack _x;
 }
} foreach (playableUnits);

W_player = _units call BIS_fnc_selectRandom;

 

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

×