This repository has been archived by the owner on May 4, 2021. It is now read-only.
/
DZMSAISpawn.sqf
152 lines (118 loc) · 4.41 KB
/
DZMSAISpawn.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* //
DZMSAISpawn.sqf by Vampire
Usage: [position,unitcount,skillLevel] execVM "dir\DZMSAISpawn.sqf";
Position is the coordinates to spawn at [X,Y,Z]
UnitCount is the number of units to spawn
SkillLevel is the skill number defined in DZMSAIConfig.sqf
*/ //
private ["_position","_newPos","_unitcount","_skill","_isStatic","_wpRadius","_xpos","_ypos","_unitGroup","_aiskin","_unit","_weapon","_magazine","_wppos1","_wppos2","_wppos3","_wppos4","_wp1","_wp2","_wp3","_wp4","_wpfin","_unitArrayName","_unitMissionCount"];
_position = _this select 0;
_unitcount = _this select 1;
_skill = _this select 2;
_unitArrayName = _this select 3;
_isStatic = _this select 4;
if (isNil "_isStatic") then {_isStatic = false;};
//diag_log text format ["[DZMS]: AI Pos:%1 / AI UnitNum: %2 / AI SkillLev:%3",_position,_unitcount,_skill];
_wpRadius = 10;
_xpos = _position select 0;
_ypos = _position select 1;
//Create the unit group. We use east by default.
_unitGroup = createGroup east;
//Probably unnecessary, but prevents client AI stacking
if (!isServer) exitWith {};
for "_x" from 1 to _unitcount do {
//Lets pick a skin from the array
_aiskin = DZMSBanditSkins call BIS_fnc_selectRandom;
//Lets spawn the unit
_newPos = _position findEmptyPosition [0,20,(DZMSBanditSkins select 0)];
_unit = _unitGroup createUnit [_aiskin, _newPos, [], 10, "PRIVATE"];
//Make him join the correct team
[_unit] joinSilent _unitGroup;
//Add the behaviour
_unit enableAI "TARGET";
_unit enableAI "AUTOTARGET";
_unit enableAI "MOVE";
_unit enableAI "ANIM";
_unit enableAI "FSM";
_unit setCombatMode "YELLOW";
_unit setBehaviour "SAFE";
//Remove the items he spawns with by default
removeAllWeapons _unit;
removeAllItems _unit;
//Now we need to figure out their loadout, and assign it
//Get the weapon array based on skill
_weaponArray = [_skill] call DZMSGetWeapon;
_weapon = _weaponArray select 0;
_magazine = _weaponArray select 1;
//diag_log text format ["[DZMS]: AI Weapon:%1 / AI Magazine:%2",_weapon,_magazine];
//Get the gear array
_aigearArray = [DZMSGear0,DZMSGear1,DZMSGear2,DZMSGear3,DZMSGear4];
_aigear = _aigearArray call BIS_fnc_selectRandom;
_gearmagazines = _aigear select 0;
_geartools = _aigear select 1;
//Gear the AI backpack
_aipack = DZMSPacklist call BIS_fnc_selectRandom;
//Lets add it to the Unit
for "_i" from 1 to 3 do {
_unit addMagazine _magazine;
};
_unit addWeapon _weapon;
_unit selectWeapon _weapon;
_unit addBackpack _aipack;
if (DZMSUseNVG) then {
_unit addWeapon "NVGoggles";
};
{
_unit addMagazine _x
} forEach _gearmagazines;
{
_unit addWeapon _x
} forEach _geartools;
_aicskill = DZMSSkills1;
//Lets set the skills
switch (_skill) do {
case 0: {_aicskill = DZMSSkills0;};
case 1: {_aicskill = DZMSSkills1;};
case 2: {_aicskill = DZMSSkills2;};
case 3: {_aicskill = DZMSSkills3;};
};
{
_unit setSkill [(_x select 0),(_x select 1)]
} forEach _aicskill;
//Lets prepare the unit for cleanup
_unit addEventHandler ["Killed",{ [(_this select 0), (_this select 1)] ExecVM DZMSAIKilled; }];
_unit setVariable ["DZMSAI", true];
};
//Lets give a launcher if enabled
//The last _unit should still be defined from the FOR above
if (DZMSUseRPG && !_isStatic) then {
_unit addWeapon "RPG7V";
_unit addMagazine "PG7V";
_unit addMagazine "PG7V";
};
// These are 4 waypoints in a NorthSEW around the center
_wppos1 = [_xpos, _ypos+60, 0];
_wppos2 = [_xpos+60, _ypos, 0];
_wppos3 = [_xpos, _ypos-60, 0];
_wppos4 = [_xpos-60, _ypos, 0];
// We add the 4 waypoints
if (!_isStatic) then {
_wp1 = _unitGroup addWaypoint [_wppos1, _wpRadius];
_wp1 setWaypointType "MOVE";
_wp2 = _unitGroup addWaypoint [_wppos2, _wpRadius];
_wp2 setWaypointType "MOVE";
_wp3 = _unitGroup addWaypoint [_wppos3, _wpRadius];
_wp3 setWaypointType "MOVE";
_wp4 = _unitGroup addWaypoint [_wppos4, _wpRadius];
_wp4 setWaypointType "MOVE";
// Then we add a center waypoint that tells them to visit the rest
_wpfin = _unitGroup addWaypoint [[_xpos,_ypos, 0], _wpRadius];
_wpfin setWaypointType "CYCLE";
};
//diag_log text format ["[DZMS]: Spawned %1 AI at %2",_unitcount,_position];
// load the unit groups into a passed array name so they can be cleaned up later
call compile format["
%1 = %1 + (units _unitGroup);
_unitMissionCount = count %1;
",_unitArrayName];
diag_log text format["[DZMS]: (%3) %1 AI Spawned, %2 units in mission.",count (units _unitGroup),_unitMissionCount,_unitArrayName];