Jump to content

Andre Organized Spawn Vehicles


Donnovan

Recommended Posts

Run it on the server, at the end of the server file init\server_functions.sqf.

Play with the configurations.

It will spawn temporary vehicles all over the map, acordingly to your configuration.

Any doubt, please ask.

Thankyou, and sory for no more info, there is nothing else can i say, but if you want to know something, please ask.

//=========================
// By Donnovan/Rubycon
//=========================
// Spawn Temporary Vehicles
//=========================

//CONFIGURATION 1

_mapSize = 15360; //SIZE OF THE MAP (DEFAULT IS CHERNARUS SIZE)
_useVehAntiGlitch = true; //AVOID USE OF VEHICLES TO INVADE BASES
_useTempVehMsg = true; //SEND MESSAGE ALERTING ABOUT TEMPORARY VEHICLE
mtdr_runningMod = 0; //0 FOR EPOCH, 1 FOR DAYZ MOD AND 2 FOR OTHERS

//CONFIGURATION 2
//VEHICLES TO SPAWN
_vehClassAll = [
	[//CARS (WEAK,NORMAL,STRONG)
		["Tractor","car_sedan","SkodaRed","SkodaBlue","SkodaGreen","Lada1","Lada2"],
		["UAZ_CDF","UralCivil","hilux1_civil_1_open","Baf_Offroad_W"],
		["HMMWV_DZ","Offroad_DSHKM_INS","M113_PMC","landRover_CZ_EP1","SUV_TK_CIV_EP1"]
	],
	[//HELI (WEAK,NORMAL,STRONG)
		["MH6J_DZ","AH6X_DZ"],
		["UH1H_DZ"],
		["Mi17_DZ"]
	]
];

//NUMBER OF EACH VEHICLES
_vehClassQttAll = [
	[//CARS QTT (WEAK,NORMAL,STRONG): TOTAL 70*
		40,
		20,
		10
	],
	[//HELI QTT (WEAK,NORMAL,STRONG): TOTAL 15**
		5,
		5,
		5
	]
];

//LOCATIONS TO SPAWN
_locationTypesAll = [
	[//CAR SPAWN LOCATION (VILLAGE/CITY/CAPITAL)
		//A LOT OF PLACES
		["NameVillage"],
		//BEREZINO, KRASNOSTAV, SOLNICHNTY, ELEKTROZAVODSK, ETC
		["NameCity"],
		//CHERNOGORSK, BALOTA AIRPORT AND NORTHWEST AIRPORT
		["NameCityCapital","Airport"]
	],
	[//HELI SPAWN LOCATION (VILLAGE/CITY/CAPITAL)
		//A LOT OF PLACES
		["NameVillage"],
		//BEREZINO, KRASNOSTAV, SOLNICHNTY, ELEKTROZAVODSK, ETC
		["NameCity"],
		//CHERNOGORSK, BALOTA AIRPORT AND NORTHWEST AIRPORT
		["NameCityCapital","Airport"]
	]
];

//NUMBER OF VEHICLES IN EACH LOCATION
_locationTypesQttAll = [
	[//CAR QTT IN LOCATION (VILLAGE/CITY/CAPITAL): TOTAL 70* (MUST MATCH TOTAL OF CARS)
		40,
		24,
		 6
	],
	[//HELI QTT IN LOCATION (VILLAGE/CITY/CAPITAL): TOTAL 15** (MUST MATCH TOTAL OF HELIS)
		2,
		5,
		8
	]
];

//LOCATIONS SPAWN RAD
_locationTypesRadAll = [
	[//LOCATION RAD FOR CAR (VILLAGE/CITY/CAPITAL)
		100,
		200,
		300
	],
	[//LOCATION RAD FOR HELI (VILLAGE/CITY/CAPITAL)
		200,
		400,
		600
	]
];

//TENDENCIE MATRIX:
//TRY THE MOST TO MARRY VILLAGE / CITY / CAPITAL PLACES WITH WEAK / NORMAL / STRONG VEHICLES,
//RESPECTVELY, WITHOUT CHANGING THE TOTALS IN _vehClassQttAll AND _locationTypesQttAll
_vehTendenciesUse = true;
_vehTendencies = [
	[
		[ 0.02,-0.01,-0.01],
		[-0.01, 0.02,-0.01],
		[-0.01,-0.01, 0.02]
	],
	[
		[ 0.01, 0.00,-0.01],
		[ 0.00, 0.00, 0.00],
		[-0.01, 0.00, 0.01]
	],
	[
		[ 0.00, 0.00, 0.00],
		[ 0.00, 0.01,-0.01],
		[ 0.00,-0.01, 0.01]
	],
	[
		[ 0.01,-0.01, 0.00],
		[-0.01, 0.01, 0.00],
		[ 0.00, 0.00, 0.00]
	]
];

//CLASSES OF THE VEHICLES TO BE SPAWNED TO FIX ROUND ERRORS
_basketVehClass = ["UAZ_CDF","UralCivil","hilux1_civil_1_open","MH6J_DZ","AH6X_DZ","UH1H_DZ"];

//END OF CONFIGURATION

//SCRIPT
_countVeh = [];
{_countVeh = _countVeh + [0];} forEach _vehClassAll;
{
	//SET VARS
	_vehSet = _forEachIndex;
	_vehClass = _vehClassAll select _vehSet;
	_vehClassQtt = _vehClassQttAll select _vehSet;
	_locationTypes = _locationTypesAll select _vehSet;
	_locationTypesQtt = _locationTypesQttAll select _vehSet;
	_locationTypesRad = _locationTypesRadAll select _vehSet;
	
	//TOTAL VEHICLES
	_vehQtt = 0;
	{_vehQtt = _vehQtt + _x;} forEach _vehClassQtt;
	
	//QTT MATRIX CALCULATION
	_vehLocQtt = [
		[(_vehClassQtt select 0)*(_locationTypesQtt select 0),(_vehClassQtt select 0)*(_locationTypesQtt select 1),(_vehClassQtt select 0)*(_locationTypesQtt select 2)],
		[(_vehClassQtt select 1)*(_locationTypesQtt select 0),(_vehClassQtt select 1)*(_locationTypesQtt select 1),(_vehClassQtt select 1)*(_locationTypesQtt select 2)],
		[(_vehClassQtt select 2)*(_locationTypesQtt select 0),(_vehClassQtt select 2)*(_locationTypesQtt select 1),(_vehClassQtt select 2)*(_locationTypesQtt select 2)]
	];

	_vehLocQtt = [
		[(_vehLocQtt select 0 select 0)/_vehQtt,(_vehLocQtt select 0 select 1)/_vehQtt,(_vehLocQtt select 0 select 2)/_vehQtt],
		[(_vehLocQtt select 1 select 0)/_vehQtt,(_vehLocQtt select 1 select 1)/_vehQtt,(_vehLocQtt select 1 select 2)/_vehQtt],
		[(_vehLocQtt select 2 select 0)/_vehQtt,(_vehLocQtt select 2 select 1)/_vehQtt,(_vehLocQtt select 2 select 2)/_vehQtt]
	];

	//APLYES TENDENCIES
	if (_vehTendenciesUse) then {
		{
			_vehTendencie = _x;
			_lastMatrix = +_vehLocQtt;
			_stop = false;
			while {true} do {
				_newMatrix = [];
				{
					_line = _x;
					_lineI = _forEachIndex;
					_newLine = [];
					{
						_colI = _forEachIndex;
						_tend = _vehTendencie select _lineI select _colI;
						_newValor = _x + _tend;
						if (_newValor < 0) exitWith {_stop = true;};
						_newLine = _newLine + [_newValor];
					} forEach _line;
					if (_stop) exitWith {};
					_newMatrix = _newMatrix + [_newLine];
				} forEach _lastMatrix;
				if (_stop) exitWith {_vehLocQtt = +_lastMatrix;};
				_lastMatrix = +_newMatrix;
			};
		} forEach _vehTendencies;
	};
	
	//ROUND VALUES
	_villBasket = 0;
	_cityBasket = 0;
	_captBasket = 0;
	_vehLocQttRnd = [];
	{
		_vill = (_x select 0);
		_city = (_x select 1);
		_capt = (_x select 2);
		_villR = round _vill;
		_cityR = round _city;
		_captR = round _capt;
		_villBasket = _vill - _villR;
		_cityBasket = _city - _cityR;
		_captBasket = _capt - _captR;
		_vehLocQttRnd = _vehLocQttRnd + [[_villR,_cityR,_captR]];
	} forEach _vehLocQtt;

	//CORRECT ERROR GENERATED BY ROUND
	_vehLocQttRnd = _vehLocQttRnd + [[round _villBasket,round _cityBasket,round _captBasket]];
	_vehClass = _vehClass + [_basketVehClass];

	//FIND PLACES
	_places = [];
	_mapCenter = [_mapSize/2,_mapSize/2,0];
	{
		_subPlaces = [];
		{_subPlaces = _subPlaces + nearestLocations [_mapCenter,[_x],15000];} forEach _x;
		_places = _places + [_subPlaces];
	} forEach _locationTypes;

	//ANTI GLITCH FOR EXIT VEHICLE
	mtdr_getOut = {
		private ["_player","_veh","_builds"];
		_veh = _this select 0;
		_player = _this select 2;
		if (mtdr_runningMod == 0) then {
			_builds = count (_veh nearObjects ["ModularItems",5]);
			_builds = _builds + count (_veh nearObjects ["Land_DZE_WoodDoorLocked_Base",5]);
			_builds = _builds + count (_veh nearObjects ["CinderWallDoorLocked_DZ_Base",5]);
		};
		if (mtdr_runningMod == 1) then {
			_builds = count (_veh nearObjects ["DZ_buildables",5]);
		};
		if (_builds > 0 && _veh isKindOf "LandVehicle") then {
			_bBox = boundingBox _veh;
			_h = abs((_bBox select 0 select 2) - (_bBox select 1 select 2));
			_pos = getPosATL _veh;
			_pos = [_pos select 0,_pos select 1,_h];
			_player setPosATL _pos;
			[nil,_player,"loc",rTITLETEXT,"You can''t exit vehicle too close to buildables objects.","PLAIN DOWN",5] call RE;
		};
	};
	
	//SEND MESSAGE ABOUT TEMPORARY VEHICLE
	mtdr_message = {
		private ["_player","_veh"];
		_veh = _this select 0;
		_player = _this select 2;
		[nil,_player,"loc",rTITLETEXT,"\nThis is a temporary vehicle!","PLAIN DOWN",2] call RE;
	};

	//SPAWN VEHICLES
	_failed = 0;
	_placeIndex = 0;
	waitUntil {!isNil "BIS_fnc_findSafePos" && !isNil "PVDZE_serverObjectMonitor"}; //NEW LINE!
	{
		_line = _x;
		_vehicles = _vehClass select _forEachIndex;
		{
			for "_c" from 1 to _x do {
				_placesSub = _places select _forEachIndex;
				_place = _placesSub select (_placeIndex mod (count _placesSub));
				_placeIndex = _placeIndex + 1;
				_placePos = locationPosition _place;
				_placeRad = _locationTypesRad select _forEachIndex;
				_vehicle = _vehicles call BIS_fnc_selectRandom;
				_vehicleSize = (sizeOf _vehicle)/2;
				_pos = [_placePos,0,_placeRad,_vehicleSize,0,20,0,[],[_placePos,[0,0,0]]] call BIS_fnc_findSafePos;
				if !(_pos select 0 == _placePos select 0 && _pos select 1 == _placePos select 1) then {
					_pos = [_pos select 0,_pos select 1,1];
					_veh = createVehicle [_vehicle,_pos,[],0,"CAN_COLLIDE"];
					PVDZE_serverObjectMonitor = PVDZE_serverObjectMonitor + [_veh]; //NEW LINE!
					if (_useVehAntiGlitch && mtdr_runningMod < 2) then {
						_veh addEventHandler ["GetOut",{_this call mtdr_getOut;}];
					};
					if (_useTempVehMsg) then {
						_veh addEventHandler ["GetIn",{_this call mtdr_message;}];
					};
					_veh setDir random 360;
					_veh setVelocity [0,0,0.5];
					_countVeh set [_vehSet,(_countVeh select _vehSet) + 1];
					sleep (1/50);
				} else {
					_failed = _failed + 1;
					diag_log ("[SPAWN VEHICLE FAILED] fails = " + str _failed);
				};
			};
		} forEach _line;
	} forEach _vehLocQttRnd;

	diag_log ("[VEHICLES SPAWNED ON THE MAP] = " + str _countVeh);
} forEach _vehClassAll;

 

Edited by Donnovan
Link to comment
Share on other sites

Run it on the server, at the end of the server file init\server_functions.sqf.

Play with the configurations.

It will spawn temporary vehicles all over the map, acordingly to your configuration.

Any doubt, please ask.

Thankyou, and sory for no more info, there is nothing else can i say, but if you want to know something, please ask.

 

How i can define my own positions for vehicle's spawn, this is possible? 

Link to comment
Share on other sites

So if i get this correct you can use this instead off using the dynamic vehicle list .

Would you see any increased server performance by using this instead of the dynamic vehicle list Donnovan ?

Best regards ..

Edited by creativv
Link to comment
Share on other sites

Creativv,

The cost for the server of a temporary vehicle is most the same of a permanent one, except that the server dont need to update the temporary vehicle on the database when it get damaged or someone enter/exit it.

But with all vehicles temporary you have total control of how many vehicles are in the server and can change the quantity form 400 to 300, for example, in one restart.

This is good for the PVP server i'm creating. But for Epoch may be its better to have it along with permanent vehicles, or create the possibilitie to make a vehicle permanente in some way.

Edited by Donnovan
Link to comment
Share on other sites

Making vehicles permanent with this script wouldnt be so hard with the claim vehicle or vehicle key changer script .

But indeed this looks like a far better way to control the vehicles on the map then dynamic vehicles .

Going to see on my test server if it does something for performance because the dynamic vehicles do need to update .

Thanks for the reply .

Link to comment
Share on other sites

Donnovan and other players that will use this on epoch .

Might want to make a change in your server_functions.sqf .

//server_checkHackers = {
   if (DZE_DYN_AntiStuck2nd > 3) then { DZE_DYN_HackerCheck = nil; DZE_DYN_AntiStuck2nd = 0; };
   if(!isNil "DZE_DYN_HackerCheck") exitWith {  DZE_DYN_AntiStuck2nd = DZE_DYN_AntiStuck2nd + 1;};
   DZE_DYN_HackerCheck = true;
   {
      if(vehicle _x != _x && !(vehicle _x in PVDZE_serverObjectMonitor) && (isPlayer _x)  && !((typeOf vehicle _x) in DZE_safeVehicle)) then {
         //diag_log ("CLEANUP: KILLING A HACKER " + (name _x) + " " + str(_x) + " IN " + (typeOf vehicle _x));
         (vehicle _x) setDamage 1;
         _x setDamage 1;
         sleep 0.25;
      };
      sleep 0.001;
   } forEach allUnits;
   DZE_DYN_HackerCheck = nil;
};

to this

server_checkHackers = {
if (DZE_DYN_AntiStuck2nd > 3) then { DZE_DYN_HackerCheck = nil; DZE_DYN_AntiStuck2nd = 0; };
if(!isNil "DZE_DYN_HackerCheck") exitWith { DZE_DYN_AntiStuck2nd = DZE_DYN_AntiStuck2nd + 1;};
DZE_DYN_HackerCheck = true;
DZE_DYN_HackerCheck = nil;
};

Or this will happen "CLEANUP: KILLING A HACKER Mr.X B 1-1-B:1 (Mr.X) REMOTE IN Lada2"

Also the vehicles dissapear when you get in them .

I'll be leaving this script because i do not want to make this edit on my server .

Link to comment
Share on other sites

EXPLODING VEHICLES

Thankyou a lot Creativv!

I believe changing this line on the script:

_veh = createVehicle [_vehicle,_pos,[],0,"CAN_COLLIDE"];

to that:

_veh = createVehicle [_vehicle,_pos,[],0,"CAN_COLLIDE"];
PVDZE_serverObjectMonitor = PVDZE_serverObjectMonitor + [_veh];

Could also solve the problem.

But i did like you, and removed the code, since i believe it's outdated and mostly useless.

 

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
13 hours ago, Richie said:

Search the forum, there is a work around posted as the same issues happened with the deploy bike/other vehicle scripts.

So i could make use of "fnc_set_temp_deployable_id" or add all vehicles to the array for allowed without Objectuid but that is dangerous .

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...