Jump to content
Sign in to follow this  
beako

Trying to execute setVectorUp locally

Recommended Posts

Hi All, 

 

I'm spawning objects on top of buildings while trying to orient  "temp_veh" using setVectorUp to the buildings slanted surface, but with no luck.

 

As per setVectorUp, "Set object's up vector. Direction vector will remain unchanged. Default object's vectorUp is [0,0,1]. In Multiplayer, setVectorUp must be executed on the machine where the object it applied to is local."

 

I've tried to run this script from [[_stuff], "BEAKS_fnc_ObjectPositionAndDirectionD", player] call BIS_fnc_MP; thinking this would execute it locally on the player's machine but it is still executed on the server?

 

fn_ObjectPositionAndDirectionD

["move_ghost", "onEachFrame", {
  
...more code

    _pos = screenToWorld [0.5,0.5];// land position 
		_topPos = [_pos select 0, _pos select 1, 100];
		_intersections = lineIntersectsSurfaces [_topPos,_pos, temp_veh, player, true, 1];
		_intersectPosASL  = (_intersections select 0) select 0;
		_surfaceNormal = (_intersections select 0) select 1;
		_building = (_intersections select 0) select 3; 
		_posDrop = _intersectPosASL;
		temp_veh setPosASL [_intersectPosASL select 0, _intersectPosASL select 1, _intersectPosASL select 2]; // this part works
		temp_veh setVectorUp _surfaceNormal;  // this line DOES NOT work

	hint format ["ObjectPositionAndRotation \n\n  _intersections: %1 \n\n _intersectPosASL: %2 \n\n _surfaceNormal: %3 \n\n _building: %4", _intersections, _intersectPosASL, _surfaceNormal, _building];

... more code

}] call BIS_fnc_addStackedEventHandler; 

Any tips you can provide would be appreciated.

Thanks

Share this post


Link to post
Share on other sites

I've tried to run this script from [[_stuff], "BEAKS_fnc_ObjectPositionAndDirectionD", player] call BIS_fnc_MP; thinking this would execute it locally on the player's machine but it is still executed on the server?

Maybe you should execute that "on the machine where the object it applies to is local", like this:

[[_stuff], "BEAKS_fnc_ObjectPositionAndDirectionD", temp_veh] call BIS_fnc_MP;
Just a suggestion,

 

Nikander

Share this post


Link to post
Share on other sites

One thing you definitely don't want to do is to remote execute code each frame. I suggest you change locality of temp_veh to the PC where oneachframe loop runs. If this is not possible then move execution to the locality of the temp_veh.

Share this post


Link to post
Share on other sites

Thanks above for the tips,

 

I tried using remoteExecCall  with target "_veh" as it is local, but is does not execute.

 

If I replace  "_veh" with player  [_holder,_veh, _vehCost,_vehType] remoteExecCall ["BEAKS_fnc_ObjectPosDirBankPitch", player]; it works but when I test fn_ObjectPosDirBankPitch.sqf with if if (!isServer) then {...}; it won't execute so player is not local.

 

fn_ObjectPositionAndDirectionD

// init Ghost vehicle   
_pos =  screenToWorld [0.5,0.5];// land position  
_center = createCenter sideLogic; 
_group = createGroup _center; 

_holder = _group createUnit ["LOGIC",[(_pos select 0), (_pos select 1), 0.5], [],0, "CAN_COLLIDE"];
_veh = _vehType createVehicleLocal [(_pos select 0), (_pos select 1),  0.5];
_veh allowDamage false;	
_veh attachTo [_holder]; 	// to avoid collisions use attachTo 

[_holder,_veh, _vehCost,_vehType] remoteExecCall ["BEAKS_fnc_ObjectPosDirBankPitch", _veh];

fn_ObjectPosDirBankPitch.sqf

if (!isServer) then {

	// Get variables from vehicle selected
	params ["_holder","_veh","_vehCost","_vehType"];
	
	HintC format ["ObjectPosDirBankPitch \n\n local _veh: %1 \n\n local _holder: %2", local _veh, local _holder];


	// to rotate vehicle use mouse scroll wheel to terminate and spawn press backspace button. 
	disableSerialization; 
	
	dir1 = 0;// may need changing to setvariable 
	missionnamespace setvariable ["place",false]; 
	missionnamespace setvariable ['cancel',false]; 
	// setup mouse/keyboard buttons 
	waituntil {!(IsNull (findDisplay 46))}; 
	disableSerialization; 
	_mouseZ  = (findDisplay 46) displayAddEventHandler ["MouseZChanged","if ((_this select 1) <0) then {dir1=dir1+(abs (_this select 1)*2)} else {dir1=dir1-(abs (_this select 1)*2)}"];// mouse scroll 
	 _mouseM  = (findDisplay 46) displayAddEventHandler ["MouseButtonDown", "if (_this select 1 == 1) then {missionnamespace setvariable ['place',true]};"];// left mouse button down
	 _backspace  = (findDisplay 46) displayAddEventHandler ["KeyDown", "if (_this select 1 == 14) then {missionnamespace setvariable ['cancel',true]}"];

	// line that intersect building roofs from 100m above
	_pos = screenToWorld [0.5,0.5];
	_topPos = [];
	_intersectPosASL = [];
	_intersections = [];
	_surfaceNormal = [];
	_building = objNull;
	_buildingArray = [];
	_topPos = [_pos select 0, _pos select 1, 100];
	_intersections = lineIntersectsSurfaces [_topPos,_pos, player, objNull, true, 1];
	_intersectPosASL = (_intersections select 0) select 0;
	_surfaceNormal = (_intersections select 0) select 1;
	_building = (_intersections select 0) select 3; 
				
	//for "_x" from 0 to 3 do {_veh setObjectTexture [_x, "#(rgb,8,8,3)color(0,0.5,0,1)"]};   // set texture colours   
	//_veh attachto [_holder]; 	// to avoid collisions use attachto 
	
	
	
	// Move Ghost this bit may need the oneachframe commands  
	temp_hol = _holder; 
	temp_veh = _veh; 
	player  disableCollisionWith _veh; 
	disabled = [];

	["move_ghost", "onEachFrame", {  
		_pos = screenToWorld [0.5,0.5];// land position 
		_topPos = [_pos select 0, _pos select 1, 100];
		_intersections = lineIntersectsSurfaces [_topPos,_pos, temp_veh, player, true, 1];
		_intersectPosASL  = (_intersections select 0) select 0;
		_surfaceNormal = (_intersections select 0) select 1;
		_building = (_intersections select 0) select 3; 
		_posDrop = _intersectPosASL;
		temp_veh setPosASL [_intersectPosASL select 0, _intersectPosASL select 1, _intersectPosASL select 2];
		temp_veh setVectorUp _surfaceNormal;

		//hint format ["ObjectPositionAndRotation \n\n  _intersections: %1 \n\n _intersectPosASL: %2 \n\n _surfaceNormal: %3 \n\n _building: %4", _intersections, _intersectPosASL, _surfaceNormal, _building];

		// DROP ASSETS IF IN RANGE 	[_box, _boxPos] call KK_fnc_setPosAGLS;
		if ((typeOf temp_veh == "B_Plane_CAS_01_F") or (typeOf temp_veh == "O_Plane_CAS_02_F") or (typeOf temp_veh == 	"B_MBT_01_arty_F") or (typeOf temp_veh == "O_MBT_02_arty_F")) then {
				if ((_pos distance player) > 500) then {
					// SET TEXTURE COLOUR FOR OUT OF RANGE   
					for "_x" from 0 to 3 do {temp_veh setObjectTexture [_x, "#(rgb,8,8,3)color(0.5,0,0,1)"]}; 
					hint "OUT OF RANGE \n CANNOT PLACE HERE";
					missionNamespace setVariable ["dropHere", FALSE];
					missionnamespace setvariable ["place",FALSE]; 
				} else {
					// SET TEXTURE COLOUR FOR IN RANGE  
					for "_x" from 0 to 3 do {temp_veh setObjectTexture [_x, "#(rgb,8,8,3)color(0,0.5,0,1)"]}; 
					hintSilent "Use mouse wheel to rotate object. \n Use right mouse button to select unit. \n Use backspace to cancel."; 
					missionNamespace setVariable ["dropHere", TRUE];
				}; 
			// ALL OTHER ASSETS
			} else {   
				if ((_pos distance player) > 50) then {
						// SET TEXTURE COLOUR FOR OUT OF RANGE   
						for "_x" from 0 to 3 do {temp_veh setObjectTexture [_x, "#(rgb,8,8,3)color(0.5,0,0,1)"]}; 
						hint "OUT OF RANGE \n CANNOT PLACE HERE";
						missionNamespace setVariable ["dropHere", FALSE];
						missionnamespace setvariable ["place",FALSE]; 
						//hint format ["temp_veh: %1 \n ""B_Plane_CAS_01_F"":%2",typeOf temp_veh, (typeOf temp_veh == "B_Plane_CAS_01_F")];
					} else {
						// SET TEXTURE COLOUR FOR IN RANGE  
						for "_x" from 0 to 3 do {temp_veh setObjectTexture [_x, "#(rgb,8,8,3)color(0,0.5,0,1)"]}; 
						//hintSilent "Use mouse wheel to rotate object. \n Use right mouse button to select unit. \n Use backspace to cancel."; 	
						missionNamespace setVariable ["dropHere", TRUE];
					}; 
			};	
				   //deactivate all mines in range of ghost vehicle
					{
							if ((_x distance temp_veh < 10) and (_x distance player > 2)) then {
								if !(_x in disabled)  then {
									disabled pushBack _x;
								};
								_x enableSimulation false;								
							} else { 
								if (_x distance player < 2) then {	// unless the player is nearby 
								_x enableSimulation true;
								};
							};
					} forEach allMines;

				   //temp_hol setpos _pos; 
				   temp_hol setpos [(_pos select 0), (_pos select 1), (_pos select 2) + 0.5];
				   temp_veh setDir (getdir player )+ dir1;

				   //temp_hol setVectorUp surfaceNormal position temp_hol; 
				   temp_hol setVectorUp surfaceNormal getPosATL temp_hol; 

	}] call BIS_fnc_addStackedEventHandler; 

	waituntil {missionnamespace getvariable ["dropHere",false] && missionnamespace getvariable ["place",false] or missionnamespace getvariable ["cancel",false]};
	_posDrop = getPosASL temp_veh;
	[temp_veh, _posDrop] call KK_fnc_setPosAGLS;

	["move_ghost", "onEachFrame"] call BIS_fnc_removeStackedEventHandler;// terminates oneachframe 


	player  disableCollisionWith _veh; 
	_vehDir = getDir _veh;
	//{_x setPosASL [0,0,0]} forEach [_veh, temp_veh, _holder];

	//reactivate mines back 
	//hint format ["reactivated disabled mines: %1", disabled];
	_disabledAPMinePositions = [];
	_disabledATMinePositions = [];
	{
		//_x enableSimulation TRUE;
		//GET THE POSITION forEach mine 
		if ((typeOf _x) == "APERSMine_Range_Ammo") then {
			_disabledAPMinePositions pushBack [(getPosATL _x) select 0, (getPosATL _x) select 1, 0];
		};
			if ((typeOf _x) == "ATMine_Range_Ammo") then {
			_disabledATMinePositions pushBack [(getPosATL _x) select 0, (getPosATL _x) select 1, 0];
		};
		deleteVehicle _x;	
	} forEach disabled;

	// REPLACE EACH POSITION WITH A MINE
	_mine = [];
	{
		//_disabledAPMinePositions set [2,0];
		_APmine = createMine ["APERSMine", _x, [], 0];
		//_ATmine = createMine ["ATMine", _x, [], 0];
		_mine pushBack _APmine;
	} forEach _disabledAPMinePositions;
	{
		//_disabledAPMinePositions set [2,0];
		_ATmine = createMine ["ATMine", _x, [], 0];
		_mine pushBack _ATmine;
	} forEach _disabledATMinePositions;

	{side player revealMine _x} forEach _mine;

	{deleteVehicle _x} forEach [_veh,temp_veh,_holder];
	//deleteVehicle _veh;// remove Ghost 
	//deleteVehicle temp_veh;// remove Ghost 
	//deleteVehicle _holder; 
	sleep 0.2; // allow time for removal of Ghost 

	// Spawn actual vehicle or  call another script and reactivate mines back 
	switch (true) do { 
		case   ((_vehType iskindof "car") or (_vehType iskindof "tank") and !(((_vehType == "B_MBT_01_arty_F") or (_vehType == "O_MBT_02_arty_F")))) : { if !(missionnamespace getvariable "cancel") then {{_x enableSimulation true} forEach disabled, [_posDrop, _vehDir,_vehType] spawn BEAKS_fnc_cargoPlane, [ _vehCost, "DNA_fnc_removeMoney", side player ] spawn BIS_fnc_MP};};
		case   (_vehType iskindof "StaticWeapon") : {if !(missionnamespace getvariable "cancel") then {{_x enableSimulation true} forEach disabled, [_posDrop, _vehDir,_vehType,0,_intersections] spawn BEAKS_fnc_cargoPlane,[ _vehCost, "DNA_fnc_removeMoney", side player ] spawn BIS_fnc_MP};};
		case   (_vehType iskindof "Man") : {if !(missionnamespace getvariable "cancel") then {{_x enableSimulation true} forEach disabled, [_posDrop, _vehDir,_vehType] spawn BEAKS_fnc_cargoPlane, [ _vehCost, "DNA_fnc_removeMoney", side player ] spawn BIS_fnc_MP};};

		case   ((_vehType == "B_Plane_CAS_01_F") or (_vehType == "O_Plane_CAS_02_F")) : {if !(missionnamespace getvariable "cancel") then {{_x enableSimulation true} forEach disabled, [_vehType, _vehDir, _posDrop, 2] spawn BEAKS_fnc_BCAS, [ _vehCost, "DNA_fnc_removeMoney", side player ] spawn BIS_fnc_MP};};
		case   ((_vehType == "B_MBT_01_arty_F") or (_vehType == "O_MBT_02_arty_F")) : {if !(missionnamespace getvariable "cancel") then {{_x enableSimulation true} forEach disabled, [_vehType, _posDrop, 2] spawn BEAKS_fnc_Artillery, [ _vehCost, "DNA_fnc_removeMoney", side player ] spawn BIS_fnc_MP};};
	}:

	//deleteVehicle _holder; 
	sleep 0.2; 
	missionnamespace setvariable ["place",true];// rest to allow respawn  
	sleep 0.2; 
	(finddisplay 46) displayRemoveAllEventHandlers "MouseZChanged";
	(finddisplay 46) displayRemoveAllEventHandlers "MouseButtonDown";   
	(finddisplay 46) displayRemoveAllEventHandlers "KeyDown";  

	//(finddisplay 46) displayremoveeventhandler ["MouseZChanged",_mouseZ];  
	//(finddisplay 46) displayremoveeventhandler ["MouseButtonDown",_mouseM];   
	//(finddisplay 46) displayremoveeventhandler ["KeyDown",_backspace];  
	dir1 = 0;  

};

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
Sign in to follow this  

×