Jump to content
Purzel

Check distance to nearest player (Mulitplayer!)

Recommended Posts

Hi Folks,

how do I check the distance to the nearest player in Multiplayer...?
I tried this:

while {(jeep1 distance allPlayers) > 500;} do {jeep1 allowdamage false;};

The object "jeep1" should be indistructible as long as any player is not closer than 500m,
because sometimes the jeep (driven by AI) crashes at walls or got flat tires...

How do I get this...?
(Yes, all waypoints are "SAFE" and speed is "NORMAL" for staying on road, but sometimes it happens...)

Greetz & Thx

Purzel

Share this post


Link to post
Share on other sites


while {true} do

{

if ({_x distance jeep1 > 500} count allPlayers > 0) then

{

jeep1 allowDamage false;

} else

{

jeep1 allowDamage true;

};

sleep 5;

};

  • Thanks 1

Share this post


Link to post
Share on other sites

probably rather so:

while {alive jeep1} do
{
    if ({_x distance jeep1 < 500} count allPlayers > 0) then
    {
        jeep1 allowDamage true;
    } else
    {
        jeep1 allowDamage false;
    };
    sleep 5;
};

Is there any difference between checking if the player is far enough or close enough?

Share this post


Link to post
Share on other sites

probably rather so:

while {alive jeep1} do
{
    if ({_x distance jeep1 < 500} count allPlayers > 0) then
    {
        jeep1 allowDamage true;
    } else
    {
        jeep1 allowDamage false;
    };
    sleep 5;
};
Is there any difference between checking if the player is far enough or close enough?

Nice catch on checking alive status, and no, not really, same exact calculation, just the opposite direction.

Share this post


Link to post
Share on other sites

That was fast...!
THANK YOU!!!!
:)

Share this post


Link to post
Share on other sites

Ok... next problem:
I have a crashsite and a destination (where to go with hostage).
I want to use a spawn script which needs a marker in the middle of both spots
How do I get the half distance between both start (crashsite) and destination (safehouse) and how do I get a marker on that spot...?

Goal is to spawn a bunch of enemies at half the walking track, from where ever the crashsite is to the destination...

Share this post


Link to post
Share on other sites

I'm going to assume here that the crashsite and destination are markers,

_crashPos = getMarkerPos "crashSiteMarker";
_destination = getMarkerPos "destinationMarker";

_dir = [_crashPos,_destination] call BIS_fnc_relativeDirTo;

_enemySpawnPosition = [_crashPos,((_crashPos distance _destination / 2)),_dir] call BIS_fnc_relPos;
_spawnMarker = createMarker ["enemySpawnMarker",_enemySpawnPosition];

Share this post


Link to post
Share on other sites

Hello. How to activate a trigger based on distance, for example:
(Player distance object) <5, so that it works with any player in Multi player?

Share this post


Link to post
Share on other sites

{_x distance object < 5} count allPlayers > 0

Share this post


Link to post
Share on other sites

Thank you. It works perfectly

Share this post


Link to post
Share on other sites

Just one more question, let's say the trigger triggered when the player came close to the hostage, the same was released, how to make the refem unite to this player? Sorry for my ignorance, but in SP everything is easier ...

Share this post


Link to post
Share on other sites
54 minutes ago, Dinei Devos said:

refem unite to this player

What do you mean by this?

Make the unit join the player?

 

Cheers

Share this post


Link to post
Share on other sites
14 minutes ago, Grumpy Old Man said:

O que você quer dizer com isso?

Fazer a unidade juntar o jogador?

 

Felicidades

In Multi player
Trigger in condition:
{_x distance hostage <5} count allPlayers> 0
On activation:
????? hostage to join the player group

Share this post


Link to post
Share on other sites

Condition:

 

{if (_x distance hostage < 5) exitWith {missionNamespace setVariable ["executingPlayer",_x]; true;}; false;} count allPlayers > 0

 

OnAct:


tempVar = missionNamespace getVariable ["executingPlayer",nil]; if (!isNil "tempVar") then {[hostage] join (group tempVar)}; tempVar = nil; missionNamespace setVariable ["executingPlayer",nil];

 

This may be a little messy and there may be a better way of doing it, but I'm doing this quickly from my phone, so if it doesn't work or there is a better way hopefully someone else can help :).

Edited by jshock
Fixed join command usage (been a while since I've used it).

Share this post


Link to post
Share on other sites
2 hours ago, Dinei Devos said:

In Multi player
Trigger in condition:
{_x distance hostage <5} count allPlayers> 0
On activation:
????? hostage to join the player group

Ah allright.

So trigger condition:

{_x distance hostage <5} count allPlayers> 0

On Activation:

[Hostage] joinSilent group (allplayers select {_x distance hostage < 5 AND alive _x} select 0);
deleteVehicle thisTrigger;

 

Cheers

  • Like 1

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

×