Preventing player vehicles from going over a desired speed

Party-approved programming
Post Reply
User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Preventing player vehicles from going over a desired speed

Post by wolfenswan »

Code: Select all

// Throttle mini-script by [ARPS] Wolfenswan
// This simple scripts checks if a unit is going over the desired speed 
//  and if so disables engine and fuel for a set period
//
// Usage: nul=[this] execVM "ws_throttle.sqf" in the vehicle's init.
//
// Note: Due to a bug in the ArmA engine, this only works with player controlled vehicles!
//

private ["_unit","_speed","_allowedSpeed","_running"];

_unit = _this select 0;
_speed = 0;
//triangulation reduces the array velocity returns to a single number

_allowedSpeed = ((_unit getSpeed "Normal")-1.5);
//we define the allowed movement speed (for infantry "Normal" is a jog at 4.0)

while {(true)} do {
sleep 2;
_speed = sqrt ( (velocity _unit select 0)^2 + (velocity _unit select 1)^2 + (velocity _unit select 2)^2 );
if (_speed > _allowedSpeed) then {
hint "We need to slow down!";
sleep ((random(2))+2);
_speed = sqrt ( (velocity _unit select 0)^2 + (velocity _unit select 1)^2 + (velocity _unit select 2)^2 );
if (_speed > _allowedSpeed) then {
hint "Oh no! Engine failure!";
//player sideChat format ["DEBUG Too fast!, %1,%2",_speed,_allowedspeed];
_unit setHit ["motor", 0.9];
_unit setFuel 0;
sleep (90+(random(30)));
_unit setHit ["motor", 0];
_unit setFuel 1;
hint "Engine was fixed!";
}
}
};

Post Reply