Removed spawn usage from limit movement speed functions

This commit is contained in:
Thomas Kooi
2015-01-17 12:53:23 +01:00
parent 041a4fccc5
commit e5579f1c32
2 changed files with 67 additions and 46 deletions

View File

@ -10,17 +10,35 @@
#include "script_component.hpp" #include "script_component.hpp"
_this spawn { private ["_unit","_carriedObj"];
private ["_unit","_carriedObj"]; _unit = _this select 0;
_unit = _this select 0; _fallDown = false;
_fallDown = false; if (count _this > 1) then {
if (count _this > 1) then {
_fallDown = _this select 1; _fallDown = _this select 1;
};
if ((_vehicle getvariable [QGVAR(limitMovementSpeed),false])) exitwith {
_vehicle setvariable [QGVAR(limitMovementSpeed),nil,true];
};
{
private["_unit","_fallDown","_carriedObj"];
_unit = (_this select 0) select 0;
_fallDown = (_this select 0) select 1;
_carriedObj = [_unit] call FUNC(getCarriedObj)
if !(_vehicle getvariable [QGVAR(limitMovementSpeed),false]) exitwith {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
}; };
_carriedObj = [_unit] call FUNC(getCarriedObj); if !((!isNull _carriedObj) && (alive _unit)) exitwith {
while {sleep 1;_carriedObj = [_unit] call FUNC(getCarriedObj); ((!isNull _carriedObj) && (alive _unit))} do { [(_this select 1)] call cba_fnc_removePerFrameHandler;
if (speed _unit > 12 && vehicle _unit == _unit) then { };
[format["Unit ran to fast (Speed: %1, is now dropping carrying obj",speed _unit],2] call FUNC(debug);
if (speed _unit > 12 && vehicle _unit == _unit && isTouchingGround) then {
_unit setVelocity [0,0,0];
if (_fallDown) then { if (_fallDown) then {
_unit playMove "amovppnemstpsraswrfldnon"; _unit playMove "amovppnemstpsraswrfldnon";
}; };
@ -32,5 +50,4 @@ _this spawn {
}; };
[_unit,ObjNull] call FUNC(carryObj); [_unit,ObjNull] call FUNC(carryObj);
}; };
}; }, 0.5, [_unit,_fallDown] ] call CBA_fnc_addPerFrameHandler;
};

View File

@ -10,19 +10,25 @@
#include "script_component.hpp" #include "script_component.hpp"
_this spawn { private ["_vehicle", "_maxSpeed"];
private ["_vehicle", "_maxSpeed", "_velocity"]; _vehicle = _this select 0;
_maxSpeed = _this select 1;
_vehicle = _this select 0; if ((_vehicle getvariable [QGVAR(limitSpeed_f),false])) then {
_maxSpeed = _this select 1;
if ((_vehicle getvariable [QGVAR(limitSpeed_f),false])) then {
_vehicle setvariable [QGVAR(limitSpeed_f),nil,true]; _vehicle setvariable [QGVAR(limitSpeed_f),nil,true];
};
if (_maxSpeed < 0) exitwith {};
_vehicle setvariable [QGVAR(limitSpeed_f),true,true];
{
private["_vehicle","_maxSpeed","_speed","_x","_y","_z", "_diff","_percentage","_newVelocity","_velocity"];
_vehicle = (_this select 0) select 0;
_maxSpeed = (_this select 0) select 1;
if !(_vehicle getvariable [QGVAR(limitSpeed_f),false]) exitwith {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
}; };
if (_maxSpeed < 0) exitwith {};
_vehicle setvariable [QGVAR(limitSpeed_f),true,true];
waitUntil {
_speed = speed _vehicle; _speed = speed _vehicle;
if (_speed > _maxSpeed) then { if (_speed > _maxSpeed) then {
_velocity = velocity _vehicle; _velocity = velocity _vehicle;
@ -35,6 +41,4 @@ _this spawn {
_newVelocity = [_x - (_x * _percentage), _y - (_y * _percentage), _z - (_z * _percentage)]; _newVelocity = [_x - (_x * _percentage), _y - (_y * _percentage), _z - (_z * _percentage)];
_vehicle setVelocity _newVelocity; _vehicle setVelocity _newVelocity;
}; };
!(_vehicle getvariable [QGVAR(limitSpeed_f),false]) }, 0, [_vehicle,_maxSpeed] ] call CBA_fnc_addPerFrameHandler;
};
};