ArmaMan360 94 Posted November 21, 2015 Ok by default, I want my ai mates to spawn with a loadout script and unlimited reloads like so: this addeventhandler ["Fired",{if (_this select 1=="Strela") then {_this select 0 addMagazine (_this select 5)}}]; null = [this] execVM "loadout.sqf"; Which works amazing. But, I want them to have these 2 scripts run again when they respawn, that is with the same custom layout and the ability to have unlimited reloads. WIKI isnt helping. Will the following code suffice? I mean the Fired eventhandler will still execute automatically even at his respawn? : this addeventhandler ["Fired",{if (_this select 1=="Strela") then {_this select 0 addMagazine (_this select 5)}}]; this addeventhandler ["respawn","_this execVM 'loadout.sqf'"]; Thank you. :) Share this post Link to post Share on other sites
davidoss 552 Posted November 21, 2015 How you are respawning AI units? Share this post Link to post Share on other sites
ArmaMan360 94 Posted November 21, 2015 How you are respawning AI units?Through a fantastic script called AI Respawn System a.k.a. AIRS... as I only play SP.Please suggest any better way to execute all these things together.. :) Share this post Link to post Share on other sites
R3vo 2654 Posted November 21, 2015 Why change it, looks fine to me. Is there a particular problem you have? Share this post Link to post Share on other sites
ArmaMan360 94 Posted November 21, 2015 No man. I am still to try it. I just made the script up by combining these snippets through various forums. If you feel its ok R3vo i'll try it tonight :) EDIT: Ok so its not working. He spawns with the custom loadout, but he respawns with the defaultkit. Here is the new init: null = [this] execVM "loadout.sqf"; this addeventhandler ["Fired",{if (_this select 1=="Strela") then {_this select 0 addMagazine (_this select 5)}}]; nul = [this,["east","DEFEND"],0,"original",5] execVM "AIRS\addAIgroupToPool.sqf"; << respawn script this addeventhandler ["respawn","this execVM 'loadout.sqf'"]; Share this post Link to post Share on other sites
Larrow 2823 Posted November 21, 2015 AIRS does not respawn units. It monitors units and when they are dead creates new ones of the same kind. So adding eventhandlers to the units will have no effect on any new units it creates. Open AIRespawnInit.sqf and add the following lines.. line 4 private["_defaultCleanUp","_diag"]; AIRS_respawn_init = { //Add from here <<<<<<<< private[ "_loadoutScript", "_unit", "_nul" ]; params[ "_group" ]; _loadoutScript = _group getVariable [ "loadoutScript", [] ]; { _unit = _x; { switch ( typeName _x ) do { case ( typeName "" ) : { _nul = _unit execVM _x; }; case ( typeName {} ) : { _nul = _unit spawn _x; }; }; }forEach _loadoutScript; }forEach units _group; }; //To here <<<<<<<<< AIRS_respawn_delay = 25;Open up addAIgroupToPool.sqf and add the following lines..line 23 _air = if(count _this > 5)then{_this select 5}else{false}; _loadoutScript = param[ 6, [], [ [] ] ]; //Add this <<<<<< _classnames = [];line 42 _grp setVariable ["air", _air]; _grp setVariable [ "loadoutScript", _loadoutScript ]; //Add this <<<<< _grp call AIRS_respawn_init; //Add this <<<<<< if(isNil("_azi"))then{_azi = (random 360)};Then in spawnGroup.sqfline 60 deleteGroup _grp; _group call AIRS_respawn_init; //Add this <<<<< _lifes = _group getVariable "lifes";Then your init will look like nul = [this,["east","DEFEND"],0,"original",5,[ "loadout.sqf", { _this addeventhandler ["Fired",{if (_this select 1=="Strela") then {_this select 0 addMagazine (_this select 5)}}]; } ]] execVM "AIRS\addAIgroupToPool.sqf";The new array at the end of the call to addAIgroupToPool can takea reference to a file to run on each new unit as a STRING e.g "loadout.sqf" some code to run where _this is a reference to the unit as in _this addEventHandler You can fill the array with as many file names or code as you like.Untested but should do as a quick fix. Let me know if you have any problems. 1 Share this post Link to post Share on other sites
ArmaMan360 94 Posted November 22, 2015 Wow Larrow, thank you such a detailed explanation. But sadly it is not working. Still a "new" soldier is spawned. :( AIRespawnInit.sqf //AIrespawnInit 1.0 by SPUn if(!isServer)exitWith{}; private["_defaultCleanUp","_diag"]; AIRS_respawn_init = { //Add from here <<<<<<<< private[ "_loadoutScript", "_unit", "_nul" ]; params[ "_group" ]; _loadoutScript = _group getVariable [ "loadoutScript", [] ]; { _unit = _x; { switch ( typeName _x ) do { case ( typeName "" ) : { _nul = _unit execVM _x; }; case ( typeName {} ) : { _nul = _unit spawn _x; }; }; }forEach _loadoutScript; }forEach units _group; }; //To here <<<<<<<<< AIRS_respawn_delay = 25; //AI respawn delay (if not defined in squad leaders init) _defaultCleanUp = true; //cleanUp script [WIP] (removes corpses & wrecks > 300m of player(s) every 60 secs) _diag = false; //if true, script hints live unit amount statistics during editor testing, helps you to adjust group amounts & sizes better) //You can set respawning off side related by changing these variables from your mission: AIRS_respawn_WEST = true; //respawn WEST groups AIRS_respawn_EAST = true; //respawn EAST groups AIRS_respawn_INDE = true; //respawn INDEPENDENT groups //Just to make sure it's safe to spawn units WESTcenter = createCenter west; EASTcenter = createCenter east; INDEcenter = createCenter resistance; //Prepare some AIRS functions AIRS_SpawnGroup = compile preprocessFile "AIRS\spawnGroup.sqf"; AIRS_StartTask = compile preprocessFile "AIRS\startAItask.sqf"; AIRS_buildingPatrol = compile preprocessFile "AIRS\buildingPatrol.sqf"; AIRS_taskPatrol = compile preprocessFile "AIRS\BIS_fnc_taskpatrol2.sqf"; AIRS_taskDefend = compile preprocessFile "AIRS\BIS_fnc_taskdefend2.sqf"; AIRS_fnc_spawnVehicle = compile preprocessFile "AIRS\BIS_fnc_spawnVehicle2.sqf"; AIRS_fnc_spawnGroup = compile preprocessFile "AIRS\BIS_fnc_spawnGroup2.sqf"; AIRS_DestroyEmptyVehicle = compile preprocessFile "AIRS\destroyEmptyVehicle.sqf"; //Start monitoring AI groups execVM "AIRS\monitorAIgroups.sqf"; //Prepare some LV functions LV_GetPlayers = compile preprocessFile "LV\LV_functions\LV_fnc_getPlayers.sqf"; LV_NearestBuilding = compile preprocessFile "LV\LV_functions\LV_fnc_nearestBuilding.sqf"; LV_RemoveDead = compile preprocessFile "LV\LV_functions\LV_fnc_removeDead.sqf"; LV_VehicleInit = compile preprocessFile "LV\LV_functions\LV_fnc_vehicleInit.sqf"; LV_Follow = compile preprocessFile "LV\LV_functions\LV_fnc_follow.sqf"; LV_InMarker = compile preprocessFile "LV\LV_functions\LV_fnc_isInMarker.sqf"; //Cleanup: if(_defaultCleanUp)then{execVM "AIRS\cleanUp.sqf"}; if(_diag)then{execVM "AIRS\diag.sqf"}; AIRS_Initialized = true; addAIgroupToPool.sqf if(!isServer)exitWith{}; waitUntil{!isNil("AIRS_Initialized")}; private["_grp","_classnames","_lifes","_task","_base","_delay","_vehicles","_air","_azi"]; _grp = group (_this select 0); _task = if(count _this > 1)then{_this select 1}else{nil}; _lifes = if(count _this > 2)then{_this select 2}else{0}; _base = if(count _this > 3)then{_this select 3}else{nil}; _delay = if(count _this > 4)then{_this select 4}else{AIRS_respawn_delay}; _air = if(count _this > 5)then{_this select 5}else{false}; _loadoutScript = param[ 6, [], [ [] ] ]; //Add this <<<<<< _classnames = []; _vehicles = []; { if(vehicle _x != _x)then{ if(_x == (driver (vehicle _x)))then{ _classnames set[(count _classnames),(typeOf (vehicle _x))]; }; if(!((vehicle _x) in _vehicles))then{_vehicles set[(count _vehicles),(vehicle _x)]}; _azi = direction (vehicle _x); }else{ _classnames set[(count _classnames),(typeOf _x)]; }; }forEach units _grp; _grp setVariable ["classnames", _classnames]; _grp setVariable ["lifes", _lifes]; _grp setVariable ["state", "alive"]; _grp setVariable ["delay", _delay]; _grp setVariable ["air", _air]; _grp setVariable [ "loadoutScript", _loadoutScript ]; //Add this <<<<< _grp call AIRS_respawn_init; //Add this <<<<<< if(isNil("_azi"))then{_azi = (random 360)}; _grp setVariable ["azi", _azi]; if(!isNil("_base"))then{ if(_base == "original")then{ _grp setVariable ["base", (getPos (leader _grp))]; }else{ _grp setVariable ["base", _base]; }; }; if(!isNil("_task"))then{_grp setVariable ["task", _task]; [_grp] call AIRS_StartTask;}; { [_x] spawn AIRS_DestroyEmptyVehicle }forEach _vehicles; spawnGroup.sqf //spawnGroup 1.0 by SPUn if(!isServer)exitWith{}; private ["_array","_faction","_group","_side","_base","_grp","_tempGrp","_lifes","_setBase","_task","_delay","_air","_azi","_basePos"]; _array = _this select 0; _faction = _this select 1; _group = _this select 2; _group setVariable ["state", "spawning"]; _delay = _group getVariable "delay"; sleep _delay; switch(_faction)do{ case "BLU_F":{ _side = west; }; case "BLU_G_F":{ _side = west; }; case "OPF_F":{ _side = east; }; default { _side = resistance; }; }; if((_side == west)&&(!AIRS_respawn_WEST))exitWith{}; if((_side == east)&&(!AIRS_respawn_EAST))exitWith{}; if((_side == resistance)&&(!AIRS_respawn_INDE))exitWith{}; _setBase = _group getVariable "base"; if(isNil("_setBase"))then{ if(_side == resistance)then{ _base = "respawn_guerrila"; }else{ _base = "respawn_" + (str _side); }; _basePos = getMarkerPos _base; }else{ if((typeName _setBase) == "ARRAY")then{ if((_setBase select 0) in allMapMarkers)then{ _base = _setBase call BIS_fnc_selectRandom; _basePos = getMarkerPos _base; }else{ _basePos = _setBase; }; }else{ _basePos = getMarkerPos _setBase; }; }; _air = _group getVariable "air"; _azi = _group getVariable "azi"; _grp = [_basePos, _side, _array,nil,nil,nil,nil,nil,_azi,_air] call AIRS_fnc_spawnGroup; _tempGrp = []; { _tempGrp set[(count _tempGrp),_x] }forEach units _grp; _tempGrp joinSilent _group; deleteGroup _grp; _group call AIRS_respawn_init; //Add this <<<<< _lifes = _group getVariable "lifes"; if(_lifes > 0)then{ if(_lifes > 1)then{ _lifes = _lifes - 1; _group setVariable ["lifes", _lifes]; }else{ _group setVariable ["classnames", nil]; _group setVariable ["lifes", nil]; _group setVariable ["task", nil]; _group setVariable ["base", nil]; _group setVariable ["state", nil]; _group setVariable ["delay", nil]; _group setVariable ["air", nil]; _group setVariable ["azi", nil]; }; }; _group setVariable ["state", "alive"]; _task = _group getVariable "task"; if(!isNil("_task"))then{ [_group] call AIRS_StartTask; }; unit init line null = [this] execVM "loadout.sqf"; nul = [this,["east","DEFEND"],0,"original",5,[ "loadout.sqf", { _this addeventhandler ["Fired",{if (_this select 1=="Strela") then {_this select 0 addMagazine (_this select 5)}}]; } ]] execVM "AIRS\addAIgroupToPool.sqf"; :( Share this post Link to post Share on other sites
Larrow 2823 Posted November 22, 2015 Sorry thats my fault i just copied and paste your original init script and placed the new array on the end not realising you had left out the air parameter as you where not using it.Just add the missing param e.g nul = [this,["east","DEFEND"],0,"original",5,false,[ "loadout.sqf", { _this addeventhandler ["Fired",{if (_this select 1=="Strela") then {_this select 0 addMagazine (_this select 5)}}]; } ]] execVM "AIRS\addAIgroupToPool.sqf"; Notice the false after 5. You should no longer need to do anything else in your init as the changes made automatically run the passed file/code on the initial unit aswell as further spawns. This line in AIRespawnInit.sqf also needs to be changed... case ( typeName "" ) : { _nul = _unit execVM _x; }; to look like.. case ( typeName "" ) : { _nul = [ _unit ] execVM _x; }; Just to make sure your unit is passed correctly (as an ARRAY) to your loadout script. Still untested, recovering from a harddrive crash atm :/, once its finished ill run up arma and make sure ive not made any mistakes. Let me know how it goes. Share this post Link to post Share on other sites
ArmaMan360 94 Posted November 22, 2015 Just to make sure your unit is passed correctly (as an ARRAY) to your loadout script. Still untested, recovering from a harddrive crash atm :/, once its finished ill run up arma and make sure ive not made any mistakes. Let me know how it goes. Dear Sir Mr. Larrow !! You are my herooo !! :D How could you generate such a behemoth of a script without testing ?? I am thoroughly impressed. Would love to get some scripting lessons from you man sometime. Allow me to buy you a fine dinner some day :) I see you are a very senior member of the arma community. I Salute you Sir :) Share this post Link to post Share on other sites
ArmaMan360 94 Posted November 22, 2015 One more thing please. In my mission I have included a cleanup script as in-built: .... // remove mans/vehicles/air/static "optional" {if (!(isplayer _x)) then {deleteVehicle _x;};} foreach nearestobjects [_sidepos,[ "air","StaticWeapon","Landvehicle" ],900]; sleep 10; {if (!(isplayer _x)) then {deleteVehicle _x;};} foreach nearestobjects [_sidepos,[ "man" ],900]; ... However this does not delete the weapons with the corpses and also deletes even my teammates. Now I want it to clean just units from west side and have a single line for all the object types "man, air, landvehicle,staticweapon" rather than 2 diffferent lines as above. This is not working: _sidepos = getMarkerPos "m1"; sleep 30; {if (!(isplayer _x) && {side _x isEqualTo west}) then {deleteVehicle _x;};} foreach nearestobjects [_sidepos,[ "man","air","StaticWeapon","Landvehicle" ],900]; Any help would be appreciated. Share this post Link to post Share on other sites
barbolani 198 Posted November 22, 2015 For the weapon issue: This are the params you need: ["WeaponHolderSimulated", "GroundWeaponHolder", "WeaponHolder"] For the other. My suggestion is: make an array with the nearestobjects content and then: { if ((side _x == WEST) and (!isPlayer (leader _x)) then {deleteVehicle _x}; } forEach _array; 1 Share this post Link to post Share on other sites