Jump to content

Recommended Posts

I am looking for some help here :D,  basically looking to run this script on MP but need help with the addaction and the conditions (if player is within 5 metres, vehicle is flipped over then addaction is available)

 

 

_vehicle = cursorTarget;

_vehicle setVectorUp surfaceNormal getPos _vehicle;

_vehicle setPosATL [getPosATL _vehicle select 0, getPosATL _vehicle select 1, 0];

};

 

Share this post


Link to post
Share on other sites
_this addAction ["Flip vehicle",{
	params ["_vehicle", "_caller", "_actionId", "_arguments"];
	_normalVec = surfaceNormal getPos _vehicle;
	if (!local _vehicle) then {
		[_vehicle,_normalVec] remoteExec ["setVectorUp",_vehicle];
	} else {
		_vehicle setVectorUp _normalVec;
	};
	_vehicle setPosATL [getPosATL _vehicle select 0, getPosATL _vehicle select 1, 0];
},[],1.5,true,true,"","!((vectorUp _target apply {abs _x toFixed 2}) isEqualTo ((surfaceNormal getPos _target) apply {abs _x toFixed 2}))",5];

 

  • Like 3

Share this post


Link to post
Share on other sites

Same code but using another condition:

 

"(vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5"

 

Seems to be faster and I don't have false friend when terrain is unlevel. (HEMTT placed in Tanoa, [7285.61,7288.9,-1.19209e-007] , one main airfield ditch.

 

  • Like 3

Share this post


Link to post
Share on other sites

I  had some idea too about this.

How about to automatically un flip any up sided vehicle and not only these with wheels pointing up.

I have created some gameplay improvements for Barbolani's Antistasi and this code is part of it :

 

/*
file: VEH_fnc_xehInit.sqf
by DaVidoSS
add possibility to automatically turn back vehicle on wheels once flipped
to event take place vehicle needs to be side/up flipped and empty and no units in 10m around
created for Barbolani's Antistasi
parameters:
0: OBJECT
return VOID
*/
params [["_vehicle",objNull,[objNull]]];
if (!isServer) exitWith {};
if (!((getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "hasDriver")) isEqualTo 1)) exitWith {};

_vehicle addEventHandler ["GetOut", {
	private _vehicle = param [0, objNull, [objNull]];
	if !((crew _vehicle) isEqualTo []) exitWith {}; //skip if anyone still in veh
	(_vehicle call BIS_fnc_getPitchBank) params ["_vx","_vy"];
	if (([_vx,_vy] findIf {_x > 80 || _x < -80}) != -1) then {	
		0 = [_vehicle] spawn {
			private _vehicle = param [0, objNull, [objNull]];
			waitUntil {(_vehicle nearEntities ["Man", 10]) isEqualTo [] || !alive _vehicle};
			if (!alive _vehicle) exitWith {};
			_vehicle allowDamage false;
			_vehicle setVectorUp [0,0,1];
			_vehicle setPosATL [(getPosATL _vehicle) select 0, (getPosATL _vehicle) select 1, 0];
			_vehicle allowDamage true;
		};
	};
}];

 

 

  • Like 2

Share this post


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

I  had some idea too about this.

How about to automatically un flip any up sided vehicle and not only these with wheels pointing up.

I have created some gameplay improvements for Barbolani's Antistasi and this code is part of it :

 


/*
file: VEH_autoflip.sqf
by DaVidoSS
add possibility to automatically turn back vehicle on wheels once flipped
to event take place vehicle needs to be side/up flipped and empty and no units in 10m around
created for Barbolani's Antistasi
parameters:
none
return VOID
*/
if !(isServer) exitWith {};

private ["_allVehicles","_vehicle","_fnc_flipVeh"];

_fnc_flipVeh = {

	params[ ["_object",objNull,[objNull]] ];

		waitUntil {
			sleep 1;
			(_object nearEntities ["Man", 10]) isEqualTo [] || !alive _object
		};
		if (!alive _object) exitWith {};
		_object allowDamage false;
		_object setVectorUp [0,0,1];
		_object setPosATL [(getPosATL _object) select 0, (getPosATL _object) select 1, 0];
		_object allowDamage true;
};

while {true} do {

	_allVehicles = (entities [["LandVehicle"], [], false, true]) select {
		(getNumber (configFile >> "CfgVehicles" >> typeOf _x >> "hasDriver")) isEqualTo 1 &&
		 {(crew _x) isEqualTo []}
	};

	{	
		_vehicle = _x;
		(_vehicle call BIS_fnc_getPitchBank) params ["_vx","_vy"];
		if (([_vx,_vy] findIf {_x > 80 || _x < -80}) != -1 && {!canMove _vehicle}) then {
			0 = [_vehicle] spawn _fnc_flipVeh;
		};

	} forEach _allVehicles;
	sleep 20;
};

 

 

 

 

Funny that you mention doing that for antistasi as i was sick of having tanks/apcs flip over while playing antistasi.

 

Would you call this script in the initserver?

  • Like 1

Share this post


Link to post
Share on other sites

5. Vehicle autoflip. Adds event fired when vehicle is upturned.
After crew  leave vehicle and go about 10m away vehicle will automatically turn back to normal position in about 20 sec

5a. Add in init.sqf at very below:

0 = [] execVM "Scripts\improvements\VEH_autoflip.sqf";

  • Like 1

Share this post


Link to post
Share on other sites

How would I adapt this to work with only the Bobcat, as the driver or commander? Can I just post in the init of vehicle? It will be for dedicated and multiplayer. 

Spoiler

_this addAction ["Flip vehicle",{ params ["_vehicle", "_caller", "_actionId", "_arguments"]; _normalVec = surfaceNormal getPos _vehicle; if (!local _vehicle) then { [_vehicle,_normalVec] remoteExec ["setVectorUp",_vehicle]; } else { _vehicle setVectorUp _normalVec; }; _vehicle setPosATL [getPosATL _vehicle select 0, getPosATL _vehicle select 1, 0]; },[],1.5,true,true,"","(vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5",5];

Thanks. 

Share this post


Link to post
Share on other sites

Yes, you can post in the init field of the vehicle but you must write this addAction...  , not _this addAction   (no underscore).

 

Just driver or commander, just replace:

"(vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5"

by

"(vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5 && (driver _target == _this or commander _target == _this)"

 

or even

"(vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5 && _target == vehicle _this"

  • Like 1

Share this post


Link to post
Share on other sites
this addAction ["Flip vehicle",{
	params ["_vehicle", "_caller", "_actionId", "_arguments"];
	_normalVec = surfaceNormal getPos _vehicle;
	if (!local _vehicle) then {
		[_vehicle,_normalVec] remoteExec ["setVectorUp",_vehicle];
	} else {
		_vehicle setVectorUp _normalVec;
	};
	_vehicle setPosATL [getPosATL _vehicle select 0, getPosATL _vehicle select 1, 0];
},[],1.5,true,true,"","(vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5 && _target == vehicle _this",5];

I pasted this into my Bobcat and it does not bring up the action. Did I mess the code up?

Share this post


Link to post
Share on other sites
20 minutes ago, Jnr4817 said:

_target == vehicle _this

 

This condition states that you have to be inside of the vehicle. Are you trying to flip it from the outside?

Share this post


Link to post
Share on other sites

No, I am inside. I used all positions. I even looked right at the flipped vehicle I placed in editor. Never get an action to flip.

 

Tired again with no success. I am not sure why. I am not getting any errors either.

 

this addAction ["Flip vehicle",{
	params ["_vehicle", "_caller", "_actionId", "_arguments"];
	_normalVec = surfaceNormal getPos _vehicle;
	if (!local _vehicle) then {
		[_vehicle,_normalVec] remoteExec ["setVectorUp",_vehicle];
	} else {
		_vehicle setVectorUp _normalVec;
	};
	_vehicle setPosATL [getPosATL _vehicle select 0, getPosATL _vehicle select 1, 0];
},[],1.5,true,true,"","(vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5 && _target == vehicle _this"];

 

Share this post


Link to post
Share on other sites

works fine for me (if player is inside of course). In this case, You don't need to keep the ,5 (distance between the caller and the vehicle). Perhaps too small for HEMTT. remove it.

Share this post


Link to post
Share on other sites

I tried again. I’m using a prowler that I’ve placed upside as a flipped vehicle and set damage to false. Still doesn’t work.

 

When I get home I’ll try again without the 5.

 

does my code look correct I posted above?

Share this post


Link to post
Share on other sites

There is also a new (since 1.63) argument for addAction command which allows you to specify radius for action to be shown. I still use the old method though.

I just noticed new argument since 1.81 which I didn't see in the changelog before:

Quote

New condition variable is available: _originalTarget is the original object to which the action is attached, regardless if the object/unit is in a vehicle or not.

Hm.  Not sure in what case I'll need this.

@davidoss

Why the while loop? I'll never understand why people favour this over simple easier EH (when available). Hmm.

I see that you want to automatically execute the flip once no crew inside and moved > 10 m away but you could simply do this with GetOut EH.

Share this post


Link to post
Share on other sites

@HazJ

Its not  "people favour loops" it was just an quick throw and there are nothing to understand.

Thanks for an idea.  Already rewritten.

Its better now but i need  use XEH to init every single vehicle with.

Share this post


Link to post
Share on other sites

I have tried and tried to get this to work.

 

7erra code gives an add action but wont flip vehicle back

Spoiler

this addAction ["Flip vehicle",{
	params ["_vehicle", "_caller", "_actionId", "_arguments"];
	_normalVec = surfaceNormal getPos _vehicle;
	if (!local _vehicle) then {
		[_vehicle,_normalVec] remoteExec ["setVectorUp",_vehicle];
	} else {
		_vehicle setVectorUp _normalVec;
	};
	_vehicle setPosATL [getPosATL _vehicle select 0, getPosATL _vehicle select 1, 0];
},[],1.5,true,true,"","!((vectorUp _target apply {abs _x toFixed 2}) isEqualTo ((surfaceNormal getPos _target) apply {abs _x toFixed 2}))",5];

 

 

pierremgi new condition wont work for me either, I don't even get an addaction

Spoiler

this addAction ["Flip vehicle",{
	params ["_vehicle", "_caller", "_actionId", "_arguments"];
	_normalVec = surfaceNormal getPos _vehicle;
	if (!local _vehicle) then {
		[_vehicle,_normalVec] remoteExec ["setVectorUp",_vehicle];
	} else {
		_vehicle setVectorUp _normalVec;
	};
	_vehicle setPosATL [getPosATL _vehicle select 0, getPosATL _vehicle select 1, 0];
},[],1.5,true,true,"","(vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5",5];

 

 

I know it should be simplet but it is not for some reason. I am hosting a mulitplayer to test, but it will be used on a dedicated server.

 

Thanks for any help.

 

 

Share this post


Link to post
Share on other sites

First of all I'd recommend @pierremgi's solution for the condition as it is faster

Mine: 0.0164 ms

pierre: 0.0062 ms

 

Secondly where are you putting the code? It is meant for the init line of the vehicle.

Share this post


Link to post
Share on other sites

How much is your vehicle flipped? I wrote a vectorCos < 0.5 . That means an angle > 60° . If you want you can test with 0.9 (angle > 25°).

Share this post


Link to post
Share on other sites

I am putting it in the init code of the vehicle, also without _.

 

I was sitting the vehicle upside down completely.

 

Ill test 0.9

 

Thanks

 

Share this post


Link to post
Share on other sites

I figured it out, not sure why it works, but I changed the vectorCos >0.5, instead of <0.5.

 

Works now.

 

Thanks

  • Confused 1

Share this post


Link to post
Share on other sites

hmmm. I can't imagine that. the vectorCos is near 1 when vehicle and terrain normal are close. cos 0° = 1 for 0° angle between them. If flipped upside down, the angle is close to 180° (depending on roof and armament geometry) so vectorCos returns something close to -1 !

You should check in debug console (watch lines), the different values :

vectorUp yourvehicle (a vector)

surfaceNormal getPos yourVehicle (a vector)

(vectorUp yourVehicle) vectorCos (surfaceNormal getPos yourVehicle) (a number)

 

 

 

Share this post


Link to post
Share on other sites

Old thread, I know... But I needed to write something similar real quick, and found valuable advice here; so I thought I would share my take on this. icon7.png

 

[
	_vehicle,// Object the action is attached to
	"Flip Vehicle",// Title of the action
	"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_takeOff2_ca.paa",	// Idle icon shown on screen
	"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_takeOff2_ca.paa",	// Progress icon shown on screen
	"_this distance _target < 5 && {crew _target isEqualTo [] && (vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5}",// Condition for the action to be shown
	"_caller distance _target < 5 && {crew _target isEqualTo [] && (vectorUp _target) vectorCos (surfaceNormal getPos _target) <0.5}",// Condition for the action to progress
	{_caller playMoveNow "Acts_carFixingWheel"},// Code executed when action starts
	{_caller setFatigue (getFatigue _caller + 0.2)},// Code executed on every progress tick
	{
		params ["_vehicle", "_caller", "_actionId", "_arguments"];
		[_vehicle,surfaceNormal getPos _vehicle] remoteExec ["setVectorUp",_vehicle];
		_vehicle setPosATL [getPosATL _vehicle select 0, getPosATL _vehicle select 1, 0];
		sleep 1;
		_caller playMoveNow "amovpknlmstpslowwrfldnon"
	},// Code executed on completion
	{_caller playMoveNow "amovpknlmstpslowwrfldnon"},// Code executed on interrupted
	[],													// Arguments passed to the scripts as _this select 3
	5,													// Action duration [s]
	0,													// Priority
	false,												// Remove on completion
	false												// Show in unconscious state
] remoteExec ["BIS_fnc_holdActionAdd", 0, _vehicle];

 

Uses holdAction, adds fatigue and animations to the player. Ideally it needs a check to make sure the vehicle isn't too big, but I'm too lazy right now. ninja.png

  • Like 1
  • Thanks 2

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

×