Jump to content
Sign in to follow this  
carlostex

init line of a spawned unit?

Recommended Posts

OK i have this script:

//AI_Vehicle_Respawn
//Concept and code by =WB=Tex
// put in init line of any vehicle: _null = [this, "markername", number of lives, time until respawn, external script] execVM "script_name.sqf"
// create a new plane after first is dead _x amount of times.

if (!isDedicated) exitwith {};

private ["_veh","_spawnpos","_respawns","_delay","_movescript","_vehicleType","_side","_altitude","_vehicle","_gunner"];

_veh = _this select 0; // this is the vehicle that runs the script.
_spawnpos = _this select 1; // this is the marker where you want it to spawn at.
_respawns = _this select 2; // this is where you get the number of lives (respawns) of the unit.
_delay = _this select 3; // this gets the time until a new unit respawns and other is deleted;
_movescript = _this select 4; // sets execution of script defined in editor unit init
_vehicleType = typeOf _veh; // gets the type of vehicle.
_side = side (driver _veh); // gets the side of vehicle.
_gunner = (gunner _veh);
[_veh] execVM _movescript; //external script execution for editor unit.

_altitude = 0; // default altitude if not Air unit.
if (_veh isKindOf "Air") then {
_altitude = 150; //spawn altitude for Air units.
};

while {canMove _veh} do {
if (fuel _veh < 0.2) then
{_veh setfuel 1};
sleep 1;
};

waitUntil {!alive _veh OR !canMove _veh}; // wait until the placed unit in the editor is destroyed or disabled.
_veh lock true;
sleep _delay; // delayed timer defined in the initialization
deleteVehicle _veh; // deletes the placed editor unit.

while {_respawns != 0} do {
_sv = [[getMarkerPos _spawnpos select 0,getMarkerPos _spawnpos select 1, _altitude], (random 360), _vehicleType, _side] call BIS_fnc_spawnVehicle; // creates a new unit regarding it hasn't ran out of lives.
sleep 1;

_vehicle = _sv select 0; // vehicle spawned
_vehiclegrp = _sv select 2; //vehicle spawned group
[_vehicle] execVM _movescript; // external script execution for respawned unit.

//helo1= _vehicle; // just for testing purposes when using triggers.

while {canMove _vehicle} do {
if (fuel _vehicle < 0.2) then {_vehicle setfuel 1};
sleep 1;
};

waitUntil { !alive _vehicle OR !canMove _vehicle }; // this waits until vehicle is dead (!alive) or vehicle cannot move due to damage.
_vehicle lock true;
_respawns = _respawns - 1; // _x amount respawns is now -1 and will create the plane again in exact same way as first one.
sleep _delay; // this is how long after vehicle is dead before it will respawn.

[_vehicle] spawn {
_vehicle = _this select 0;
sleep _delay;
deleteVehicle _vehicle;
};

};

How can i make the spawned unit run this line:

(group this) setVariable ["CEP_disableCache",true,true];

like if it was put in the init line of an editor placed unit?

in other words i need that the spawned units of this script have this line

(group this) setVariable ["CEP_disableCache",true,true];

in their init like if they were a normal editor unit.

Really need this to solve this, because i use this script on a modified version of the MSO. For the editor placed unit it works fine because i added that line on the editor placed unit for the MSO stop caching the AI inside the vehicles and it works fine, but it keeps caching the spawned vehicles AI because i don't know how to disable the caching for the spawned vehicles.

Really need help!!!

Share this post


Link to post
Share on other sites

make sure _sv is set to private so that it isnt being locally created in that particular instance of spawning.

then:

_grpSpawn = group _sv;
_grpSpawn setVariable ["CEP_disableCache",true,true];

that will set the variable in the namespace of the group, if thats what you want. If you want to add it to all units then:

{(units _x) setVariable ["CEP_disableCache", true, true] foreach (units _grpSpawn)

however, i would avoid using boolean values inside setvariable, every time i have tried to use boolean values inside setvariable and calling them i always was returned with an error about boolean not being supported.

might be best to stick to 0 and 1 for false and true respectfully.

also this might work as well:

_sv setvehicleinit "guy = this";

but im not sure what the return value is for spawn group, it might be the group itself, or the ai leader,

Share this post


Link to post
Share on other sites

Is this right?

//AI_Vehicle_Respawn
//Concept and code by =WB=Tex
// put in init line of any vehicle: _null = [this, "markername", number of lives, time until respawn, external script] execVM "script_name.sqf"
// create a new plane after first is dead _x amount of times.

if (!isDedicated) exitwith {};

private ["_veh","_spawnpos","_respawns","_delay","_movescript","_vehicleType","_side","_sv","_altitude","_vehicle","_gunner"];

_veh = _this select 0; // this is the vehicle that runs the script.
_spawnpos = _this select 1; // this is the marker where you want it to spawn at.
_respawns = _this select 2; // this is where you get the number of lives (respawns) of the unit.
_delay = _this select 3; // this gets the time until a new unit respawns and other is deleted;
_movescript = _this select 4; // sets execution of script defined in editor unit init
_vehicleType = typeOf _veh; // gets the type of vehicle.
_side = side (driver _veh); // gets the side of vehicle.
_gunner = (gunner _veh);
[_veh] execVM _movescript; //external script execution for editor unit.

_altitude = 0; // default altitude if not Air unit.
if (_veh isKindOf "Air") then {
_altitude = 150; //spawn altitude for Air units.
};

while {canMove _veh} do {
if (fuel _veh < 0.2) then
{_veh setfuel 1};
sleep 1;
};

waitUntil {!alive _veh OR !canMove _veh}; // wait until the placed unit in the editor is destroyed or disabled.
_veh lock true;
sleep _delay; // delayed timer defined in the initialization
deleteVehicle _veh; // deletes the placed editor unit.

while {_respawns != 0} do {
_sv = [[getMarkerPos _spawnpos select 0,getMarkerPos _spawnpos select 1, _altitude], (random 360), _vehicleType, _side] call BIS_fnc_spawnVehicle; // creates a new unit regarding it hasn't ran out of lives.
sleep 1;

_grpSpawn = group _sv;
_grpSpawn setVariable ["CEP_disableCache",true,true];

{(units _x) setVariable ["CEP_disableCache", true, true] foreach (units _grpSpawn);

_vehicle = _sv select 0; // vehicle spawned
_vehiclegrp = _sv select 2; //vehicle spawned group
[_vehicle] execVM _movescript; // external script execution for respawned unit.

//helo1= _vehicle; // just for testing purposes when using triggers.

while {canMove _vehicle} do {
if (fuel _vehicle < 0.2) then {_vehicle setfuel 1};
sleep 1;
};

waitUntil { !alive _vehicle OR !canMove _vehicle }; // this waits until vehicle is dead (!alive) or vehicle cannot move due to damage.
_vehicle lock true;
_respawns = _respawns - 1; // _x amount respawns is now -1 and will create the plane again in exact same way as first one.
sleep _delay; // this is how long after vehicle is dead before it will respawn.

[_vehicle] spawn {
_vehicle = _this select 0;
sleep _delay;
deleteVehicle _vehicle;
};

};

Share this post


Link to post
Share on other sites
Return Value:

Array - 0: created vehicle (Object), 1: all crew (Array of Objects), 2: vehicle's group (Group)

_returnValue of BIS_fnc_spawnvehicle.

_grpSpawn = group _sv;

this is wrong, the correct one you have a few lines below, hint: vehiclegrp

Share this post


Link to post
Share on other sites
_returnValue of BIS_fnc_spawnvehicle.

this is wrong, the correct one you have a few lines below, hint: vehiclegrp

ah, didnt check to see if it returns those. good to know.

so my mistake then:

you can just do:

{_x setvariable ["var", 1, true]} foreach units (_sv select 2)

Share this post


Link to post
Share on other sites

I did this after _vehiclegrp:

_vehiclegrp = _sv select 2; //vehicle spawned group
_vehiclegrp setVariable ["CEP_disableCache",true,true];

Could this work?

Share this post


Link to post
Share on other sites

Really need confirmation on this!

I tested it it seems ok! But just need to know if the code itself is doing it.

Share this post


Link to post
Share on other sites

_vehicle = _sv select 0; // vehicle spawned

_vehicle setVehicleInit "(group this) setVariable ['CEP_disableCache',true,true]; null = [this, 'markername', number of lives, time until respawn, external script] execVM 'script_name.sqf'";

processInitCommands;

Of course you need to set the parameters in the respawn script.

Share this post


Link to post
Share on other sites
_vehicle = _sv select 0; // vehicle spawned

_vehicle setVehicleInit "(group this) setVariable ['CEP_disableCache',true,true]; null = [this, 'markername', number of lives, time until respawn, external script] execVM 'script_name.sqf'";

processInitCommands;

Of course you need to set the parameters in the respawn script.

I tried just like this:

_vehicle setVehicleInit "(group this) setVariable ['CEP_disableCache',true,true]; processInitCommands;

because i don't need to call the same script again.

Anyway it doesn't help. The commands do work fine but do nothing on the MSO and the spawned choppers continue to have a very strange behaviour where they spawn without crew inside.

I have never seen something like that. The script works great in every other mission, but not in the MSO. Even disabled the caching module and the same thing happens. Apparently MSO continues to cahe the units somehow, and screws the choppers behaviour.

Share this post


Link to post
Share on other sites
I tried just like this:
_vehicle setVehicleInit "(group this) setVariable ['CEP_disableCache',true,true]; processInitCommands;

because i don't need to call the same script again.

Ahh i didn't read through your script so i thought it were needed to be executed on spawned units aswell.

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  

×