Author: hellop
Author Website:

Requirements: No addons required

Version: 1.0

Short description:

Date: 2009-01-14 16:29


Comments: (2)
Rating:



 

Nitro script
by
hellop


Description:
If anyone would like to add "Nitro" to cars in their mission, here is an example script. There is info on how to use it in the header. You will have to adjust the path to point to the location of the Nitro script in your mission folder. It works great on all land vehicles including tanks and is loads of fun.


Usage:
A global variable on client computer "cli_nitroLock" so that the nitro can't be engaged more than once at at time.

The example eventHandlers add an actionmenu item to the vehicle when someone gets in as driver, then removes it when they get out. It may need a little fine tuning, such as checking to see that it is the driver that gets out. For multiplayer, if you add the "Nitro" action to a vehicle using the initline in the mission editor, the nitro script will be available to all players. If you want only one player to have access to it, then you will have to write some code, and add the two event handlers just on that client's computer, instead of in an initline.

Pre: 1. Global var: cli_nitroLock = true;
2. Player's vehicle has an action menu item enabled that runs this script. e.g. in the initline of a car/tank:
this addEventHandler ["getin", {if ((_this select 1) == "driver" then {
actionIDNitro = _this select 0 addAction ["Nitro", "client\action\cliS_actionNitro.sqf"]; 
};
}];
this addEventHandler ["getout", {_this select 0 removeAction actionIDNitro;}];
Post: cli_nitroLock is set to true;

Known issues:
Reverse doesn't work. Would be nice if it worked dynamically from vehicle weight/maxspeed.
Air Vehicles not tested.


/*cliS_actionNitro.sqf
By: Hellop 2008
Copyright: Released to the Public Domain.  It would be cool if you gave me credit in your mission if you use it.
Purpose: Simulate Nitrous Oxide speed-boost for vehicles.  Sets global variable on client computer, cli_nitroLock 
so that the nitro can't be engaged more than once at at time.

Pre: 1. Global var: cli_nitroLock = true;
	2. Player's vehicle has an action menu item enabled that runs this script. e.g. in the initline of a car/tank:
	this addEventHandler ["getin", {
		if ((_this select 1) == "driver") then {
			actionIDNitro = _this select 0 addAction ["Nitro", "client\action\cliS_actionNitro.sqf"];  			
		}; 
	}]; 
	this addEventHandler ["getout", {_this select 0 removeAction actionIDNitro;}]; 
	
Post: cli_nitroLock is set to true;

Testing: 5 min. reverse doesn't work.  Would be nice if it worked dynamically from vehicle weight/maxspeed.
	Air Vehicles not tested.
*/

private ["_obj", "_vel", "_tmrInterval", "_dir", "_maxSpeed"];

_actionID = _this select 2; 
_obj = vehicle player;
//Tanks and stuff get less nitro.
_tmrInterval = .1;
_maxSpeed = 120;
_speedMultiplier = .4; //2 is good for cars, too much for tanks
_nitroDuration = 5;

if ((typeOf _obj) isKindOf "Car")  then {
	_tmrInterval = .02;
	_maxSpeed = 180;
	_speedMultiplier = 1.5;	
};

if ((typeOf _obj) isKindOf "Air") then {
	_tmrInterval = .02;
	_maxSpeed = 500;  //What is best val here?
	_speedMultiplier = .3;	
};

if ((typeOf _obj) isKindOf "Motorcycle") then {
	_tmrInterval = .02;
	_maxSpeed = 140;  //What is best val here?
	_speedMultiplier = .2;	
};


//Initialize vars;
_vel = 0;
_velX = 0;
_velY = 0;
_velZ =0;
_dir = 0;
_sinDir = 0;
_cosDir = 0;
_previousVel = velocity _obj;
_previousSpeed = speed _obj;
_curSpeed = 0;
if ((speed _obj) <= 3) then {
	player sideChat format ["You must be moving to activate Nitro."];
}
else {    
	if (cli_nitroLock) then { 
		cli_nitroLock = false;
		player sideChat format ["Nitro Engaged."];
		//player globalchat format["Time: %1, Vehicle Type: %2, MaxSpeed: %3", time, typeOf _obj, _maxSpeed];	
		_startTime = time;
		_tmpSpeedMultiplier = _speedMultiplier;
		while {(time - _startTime) < _nitroDuration} do {	
			sleep _tmrInterval;
			_vel = velocity _obj;
			_curSpeed = (speed _obj);
			if (((abs _curSpeed) - (abs _previousSpeed)) > 30) then {_vel = _previousVel};  //To prevent getting thrown far in collisions
			_velX = _vel select 0;
			_velY = _vel select 1;
			_velZ = _vel select 2;
			_dir = getdir _obj;
			//player globalChat format ["Speed: %1", speed _obj];
			if ((speed _obj) > _maxSpeed) then {_tmpSpeedMultiplier = 0} else {_tmpSpeedMultiplier = _speedMultiplier}; 
			_sinDir = _tmpSpeedMultiplier*(sin _dir);
			_cosDir = _tmpSpeedMultiplier*(cos _dir);
			_obj setvelocity [_velX + _sinDir, _velY + _cosDir, _velZ -.1];	//Keep Z vector moving with gravity
			_previousSpeed = _curSpeed;
			_previousVel = _vel;			
		};
		cli_nitroLock = true;
		player sideChat format ["Nitro test Done! Ending Vel: %1. Dir: %2, Speed: %3", velocity _obj, direction _obj, speed _obj];
	};
};






Enable javascript to be able to download from Armaholic please!



Tags: No tags