Jump to content
Sign in to follow this  
TyrDaishi

Help with Hostage script please. locality/ control structure issues?

Recommended Posts

Hi I have a few issues I need a fresh perspective with.

 

My Problems are:

 

1. The hostage is only sometimes getting in the car, sometimes not. after trying a few times and releasing, taking it works for some reason I can't figure out.

2. The animations are going crazy because of attachto, I need to match the hostage animation with the animation of the player it is attached to. I have a vague Idea how to do this but if someone already did the input would be appreciated.

3. In a local server or dedicated server the Hostage is not matching the stance of the player it is attached to.

 

If anyone wants to give it a try here is a .pbo to test: https://drive.google.com/file/d/0B3UwVAEkxk4TWUxqSEVnZ1Q1S2c/view?usp=sharing

 

Here is my attempt so far:

 

grabnew.sqf

// Needed file: releasenew.sqf
// place this in the init of the unit that is a hostage: this addaction["<t color='#FF0000'>Move HVT</t>","grabnew.sqf",nil,1,false,true,"","((_target distance _this)<2"];

_HVT=_this select 0;
_taker=_this select 1;


if ((count (attachedObjects _taker))==0) then {
	//add hostage to taker, add him to the players group.
	detach _HVT;
	_HVT attachto [_taker,[-0.3,0.5,0]];
	_index=_taker addaction["Release HVT","releasenew.sqf"];
	_HVT disableAI "FSM";
	_HVT disableAI "AUTO";
	_HVT disableAI "AUTOTARGET";
	_HVT enableAI "Move";
	_HVT enableAI "Anim";
	_HVT setbehaviour "Careless";
	_HVT allowfleeing 0; 	
//	[_HVT] joinsilent _taker;
	//copy player stance
	while {(count attachedObjects _taker >0)} do
	{	
		//set unit stance according to _taker
		sleep 0.1;
		_stance=stance _taker;
		//hint Format["Stance:%1",_stance];
		_unitpos="up";
		if(_stance=="prone") then{
					_unitpos="down";
					
				}else{
					if(_stance=="crouch") then{
						_unitpos="middle";
						
					};
				};
	_HVT setUnitPos _unitpos;
	};
	_taker removeaction _index;
};
//check if player in and near vehicle, add hvt to vehicle accordingly
	while {alive _HVT && _HVT distance _taker <=4} do
	{	
		waituntil{vehicle _taker != _taker}; 
			detach _HVT;
			_HVT assignAsCargo vehicle _taker;
			_HVT action ["getInCargo",vehicle _taker];
		waituntil {vehicle _taker == _taker};
			unassignVehicle _HVT;
			moveOut _HVT;
		if (true) exitWith {};
	};

releasenew.sqf

_Taker=_this select 0;
_index=_this select 3;
_id=_this select 2;
_HVT =((attachedObjects _Taker) select 0);
detach _HVT;
_HVT enableAI "FSM";
_HVT enableAI "AUTO";
_HVT enableAI "AUTOTARGET";
_HVT enableAI "Move";
_HVT enableAI "Anim";
_HVT setbehaviour "Aware";
_HVT allowfleeing 1;
//[_HVT] joinsilent grpNull;
player removeaction _id;

I'm not seeing the tree in the woods here. Tried for quite some time now. I tried to check locality aso. Still not working.

Any ideas?

 

bw

Daishi

Share this post


Link to post
Share on other sites

So this is what I came up with finally, seems to work like a charm. I even got the animations to work, problem is I would have to add EVERY animation a player can make and match it to a set of movements for the hostage, and I'm not willing to add hundreds of animations to make the hostagemovement look smooth.

// Needed file: releasenew.sqf
// place this in the init of the unit that is a hostage(called _HVT): _HVT addaction["<t color='#FF0000'>Move _HVT</t>","grabnew.sqf",nil,1,false,true,"","(_target distance _this <3)"];
//Author: TyrDaishi

_HVT =_this select 0;
_taker =_this select 1;
_stance = 0;
_lastStance = "UP";

if ((count (attachedObjects _taker))==0) then {
	//add hostage to _taker and add release
	_HVT attachto [_taker,[-0.3,0.5,0]];
	_index=_taker addaction["Release _HVT","releasenew.sqf"];
	while {alive _HVT && (count attachedObjects _taker >0) && (_HVT distance _taker <=4)} do
	{	
		_HVT EnableAI "FSM";
		_HVT disableAI "AUTO";
		_HVT disableAI "AUTOTARGET";
		_HVT enableAI "Move";
		_HVT enableAI "Anim";
		_HVT setbehaviour "Careless";
		_HVT allowfleeing 0; 	
		_HVT setCombatMode "Blue";
		//set unit stance according to _taker
		sleep 0.1;
		//hint Format["Stance:%1",_stance];
		switch (stance _taker) do
			{
			case "STAND": {_stance = "UP";sleep 0.2;};
			case "CROUCH": {_stance = "MIDDLE";sleep 0.2;};
			case "PRONE": {_stance = "DOWN";sleep 0.2;};
			case "UNDEFINED": {_stance = _lastStance;sleep 0.2;};
			default {_stance = _lastStance;sleep 0.2;};
			};
		//_HVT setUnitPos _stance;
		[[_HVT,_stance],"setUnitPos",true,true] call BIS_fnc_MP;

		//check if player in and near vehicle, add _HVT to vehicle accordingly
		if (_taker != vehicle _taker) then {
			_HVT EnableAI "FSM";
			detach _HVT;
			sleep 0.2;
			_HVT action ["getInCargo",vehicle _taker];
			waitUntil{_taker == vehicle _taker && ((count attachedObjects _taker >0) || (count attachedObjects _taker == 0))}; 
			[_HVT,"unassignVehicle",true,true] call BIS_fnc_MP;
		};
	};
	_taker removeaction _index;
};

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  

×