Files
DayZ-Epoch/SQF/dayz_code/compile/player_crossbowBolt.sqf
ebaydayz d0e8291159 Fix floating arrows
Fixes #1815
2016-12-10 15:06:48 -05:00

65 lines
2.2 KiB
Plaintext

private ["_endPos","_vUp","_doLoop","_hitArray","_countr","_hitObject","_hitSelection","_config","_hitMemoryPt","_variation","_val","_dir","_bolt","_obj","_unit","_ammo","_projectile","_height","_nearArrows"];
_obj = _this select 0;
_unit = _obj select 0;
//_weapon = _obj select 1;
_ammo = _obj select 4;
//_magazine = _obj select 5;
_projectile = _obj select 6;
_projectile = nearestObject [_unit,_ammo];
_vUp = vectorUp _projectile;
_endPos = getPosATL _projectile;
_dir = 0;
while {alive _projectile} do {
_endPos = getPosATL _projectile;
_vUp = vectorUp _projectile;
sleep 0.01;
};
/*
Match near arrow position if one is already close by.
Prevents arrows floating in air when multiple are shot against wall at same position. Projectile was hitting end of previous arrow.
From testing anything less than 2m does not work to prevent this. Radius may need to be increased for some cases if issue still occurs.
*/
_nearArrows = nearestObjects [_endPos,["WoodenArrowF"],2];
if (count _nearArrows > 0) then {
_endPos = getPosATL (_nearArrows select 0);
_vUp = vectorUp (_nearArrows select 0);
};
//_distance = _unit distance _endPos;
_height = _endPos select 2;
_doLoop = true;
_countr = 0;
if (_height < 100) then {
_bolt = createVehicle ["WoodenArrowF", _endPos, [], 0, "CAN_COLLIDE"];
_bolt setPosATL _endPos;
_bolt setDir (getDir _unit);
_bolt setVectorUp _vUp;
_hitArray = _unit getVariable["firedHit",[]];
while {_doLoop} do {
_hitArray = _unit getVariable["firedHit",[]];
if (count _hitArray > 0) then {_doLoop = false};
if (_countr > 50) then {_doLoop = false};
_countr = _countr + 1;
uiSleep 0.1;
};
if (count _hitArray > 0) then {
_hitObject = _hitArray select 0;
_hitSelection = _hitArray select 1;
_config = configFile >> "cfgBody" >> _hitSelection;
_hitMemoryPt = getText(_config >> "memoryPoint");
_variation = getNumber(_config >> "variation");
_val = [((random (_variation * 2)) - _variation),((random (_variation * 2)) - _variation),((random (_variation * 2)) - _variation)];
_bolt attachTo [_hitObject,_val,_hitMemoryPt];
_dir = ([_hitObject,_unit] call BIS_fnc_relativeDirTo) + 180;
_bolt setDir (_dir);
_bolt setPos (getPosATL _bolt);
_unit setVariable["firedHit",[]];
_unit setVariable["firedDamage",0,true];
};
};