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,27 +10,44 @@
#include "script_component.hpp"
_this spawn {
private ["_unit","_carriedObj"];
_unit = _this select 0;
_fallDown = false;
if (count _this > 1) then {
_fallDown = _this select 1;
};
_carriedObj = [_unit] call FUNC(getCarriedObj);
while {sleep 1;_carriedObj = [_unit] call FUNC(getCarriedObj); ((!isNull _carriedObj) && (alive _unit))} do {
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 (_fallDown) then {
_unit playMove "amovppnemstpsraswrfldnon";
};
if (_carriedObj isKindOf "Man") then {
hint "You can not move this fast while transporting this person.";
} else {
hint "You can not move this fast while carrying this object";
};
[_unit,ObjNull] call FUNC(carryObj);
};
};
private ["_unit","_carriedObj"];
_unit = _this select 0;
_fallDown = false;
if (count _this > 1) then {
_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;
};
if !((!isNull _carriedObj) && (alive _unit)) exitwith {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
if (speed _unit > 12 && vehicle _unit == _unit && isTouchingGround) then {
_unit setVelocity [0,0,0];
if (_fallDown) then {
_unit playMove "amovppnemstpsraswrfldnon";
};
if (_carriedObj isKindOf "Man") then {
hint "You can not move this fast while transporting this person.";
} else {
hint "You can not move this fast while carrying this object";
};
[_unit,ObjNull] call FUNC(carryObj);
};
}, 0.5, [_unit,_fallDown] ] call CBA_fnc_addPerFrameHandler;

View File

@ -10,31 +10,35 @@
#include "script_component.hpp"
_this spawn {
private ["_vehicle", "_maxSpeed", "_velocity"];
private ["_vehicle", "_maxSpeed"];
_vehicle = _this select 0;
_maxSpeed = _this select 1;
_vehicle = _this select 0;
_maxSpeed = _this select 1;
if ((_vehicle getvariable [QGVAR(limitSpeed_f),false])) then {
_vehicle setvariable [QGVAR(limitSpeed_f),nil,true];
if ((_vehicle getvariable [QGVAR(limitSpeed_f),false])) then {
_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];
_speed = speed _vehicle;
if (_speed > _maxSpeed) then {
_velocity = velocity _vehicle;
_x = _velocity select 0;
_y = _velocity select 1;
_z = _velocity select 2;
waitUntil {
_speed = speed _vehicle;
if (_speed > _maxSpeed) then {
_velocity = velocity _vehicle;
_x = _velocity select 0;
_y = _velocity select 1;
_z = _velocity select 2;
_diff = _speed - _maxSpeed;
_percentage = (_speed / 100) * _diff;
_newVelocity = [_x - (_x * _percentage), _y - (_y * _percentage), _z - (_z * _percentage)];
_vehicle setVelocity _newVelocity;
};
!(_vehicle getvariable [QGVAR(limitSpeed_f),false])
_diff = _speed - _maxSpeed;
_percentage = (_speed / 100) * _diff;
_newVelocity = [_x - (_x * _percentage), _y - (_y * _percentage), _z - (_z * _percentage)];
_vehicle setVelocity _newVelocity;
};
};
}, 0, [_vehicle,_maxSpeed] ] call CBA_fnc_addPerFrameHandler;