Jump to content

Recommended Posts

thanks man !!
exactly, i wish to create a "spawner-bubble" around player for random map population, should be simpler than caching AI !
this is full script, and my final aim is to be able to select the amount of vehicles to spawn, choose them randomly from a types list, and spawn them....if one gets too far or gets disabled, another one should spawn !
thanks for your help !

Share this post


Link to post
Share on other sites

Example mission :

https://1drv.ms/u/s!ArYSs9w5RSIDhCpn3oR4akK3WJfn

fn_boatSpawner.sqf :

if ((isDedicated) || (!hasInterface)) exitWith {};

params
[
	["_minBoats", 1],
	["_maxBoats", 2],
	["_spawnDelay", 300] // Delay before spawning again...
];

sleep _spawnDelay;

_totalBoats = missionNamespace setVariable ["totalBoats", 0];

// [] call Haz_fnc_createBoat; // Default parameters will be used.
// Example: ["I_Boat_Armed_01_minigun_F", independent, 2000, 4000] call Haz_fnc_createBoat;
["I_Boat_Armed_01_minigun_F", independent, 750, 1000, 1000] call Haz_fnc_createBoat;

fn_createBoat.sqf :

if ((isDedicated) || (!hasInterface)) exitWith {};

params
[
	["_type", "O_Boat_Armed_01_minigun_F"], // If you supply an array of classnames, a random one will be selected!
	["_side", opfor],
	["_minDistance", 1500],
	["_maxDistance", 3000],
	["_deleteDistance", 1500]
];

private _boatType = "";

if ((typeName _type isEqualTo "ARRAY")) then
{
	_boatType = selectRandom _type;
} else
{
	_boatType = _type;
};

private _targets = [];

{
	if ((isNil {_x getVariable "targetAvailable"})) then
	{
		_targets pushBack _x;
	};
} forEach allPlayers - (entities "HeadlessClient_F");

private _distance = _minDistance + (ceil (random _maxDistance));
private _target = selectRandom _targets;
private _spawn = [((getPosASL _target select 0) + (sin (random 360)) * _distance), ((getPosASL _target select 1) + (cos (random 360)) * _distance), 0];

private _boat = createVehicle [_boatType, _spawn, [], 0, "FLY"];
_boat setPosASL _spawn;
vehicle player setPosASL [((getPosASL _boat select 0) + 10), (getPosASL _boat select 1), 0];

private _center = createCenter _side;
private _group = createGroup _side;
private _crew = [_boat, _group] call BIS_fnc_spawnCrew;

// TODO: Create waypoints and task for the boat...

private _nearbyPlayers = [];

while {(alive _boat)} do
{
	{
		if ((_boat distance2D _x >= _deleteDistance)) then
		{
			_nearbyPlayers pushBack _x;
		};
	} forEach allUnits;
	if ((count _nearbyPlayers > 0)) then
	{
		{
			deleteVehicle _x;
		} forEach [_boat] + (crew _boat);
		[1, 3, 15] call Haz_fnc_boatSpawner;
	};
	sleep 1;
};

Still needs a bit of cleaning up to do but it's late right now so save that for another day!

  • Like 1

Share this post


Link to post
Share on other sites

i've tested a bit....and sadly there are many things i cant understand...
first strange thing is that when a boat spawn, player get teleported to the spawned boat.
second thing is that it can get teleported on ground too.
i really appreciate and wish to thank you for your efforts, but i think i'll try to fix my script for now!
thanks!

Share this post


Link to post
Share on other sites

ok, this seems to work in MP too!
 

Spoiler

if (isServer) then {
  [] spawn {
    while {true} do {   
      _maxDist = 2000;
      _minDist = 300;
      _Dside = WEST;
      _Dtype = "I_boat_armed_01_minigun_F";

      _allPlayerPos = {getpos _x} foreach allplayers;
	
//      _Darea = [getPos player, _minDist, _maxDist, 12, 0, 10, 0] call BIS_fnc_findSafePos;        // 0 = land only  1=waterORland 2=water only 
      _Darea = [_allPlayerPos, _minDist, _maxDist, 12, 2, 10, 0] call BIS_fnc_findSafePos;        // 2 = on water
      _grpDveh = [_Darea,_Dside,[_Dtype]] call BIS_fnc_spawnGroup;
//      [_grpDveh, _Darea, 9000] call BIS_fnc_taskPatrol;
      [_grpDveh, _Darea, 3000] execVM "DDscripts\DwaterPatrol.sqf";
      _Dveh = vehicle leader _grpDveh;
      _crewDveh = crew _Dveh; 
      HINT "SPAWNED";
      waitUntil{sleep 10;{_plyr = _x;_near = false;{if (_plyr distance2D _x > _maxDist) exitWith {_near = true};true} count _crewDveh;_near} count allPlayers > 0 || !canMove _Dveh};
      {deleteVehicle _x} forEach _crewDveh;
      deletevehicle _Dveh;
      HINT "DELETED";
      uiSleep 5;      

    };
  };
};

 

...it does what it should (spawn and de-spawn a unit)...now i wish to make it so it can menage many units at same time...and i really need you help on this guys!
thanks !

Share this post


Link to post
Share on other sites

ok...i probably got blessed by a Tsunami of luck, because that seems to work!!
 

Spoiler

if (isServer) then {
  [] spawn {
//    while {true} do {   

   D_fnc_spw = 
   {
    while {true} do {  
      _maxDist = 2000;
      _minDist = 300;
      _Dside = WEST;
      _Dtype = selectRandom ["I_boat_armed_01_minigun_F","I_SDV_01_F"];
      _allPlayerPos = {getpos _x} foreach allplayers;
//      _Darea = [_allPlayerPos, _minDist, _maxDist, 12, 0, 10, 0] call BIS_fnc_findSafePos;        // 0 = land only  1=waterORland 2=water only 
      _Darea = [_allPlayerPos, _minDist, _maxDist, 12, 2, 10, 0] call BIS_fnc_findSafePos;        // 2 = on water
      _grpDveh = [_Darea,_Dside,[_Dtype]] call BIS_fnc_spawnGroup;
//      [_grpDveh, _Darea, 9000] call BIS_fnc_taskPatrol;
      [_grpDveh, _Darea, 3000] execVM "DDscripts\DwaterPatrol.sqf";         //init
      _Dveh = vehicle leader _grpDveh;
      _crewDveh = crew _Dveh; 
      HINT "SPAWNED";
      waitUntil{sleep 10;{_plyr = _x;_near = false;{if (_plyr distance2D _x > _maxDist) exitWith {_near = true};true} count _crewDveh;_near} count allPlayers > 0 || !canMove _Dveh};
      {deleteVehicle _x} forEach _crewDveh;
      deletevehicle _Dveh;
      HINT "DELETED";
      uiSleep 5;      
   };
};

private "_i";
	_i = 5;
	while {_i > 0} do {
		_i = _i - 1;
                _nul = [] spawn D_fnc_spw;
	};

//_nul = [] spawn aa_fnc_spw;

//    };
  };
};

 

right now it can spawn multiple instances of the same type.
 

Share this post


Link to post
Share on other sites

ehh...seemed too good to belive...
here is latest version:
 

Spoiler

if (isServer) then {
  [] spawn {
 
D_fnc_spwCC = {
    while {true} do {  
      _maxDist = 2000;
      _minDist = 400;
      _Dside = CIVILIAN;
      _Dtype = selectRandom ["C_Offroad_01_F", "C_Offroad_01_repair_F", "C_Quadbike_01_F", "C_Hatchback_01_F", "C_Hatchback_01_sport_F", "C_SUV_01_F", "C_Van_01_transport_F", "C_Van_01_box_F", "C_Van_01_fuel_F"];
      _allPlayerPos = {getpos _x} foreach allplayers;
      _Darea = [_allPlayerPos, _minDist, _maxDist, 12, 0, 10, 0] call BIS_fnc_findSafePos;        // 0 = land only  1=waterORland 2=water only 
//      _Darea = [_allPlayerPos, _minDist, _maxDist, 12, 2, 10, 0] call BIS_fnc_findSafePos;        // 2 = on water
      _grpDveh = [_Darea,_Dside,[_Dtype]] call BIS_fnc_spawnGroup;
      [_grpDveh, _Darea, 9000] execVM "DDscripts\DgroundPatrol.sqf";                                // for VEHICLE  patrol
//      [_grpDveh, _Darea, 3000] execVM "DDscripts\DwaterPatrol.sqf";                               // for water patrol
      _Dveh = vehicle leader _grpDveh;
      _crewDveh = crew _Dveh; 
//      HINT "SPAWNED";
      waitUntil{sleep 10;{_plyr = _x;_near = false;{if (_plyr distance2D _x > _maxDist) exitWith {_near = true};true} count _crewDveh;_near} count allPlayers > 0 || !canMove _Dveh};
      {deleteVehicle _x} forEach _crewDveh;
      _Dveh setdamage 1;
//      deletevehicle _Dveh;
//      HINT "DELETED";
      uiSleep 5;      
   };
};
        uiSleep 1;
	_i = 8;                                                                                   // DEFINE HOW MANY VEHICLES
	while {_i > 0} do {uiSleep 1;_i = _i - 1;_nul = [] spawn D_fnc_spwCC;};

  };
};

 

..it work perfectly (spawns 8 units) in eden MP preview...but on dedicated it spawns just 2 units!
its total nosense...should work or not work....plz cast some light on this...thanks!

Share this post


Link to post
Share on other sites

may it be something related to my init.sqf ? maybe too many script to exec at start ?
 

Spoiler

execVM "R3F_LOG\init.sqf";
uiSleep 2;
[] execVM "outlw_magRepack\MagRepack_init_sv.sqf";                                // add mag repack
uiSleep 2;
      null = [] execVM "DDscripts\minedetector.sqf";                              // enable mine detector beeps;
      null = [] execVM "DDscripts\Dbriefing.sqf";
uiSleep 1;
if (isServer) then                                                                // set random time, inside i put a line about ENIGMA civilian script 
{
      null = [] execVM "DDscripts\DvehSPAWNER.sqf";
      null = [] execVM "DDscripts\GMOreset.sqf";
      null = [] execVM "DDscripts\HQBtroops.sqf";
      null = [] execVM "DDscripts\HQRtroops.sqf";
      null = [] execVM "DDscripts\GMOhostages.sqf";
      null = [] execVM "DDscripts\Dclean.sqf";
      null = [] execVM "DDscripts\AUSMD_noMineMarker.sqf";                        // needed for infantry mines
      null = [player] execVM "DDscripts\Dserverfps.sqf";
/*
null = [] execVM "DDscripts\DambientMINE.sqf";
null = [] execVM "DDscripts\DambientGveh.sqf";
null = [] execVM "DDscripts\DambientGinf.sqf";
null = [] execVM "DDscripts\DambientCARS.sqf";
null = [] execVM "DDscripts\DambientCIV.sqf";
null = [] execVM "DDscripts\DambientBOAT.sqf";
*/


null = spawn "DDscripts\DambientMINE.sqf";
null = spawn "DDscripts\DambientGveh.sqf";
null = spawn "DDscripts\DambientGinf.sqf";
null = spawn "DDscripts\DambientCARS.sqf";
null = spawn "DDscripts\DambientCIV.sqf";
null = spawn "DDscripts\DambientBOAT.sqf";

      uiSleep 1;
	myNewTime = random 24;
	publicVariable "myNewTime";   
};
waitUntil{not isNil "myNewTime"};
skipTime myNewTime;

      null = [player] execVM "DDscripts\Dfps.sqf";

 

 

Share this post


Link to post
Share on other sites

That was for testing purposes. I forgot to remove that line.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×