Jump to content
smithers282

Script to make AI shoot unarmed "civilian" player if he gets too close

Recommended Posts

Hi everyone!  First thread post so bear with me here for a sec :f:.  

 

Concept of the mission I'm making is the players will be members of American resistance to Russian invasion (a la Red Dawn).  The script I need help crafting will need to set players as "civilians" when they have no weapons in their hands/on their backs so OPFOR won't immediately shoot on sight, yet as soon as they take weapons out, they again are labeled as threats (BLUFOR) and shot at by the OPFOR.  I think I have this part figured out using a script I  found on this forum:  

 

Quote

[
    "checkWeapon",
    "onEachFrame",
    {
        if (currentWeapon player != "") then
        {
            player setCaptive false;
        }
        else
        {
            if (currentWeapon player isEqualTo "") then
            {
                player setCaptive true;
            }
        };
    }
] call BIS_fnc_addStackedEventHandler;

 

This works quite well, however I also want to add on top of this a feature where if a player gets within a certain radius of an OPFOR AI, his status as setCaptive true is switched to setCaptive false so the players in my mission cannot abuse their "civilian" status and go into military installations unimpeded.  This is the part where I seem to be stuck as all my research on forums has come up dry.  

 

I did find austin(medic)'s Combatant Detection script in the compilation thread, but while working flawlessly in SP I am unable to get it to work on my private server.  If anyone has suggestions on how to alter his script to work on a server I would love to hear those as well.

 

Thanks for any help yall can give!  

 

Edited by smithers282
clarification

Share this post


Link to post
Share on other sites

Calling setCaptive on each frame is, imo, stupid. As for your question, it's rather easy no? If you want to check if there is any opfor unit in the vicinity then... check it?

 

while {sleep 1; true} do {
_nearUnits = (nearestObjects [player, ["Man"], 50]) select {side _x == east};
if (currentWeapon player != "" || count _nearUnits > 0) then
        {
            player setCaptive false;
        }
        else
        {
            player setCaptive true;
        };
}

Edit: It still doesn't make much sense since you can holster, run away and just come back like nothing happened. You should implement some persistent cover variable, possibly with a timer or the need to change uniforms.

Share this post


Link to post
Share on other sites

How would I go about adding a variable like that?  I'm relatively new to Arma scripting so trying to learn as much as I can, but adding something that would require a uniform change would fit my needs perfectly.  If someone could point me in the right direction that would be greatly appreciated.  

Share this post


Link to post
Share on other sites

You'll just declare a var holding info of whether your cover is blown or not. Like blown = false. Then when you call player setCaptive false, you also call blown = true and prevent going captive until blown = false. Blown will change to false when you hide for long enough or pick up an uniform.

As for the uniform thing, can you even pick up uniforms in A3? If you can then https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Take would work, if not then you nedd to do it through addAction.

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

×