Jump to content

HC: Occupy script


horbin

Recommended Posts

Populates an area with civilian humans with little training in fire arms.

Once all humans are killed their cache of goods becomes available for looting.

 

Designed to run on an HC, should be easily adapted to a non-HC environment.

Encounter designed to only be available once per server reset/HC reset (ie no control loop), and could be spawned as an encounter all in itself.

//Occupy.sqf
// Horbin
// 12/17/14
// 
// Requirements:
// 1)spunFin's AI Spawn Script Pack
// http://forums.bistudio.com/showthread.php?165089-AI-Spawn-Script-Pack
// 2) launched from a Headless Client
//   see: http://epochmod.com/forum/index.php?/topic/29541-headless-clientswalkthrough-w-custom-ai-mission-wip-updateddec-10th/
//
// Inputs: "City Name", 2D city position, radius of encounter, city population, "Loot Description", 2D loot location
//  ["Therisa", [10650.1, 12298.4], 200, 34, "Church", [10633.2, 12305.3]] execVM "HC\Occupy.sqf";  
// Blue circle of radius _radius appears on the map.
// area is populated with 'human civilians' that will patrol in and out of buildings
// Once all humans are killed, loot will spawn and associated message provided.

private ["_group","_ogjstr","_unit","_civilian_outfits","_civilian_hats","_center",
			"_radius","_dt","_cityname","_loot_pos","_lootname","_markername","_marker2name",
"_xx","_yy","_position","_population","_distroBoxes","_curUnit","_increment","_sizeDistroBox","_r",
"_modPos","_boxside"];

_cityname = _this select 0;
_center = _this select 1;
_radius = _this select 2;
_population = _this select 3;
_lootname = _this select 4;// descriptive location of where loot will be spawned. This will go into the mission
   // completion message.
_loot_pos = _this select 5;

diag_log format ["##Civilian Occupation Initializing for ##",_cityname];   

_civilian_outfits = ["U_OrestesBody","U_C_Scientist","U_C_Journalist","U_C_WorkerCoveralls",
"U_C_Poor_1","U_C_Poloshirt_redwhite","U_C_Poloshirt_salmon","U_C_Poloshirt_tricolour",
"U_C_Poloshirt_burgundy","U_C_Poloshirt_blue","U_C_Poloshirt_stripped"];
_civilian_hats = ["H_11_EPOCH","H_28_EPOCH","H_34_EPOCH","H_39_EPOCH","H_40_EPOCH"];

_markername = format ["%1_zone",_cityname];
_marker2name = format ["%1_zone_two",_cityname];

//AI Operational Area
AO = createMarker [_markername, _center ];
_markername setMarkerShape "ELLIPSE";
_markername setMarkerSize [_radius,_radius];
_markername setMarkerColor "ColorBlue";
_markername setMarkerAlpha .5;
_markername setMarkerBrush "FDiagonal";
//Solid, Horizontal, Vertical, Grid, FDiagonal, BDiagonal, DiagGrid, Cross
_markername setMarkerAlpha 1;
publicVariable _markername;
AO2 = createMarker [_marker2name, _center];
_marker2name setMarkerType "mil_dot";
_marker2name setMarkerText "Civilian Occupation";
publicVariable _marker2name;

_group = createGroup RESISTANCE; 
//_group setLeader _unit;
// Set Squads ROE and behavior
_group setBehaviour "AWARE";
// "SAFE" - will use roads, groups travel in convoy (overrides formation command), 
//			stance with lowered weapon, turned out from vehicle, lie down when scared, 
//			less turning head, less observing surroundings
// "AWARE" - lie down when scared, sometimes take cover, vehicles prefer roads, travel in convoy
// "COMBAT" -loiter movements cancelled, tends kneel or prone, move to cover, disembark from some vehicles, turns off vehicle lights
// "STEALTH" - faster target acquisition, soldiers move in cover, + "COMBAT"
_group setCombatMode "RED";
// "BLUE" - track hostiles, not fire back
// "YELLOW" - AI will fire on units spoted at effective range, if leader calls target, unit will aim w/o breaking formation
// "RED" - break formation find best place to attack from

// matrix of spawn areas located within the city. Grid is 5x5 with each area sized proportional to the _radius of the encounter
_distroBoxes = [
    [0,0], // center
    [1,0],[0,1],[0,-1],[-1,0],[1,1],[-1,-1],[1,-1],[-1,1],     
    [2,0],[0,2],[-2,0],[0,-2],[2,2],[-2,2],[-2,-2],[2,-2],
    [2,1],[-1,2],[-2,-1],[1,-2],[2,-1],[1,2],[-2,1],[-1,-2] 
];

_curUnit = 0;
_increment = 0;
_sizeDistroBox = count _distroBoxes;

//size of a box that will fit into the encounter radius.
_boxside = sqrt ( _radius * _radius / 2);
// unit spawn radius will be _boxside / 10 when they are created
// 5 boxes per side, centroid in center of each box.
// With [0,0] box in center, centroid of adjacent areas would  be:
_r = _boxside/10*2;

while {_curUnit < _population } do
{
	//get 'grid' modifiers from _distroboxes
    _modPos = _distroBoxes select ( _curUnit - (_sizeDistroBox* _increment) );
	// find center of box to spawn next AI
    _xx = _center select 0;
    _yy = _center select 1;
    _xx = _xx + (_modPos select 0) * _r;
    _yy = _yy + (_modPos select 1) * _r;
    _position = [_xx, _yy];
    // Build AI here, with random offset of 1/10th boxside away from box center (_position)
    _unit = _group createUnit["I_Soldier_EPOCH", _position, [], _boxside/10, "CAN_COLLIDE"];
    removeUniform _unit;
    removeHeadgear _unit;
    removeAllWeapons _unit;
    _unit removeweapon "ItemWatch";
    _unit removeweapon "EpochRadio0";
    _unit removeweapon "ItemCompass";
    _unit removeweapon "ItemMap";
    //_unit addEventHandler ["Killed",{ [(_this select 0), (_this select 1)] ExecVM "HC\AI_Killed.sqf"; }];
    _unit forceAddUniform  (_civilian_outfits call BIS_fnc_selectRandom);
    _unit addVest "V_2_EPOCH";
    _unit addHeadgear (_civilian_hats call BIS_fnc_selectRandom);
    _unit addMagazines ["11Rnd_45ACP_Mag", 3];
    _unit addWeapon "hgun_Pistol_heavy_01_F";
    _unit setSkill 0.4;
    nul = [_unit] execVM "LV\patrol-vG.sqf";      
    
    _curUnit = _curUnit +1;
    if (_curUnit%_sizeDistroBox == 0) then 
    {
        _increment = _increment +1;
    };
}; 

diag_log format ["##HC:Civilian Occupation of %1 complete",_cityname];   

//Mission Completion Triggger
// Create trigger around location.
_dt = createTrigger ["EmptyDetector", _center];
// add 50 to include any AI that may wonder outside their spawn parameters
_dt setTriggerArea [_radius+50, _radius+50, 0, false];
_dt setTriggerActivation ["GUER", "NOT PRESENT", false];

waitUntil {(count list _dt < 1)};
// Wait until all the civilians are dead
deleteVehicle _dt;  
//Loot for mission completion
[2, _loot_pos] execVM "HC\Items.sqf";

_markername setMarkerColor "ColorGreen";
publicVariable _markername;   
_ogjstr = format ["<t align='center' size='2.0'>%1</t><br/>
______________<br/><br/>
The town has been freed from encroaching humans!<br/>
Look in the town %2 for their cache!", _cityname, _lootname];
GlobalHint = _ogjstr;
publicVariable "GlobalHint";

//leave green circle up for 30secs, then remove markers
sleep 30;
_markername setMarkerAlpha 0;
_marker2name setMarkerAlpha 0;
publicVariable _markername;
publicVariable _marker2name;
deleteMarker _markername;
deleteMarker _marker2name;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...