Jump to content
Robustcolor

Spawn units when player near markers

Recommended Posts

lol, missed reading that 😄

3 hours ago, Dedmen said:

private _activeMarkers = _markers select { private _markerPos = getmarkerpos _x; //Get all players inside circle of _markerdist radius around _markerPos //_markerdist might need to be halfed here, didn't use inAreaArray before private _playersInArea = allPlayers inAreaArray [_markerPos, _markerdist, _markerdist]; count _playersInArea > 0 };

Thanks @Dedmen

Share this post


Link to post
Share on other sites
3 hours ago, Dedmen said:

Get all markers with players in <_markerdist distance to it.


private _activeMarkers = _markers select {
    private _markerPos = getmarkerpos _x;

    //Get all players inside circle of _markerdist radius around _markerPos
    //_markerdist might need to be halfed here, didn't use inAreaArray before
    private _playersInArea = allPlayers inAreaArray [_markerPos, _markerdist, _markerdist];
    count _playersInArea > 0
};

 

 

Thank you, exactly what I needed! 

Share this post


Link to post
Share on other sites

Is it possible to make a "allPlayers" check instead of the "player" with this code? Like Allplayers findif etc.

_distanceMarkers = _markers apply {[player distance getmarkerpos _x, _x]};

 

Share this post


Link to post
Share on other sites
17 hours ago, Robustcolor said:

Is it possible to make a "allPlayers" check instead of the "player" with this code? Like Allplayers findif etc.


_distanceMarkers = _markers apply {[player distance getmarkerpos _x, _x]};

 

I don't quite know what you want?

_distanceMarkers = [];
{
    private _marker = _x;
    _distanceMarkers append (allPlayers apply {[_x distance getmarkerpos _marker, _marker, _x]})
} forEach _markers;

distanceMarkers now contains distances for all players, and all markers.

Share this post


Link to post
Share on other sites
1 hour ago, Dedmen said:

I don't quite know what you want?


_distanceMarkers = [];
{
    private _marker = _x;
    _distanceMarkers append (allPlayers apply {[_x distance getmarkerpos _marker, _marker, _x]})
} forEach _markers;

distanceMarkers now contains distances for all players, and all markers.

Thank you @Dedmen

 

My script looks like this now.

_markers =  ["A1","A2","A3","A4","A5","A6","A7","A8","A9"];

_markerdist = 400;

while {true} do {

_distanceMarkers = [];
{
private _marker = _x;
_distanceMarkers append (allPlayers apply {[_x distance getmarkerpos _marker, _marker, _x]})
} forEach _markers;

_distanceMarkers sort true;

_marker = (_distanceMarkers select 0) select 1;

_markerPosition = (_distanceMarkers select 0) select 0;

if (_markerPosition < _markerdist) then {

[getmarkerpos _marker] call Wise_fnc_Ambushai;   

waitUntil {sleep 5; allPlayers findIf {(_x distance2d getmarkerpos _marker) < 500} ==-1};

};

sleep 5;

};

 

Share this post


Link to post
Share on other sites
11 minutes ago, GEORGE FLOROS GR said:

 

Just check this a little bit , because , this way it will activate even for the dead players since

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

Would you recommend doing something like this?

 

_ap = allPlayers;

 

_Aliveplayers = _ap select {alive _x};

 

Would it work?

Share this post


Link to post
Share on other sites
_allPlayers = (allPlayers - entities "HeadlessClient_F") select {alive _x};

this can be also with different ways.

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, GEORGE FLOROS GR said:

_allPlayers = (allPlayers - entities "HeadlessClient_F") select {alive _x};

this can be also with different ways.

Thank you @GEORGE FLOROS GR.

 

Since i'm using this waitUntil {sleep 5; allPlayers findIf in few more scripts, maybe i should be using this that i found in one of the bohemias mission.

onPlayerRespawn.sqf

_null = (_this select 1) execVM "Scripts\BuryCorpse.sqf";
BuryCorpse.sqf

_body = _this;

waitUntil {sleep 1; {(_x distance _body) < 25} count allPlayers == 0};

deleteVehicle _body;

That should do it, removing the dead players near those allPlayers findIf positions.

I'm rarely using execVM so gonna make it a function instead since it will be activating alot, or if it would work just putting the code inside the onPlayerRespawn.sqf.

  • Thanks 1

Share this post


Link to post
Share on other sites
44 minutes ago, Robustcolor said:

Since i'm using this waitUntil {sleep 5; allPlayers findIf in few more scripts, maybe i should be using this that i found in one of the bohemias mission.

No you shouldn't.

 

44 minutes ago, Robustcolor said:

_null =

This is useless and makes no sense.

 

44 minutes ago, Robustcolor said:

{(_x distance _body) < 25} count allPlayers == 0

this always iterates through all players, even if the condition is already true for the first player thats checked. findIf exists at the first hit, thus being way more efficient.

  • Like 1

Share this post


Link to post
Share on other sites
14 hours ago, Robustcolor said:

onPlayerRespawn.sqf

 

Try :

( and maybe add some sleep also )

initplayerlocal.sqf

player addEventHandler ["Killed", {
	params ["_unit", "_killer", "_instigator", "_useEffects"];
	_unit  = _this select 0;
    _pos = getPosATL _unit;
    _holder = nearestObjects [_pos, ["WeaponHolder", "groundWeaponHolder", "WeaponHolderSimulated"], 2];
    {
        deleteVehicle _x;
    }forEach _holder + [_unit];
}];

 

Share this post


Link to post
Share on other sites

This work great @Dedmen I just have one question. Is it possible to make it exclude players in air so it won't activate.

private _markers =  ["A1","A2","A3","A4","A5","A6","A7","A8","A9"];

private _markerdist = 400;

_allPlayers = (allPlayers - entities "HeadlessClient_F") select {alive _x};

while {true} do {

_distanceMarkers = [];
{
private _marker = _x;
_distanceMarkers append (_allPlayers apply {[_x distance getmarkerpos _marker, _marker, _x]})
} forEach _markers;

_distanceMarkers sort true;

_marker = (_distanceMarkers select 0) select 1;

_markerPosition = (_distanceMarkers select 0) select 0;

if (_markerPosition < _markerdist) then {

[getmarkerpos _marker] spawn Ambushai;   

waitUntil {sleep 5; _allPlayers findIf {(_x distance2d getmarkerpos _marker) < 500} ==-1};

};

sleep 5;

};

 

Share this post


Link to post
Share on other sites
15 minutes ago, Robustcolor said:

Is it possible to make it exclude players in air so it won't activate.

_allPlayers = (allPlayers - entities "HeadlessClient_F") select {alive _x && (getPos _x select 2 < 20)};

 

only players below height of 20m

Share this post


Link to post
Share on other sites
18 minutes ago, Dedmen said:

_allPlayers = (allPlayers - entities "HeadlessClient_F") select {alive _x && (getPos _x select 2 < 20)};

 

only players below height of 20m

Did not work, it still activated fnc if in air and above 100meters.

Share this post


Link to post
Share on other sites
39 minutes ago, Robustcolor said:

Did not work, it still activated fnc if in air and above 100meters.

Ah yeah. I only did that check once, outside of the while loop. Ofc thats not gonna work. I'm too tired to think I shouldn't post here.

 

As KK said..
But I wonder whether this works.. replacing the _allPlayers variable like this, but not modifying the original (the private is important)

while {true} do {
private _allPlayers = _allPlayers unitsBelowHeight 20;

 

  • Like 2

Share this post


Link to post
Share on other sites

For anyone using this script i added this code at the top, makes it only check for alive players and below height 20.

 

The isEqualTo stops the script from running if no players is found. So no errors.

private _markers =  ["A1","A2","A3","A4","A5","A6","A7","A8","A9","A10","A11","A12","A13","A14","A15"];

private _markerdist = 350;

while {true} do {

private _allPlayers = (allPlayers - alldeadmen unitsBelowHeight 20);

if !(_allPlayers isEqualTo []) then {

 

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

×