Jump to content
SkweeZ

[HELP] Create marker with RemoteExec

Recommended Posts

Hello.

I have a issue with a parameters of remoteExec.

I make a insurgency style mission and i want to run a script on a intel to create a marker randomly positioned around the cache.

 

This my script for Intel drop & Add Action :

 

0 = [] spawn {
  if (isServer) then {
    while {true} do {
      {
        _unit = _x;
        if !(_unit getVariable ["hasIntelEVH",false]) then {
          _unit addEventHandler ["killed",{
            params ["_unit"];
            if (random 100 < ("droprate" call BIS_fnc_getParamValue) ) then {
              _suitcase = "Land_Suitcase_F" createVehicle (getpos _unit);
              [_suitcase,["Pick up INTEL", {params ["_suitcase","_caller","_id"]; "scripts\addMarker.sqf" remoteExec ["execvm",-2,true]; [_suitcase,_id] remoteExec ["removeAction"]; deleteVehicle _suitcase } ] ]  remoteExec ["addAction",0,_suitcase];
            };
          }];
          _unit setVariable ["hasIntelEVH",true];
        };
      } forEach (allUnits select {side _x == WEST});
      sleep 10;  
    };
  };
};

When i pick up INTEL, the script runs well. But in my server, a marker is created for each client connected.

When I am alone, it's ok, only one marker is created. But when we are 2, with only one intel, two markers (each for 1 player) is created.

 

What is the solution ?

 

Thank you.

PS : sorry for my bad english.

  • Like 1

Share this post


Link to post
Share on other sites

i assume this is a joke?

constantly add eventhandler for blufor units than remotexexec things in remotexec code and this all again remoteexec.

Never saw something that fantastic.

 

 

  • Haha 3

Share this post


Link to post
Share on other sites

Hahaha, I never said, it was a good code ...

I don't have much experience, just try some things. Is there another way to do it ?

 

  • Like 1

Share this post


Link to post
Share on other sites

You're not so far. Just use mission EH instead of a loop for adding an killed EH on spawned units. And you can manage that from server, in initserver.sqf:


addMissionEventHandler ["EntityKilled", {

   params ["_unit"];
   if (random 100 < ("droprate" call BIS_fnc_getParamValue) && _unit isKindOf "CAManBase" && side group _unit == WEST ) then {

      _suitcase = "Land_Suitcase_F" createVehicle (getpos _unit);

      [_suitcase,["Pick up INTEL", {

          params ["_suitcase","_caller","_id"];

          [] execVM "scripts\addMarker.sqf";

          [_suitcase,_id] remoteExec ["removeAction"];

         deleteVehicle _suitcase

      } ] ] remoteExec ["addAction",0,_suitcase];

   };

}];

 

Here, you're using a randomized value to spawn a suitcase or not, all of that on server. No problem to add an action to this spawned suitcase, but, yes, you need to remoteExec it everywhere. If not, it will be shown on hosted server only. And yes, you have to remoteExec the removeAction also because the script runs locally. But your addMarker.sqf doesn't need to be remote executed if markers are global.

Depending on what you intend to do with markers.

 

You can use an alternate solution, adding this MEH everywhere (in init.sqf) but you need to roll the dice on server only for your randomization, then "public" Variable the result (here with 3rd param of setVariable):

 

So, in init.sqf:

addMissionEventHandler ["EntityKilled", {

   params ["_unit"];
   if (isServer) then {_unit setVariable ["DICE",random 100,true]};
   _unit spawn {
     params ["_unit"];

     waitUntil {!isNil {_unit getVariable "DICE"}};
   if ((_unit getVariable "DICE") < ("droprate" call BIS_fnc_getParamValue) && _unit isKindOf "CAManBase" && side group _unit == WEST ) then {

      _suitcase = "Land_Suitcase_F" createVehicle (getpos _unit);

      _suitcase addAction ["Pick up INTEL", {

          params ["_suitcase","_caller","_id"];

          [] execVM "scripts\addMarker.sqf";

          [_suitcase,_id] remoteExec ["removeAction"];

         deleteVehicle _suitcase;

      } ] ;

    };
  };

}];

  • Like 1

Share this post


Link to post
Share on other sites

Hello, Davidoss gave me some solutions & modifications of scripts.

There it is :

 

I spawn unit with EOS, so there is a modification in it (fnc_spawnGroups.sqf) :

if (!isServer) exitWith {};
// SINGLE INFANTRY GROUP
private ["_grp","_unit","_pool","_pos","_faction"];

_pos=(_this select 0);
_grpSize=(_this select 1);
_faction=(_this select 2);
_side=(_this select 3);

_grpMin=_grpSize select 0;
_grpMax=_grpSize select 1;
_d=_grpMax-_grpMin;				
_r=floor(random _d);							
_grpSize=_r+_grpMin;
				
	if (surfaceiswater _pos) then {_pool=[_faction,1] call eos_fnc_getunitpool;}else{_pool=[_faction,0] call eos_fnc_getunitpool;};
	
	_grp=createGroup _side;
			
for "_x" from 1 to _grpSize do {					
		_unitType=_pool select (floor(random(count _pool)));
		_unit = _grp createUnit [_unitType, _pos, [], 6, "FORM"];*/
    0 = [_unit] spawn fnc_addIntelDrop; //add this line
};
_grp
*/

then in init.sqf :

//init.sqf
fnc_addIntelDrop = compileFinal preprocessFileLineNumbers "path to your script.sqf"; //script 

finally :

//script
params [["_unit",objNull,[objNull]]];

if (isNull _unit) exitWith {};
_unit addEventHandler ["Killed",{

	params ["_victim","",""];
	private _intelchance = "droprate" call BIS_fnc_getParamValue;
	if (random 1 < (_intelchance / 100) then {				
		private _intelObjects = ["Land_Suitcase_F"];//add more if you like separated with coma
		private _intel = (selectRandom _intelObjects) createVehicle (_victim modelToWorld [0,1,0]);
  
		0 = [_intel,
			[
				"<t>Take Intel</t><img size='1' image='\a3\ui_f\data\IGUI\Cfg\Actions\take_ca'/>",
				{
					params ["_target", "", "", ""];
					deleteVehicle _target;
					0 = [] execVm "scripts\addMarker.sqf";
				},nil,0,true,true,"","true",3,false,"",""
			]
		] remoteExec ["addAction", [0,-2] select isDedicated,_intel]; 
	};		
}];

 

But i have a problem again, markers are not created on my Dedicated server, i don't know where is the problem.

Share this post


Link to post
Share on other sites
if (PARAMS_Cache ==2) then {
if ((alive cache_1) && (alive cache_2)) then
{
_target = [cache_1,cache_2] call BIS_fnc_selectRandom;
_dist = floor (random 100) +100;
_dir = random 360;
_pos = getpos _target;
_position = [(_pos select 0) + (sin _dir) * _dist, (_pos select 1) + (cos _dir) * _dist, 0]; 
_randomnumber = floor random 100000;
_name = "Markername" + (str _randomnumber);
_marker = createMarker [_name, _position];
_marker setMarkerShape "ICON";
_marker setMarkerType "hd_unknown";
_marker setMarkerColor "ColorBlack";
_text = format ["Cache - %1m ",_dist];
_name setMarkerText _text;
}
else
{
if ((alive cache_1)) then
{
_target = cache_1;
_dist = floor (random 100) +100;
_dir = random 360;
_pos = getpos _target;
_position = [(_pos select 0) + (sin _dir) * _dist, (_pos select 1) + (cos _dir) * _dist, 0]; 
_randomnumber = floor random 100000;
_name = "Markername" + (str _randomnumber);
_marker = createMarker [_name, _position];
_marker setMarkerShape "ICON";
_marker setMarkerType "hd_unknown";
_marker setMarkerColor "ColorBlack";
_text = format ["Cache - %1m ",_dist];
_name setMarkerText _text;
}
else{
if ((alive cache_2)) then
{
_target = cache_2;
_dist = floor (random 100) +100;
_dir = random 360;
_pos = getpos _target;
_position = [(_pos select 0) + (sin _dir) * _dist, (_pos select 1) + (cos _dir) * _dist, 0]; 
_randomnumber = floor random 100000;
_name = "Markername" + (str _randomnumber);
_marker = createMarker [_name, _position];
_marker setMarkerShape "ICON";
_marker setMarkerType "hd_unknown";
_marker setMarkerColor "ColorBlack";
_text = format ["Cache - %1m ",_dist];
_name setMarkerText _text;
}
}
}
}
else
{
if ((alive cache_1)) then
{
_target = cache_1;
_dist = floor (random 100) +100;
_dir = random 360;
_pos = getpos _target;
_position = [(_pos select 0) + (sin _dir) * _dist, (_pos select 1) + (cos _dir) * _dist, 0]; 
_randomnumber = floor random 100000;
_name = "Markername" + (str _randomnumber);
_marker = createMarker [_name, _position];
_marker setMarkerShape "ICON";
_marker setMarkerType "hd_unknown";
_marker setMarkerColor "ColorBlack";
_text = format ["Cache - %1m ",_dist];
_name setMarkerText _text;
}
};

here we go, it's poor scripting btw

Share this post


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

Hello, Davidoss gave me some solutions & modifications of scripts.

But i have a problem again, markers are not created on my Dedicated server, i don't know where is the problem.

 

Without me this time. Thanks for your "consideration".

  • Like 1
  • Confused 1

Share this post


Link to post
Share on other sites

well there are only one possibility why this is not working on dedi:

one or all of fallowing variables are not known by clients:

 

PARAMS_Cache is nil  or its value is not equal to 2

cache_1 is nil or not alive

cache_2 is nill or not alive

 

this should give  rpt error on client machine who pickup intel

check this  out and you will find the problem

 

Possible solutions if this is true:

1.remoteexec  marker creations to server

2.public variables everywhere

3.rewrite script addMarker.sqf

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

×