Guest User

AI Patrols

a guest
May 22nd, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.50 KB | None | 0 0
  1. // =========================================================================================================
  2. // SAR_AI - DayZ AI library
  3. // Version: 1.1.0
  4. // Author: Sarge ([email protected])
  5. //
  6. // Wiki: to come
  7. // Forum: http://opendayz.net/index.php?threads/sarge-ai-framework-public-release.8391/
  8. //
  9. // ---------------------------------------------------------------------------------------------------------
  10. // Required:
  11. // UPSMon
  12. // SHK_pos
  13. //
  14. // ---------------------------------------------------------------------------------------------------------
  15. // SAR_setup_AI_patrol.sqf
  16. // last modified: 1.4.2013
  17. // ---------------------------------------------------------------------------------------------------------
  18. // Parameters:
  19. // [ _patrol_area_name (Markername of area to patrol),
  20. // grouptype (numeric -> 1=military, 2=survivor, 3=bandits),
  21. // number_of_snipers (numeric),
  22. // number of riflemen (numeric),
  23. // number of sidearmonly (numeric),
  24. // behaviour (string -> "patrol", "fortify", "ambush", "noUpsmon")
  25. // respawn (boolean, -> true,false)
  26. // ]
  27. // ------------------------------------------------------------------------------------------------------------
  28.  
  29.  
  30. private ["_leadername","_patrol_area_name","_grouptype","_snipers","_riflemen","_action","_side","_leader_group","_riflemenlist","_sniperlist","_rndpos","_group","_leader","_i","_cond","_respawn","_leader_weapon_names","_leader_items","_leader_tools","_soldier_weapon_names","_soldier_items","_soldier_tools","_sniper_weapon_names","_sniper_items","_sniper_tools","_leaderskills","_riflemanskills","_sniperskills","_ups_para_list"];
  31.  
  32. if(!isServer) exitWith {};
  33.  
  34. _patrol_area_name = _this select 0;
  35. _grouptype = _this select 1;
  36. _snipers = _this select 2;
  37. _riflemen = _this select 3;
  38. _action = _this select 4;
  39. _respawn = _this select 5;
  40.  
  41. switch (_grouptype) do
  42. {
  43. case 1: // military
  44. {
  45. _side = SAR_AI_friendly_side;
  46. _leader_group = SAR_leader_sold_list call BIS_fnc_selectRandom;
  47. _riflemenlist = SAR_soldier_sold_list;
  48. _sniperlist = SAR_sniper_sold_list;
  49.  
  50. _leaderskills = SAR_leader_sold_skills;
  51. _riflemanskills = SAR_soldier_sold_skills;
  52. _sniperskills = SAR_sniper_sold_skills;
  53.  
  54. _leader_weapon_names = ["leader_sold"] call SAR_unit_loadout_weapons;
  55. _leader_items = ["leader_sold"] call SAR_unit_loadout_items;
  56. _leader_tools = ["leader_sold"] call SAR_unit_loadout_tools;
  57.  
  58. _soldier_weapon_names = ["soldier_sold"] call SAR_unit_loadout_weapons;
  59. _soldier_items = ["soldier_sold"] call SAR_unit_loadout_items;
  60. _soldier_tools = ["soldier_sold"] call SAR_unit_loadout_tools;
  61.  
  62. _sniper_weapon_names = ["sniper_sold"] call SAR_unit_loadout_weapons;
  63. _sniper_items = ["sniper_sold"] call SAR_unit_loadout_items;
  64. _sniper_tools = ["sniper_sold"] call SAR_unit_loadout_tools;
  65.  
  66.  
  67.  
  68. };
  69. case 2: // survivors
  70. {
  71. _side = SAR_AI_friendly_side;
  72. _leader_group = SAR_leader_surv_list call BIS_fnc_selectRandom;
  73. _riflemenlist = SAR_soldier_surv_list;
  74. _sniperlist = SAR_sniper_surv_list;
  75.  
  76. _leaderskills = SAR_leader_surv_skills;
  77. _riflemanskills = SAR_soldier_surv_skills;
  78. _sniperskills = SAR_sniper_surv_skills;
  79.  
  80. _leader_weapon_names = ["leader_surv"] call SAR_unit_loadout_weapons;
  81. _leader_items = ["leader_surv"] call SAR_unit_loadout_items;
  82. _leader_tools = ["leader_surv"] call SAR_unit_loadout_tools;
  83.  
  84. _soldier_weapon_names = ["soldier_surv"] call SAR_unit_loadout_weapons;
  85. _soldier_items = ["soldier_surv"] call SAR_unit_loadout_items;
  86. _soldier_tools = ["soldier_surv"] call SAR_unit_loadout_tools;
  87.  
  88. _sniper_weapon_names = ["sniper_surv"] call SAR_unit_loadout_weapons;
  89. _sniper_items = ["sniper_surv"] call SAR_unit_loadout_items;
  90. _sniper_tools = ["sniper_surv"] call SAR_unit_loadout_tools;
  91.  
  92. };
  93. case 3: // bandits
  94. {
  95. _side = SAR_AI_unfriendly_side;
  96. _leader_group = SAR_leader_band_list call BIS_fnc_selectRandom;
  97. _riflemenlist = SAR_soldier_band_list;
  98. _sniperlist = SAR_sniper_band_list;
  99.  
  100. _leaderskills = SAR_leader_band_skills;
  101. _riflemanskills = SAR_soldier_band_skills;
  102. _sniperskills = SAR_sniper_band_skills;
  103.  
  104. _leader_weapon_names = ["leader_band"] call SAR_unit_loadout_weapons;
  105. _leader_items = ["leader_band"] call SAR_unit_loadout_items;
  106. _leader_tools = ["leader_band"] call SAR_unit_loadout_tools;
  107.  
  108. _soldier_weapon_names = ["soldier_band"] call SAR_unit_loadout_weapons;
  109. _soldier_items = ["soldier_band"] call SAR_unit_loadout_items;
  110. _soldier_tools = ["soldier_band"] call SAR_unit_loadout_tools;
  111.  
  112. _sniper_weapon_names = ["sniper_band"] call SAR_unit_loadout_weapons;
  113. _sniper_items = ["sniper_band"] call SAR_unit_loadout_items;
  114. _sniper_tools = ["sniper_band"] call SAR_unit_loadout_tools;
  115. };
  116. };
  117.  
  118.  
  119. // get a random starting position that is on land
  120.  
  121. _rndpos = [_patrol_area_name] call SHK_pos;
  122.  
  123. _group = createGroup _side;
  124.  
  125. // protect group from being deleted by DayZ
  126. _group setVariable ["SAR_protect",true,true];
  127.  
  128. // create leader of the group
  129. _leader = _group createunit [_leader_group, [(_rndpos select 0) + 10, _rndpos select 1, 0], [], 0.5, "FORM"];
  130.  
  131. [_leader,_leader_weapon_names,_leader_items,_leader_tools] call SAR_unit_loadout;
  132.  
  133. _leader setVehicleInit "null = [this] execVM 'addons\SARGE\SAR_trace_entities.sqf';this setIdentity 'id_SAR_sold_lead';";
  134. _leader addMPEventHandler ["MPkilled", {Null = _this execVM "addons\SARGE\SAR_aikilled.sqf";}];
  135. _leader addMPEventHandler ["MPHit", {Null = _this execVM "addons\SARGE\SAR_aihit.sqf";}];
  136.  
  137. _leader addEventHandler ["HandleDamage",{if (_this select 1!="") then {_unit=_this select 0;damage _unit+((_this select 2)-damage _unit)*SAR_leader_health_factor}}];
  138.  
  139. _cond="(side _this == west) && (side _target == resistance) && ('ItemBloodbag' in magazines _this)";
  140.  
  141. [nil,_leader,rADDACTION,"Give me a blood transfusion!", "addons\SARGE\SAR_interact.sqf","",1,true,true,"",_cond] call RE;
  142.  
  143. [_leader] joinSilent _group;
  144.  
  145. // set skills of the leader
  146. {
  147. _leader setskill [_x select 0,(_x select 1 +(floor(random 2) * (_x select 2)))];
  148. } foreach _leaderskills;
  149.  
  150. SAR_leader_number = SAR_leader_number + 1;
  151.  
  152. _leadername = format["SAR_leader_%1",SAR_leader_number];
  153.  
  154. _leader setVehicleVarname _leadername;
  155.  
  156. // SARGE - do i need this name on the clientside ???
  157.  
  158. // create global variable for this group
  159. call compile format ["KRON_UPS_%1=1",_leadername];
  160.  
  161. // if needed broadcast to the clients
  162. //_leader Call Compile Format ["%1=_This ; PublicVariable ""%1""",_leadername];
  163.  
  164. // create crew
  165. for [{_i=0}, {_i < _snipers}, {_i=_i+1}] do
  166. {
  167. _this = _group createunit [_sniperlist call BIS_fnc_selectRandom, [(_rndpos select 0) - 30, _rndpos select 1, 0], [], 0.5, "FORM"];
  168.  
  169. [_this,_sniper_weapon_names,_sniper_items,_sniper_tools] call SAR_unit_loadout;
  170.  
  171. _this setVehicleInit "null = [this] execVM 'addons\SARGE\SAR_trace_entities.sqf';this setIdentity 'id_SAR';";
  172. _this addMPEventHandler ["MPkilled", {Null = _this execVM "addons\SARGE\SAR_aikilled.sqf";}];
  173. _this addMPEventHandler ["MPHit", {Null = _this execVM "addons\SARGE\SAR_aihit.sqf";}];
  174. [_this] joinSilent _group;
  175. // set skills
  176. {
  177. _this setskill [_x select 0,(_x select 1 +(floor(random 2) * (_x select 2)))];
  178. } foreach _sniperskills;
  179.  
  180. };
  181.  
  182. for [{_i=0}, {_i < _riflemen}, {_i=_i+1}] do
  183. {
  184. _this = _group createunit [_riflemenlist call BIS_fnc_selectRandom, [(_rndpos select 0) + 30, _rndpos select 1, 0], [], 0.5, "FORM"];
  185.  
  186. [_this,_soldier_weapon_names,_soldier_items,_soldier_tools] call SAR_unit_loadout;
  187.  
  188. _this setVehicleInit "null = [this] execVM 'addons\SARGE\SAR_trace_entities.sqf';this setIdentity 'id_SAR_sold_man';";
  189. _this addMPEventHandler ["MPkilled", {Null = _this execVM "addons\SARGE\SAR_aikilled.sqf";}];
  190. _this addMPEventHandler ["MPHit", {Null = _this execVM "addons\SARGE\SAR_aihit.sqf";}];
  191. [_this] joinSilent _group;
  192.  
  193. // set skills
  194. {
  195. _this setskill [_x select 0,(_x select 1 +(floor(random 2) * (_x select 2)))];
  196. } foreach _riflemanskills;
  197.  
  198. };
  199.  
  200. _leader = leader _group;
  201.  
  202. // initialize upsmon for the group
  203.  
  204. _ups_para_list = [_leader,_patrol_area_name,'nowait','nofollow','aware','showmarker','delete:',SAR_DELETE_TIMEOUT];
  205.  
  206. if (_respawn) then {
  207. _ups_para_list = _ups_para_list + ['respawn'];
  208. };
  209.  
  210. if(!SAR_AI_STEAL_VEHICLE) then {
  211. _ups_para_list = _ups_para_list + ['noveh'];
  212. };
  213.  
  214. if(SAR_AI_disable_UPSMON_AI) then {
  215. _ups_para_list = _ups_para_list + ['noai'];
  216. };
  217.  
  218.  
  219. if(_action == "") then {_action = "patrol";};
  220.  
  221. switch (_action) do {
  222.  
  223. case "noupsmon":
  224. {
  225. };
  226. case "fortify":
  227. {
  228. _ups_para_list = _ups_para_list + ['fortify'];
  229. _ups_para_list execVM 'addons\UPSMON\scripts\upsmon.sqf';
  230. };
  231. case "fortify2":
  232. {
  233. _ups_para_list = _ups_para_list + ['fortify2'];
  234. _ups_para_list execVM 'addons\UPSMON\scripts\upsmon.sqf';
  235. };
  236. case "patrol":
  237. {
  238. _ups_para_list execVM 'addons\UPSMON\scripts\upsmon.sqf';
  239. };
  240. case "ambush":
  241. {
  242. _ups_para_list = _ups_para_list + ['ambush'];
  243. _ups_para_list execVM 'addons\UPSMON\scripts\upsmon.sqf';
  244. };
  245. };
  246.  
  247.  
  248. processInitCommands;
  249.  
  250. if(SAR_EXTREME_DEBUG) then {
  251. diag_log format["SAR_EXTREME_DEBUG: Infantry group spawned in: %1 with action: %2",_patrol_area_name,_action];
  252. };
  253. _group;
Advertisement
Add Comment
Please, Sign In to add comment