Guest User

initHostageScenario.sqf

a guest
Jul 20th, 2016
1,358
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Made by sixtyfour, 19 July 2016
  2. //-------------------------------
  3.  
  4. //you can configure these two local variables below based on your mission:
  5. _tempHostageList = ["hostage1", "hostage2", "hostage3"];
  6. _tempExtractionZones = ["trg_extractionZone1", "trg_extractionZone2", "trg_extractionZone3"];
  7.  
  8.  
  9.  
  10. //#SERVERSIDE
  11. sv_missionComplete = false; publicVariable "sv_missionComplete";    //will automatically set to true when all hostages are extracted
  12. sv_missionFailed = false; publicVariable "sv_missionFailed";        //will automatically set to true when a hostage is killed
  13.  
  14. sv_hostageGroup = createGroup civilian;
  15. sv_hostageList = []; publicVariable "sv_hostageList";
  16. sv_extractionStatus = [];
  17. sv_extractedHostages = [];
  18.  
  19. sv_extractionZones = [];
  20.  
  21. {   //check whether the given hostage units actually exist
  22.     if (!isNil _x) then { sv_hostageList pushBack (missionNamespace getVariable _x); };
  23. } forEach _tempHostageList;
  24. publicVariable "sv_hostageList";
  25. if (count sv_hostageList <= 0) exitWith
  26. {
  27.     diag_log "ERROR: NO HOSTAGES FOUND IN THIS MISSION! (initHostageScenario.sqf)";
  28. };
  29. {   //now that we have the hostage list, let's assign the initial attributes for each one
  30.     sv_extractionStatus pushBack false;
  31.     [_x] joinSilent sv_hostageGroup;
  32.     _x setVariable ["bCarried", false, true];
  33.     _x switchMove "Acts_AidlPsitMstpSsurWnonDnon01";    //initial animation: sitting down and tied up
  34.     _x disableAI "AUTOCOMBAT";
  35.     _x disableAI "FSM";
  36.     _x disableAI "CHECKVISIBLE";
  37.     _x disableAI "TARGET";
  38.     _x disableAI "PATH";
  39.     _x disableAI "MOVE";
  40.  
  41.     _trg = createTrigger ["EmptyDetector", [0,0,0], false]; //death -> mission failure
  42.     _trg setTriggerActivation ["NONE", "PRESENT", true];
  43.     _trg setTriggerStatements
  44.     [
  45.         "!alive " + vehicleVarName _x,
  46.         "sv_missionFailed = true; publicVariable 'sv_missionFailed';",
  47.         ""
  48.     ];
  49. } forEach sv_hostageList;
  50.  
  51. {   //check whether "trg_extractionZone1", "trg_extractionZone2", or "trg_extractionZone3" exist
  52.     if (!isNil _x) then { sv_extractionZones pushBack (missionNamespace getVariable _x); };
  53. } forEach _tempExtractionZones;
  54. if (count sv_extractionZones <= 0) exitWith
  55. {
  56.     diag_log "ERROR: NO EXTRACTION ZONES FOUND IN THIS MISSION! (initHostageScenario.sqf)";
  57. };
  58. {
  59.     _x setTriggerActivation ["CIV", "PRESENT", true];
  60.     _x setTriggerStatements
  61.     [
  62.         "this && {!(_x in sv_extractedHostages)} count thisList > 0",
  63.         "{_x call sxf_fnc_setHostageExtracted;} forEach thisList;",
  64.         ""
  65.     ];
  66. } forEach sv_extractionZones;
  67.  
  68. _trg = createTrigger ["EmptyDetector", [0,0,0], true];  //victory trigger
  69. _trg setTriggerActivation ["NONE", "PRESENT", false];
  70. _trg setTriggerStatements
  71. [
  72.     "{_x} count sv_extractionStatus == count sv_hostageList",
  73.     "sv_missionComplete = true;",
  74.     ""
  75. ];
  76.  
  77.  
  78.  
  79. {   //#CLIENTSIDE (initialization for each player)
  80.     if (hasInterface) then
  81.     {
  82.         {
  83.             player setVariable
  84.             [
  85.                 ("carryAction_" + vehicleVarName _x),
  86.                 _x addAction
  87.                 [
  88.                     "Carry the hostage",
  89.                     {
  90.                         params ["_theHostage", "_thePlayer", "_actionID", "_args"];
  91.                        
  92.                         _bCarried = _theHostage getVariable "bCarried";
  93.                         if (_bCarried) then
  94.                         {   //drop the hostage     
  95.                             _thePlayer disableCollisionWith _theHostage;
  96.                             _thePlayer switchMove "";
  97.                             _theHostage playMove "Acts_PercMstpSlowWrflDnon_handup2";
  98.                             sleep 0.1;
  99.                             _theHostage switchMove "Acts_AidlPsitMstpSsurWnonDnon01";
  100.                             detach _theHostage;
  101.                             _thePlayer enableCollisionWith _theHostage;
  102.                        
  103.                             _theHostage setUserActionText [_actionID, "Carry the hostage"];
  104.                             _theHostage setVariable ["bCarried", !_bCarried, true];
  105.                         }
  106.                         else
  107.                         {   //make sure the player can only carry one hostage at a time
  108.                             if (count attachedObjects _thePlayer <= 0) then
  109.                             {   //carry the hostage
  110.                                 _position = [0,-.1,-1.2];
  111.                                 _direction = (getDir _thePlayer) + 180;
  112.  
  113.                                 _thePlayer switchMove "AcinPercMstpSnonWnonDnon";
  114.                                 _theHostage playMove "AinjPfalMstpSnonWnonDf_carried_dead";
  115.                                 sleep 0.1;
  116.                                 _theHostage switchMove "AinjPfalMstpSnonWnonDf_carried_dead";
  117.                                 _theHostage attachTo [_thePlayer, _position, "LeftShoulder"];
  118.                            
  119.                                 _theHostage setUserActionText [_actionID, "Drop the hostage"];
  120.                                 _theHostage setVariable ["bCarried", !_bCarried, true];
  121.                             };
  122.                         };
  123.                     },
  124.                     [],
  125.                     6,
  126.                     true,
  127.                     true,
  128.                     "",
  129.                     "(count attachedObjects _this <= 0)  || { (count attachedObjects _this) > 0 && {_target in (attachedObjects _this)} }",
  130.                     2.75,
  131.                     false
  132.                 ]
  133.             ];
  134.         } forEach sv_hostageList;
  135.     };
  136. } remoteExecCall ["bis_fnc_call"];
  137.  
  138.  
  139.  
  140. sxf_fnc_setHostageExtracted =
  141. {   //this function requires a single hostage unit reference (ex: hostage1 call sxf_fnc_setHostageExtracted)
  142.     _temp = sv_hostageList find _this;
  143.     if (_temp != -1) then
  144.     {
  145.         if ( !(sv_extractionStatus select _temp) ) then
  146.         {
  147.             sv_extractionStatus set [_temp, true];
  148.             sv_extractedHostages pushBack _this;
  149.         };
  150.     }
  151.     else
  152.     {
  153.         diag_log "ERROR: sxf_fnc_setHostageExtracted INVALID ARGUMENT (initHostageScenario.sqf)";
  154.     };
  155. };
  156.  
  157.  
  158.  
  159. //end of file
  160. diag_log "initHostageScenario.sqf loaded successfully!";
RAW Paste Data