Skip to content

Instantly share code, notes, and snippets.

@Petethegoat
Created March 8, 2014 19:41
Show Gist options
  • Save Petethegoat/9437728 to your computer and use it in GitHub Desktop.
Save Petethegoat/9437728 to your computer and use it in GitHub Desktop.
This is designed for garrisoning AI in buildings, without preventing them from reacting when enemies are too close for their firing positions to be useful- very near to, or inside the building. You can choose to disable reaction if you don't want the additional overhead.
//This is designed for garrisoning AI in buildings, without preventing them from reacting when enemies are too close for their firing positions to be useful- very near to, or inside the building. You can choose to disable reaction if you don't want the additional overhead.
//Usage:
//null = [this, "UP", true] execVM "ptg_garrison.sqf";
//When should garrisoned units check for close enemies? In seconds.
_INTERVAL = 5;
//How close should an enemy be before they abandon their position? In meters.
_RANGE = 8;
//Fake defines so you can just execVM from init.
hint "start";
_unit = _this select 0;
_stance = _this select 1; //"UP" "DOWN" "Middle"
_react = _this select 2; //Should they abandon their positions when enemies are very close?
_unit setUnitPos _stance; //Set their stance
_unit forceSpeed 0; //Prevent them from moving, but let them look around.
if(_react) then
{
hint "react";
_quit = false;
while{!_quit} do
{
sleep _INTERVAL;
_nme = _unit findNearestEnemy _unit;
if(_unit distance _nme < _RANGE) then
{
_unit forceSpeed -1; //Allow movement again.
_quit = true;
hint "out";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment