Advertisement
Guest User

Untitled

a guest
Oct 1st, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.39 KB | None | 0 0
  1. /*
  2.  
  3.     Script for crudely simulating guerilla type missions.
  4.     Author: Magirot
  5.  
  6.  
  7.     Installation:
  8.  
  9.     1. Save the script into your mission folder (as followCaptive.sqf, for example)
  10.  
  11.     2. Take a look at the settings (at least the first one, fc_hostile_sides)
  12.  
  13.     3. The player unit should be blufor/opfor/independent.
  14.        You could, for example, group a civilian player to a higher-ranking AI unit,
  15.        and then set this combatant side AI's probability of presence slider to zero.
  16.  
  17.     4. Execute the script for the players you want it to apply,
  18.        for example in initPlayerLocal.sqf:
  19.  
  20.         [] execVM "followCaptive.sqf";
  21.  
  22. */
  23.  
  24. ///////////////////////////////////////////////////////////////////////////////////
  25. // Settings
  26. ///////////////////////////////////////////////////////////////////////////////////
  27.  
  28. // Which sides monitor players. Separated by comma
  29. // Example:
  30. //   fc_hostile_sides = [opfor, independent];
  31. fc_hostile_sides = [opfor];
  32.  
  33.  
  34. // How well the enemy has to "know" a player unit before it's counted as spotted. Value between 0.00 and 4.00
  35. // More info at the end of the page: https://community.bistudio.com/wiki/knowsAbout
  36. fc_count_as_spotted = 2.4;
  37.  
  38. // After knowsAbout has fallen below fc_count_as_spotted value, how many seconds until the unarmed player is counted as friendly
  39. fc_forget_time = 60;
  40.  
  41.  
  42. // Names of "restricted area" triggers where spotted players become hostile even if they're unarmed.
  43. // The trigger settings should be "Anybody Present" and "Repeatedly"
  44. // Example:
  45. //  fc_restricted_areas = [restrictedTrigger1, restrictedTrigger2];
  46. fc_restricted_areas = [];
  47.  
  48.  
  49. // Names of "restricted vehicles" which instantly make you hostile if you're in them.
  50. // Example:
  51. //  fc_restricted_vehicles = [armedOffroad1, strider1];
  52. fc_restricted_vehicles = [];
  53.  
  54. // Does getting in a vehicle other than a civilian vehicle automatically make the player hostile?
  55. fc_restrict_faction_vehicles = FALSE;
  56.  
  57.  
  58. // Allow driving off road. If disabled, getting spotted while not driving on a road will make you hostile.
  59. // Note that only roads shown on the textureless map count as roads, bridges have small sections which don't count as roads, and simply parking off the road can become dangerous.
  60. fc_allow_driving_off_road = TRUE;
  61.  
  62. // Triggers where you can drive off-road, to be used if fc_allow_driving_off_road is FALSE. Useful for cities/bridges.
  63. // The trigger settings should be "Anybody Present" and "Repeatedly"
  64. // Example:
  65. //  fc_safe_driving_areas = [safeArea1, safeArea2];
  66. fc_safe_driving_areas = [];
  67.  
  68.  
  69. // Messages
  70. fc_msg_notice_restricted_area = "It feels like you've gained unwanted attention.";
  71. fc_msg_weapon_equipped        = "You're making yourself a hostile!";
  72. fc_msg_hostile_timeout        = "You should be fine now.";
  73.  
  74. ///////////////////////////////////////////////////////////////////////////////////
  75. // Settings end
  76. ///////////////////////////////////////////////////////////////////////////////////
  77.  
  78.  
  79. // no need to execute for a dedicated server
  80. if (isDedicated) exitWith {};
  81.  
  82.  
  83. // Declare some variables for monitoring captive state
  84. fc_noticed_time  = 0 - fc_forget_time;
  85. fc_getting_timed = FALSE;
  86.  
  87.  
  88.  
  89.  
  90. // Function for checking if the player's vehicle isn't a civilian vehicle
  91. fc_check_is_faction_vehicle = {
  92.  
  93.     // declare private variables
  94.     private ["_isFactionVehicle", "_vehicle"];
  95.  
  96.     _isFactionVehicle = FALSE;
  97.  
  98.     _vehicle = _this select 0;
  99.  
  100.     // only check if faction vehicles are restricted
  101.     if (fc_restrict_faction_vehicles) then {
  102.  
  103.         // only check if player is in a vehicle
  104.         if (_vehicle != player) then {
  105.  
  106.             // check the vehicle faction from config entry corresponding to the classname
  107.             if (getText (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "faction") != "CIV_F") exitWith {
  108.                 _isFactionVehicle = TRUE;
  109.             };
  110.         };
  111.     };
  112.  
  113.     _isFactionVehicle
  114. };
  115.  
  116. // function that removes captive status and then follows when to give it back again
  117. fc_handle_captive = {
  118.  
  119.     // declare private variable
  120.     private "_msg";
  121.  
  122.     // _msg defines which info message to show
  123.     _msg = [_this, 0, ""] call BIS_fnc_param;
  124.  
  125.     // only set up a timer if there's none already
  126.     if (!fc_getting_timed) then    {
  127.  
  128.         fc_getting_timed = TRUE;
  129.  
  130.         player setCaptive FALSE;
  131.  
  132.         hint _msg;
  133.  
  134.         [] spawn {
  135.  
  136.             // wait until enough time has passed and the player has gotten rid of anything branding them
  137.             waitUntil {
  138.                 sleep 1;
  139.                 ((fc_noticed_time + fc_forget_time) < time &&
  140.                   primaryWeapon   player == "" &&
  141.                   secondaryWeapon player == "" &&
  142.                   handgunWeapon   player == "" &&
  143.                   !(vehicle player in fc_restricted_vehicles) &&
  144.                   !([vehicle player] call fc_check_is_faction_vehicle)
  145.                 )
  146.             };
  147.  
  148.             fc_getting_timed = FALSE;
  149.  
  150.             player setCaptive TRUE;
  151.             hint fc_msg_hostile_timeout;
  152.         };
  153.     };
  154. };
  155. // functions defined
  156.  
  157.  
  158. // Just in case the script was executed somewhere where player is still null
  159. waitUntil {player == player};
  160.  
  161.  
  162. // set player as captive from the onset
  163. player setCaptive TRUE;
  164.  
  165.  
  166. // first loop monitoring when enemy side(s) notice(s) the player
  167. [] spawn {
  168.     while {TRUE} do {
  169.  
  170.         { // forEach block start
  171.  
  172.             if (_x knowsAbout vehicle player >= fc_count_as_spotted) then {
  173.                 fc_noticed_time = time;
  174.  
  175.                 if (!fc_allow_driving_off_road) then {
  176.                     if (vehicle player != player) then {
  177.                         if (!isOnRoad getPos vehicle player) then {
  178.  
  179.                             private "_fc_inSafeZone";
  180.                             _fc_inSafeZone = FALSE;
  181.  
  182.                             {
  183.                                 if (vehicle player in list _x) then { _fc_inSafeZone = TRUE };
  184.                             } forEach fc_safe_driving_areas;
  185.  
  186.                             if (!(_fc_inSafeZone) && captive player) then {
  187.                                 [fc_msg_notice_restricted_area] spawn fc_handle_captive;
  188.                             };
  189.                         };
  190.                     };
  191.                 };
  192.  
  193.                 if (count fc_restricted_areas > 0) then {
  194.  
  195.                     private "_fc_inRestricted";
  196.                     _fc_inRestricted = FALSE;
  197.  
  198.                     {
  199.                         if (vehicle player in list _x) then { _fc_inRestricted = TRUE };
  200.                     } forEach fc_restricted_areas;
  201.  
  202.                     if (_fc_inRestricted && captive player) then {
  203.                         [fc_msg_notice_restricted_area] spawn fc_handle_captive;
  204.                     };
  205.                 };
  206.             };
  207.  
  208.         } forEach fc_hostile_sides;
  209.  
  210.         sleep 3;
  211.     };
  212. };
  213.  
  214. // second loop for monitoring when the player equips a weapon or gets in the wrong vehicle
  215. [] spawn {
  216.     while {TRUE} do {
  217.         waitUntil {
  218.             sleep 2;
  219.             primaryWeapon   player != "" ||
  220.             secondaryWeapon player != "" ||
  221.             handgunWeapon   player != "" ||
  222.             vehicle player in fc_restricted_vehicles ||
  223.             [vehicle player] call fc_check_is_faction_vehicle
  224.         };
  225.  
  226.         [fc_msg_weapon_equipped] spawn fc_handle_captive;
  227.  
  228.         waitUntil {sleep 2; captive player};
  229.     };
  230. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement