Jump to content

Recommended Posts

Hello everyone, i need some help with my scripts.

 

Is it possible to use instead of !isPlayer something like !isWest and count everything else?

waitUntil {sleep 5; {!isPlayer _x} count allUnits <= 2;};

 

And same with my deletescript, is there a way to delete everything except West units?

{if (!isPlayer _x) then {deleteVehicle _x}} forEach allunits;

 

And my last question, Is it possible to remoteexec a script only for those players that are near a specific marker? Like teleporting them back to base.

Share this post


Link to post
Share on other sites

waitUntil {sleep 5; count allUnits - (west countSide allUnits) <= 2};

 

{deleteVehicle _x} forEach (allUnits select {side group _x != west});

  • Like 2

Share this post


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

Is it possible to remoteexec a script only for those players that are near a specific marker? Like teleporting them back to base.

Yes.

//Find players: assumes variables _marker and _distance has been defined
private _selectedPlayers = allPlayers select {_x distance2D markerPos _marker < _distance};

//Remote execution: assumes the function "fnc_someFunc" is defined elsewhere, preferably using the A3 Functions Library.
["someParameters"] remoteExec ["fnc_someFunc", _selectedPlayers];

//fnc_someFunc could look like this (note this is an inappropiate definition, use the A3 Functions Library's CfgFunctions to define it properly)
fnc_someFunc = {
	player setPos markerPos "baseMarker"; 
};

Note that if you're only teleporting players (like in the above example) you don't need remoteExec, setPos is plenty enough since it's an AG EG command (Argument Global, Effect Global).

private _selectedPlayers = allPlayers select {_x distance2D markerPos _marker < _distance};
{
	_x setPos markerPos "baseMarker";
} forEach _selectedPlayers;

 

  • Like 2

Share this post


Link to post
Share on other sites

I have a question about this code below @pierremgi

// Does it matter if it's a _x or _i etc in the code below??

private ["_pos"];

for "_x" from 1 to 5 do {

_pos = [_markerpos, 0, _markerSize, 5, 0, 0.4, 0, [],_markerpos] call BIS_fnc_findSafePos;

private ["_grp01","_unit"];

_grp01 = grpNull; <----- Is this one necessary when spawning units in this way? What does it to the group?

_grp01 = createGroup [east, true];
_unit = _grp01 createUnit [selectRandom ["uns_men_VC_mainforce_RF1","uns_men_VC_mainforce_68_MGS","uns_men_VC_mainforce_nco"], _pos, [], 200, "FORM"];

_grp01 enableDynamicSimulation true;
};

 

Share this post


Link to post
Share on other sites

_x or _i here, is the local variable for the from to loop. You can name it as you want... but it's a good habit to avoid _x often used by engine in forEach loops. You have plenty of possibilities, not limited to one letter.

_grp01 = grpNull has no interest here if you overwrite it, just after, with a created group.

Share this post


Link to post
Share on other sites

About the teleport command, i use this code below in a addAction from a object ingame. Is there a better way to do this?

call{this addAction ["<t color ='#ffcc00'>Teleport to Outpost</t>", Robust_fnc_Teleport,[],1,true,true,"","_this distance _target <5"];}; 

My fnc looks like this

private _unit = _this select 1;

titleText ["Teleporting", "BLACK OUT"];
sleep 3;
titleText ["", "BLACK FADED"];

_unit setpos getmarkerpos "respawn_west1";

sleep 2;
titleText ["", "BLACK IN"];

"dynamicBlur" ppEffectEnable true;   
"dynamicBlur" ppEffectAdjust [6];   
"dynamicBlur" ppEffectCommit 0;     
"dynamicBlur" ppEffectAdjust [0.0];  
"dynamicBlur" ppEffectCommit 5;

playSound "tele";

 

Share this post


Link to post
Share on other sites

@Robustcolor,

Quote

Is there a better way to do this?


If it does what you want then I think you got it!

You may want to consider: get/setposATL in case you want to use the function to tele above the ground (ex. second level of a building).

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

If i need to add a random number to my distance check, is round (random) a good command to use to get results like 260,270,280?

waitUntil {sleep 5; allPlayers findIf {(_x distance2d _markerpos) < (250 + round (random 50)) && (ASLToAGL getPosASL _x)#2 < 2} > -1};

Also, is it possible to add an extra check command in this line to check if the player is to close to the _markerpos? So it won't execute if your 50meters or closer.

Share this post


Link to post
Share on other sites

It's a waste of resource. There is no added value to round some randomized offset.

No added value also: (ASLToAGL getPosASL _x)#2 < 2 . you can use getPos except in specific case you paradrop/land players on buildings.

  • Like 1

Share this post


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

It's a waste of resource. There is no added value to round some randomized offset.

No added value also: (ASLToAGL getPosASL _x)#2 < 2 . you can use getPos except in specific case you paradrop/land players on buildings.

Thanks Pierre, i'm using the asltoagl to exclude players if in air. If you have a suggestion could you type the code?

Share this post


Link to post
Share on other sites
On 11/5/2019 at 12:23 AM, pierremgi said:

No. It's ok in fact. No impact on performance. My bad.

This code you helped me with gives a syntax error with (ASLToAGL getPosASL _x)#2 and a ingame generic error.

waitUntil {sleep 5; allPlayers findIf {(_x distance2d _markerpos) < (250 + round (random 50)) && (ASLToAGL getPosASL _x)#2 < 2} > -1};

 

Share this post


Link to post
Share on other sites

Should work. verify _markerPos is defined and allPlayers returns at least one player

You can try:

waitUntil {sleep 5; count allPlayers >0 && { allPlayers findIf {(_x distance2d _markerpos) < (250 + round (random 50)) && (ASLToAGL getPosASL _x)#2 < 2} > -1 } };

  • Like 1

Share this post


Link to post
Share on other sites

Is it possible to define positions in an array? All these attempts don't work.

Positions = [1009.34,4490.69,0.0197248];

Positions = [[1009.34,4490.69,0.0197248]];

Positions = ["[1009.34,4490.69,0.0197248]"];

Positions = [["1009.34,4490.69,0.0197248"]];

 

Share this post


Link to post
Share on other sites
12 hours ago, pierremgi said:

2nd one: Positions = [[1009.34,4490.69,0.0197248]]; 

Does not work to fetch the positions from array. I have tried getpos, position, setposition getpos _x.

getmarkerPos only worked if it is placed Markers.
 

{
_unit = _group createUnit [selectRandom Stationarymgs,[0,0,0],[],0,"NONE"];

_unit setposASL getPosASL _x;
} forEach Positions;

 

Share this post


Link to post
Share on other sites

Instead of asking for fragments of codes, then doubting on the answer, you should apply the very first rule: Read BIKI, mind for syntax/returned value of commands.

  • Like 1

Share this post


Link to post
Share on other sites
Positions = [[1009.34,4490.69,0.0197248]]; 
{
_unit = _group createUnit [selectRandom Stationarymgs,[0,0,0],[],0,"NONE"];

_unit setpos _x;
} forEach Positions;

 

Share this post


Link to post
Share on other sites

Could someone be so kind here to explain abit using direct private variables vs assigning the variables from private array in context like below.

I've read here in Code optimisation that it does matter how you use the private variables to increase performance when using for do loops.

params ["_pos"];

private ["_pos","_grp01"];

for "_i" from 1 to 10 do{

_grp01 = createGroup [west,true];

_unit = _grp01 createUnit [selectRandom Stationarymgs,_pos,[],100,"NONE"];

};

vs

params ["_pos"];

private ["_pos"];

for "_i" from 1 to 10 do{

private _grp01 = createGroup [west,true];

private _unit = _grp01 createUnit [selectRandom Stationarymgs,_pos,[],100,"NONE"];

};

Can i assign with array private ["_pos","_grp01"]; outside the for do loop but what would happen with variable _grp01 if i fetch the same value each loop? Maybe i need a private _unit too?

Share this post


Link to post
Share on other sites

Read again params (even notes). You don't need to double params with private.

 

In a for  do loop, you are in a inner scope level. You can create your group, your unit, add waypoint... no matter the code, you variables are defined on each loop, and you don't want to matter what they can be at the exit. In other word, no matter the last value.

So, here is the general scheme:

 

[<local parameters from previous lines, say:>  _markers, _unitsTypes] spawn {

     <main scope here for this spawned code>

    params ["_mks","_units"];  // _markers is now _mks,  and _unitsTypes is now _units in this main scope or inner ones (loops for do , forEach...)

              _markers and _unitsTypes are no more valid local name here as you just change them. You could keep the same names if you wish.

   

    for "_i" from 1 to 10 do   // _i is also a variable working inside the for do loop (see _forEachIndex in forEach loop)

        <primary inner scope here:  _mks and _units work, _markers and _unitsType DON'T, _grp01 doesn't exist at first loop (_i ==1)>

        private _grp01 = createGroup [west,true];  // _grp01 is defined now for this scope and inner ones if any but the value will change every loop and that doesn't matter

        private _unit = _grp01 createUnit [selectRandom _units, _pos,[],100,"NONE"];  // _pos is undefined here! ERROR

        you can replace _pos by a global variable like my_positions, or by something defined like selectRandom _mks where _mks is the array of markers' positions.


        for "_j" from 0 to 3 do // you could use _i also here because this local variable is for inner loop only, but it's more readable to use another name.

            <secondary inner scope here: the previous local variable from primary or main scope stay defined>

            private _wp = _grp01 addWaypoint [selectRandom _mks,0];   // _wp will change every present loop, and that doesn't matter
            _wp setWaypointType "MOVE";.......

        }; // end of secondary loop _wp is no more defined, neither _j (or whatever you wrote inside " " loop)


    }; // end of primary loop  _grp01 and _unit will not be anymore defined beyond this point

 

};  // end of spawn: _mks and _units will not be defined anymore after that, even if the sqf continues.  

 

 

Note: if you replace params ["_mks","_units"];  by params ["_mks","_units","_pos"];

on my example, or even:

params ["_mks","_units"]; 

private "_pos";

You just "prepare" the engine to stack and call a variable named _pos. But there is no value so far. You need to do something with that like done with _grp01 or _unit.

The reason why params is far complex, and is able to pass a default variable in case you missed that or entered a bad type of variable

params ["_mks","_units",["_pos",[0,0,0]]];    //will not return error anymore but you'll spawn at [0,0,0].

 

 

  • Like 1

Share this post


Link to post
Share on other sites

I have a problem when using my teleport function, it's not working at all. Players use a addAction from an object ingame to get teleported. These codes below is what i have tried to use inside the editor.

call{this addAction [ "<t color ='#ffcc00'>Teleport to Outpost</t>", {[] remoteExec["Teleport",1];},[],1,true,true,"","_this distance _target <5"];}; 
call{this addAction ["<t color ='#ffcc00'>Teleport to Outpost</t>", Teleport,[],1,true,true,"","_this distance _target <5"];};  

My teleport function

Teleport = {

private _unit = _this select 1;

_unit setpos getmarkerpos "respawn_west1";

"dynamicBlur" ppEffectEnable true;   
"dynamicBlur" ppEffectAdjust [6];   
"dynamicBlur" ppEffectCommit 0;     
"dynamicBlur" ppEffectAdjust [0.0];  
"dynamicBlur" ppEffectCommit 5;

};

 

Share this post


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

My teleport function

 

Hello there Robustcolor !

try :

call{
	this addAction 
	[
		"<t color ='#ffcc00'>Teleport to Outpost</t>", 
		{
			params ["_target", "_caller", "_actionId", "_arguments"];
			
			_caller setPos (markerPos "respawn_west");
			
			"dynamicBlur" ppEffectEnable true;   
			"dynamicBlur" ppEffectAdjust [6];   
			"dynamicBlur" ppEffectCommit 0;     
			"dynamicBlur" ppEffectAdjust [0.0];  
			"dynamicBlur" ppEffectCommit 5;

		},
		[],
		1.5, 
		true, 
		true, 
		"",
		"true",
		50,
		false,
		"",
		""
	];
};

 

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

×