Jump to content
Sign in to follow this  
Jnr4817

Initiate script on ingame spawning

Recommended Posts

Hello,

My team runs a vanilla server. Stay Alive Tactical. We only utilize scripts or server side mods, so nothing is needed to play with us. We utilize Ghost mission to assign task and missions within the game. Ghost comes with its own vehicle spawner. I am wanting to use Devas awesome Autopilot script. I can not figure out how to implement as spawned aircraft must have this code ran. I have looked at the script Ghost uses to spawn the vehicles, I just do not know where to put this code. Or if a function would be better for all spawned aircraft.

Thanks for any help.

Here is ghost air vehicle spawn script

/*
V2.3 Script by: Ghost (Original dialog from Kronzky) create a marker and name itand put this in the object initline - ghst_spawnveh = station1 addAction ["Spawn Vehicle", "spawn ghst_fnc_spawnair", ["spawnmarker",dir], 6, true, true, "","alive _target"];
*/

#include "def_VEHsel.hpp"

_host = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_paramarray = _this select 3;
_spawn = _paramarray select 0;
_dir = _paramarray select 1;
_spawn = getmarkerpos _spawn;
_check_radius = 10;//radius for vehicle spawn pad check and delete

if (not alive _host) exitwith {
hint "Vehicle Spawn Closed";

_host removeaction _id;
};

if (isnil "ghst_aircraftlist") exitwith {hint "Spawn list not ready yet";};
_vehiclelist = ghst_aircraftlist;
_PARAM_PlayerVehicles = "PARAM_PlayerVehicles" call BIS_fnc_getParamValue;

{if (count crew _x == 0) then {deletevehicle _x};} foreach (nearestObjects [_spawn, ["AllVehicles"], _check_radius]);
{deletevehicle _x;} foreach (nearestObjects [_spawn, ["Slingload_01_Base_F","USAF_MOABdisplay"], _check_radius]);
{deletevehicle _x;} foreach nearestObjects [_spawn,["CraterLong_small","CraterLong","WeaponHolder","GroundWeaponHolder"], _check_radius];

{if (!(alive _x) or (! canmove _x and count crew _x == 0)) then {
	deletevehicle _x;
	ghst_local_vehicles = ghst_local_vehicles - [_x];
};} foreach ghst_local_vehicles;

if (count ghst_local_vehicles == _PARAM_PlayerVehicles) exitwith {hint format ["You can only spawn %1 vehicles", _PARAM_PlayerVehicles];};

#ifndef VBS
 disableSerialization;
#endif

// fill dialog with vehicle names
createDialog "Selectvehicle";
sleep 0.1;
_ctrlList = findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_LIST;

private ["_index","_lstidx","_lstpos""_i"];

for "_i" from 0 to (count _vehicleList)-1 do {
	_vehicle = _vehicleList select _i;
	lbAdd [DLG_VEH_LIST,format["%1",_vehicle select 1]];
	lbSetPicture [DLG_VEH_LIST, _i, _vehicle select 2];
	lbSetValue [DLG_VEH_LIST, _i, _i];
};
lbSort (findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_LIST); 

// put the selection somewhat in the middle of the displayed listing
_index = -1;
_i=(_index -9) max 0;
lbSetCurSel [DLG_VEH_LIST, _i];
lbSetCurSel [DLG_VEH_LIST, _index];

// preview controls
_ctrlPic = findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_PIC;
_ctrlName = findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_NAME;
_ctrlDesc = findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_DESC;

_VEHidx = lbValue [DLG_VEH_LIST, _index];
_lstidx = _index;
_lstpos = -1;
DLG_VEH_SELECTED = false;

		while {ctrlVisible DLG_VEH_LIST} do {
			_index = lbCurSel DLG_VEH_LIST;
			_posidx = _index;
		#ifdef VBS	
			if !(isNil "DLG_VEH_SEL") then {
				if (DLG_VEH_SEL select 3) then {
					_posidx = _ctrlList lbPosIndex [DLG_VEH_SEL select 1,DLG_VEH_SEL select 2];
				};
			};
		#endif	
			if (DLG_VEH_SELECTED) then {
				_VEHidx=lbValue [DLG_VEH_LIST, _index];
				closeDialog DLG_VEH_IDD;
			};
			if (_posidx == -1) then {
				_posidx = _index;
			};
			if (_lstpos != _posidx) then {
				_lbidx = lbValue [DLG_VEH_LIST, _posidx];
				_wDName = (_vehicleList select _lbidx) select 1;
				_wPic = (_vehicleList select _lbidx) select 2;
				_wDesc = (_vehicleList select _lbidx) select 3;
				_ctrlPic ctrlSetText _wPic;
				_ctrlName ctrlSetText _wDName;
				_ctrlDesc ctrlSetStructuredText parseText (_wDesc);
				_lstpos=_posidx;
			};
			sleep 0.1;
		};
	if (_lstidx == _index) exitWith {};
	_VEHsel=(_vehicleList select _VEHidx) select 0;

	if (isnil "ghst_vehsel") exitwith {_caller groupchat "Nothing Spawned";};
	if (ghst_vehsel != "none" && DLG_VEH_SELECTED) then {
	_veh_name = getText (configFile >> "cfgVehicles" >> (_vehsel) >> "displayName");
	//_spawnpos = _spawn findEmptyPosition[ 2 , 10 , _vehsel ];
	//if (isnil "_spawnpos" or count _spawnpos < 2) exitwith {_caller groupchat "Spawn Pad not clear";};
	_padempty = nearestObjects [_spawn, ["LandVehicle","Air"], _check_radius];
	if (count _padempty > 0) exitwith {titleText "Spawn Pad not clear";};
	_veh1 = createVehicle [_vehsel,_spawn, [], 0, "NONE"];
	_veh1 setdir _dir;
	_veh1 setposatl [_spawn select 0, _spawn select 1, 0.1];
	_veh1 setvelocity [0,0,0];
	_veh1 setVectorUP (surfaceNormal [(getPosatl _veh1) select 0,(getPosatl _veh1) select 1]);
	if !(_vehsel iskindof "Slingload_01_Base_F") then {
		ghst_local_vehicles pushback _veh1;
	};
	
	//_veh1 addEventHandler ["killed", {_this execvm "scripts\ghst_vehdelete.sqf"}];
	[_veh1, "ColorGrey", _veh_name] spawn ghst_fnc_tracker;
	//cutText [Format ["%1 Spawned", _veh_name],"PLAIN",2];
	//hint format ["%1 Spawned", _veh_name];
	titleText [format ["%1 Spawned", _veh_name], "PLAIN DOWN"]; titleFadeOut 5;
} else {titleText ["Nothing Spawned", "PLAIN DOWN"];};

 

 

Gives autopilot functionality to every air vehicle at mission start automatically

Gives loiter (Pylon Turn) functionality to every fixed-wing at mission start automatically

For spawned airplanes and helicopters autopilot functionality should be given via following command

 [this] spawn DEVAS_AutoPilot;
  • For spawned airplanes loiter functionality should be given via following command

  • [this] spawn DEVAS_Loiter;

Share this post


Link to post
Share on other sites

Easy just add those call via script inside the object init after respawn. Which vehicle respawn are u using ?

Sent from my SM-G930T using Tapatalk

Share this post


Link to post
Share on other sites

Well since there's only one line with createVehicle it's obvious where to put it:

 

/*
V2.3 Script by: Ghost (Original dialog from Kronzky) create a marker and name itand put this in the object initline - ghst_spawnveh = station1 addAction ["Spawn Vehicle", "spawn ghst_fnc_spawnair", ["spawnmarker",dir], 6, true, true, "","alive _target"];
*/

#include "def_VEHsel.hpp"

_host = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_paramarray = _this select 3;
_spawn = _paramarray select 0;
_dir = _paramarray select 1;
_spawn = getmarkerpos _spawn;
_check_radius = 10;//radius for vehicle spawn pad check and delete

if (not alive _host) exitwith {
hint "Vehicle Spawn Closed";

_host removeaction _id;
};

if (isnil "ghst_aircraftlist") exitwith {hint "Spawn list not ready yet";};
_vehiclelist = ghst_aircraftlist;
_PARAM_PlayerVehicles = "PARAM_PlayerVehicles" call BIS_fnc_getParamValue;

{if (count crew _x == 0) then {deletevehicle _x};} foreach (nearestObjects [_spawn, ["AllVehicles"], _check_radius]);
{deletevehicle _x;} foreach (nearestObjects [_spawn, ["Slingload_01_Base_F","USAF_MOABdisplay"], _check_radius]);
{deletevehicle _x;} foreach nearestObjects [_spawn,["CraterLong_small","CraterLong","WeaponHolder","GroundWeaponHolder"], _check_radius];

{if (!(alive _x) or (! canmove _x and count crew _x == 0)) then {
	deletevehicle _x;
	ghst_local_vehicles = ghst_local_vehicles - [_x];
};} foreach ghst_local_vehicles;

if (count ghst_local_vehicles == _PARAM_PlayerVehicles) exitwith {hint format ["You can only spawn %1 vehicles", _PARAM_PlayerVehicles];};

#ifndef VBS
 disableSerialization;
#endif

// fill dialog with vehicle names
createDialog "Selectvehicle";
sleep 0.1;
_ctrlList = findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_LIST;

private ["_index","_lstidx","_lstpos""_i"];

for "_i" from 0 to (count _vehicleList)-1 do {
	_vehicle = _vehicleList select _i;
	lbAdd [DLG_VEH_LIST,format["%1",_vehicle select 1]];
	lbSetPicture [DLG_VEH_LIST, _i, _vehicle select 2];
	lbSetValue [DLG_VEH_LIST, _i, _i];
};
lbSort (findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_LIST); 

// put the selection somewhat in the middle of the displayed listing
_index = -1;
_i=(_index -9) max 0;
lbSetCurSel [DLG_VEH_LIST, _i];
lbSetCurSel [DLG_VEH_LIST, _index];

// preview controls
_ctrlPic = findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_PIC;
_ctrlName = findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_NAME;
_ctrlDesc = findDisplay DLG_VEH_IDD displayCtrl DLG_VEH_DESC;

_VEHidx = lbValue [DLG_VEH_LIST, _index];
_lstidx = _index;
_lstpos = -1;
DLG_VEH_SELECTED = false;

		while {ctrlVisible DLG_VEH_LIST} do {
			_index = lbCurSel DLG_VEH_LIST;
			_posidx = _index;
		#ifdef VBS	
			if !(isNil "DLG_VEH_SEL") then {
				if (DLG_VEH_SEL select 3) then {
					_posidx = _ctrlList lbPosIndex [DLG_VEH_SEL select 1,DLG_VEH_SEL select 2];
				};
			};
		#endif	
			if (DLG_VEH_SELECTED) then {
				_VEHidx=lbValue [DLG_VEH_LIST, _index];
				closeDialog DLG_VEH_IDD;
			};
			if (_posidx == -1) then {
				_posidx = _index;
			};
			if (_lstpos != _posidx) then {
				_lbidx = lbValue [DLG_VEH_LIST, _posidx];
				_wDName = (_vehicleList select _lbidx) select 1;
				_wPic = (_vehicleList select _lbidx) select 2;
				_wDesc = (_vehicleList select _lbidx) select 3;
				_ctrlPic ctrlSetText _wPic;
				_ctrlName ctrlSetText _wDName;
				_ctrlDesc ctrlSetStructuredText parseText (_wDesc);
				_lstpos=_posidx;
			};
			sleep 0.1;
		};
	if (_lstidx == _index) exitWith {};
	_VEHsel=(_vehicleList select _VEHidx) select 0;

	if (isnil "ghst_vehsel") exitwith {_caller groupchat "Nothing Spawned";};
	if (ghst_vehsel != "none" && DLG_VEH_SELECTED) then {
	_veh_name = getText (configFile >> "cfgVehicles" >> (_vehsel) >> "displayName");
	//_spawnpos = _spawn findEmptyPosition[ 2 , 10 , _vehsel ];
	//if (isnil "_spawnpos" or count _spawnpos < 2) exitwith {_caller groupchat "Spawn Pad not clear";};
	_padempty = nearestObjects [_spawn, ["LandVehicle","Air"], _check_radius];
	if (count _padempty > 0) exitwith {titleText "Spawn Pad not clear";};
	_veh1 = createVehicle [_vehsel,_spawn, [], 0, "NONE"];
	[_veh1] spawn DEVAS_AutoPilot;
	_veh1 setdir _dir;
	_veh1 setposatl [_spawn select 0, _spawn select 1, 0.1];
	_veh1 setvelocity [0,0,0];
	_veh1 setVectorUP (surfaceNormal [(getPosatl _veh1) select 0,(getPosatl _veh1) select 1]);
	if !(_vehsel iskindof "Slingload_01_Base_F") then {
		ghst_local_vehicles pushback _veh1;
	};
	
	//_veh1 addEventHandler ["killed", {_this execvm "scripts\ghst_vehdelete.sqf"}];
	[_veh1, "ColorGrey", _veh_name] spawn ghst_fnc_tracker;
	//cutText [Format ["%1 Spawned", _veh_name],"PLAIN",2];
	//hint format ["%1 Spawned", _veh_name];
	titleText [format ["%1 Spawned", _veh_name], "PLAIN DOWN"]; titleFadeOut 5;
} else {titleText ["Nothing Spawned", "PLAIN DOWN"];};

Cheers

Share this post


Link to post
Share on other sites

Excellent. Thank you so much.

Share this post


Link to post
Share on other sites

I updated to the newest ghost mission. Ghost is using an fsm to respawn vehicles now and I have been trying to get Devas_Autopilot to work in a Base helo spawn code in the server init. I tried placing after createVehicle but isn't working. It is giving me errors.

 

Thanks for any help.

[this] spawn DEVAS_AutoPilot;
//Spawn Base helicopters
if (true) then {
private ["_helolist","_markarray","_namearray","_air","_marksel","_VarName"];
_helolist = ["B_Heli_Transport_01_camo_F","B_Heli_Transport_03_F"];
_markarray = ["heli_1spawn","heli_2spawn"];
_namearray = ["heli_1","heli_2"];
	{
	_VarName = _namearray select 0;
	_namearray = _namearray - [_VarName];
	_marksel = _markarray select 0;
	_markarray = _markarray - [_marksel];
	_air = createVehicle [_x,(getmarkerpos _marksel), [], 0, "NONE"];
	_air setVehicleVarName _VarName;
	missionNamespace setVariable [_VarName,_air];
	publicVariable _VarName;
	_air setdir (markerdir _marksel);
	_data = [missionNamespace,_air] call BIS_fnc_addRespawnPosition;
	nul = [_air,1,false] execfsm "scripts\ghst_vehrespawn.fsm";
	} foreach _helolist;
};

Error

20:38:37 Error in expression <ipts\ghst_vehrespawn.fsm";
[_air] spawn Devas_AutoPilot;
} foreach _helolist;
};>
20:38:37   Error position: <Devas_AutoPilot;
} foreach _helolist;
};>
20:38:37   Error Undefined variable in expression: devas_autopilot
20:38:37 File C:\Users\Jason Reed\Documents\Arma 3 - Other Profiles\[SA]Reed\mpmissions\SA%20Template%20Tanoa%209%2e1%20Reed.Tanoa\initServer.sqf, line 83
20:38:37 Error in expression <ipts\ghst_vehrespawn.fsm";
[_air] spawn Devas_AutoPilot;
} foreach _helolist;
};>
20:38:37   Error position: <Devas_AutoPilot;
} foreach _helolist;
};>
20:38:37   Error Undefined variable in expression: devas_autopilot
20:38:37 File C:\Users\Jason Reed\Documents\Arma 3 - Other Profiles\[SA]Reed\mpmissions\SA%20Template%20Tanoa%209%2e1%20Reed.Tanoa\initServer.sqf, line 83

Thanks

Share this post


Link to post
Share on other sites

Why not ask @Ghost?

I'm sure he can offer a long term solution.

 

According to your error it seems like the devas function is not initialized at that point.

 

Cheers

Share this post


Link to post
Share on other sites

I have posted on the Ghost thread now. 

Thanks,

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
Sign in to follow this  

×