Jump to content
Sign in to follow this  
Gilson

Making enemy AI passive to players until they pick up a primary weapon

Recommended Posts

I've come to a complete loss; I have little to no scripting experience in any medium, however myself and a couple of people have managed to mangle this together:

Init:

waitUntil {!isNil primaryWeapon this}; [this] exec "WeaponCaptive.sqf";

weaponCaptive.sqf:

(_this select 0) setCaptive true; waitUntil {isNil primaryWeapon this}; [this] exec "NoWeaponCaptive.sqf"

noweaponCaptive.sqf:

(_this select 0) setCaptive false; waitUntil {!isNil primaryWeapon this}; [this] exec "WeaponCaptive.sqf"

What is supposed to be happening is unit(s) start with the initial state of being setCaptive true, so enemy AI do not react to them, then once they've picked up a gun their state becomes setCaptive false, then if they drop their weapon they return to the initial state of setCaptive true. The snippets above give undefined errors on both the 'this' within the {}'s and the exec part. Looking for some assistance - absolutely anything will be welcome.

Share this post


Link to post
Share on other sites
I've come to a complete loss; I have little to no scripting experience in any medium, however myself and a couple of people have managed to mangle this together:

One or two bad things there - you can't wait in a vehicle init.

I have tested this - seems to work perfectly:

Unit init:

removeAllWeapons this; this setCaptive true; nul = [this] execVM "WeaponCaptive.sqf";

private ["_unit"];
_unit = _this select 0;
while {true} do {
if (primaryWeapon _unit != "") then {
_unit setCaptive false;
} else {
_unit setCaptive true;
};
sleep 1;
};

for testing:

Add a weapon to a unit with a radio trigger:

{unitName addMagazine "30Rnd_556x45_Stanag"} forEach [1,2,3]; unitName addWeapon "M4A1";

Place a weapon on the ground that you can pick up then drop (put this in the init of a traffic cone) you can also make a unit pick up this with the 6 key menu:

wpnhld1 = "WeaponHolder" createVehicle (position player); wpnhld1 addWeaponCargoGlobal ["M4A1",1]; wpnhld1 addMagazineCargoGlobal ["30Rnd_556x45_Stanag",5];

Edited by PELHAM

Share this post


Link to post
Share on other sites

It works perfectly and is exactly what I needed. Many thanks for your help and work.

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  

×