Jump to content
Mr H.

MP Execute script only for players within a certain distance.

Recommended Posts

Hi! So here's my problem:

I want a script to execute only for players within hearing distance of a NPC
The script will be executed from another script, the latter being launched from an addaction.
I want the script to execute only on the machines of players nearby but obviously can't use a trigger area to count them.
How should I go about it?

  • Like 1

Share this post


Link to post
Share on other sites
_list = anastasia nearEntities ["Man", 10];
{0= [] execVM "fnc\dialogue1.sqf";} forEach _list;

this doesn't work

Share this post


Link to post
Share on other sites

That's how you execute the script on all clients in MP:

{[] execVM "fnc\dialogue1.sqf"} remoteExec ["bis_fnc_call",0];

And then you put this at the top of your script:

if ( (player distance anastasia) > 10 ) exitWith {};

That way the script will be executed on ALL machines, but everything after the exitWith {}; will only be executed by the machines of players who are less than 10 meters in distance to anastasia.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

I will try that immediatly thanks!

 

Share this post


Link to post
Share on other sites

It works perfectly thanks! + It's a very clever way to do it, I wouldn't have thought of it myself!

Share this post


Link to post
Share on other sites
<arguments> remoteExec ['tag_fnc_myFunction',(allPlayers select {((_x distance <center_position>) <= <radius>)})];

 

  • Like 3

Share this post


Link to post
Share on other sites
On 8/28/2017 at 3:22 PM, Mr H. said:

_list = anastasia nearEntities ["Man", 10];
{0= [] execVM "fnc\dialogue1.sqf";} forEach _list;

this doesn't work

 

On 8/28/2017 at 3:30 PM, Belbo said:

That's how you execute the script on all clients in MP:

{[] execVM "fnc\dialogue1.sqf"} remoteExec ["bis_fnc_call",0];

And then you put this at the top of your script:

if ( (player distance anastasia) > 10 ) exitWith {};

That way the script will be executed on ALL machines, but everything after the exitWith {}; will only be executed by the machines of players who are less than 10 meters in distance to anastasia.



How would this work for an OOG file on a trigger? I have the player base split and only want the players near the guy to hear the OOG "Incoming" 

Share this post


Link to post
Share on other sites

Use say3D or playSound3D, you can specify max distance at which the sound can be heard.

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

×