Jump to content
Sign in to follow this  
phronk

Spawned AI With Init

Recommended Posts

I've been trying to get a script to exec on an AI unit when it is spawned in. (I'm using EOS to spawn/despawn)

My question is, how do you execute a script in the init of each spawned AI unit? Example init that I'm trying to get to work:

"setVehicleInit "null = [this] execVM "myScript.sqf";"

or

_unit setVehicleInit {_x setVehicleInit "0 = this execVM "myScript.sqf";"} foreach units _unit; processInitCommands;

Any ideas? I'm stumped. I heard that XEH / CBA has stuff that can help with this, but have no idea how to utilize it, really.

Share this post


Link to post
Share on other sites

Perhaps I'm mis-remembering but was setVehicleInit not removed as a command ? Please ignore me if I'm wrong.

Share this post


Link to post
Share on other sites

It is, or it is not working. Instead of it, just make a call to the script using the variable of created vehicle. _nul = [_unit] execVM "script.sqf"

Share this post


Link to post
Share on other sites

setVehicleInit has been removed from Arma3 for security reasons.

Could you post more of the code that spawns the units.

Share this post


Link to post
Share on other sites

This is an edited "infantry_fnc" from BangaBob's EOS script.

if (!isServer) exitWith {};
// SINGLE INFANTRY GROUP
private ["_grp","_unit","_pool","_pos","_faction"];

_pos=(_this select 0);
_grpSize=(_this select 1);
_faction=(_this select 2);
_side=(_this select 3);

_grpMin=_grpSize select 0;
_grpMax=_grpSize select 1;
_d=_grpMax-_grpMin;				
_r=floor(random _d);							
_grpSize=_r+_grpMin;

if (surfaceiswater _pos) then {_pool=[_faction,1] call eos_fnc_getunitpool;}else{_pool=[_faction,0] call eos_fnc_getunitpool;};

_grp=createGroup _side;

for "_x" from 1 to _grpSize do {					
	_unitType=_pool select (floor(random(count _pool)));
	_unit = _grp createUnit [_unitType, _pos, [], 6, "FORM"];
	_unit removeItem "NVGoggles_OPFOR";
	_unit unassignItem "NVGoggles_OPFOR";
	_unit removeItem "ItemMap";
	_unit unassignItem "ItemMap";
	_unit removeItem "ItemCompass";
	_unit unassignItem "ItemCompass";
	_unit removeItem "ItemWatch";
	_unit unassignItem "ItemWatch";
	null = [this] execVM "MyScriptHere.sqf"; // [color="#FF0000"]This part is the issue![/color]
	_unit allowFleeing 0;
	removeAllWeapons _unit;
	_unit addeventhandler ["killed","(_this select 0) spawn {[_this] call remove_carcass_fnc}"];		
};


_grp

The line null = [this] execVM "MyScriptHere.sqf"; is the command line that is supposed to be inserted in the init of a unit. It works fine if I place a unit and paste that in his init.

Edited by Phronk

Share this post


Link to post
Share on other sites

This has no reference in that context. Try passing _unit instead of this. Also keep in mind you are spawning a new processing thread each time a unit is created with that method. It may be more efficient to add your code to the function instead.

Edited by Jigsor

Share this post


Link to post
Share on other sites

Setting [this] to [_unit] didn't get it to work. :[

[EDIT]

Fixed it. My script had a variable conflicting with EOS and now it's fixed. Thanks guys!

Edited by Phronk

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  

×