Jump to content
Sign in to follow this  
austin_medic

Spawned AI Refuse all commands?

Recommended Posts

Just trying to make a basic checkpoint system that spawned civs will drive through, everything works except for the fact that the AI that I spawn through scripts refuse any and all scripting commands, checking through debug console it seems all AI behaviour is enabled, simulation enabled, etc. But they still just stand there like they're frozen and are just holding an invisible gun (I'm spawning them near cars and trying to put them inside then telling them to drive to CP.

Currently I put all my functions inLine inside a script:

/*List of all variables needed
for cars:
AUSMD_veh_inv
For Units:
AUSMD_arrested
AUSMD_moved
AUSMD_car
AUSMD_wp
AUSMD_beingSearched
*/

startPosC = (getMarkerPos "spawn2");
AUSMD_variables = [["AUSMD_arrested",false,true],["AUSMD_moved",false,true],["AUSMD_car",objNull,true],["AUSMD_wp",[0,0,0],true]];

AUSMD_createCarClient =
{
_startPos = _this select 0;
_cpPos = _this select 1;
_endPos = _this select 2;
_inventory = [];
if(isMultiplayer) then
{
	_inventory = _this select 3;
};
//_vehicle = _this select 4;
//_unit = _this select 5;

_unit = "C_man_1_1_F" createVehicle startPosC;

sleep 0.1;
_vehicle = "C_Offroad_01_F" createVehicle _startPos;
_unit moveinDriver _vehicle;
_unit allowDamage true;

{
	_unit setVariable _x;
} forEach AUSMD_variables;

_unit setVariable["AUSMD_car",_vehicle,true];
_unit setVariable["AUSMD_wp",_endPos,true];

if(!isMultiplayer) then
{
	_inventory = [];
	_item = (["Batteries","A water Bottle","A Bomb","A MX Rifle","A Katiba Rifle", "A porn magazine", "A revolver", "Ciggerettes"]) call BIS_fnc_selectRandom;
	_inventory set[count _inventory,_item];
	_item = (["Batteries","A water Bottle","A Bomb","A MX Rifle","A Katiba Rifle", "A porn magazine", "A revolver", "Ciggerettes"]) call BIS_fnc_selectRandom;
	_inventory set[count _inventory,_item];
	_item = (["Batteries","A water Bottle","A Bomb","A MX Rifle","A Katiba Rifle", "A porn magazine", "A revolver", "Ciggerettes"]) call BIS_fnc_selectRandom;
	_inventory set[count _inventory,_item];
};

_vehicle setVariable["AUSMD_veh_inv",_inventory,true];

_unit doMove _cpPos;

_vehicle;
};



AUSMD_anim =
{
_unit = _this select 0;
_anim = _this select 1;
_unit playMoveNow _anim;

sleep 0.5;

_unit enableSimulation false;

_unit setVariable["AUSMD_arrested",true,true];

_unit addEventHandler["Hit",{_unit enableSimulation true; detach _unit; _unit setDamage 1; _unit switchMove "";}];
};

AUSMD_moveCiv =
{
_unit = cursorTarget;

_unit attachTo [player,[0,2,0]];

_unit setVariable["AUSMD_moved",true,true];
};

AUSMD_unmoveCiv =
{
_unit = cursorTarget;

detach _unit;

_unit setVariable["AUSMD_moved",false,true];
};

AUSMD_kickOut =
{
_veh = cursorTarget;
if(!(_veh isKindOf "Car")) exitWith {hint "No vehicle selected.";};
{
	doGetOut _x;

	sleep 0.1;

	_x setUnitPos "UP";

	//_x disableAI "MOVE";

	//_x disableAI "FSM";

	//_x setVariable["AUSMD_beingSearched",true,true];
} forEach crew _veh;
};

AUSMD_freeToGo =
{
_unit = cursorTarget;
if(!(_unit isKindOf "Man") || !alive _unit) exitWith {hint "Nobody selected.";};

_car = _unit getVariable "AUSMD_car";
if(!alive _car || count crew _car > 0) exitWith {hint "I can't seem to get back into my car... \n\n (it was either destoryed or somebody else is inside it)";};
_x setUnitPos "UP";
_unit enableAI "MOVE";
_unit enableAI "FSM";
_unit moveinDriver _car;
_endWP = _unit getVariable "AUSMD_wp";
waitUntil{driver _car == _unit};
_unit doMove _endWP;
};



AUSMD_interact_veh =
{
_vehicle = cursorTarget;
if(!(_vehicle isKindOf "Car")) exitWith {hint "No vehicle selected.";};
_itemsFound = _vehicle getVariable ["AUSMD_veh_inv",[]];
_itemsFoundStr = "";
{
	if(count _itemsFound == 0) then
	{
		_itemsFoundStr = "Nothing";
	}
	else
	{
		_itemsFoundStr = _itemsFoundStr + format["%1 \n\n",_x];
	};
} forEach _itemsFound;
hint format ["The Following Items were Found \n\n %1",_itemsFoundStr];
};

AUSMD_arrestCiv =
{
_unit = cursorTarget;
if(!(_unit isKindOf "Man")) exitWith {hint "Nobody selected.";};
[[_unit,"AmovPercMstpSnonWnonDnon_EaseIn"],"AUSMD_anim",true,false,false] spawn BIS_fnc_MP;
};

if(!isMultiplayer) then
{
while{true} do
{
	_veh = [(getMarkerPos "spawn1"),(getMarkerPos "cp"),(getMarkerPos "despawn1")] spawn AUSMD_createCarClient;
	sleep 2;
	waitUntil{isNull _veh};
	sleep 5;
};
};

init.sqf:

[] execVM "AUSMD_functions.sqf";

player addAction ["Search Vehicle",AUSMD_interact_veh,nil,1,False,True,"",' cursorTarget isKindOf "Car" && alive cursorTarget && speed cursorTarget < 1 '];
player addAction ["Arrest Civilian",AUSMD_arrestCiv,nil,1,False,True,"",' cursorTarget isKindOf "Man" && alive cursorTarget && !(cursorTarget getVariable "AUSMD_arrested") '];
player addAction ["Move Civilian",AUSMD_moveCiv,nil,1,False,True,"",' cursorTarget isKindOf "Man" && alive cursorTarget && cursorTarget getVariable "AUSMD_arrested" '];
player addAction ["Stop Moving Civilian",AUSMD_unmoveCiv,nil,1,False,True,"",' cursorTarget isKindOf "Man" && alive cursorTarget && cursorTarget getVariable "AUSMD_moved" '];
player addAction ["Pull Civilian Out",AUSMD_pullCiv,nil,1,False,True,"",' cursorTarget isKindOf "Car" && alive cursorTarget && count crew cursortarget > 0 '];

Share this post


Link to post
Share on other sites

Are you running the latest development branch version by any chance? I have noticed spawned AI not moving, when spawned inside buildings, but haven't had time to do a fine comb analysis.

-k

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  

×