Advertisement
capyg0zt

GTA 5 Partial Source Code

May 28th, 2023
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 398.69 KB | None | 0 0
  1. // gta source partial
  2. #include "fwanimation/animmanager.h"
  3. #include "fwanimation/directorcomponentsyncedscene.h"
  4. #include "fwscene/stores/networkdefstore.h"
  5. #include "fwscene/stores/framefilterdictionarystore.h"
  6. #include "script/commands_task.h"
  7. #include "script/wrapper.h"
  8. #include "script/thread.h"
  9. //Game headers
  10. #include "ai/debug/system/AIDebugLogManager.h"
  11. #include "animation/AnimDefines.h"
  12. #include "animation/Move.h"
  13. #include "control/WaypointRecording.h"
  14. #include "control/replay/replay.h"
  15. #include "event/EventShocking.h"
  16. #include "event/EventWeapon.h"
  17. #include "event/ShockingEvents.h"
  18. #include "game/ModelIndices.h"
  19. #include "math/angmath.h"
  20. #include "network/NetworkInterface.h"
  21. #include "network/Events/NetworkEventTypes.h"
  22. #include "peds/PedFactory.h"
  23. #include "peds/PedHelmetComponent.h"
  24. #include "peds/PedIntelligence.h"
  25. #include "peds/Pedpopulation.h"
  26. #include "peds/PedTaskRecord.h"
  27. #include "peds/Ped.h"
  28. #include "peds/WildlifeManager.h"
  29. #include "physics/WorldProbe/worldprobe.h"
  30. #include "physics/RagdollConstraints.h"
  31. #include "pickups/Pickup.h"
  32. #include "pickups/PickupPlacement.h"
  33. #include "scene/world/GameWorld.h"
  34. #include "fwpheffects/ropemanager.h"
  35. #include "fwscene/search/SearchVolumes.h"
  36. #include "script/Handlers/GameScriptEntity.h"
  37. #include "script/Handlers/GameScriptResources.h"
  38. #include "script/Handlers/GameScriptMgr.h"
  39. #include "script/scrchannel.h"
  40. #include "script/script.h"
  41. #include "script/script_cars_and_peds.h"
  42. #include "script/script_helper.h"
  43. #include "script/ScriptTaskTypes.h"
  44. #include "script/commands_waypoint.h"
  45. #include "script/commands_entity.h"
  46. #include "streaming/streaming.h"
  47. #include "Task/Animation/TaskMoveScripted.h"
  48. #include "Task/Combat/Cover/Cover.h"
  49. #include "Task/Combat/TaskNewCombat.h"
  50. #include "Task/Combat/Cover/TaskCover.h"
  51. #include "Task/Combat/Cover/TaskSeekCover.h"
  52. #include "Task/Combat/Cover/TaskStayInCover.h"
  53. #include "Task/Combat/Subtasks/TaskDraggingToSafety.h"
  54. #include "Task/Combat/Subtasks/TaskHeliChase.h"
  55. #include "Task/Combat/Subtasks/TaskPlaneChase.h"
  56. #include "Task/Combat/Subtasks/TaskStealth.h"
  57. #include "Task/Combat/Subtasks/TaskVehicleChase.h"
  58. #include "Task/Combat/Subtasks/TaskVehicleCombat.h"
  59. #include "task/Combat/TaskCombat.h"
  60. #include "task/Combat/TaskCombatMelee.h"
  61. #include "Task/Combat/TaskDamageDeath.h"
  62. #include "Task/Combat/TaskInvestigate.h"
  63. #include "Task/Combat/TaskReact.h"
  64. #include "Task/Combat/TaskSearch.h"
  65. #include "Task/Combat/TaskSharkAttack.h"
  66. #include "Task/Combat/TaskThreatResponse.h"
  67. #include "Task/Combat/TaskWrithe.h"
  68. #include "Task/Default/AmbientAnimationManager.h"
  69. #include "Task/Default/Patrol/PatrolRoutes.h"
  70. #include "Task/Default/Patrol/TaskPatrol.h"
  71. #include "Task/Default/TaskArrest.h"
  72. #include "Task/Default/ArrestHelpers.h"
  73. #include "Task/Default/TaskChat.h"
  74. #include "Task/Default/TaskCuffed.h"
  75. #include "Task/Default/TaskPlayer.h"
  76. #include "Task/Default/TaskWander.h"
  77. #include "Task/General/TaskBasic.h"
  78. #include "Task/General/TaskGeneralSweep.h"
  79. #include "Task/General/Phone/TaskMobilePhone.h"
  80. #include "Task/Scenario/info/ScenarioInfoManager.h"
  81. #include "Task/General/TaskSecondary.h"
  82. #include "Task/Motion/Locomotion/TaskMotionPed.h"
  83. #include "Task/Movement/Climbing/TaskGoToAndClimbLadder.h"
  84. #include "Task/Movement/Climbing/TaskRappel.h"
  85. #include "Task/Movement/Jumping/TaskJump.h"
  86. #include "Task/Movement/TaskFall.h"
  87. #include "Task/Movement/TaskSlideToCoord.h"
  88. #include "Task/Movement/TaskCollisionResponse.h"
  89. #include "Task/Movement/TaskFollowWaypointRecording.h"
  90. #include "Task/Movement/TaskGoto.h"
  91. #include "Task/Movement/TaskGoToPointAiming.h"
  92. #include "Task/Movement/TaskMoveFollowEntityOffset.h"
  93. #include "Task/Movement/TaskParachute.h"
  94. #include "Task/Movement/TaskJetpack.h"
  95. #include "Task/Movement/TaskSeekEntity.h"
  96. #include "Task/Physics/TaskAnimatedAttach.h"
  97. #include "Task/Physics/TaskNM.h"
  98. #include "Task/Physics/TaskNMBindPose.h"
  99. #include "Task/Physics/TaskNMElectrocute.h"
  100. #include "Task/Physics/TaskNMDangle.h"
  101. #include "Task/Physics/TaskNMHighFall.h"
  102. #include "Task/Physics/TaskNMSlungOverShoulder.h"
  103. //#include "Task/Physics/TaskNMStumble.h"
  104. #include "Task/Response/TaskAgitated.h"
  105. #include "Task/Response/TaskConfront.h"
  106. #include "Task/Response/TaskFlee.h"
  107. #include "Task/Response/TaskGangs.h"
  108. #include "task/Response/TaskReactAndFlee.h"
  109. #include "Task/Response/TaskShockingEvents.h"
  110. #include "Task/Scenario/Info/ScenarioInfo.h"
  111. #include "Task/Scenario/ScenarioManager.h"
  112. #include "Task/Scenario/ScenarioPointManager.h"
  113. #include "Task/Scenario/Types/TaskParkedVehicleScenario.h"
  114. #include "Task/Scenario/Types/TaskUseScenario.h"
  115. #include "Task/Service/Police/TaskPolicePatrol.h"
  116. #include "Task/Service/Swat/TaskSwat.h"
  117. #include "Task/System/Task.h"
  118. #include "Task/Animation/TaskAnims.h"
  119. #include "Task/Animation/TaskScriptedAnimation.h"
  120. #include "Task/System/TaskManager.h"
  121. #include "Task/Vehicle/TaskCar.h"
  122. #include "Task/Vehicle/TaskCarAccessories.h"
  123. #include "Task/Vehicle/TaskCarUtils.h"
  124. #include "Task/Vehicle/TaskEnterVehicle.h"
  125. #include "Task/Vehicle/TaskExitVehicle.h"
  126. #include "Task/Vehicle/TaskMountAnimal.h"
  127. #include "Task/Vehicle/TaskRideTrain.h"
  128. #include "Task/Vehicle/TaskVehicleWeapon.h"
  129. #include "Task/Weapons/Gun/TaskGun.h"
  130. #include "Task/Weapons/Gun/TaskAimGunScripted.h"
  131. #include "Task/Weapons/Gun/TaskReloadGun.h"
  132. #include "Task/Weapons/Gun/Metadata/ScriptedGunTaskInfo.h"
  133. #include "Task/Weapons/Gun/Metadata/ScriptedGunTaskInfoMetadataMgr.h"
  134. #include "Task/Weapons/Gun/TaskVehicleDriveBy.h"
  135. #include "Task/Weapons/TaskBomb.h"
  136. #include "Task/Weapons/TaskProjectile.h"
  137. #include "Task/Weapons/TaskSwapWeapon.h"
  138. #include "Task/Weapons/WeaponController.h"
  139. #include "debug/DebugScene.h"
  140. #include "vehicleAi/vehicleintelligence.h"
  141. #include "vehicleAi/Task/TaskVehicleGoTo.h"
  142. #include "vehicleAi/Task/TaskVehicleGotoAutomobile.h"
  143. #include "vehicleAi/Task/TaskVehicleGoToHelicopter.h"
  144. #include "vehicleAi/Task/TaskVehicleGoToPlane.h"
  145. #include "vehicleAi/Task/TaskVehicleGoToSubmarine.h"
  146. #include "vehicleAi/Task/TaskVehicleAttack.h"
  147. #include "vehicleAi/Task/TaskVehicleBlock.h"
  148. #include "vehicleAi/Task/TaskVehicleCircle.h"
  149. #include "vehicleAi/Task/TaskVehicleCruise.h"
  150. #include "vehicleAi/Task/TaskVehicleDeadDriver.h"
  151. #include "vehicleAi/Task/TaskVehicleEscort.h"
  152. #include "vehicleAi/Task/TaskVehicleFlying.h"
  153. #include "vehicleAi/Task/TaskVehicleFollowRecording.h"
  154. #include "vehicleAi/Task/TaskVehicleGoToLongRange.h"
  155. #include "vehicleAi/Task/TaskVehicleHeliProtect.h"
  156. #include "vehicleAi/Task/TaskVehiclePark.h"
  157. #include "vehicleAi/Task/TaskVehiclePoliceBehaviour.h"
  158. #include "vehicleAi/Task/TaskVehicleTempAction.h"
  159. #include "vehicleAi/Task/TaskVehicleThreePointTurn.h"
  160. #include "vehicleAi/task/TaskVehicleAnimation.h"
  161. #include "vehicleAi/task/TaskVehiclePursue.h"
  162. #include "vehicleAi/task/TaskVehicleLandPlane.h"
  163. #include "vehicles/Metadata/VehicleEntryPointInfo.h"
  164. #include "vehicles/Planes.h"
  165. #include "Weapons/Info/WeaponInfoManager.h"
  166.  
  167. //Rage headers
  168. #include "script/wrapper.h"
  169.  
  170. SCRIPT_OPTIMISATIONS ()
  171. AI_OPTIMISATIONS()
  172. AI_VEHICLE_OPTIMISATIONS()
  173.  
  174. namespace task_commands
  175. {
  176.     void UpdatePedRagdollBoundsForScriptActivation(CPed* pPed)
  177.     {
  178.         // only need to do this if we're in the viewport, not in ragdoll already and our capsule physics isn't active
  179.         if (pPed && pPed->GetIsVisibleInSomeViewportThisFrame() && !pPed->GetUsingRagdoll())
  180.         {
  181.             pPed->UpdateRagdollRootTransformFromAnimatedSkel();
  182.             pPed->UpdateRagdollBoundsFromAnimatedSkel();
  183.         }  
  184.     }
  185.  
  186.  
  187.     void CommandTaskToggleDuck( int PedIndex, s32 iToggleType )
  188.     {
  189.         if (SCRIPT_VERIFY(CGameConfig::Get().AllowCrouchedMovement(), "TASK_TOGGLE_DUCK - Crouch is disabled" ))
  190.         {
  191.             CTask* pTask = rage_new CTaskCrouchToggle(iToggleType);
  192.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_TOGGLE_DUCK, "TASK_TOGGLE_DUCK");
  193.         }
  194.     }
  195.  
  196.     void CommandTaskPause(int PedIndex, int Time)
  197.     {
  198.         CTask* pTask=rage_new CTaskPause(Time);
  199.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_PAUSE, "TASK_PAUSE");
  200.     }
  201.  
  202.     void CommandTaskStandStill(int PedIndex, int StandStillTime)
  203.     {
  204.         if (SCRIPT_VERIFY((StandStillTime == -1) || (StandStillTime > 0) ,"TASK_STAND_STILL - Time must be -1 for infinite, otherwise > 0" ))
  205.         {
  206.             const int numFramesToRun = 0; // no frame limit
  207.             const bool bMakeMountStandStill = true;
  208.             const bool bEnableTimeslicing = (StandStillTime == -1);
  209.             CTask* pTask = rage_new CTaskDoNothing(StandStillTime, numFramesToRun, bMakeMountStandStill, bEnableTimeslicing);
  210.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_STAND_STILL, "TASK_STAND_STILL");
  211.         }
  212.     }
  213.  
  214.     void CommandTaskJump(int PedIndex, bool UNUSED_PARAM(UsePlayerLaunchForce), bool DoSuperJump, bool UseFullSuperJumpForce)
  215.     {
  216.         s32 nFlags = JF_DisableVault;
  217.  
  218.         if (DoSuperJump)
  219.             nFlags |= JF_SuperJump | JF_BeastJump;
  220.  
  221.         if (UseFullSuperJumpForce)
  222.             nFlags |= JF_AIUseFullForceBeastJump;
  223.  
  224.         CTask* pTask=rage_new CTaskJumpVault(nFlags);
  225.  
  226.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_JUMP, "TASK_JUMP");
  227.     }
  228.  
  229.     void CommandTaskCower(int PedIndex, int Time)
  230.     {
  231.         if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_COWER - Time must be -1 for infinite and > 0" ))
  232.         {
  233.             CTask* pTask=rage_new CTaskCower(Time);
  234.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_COWER, "TASK_COWER");
  235.         }
  236.     }
  237.  
  238.     void CommandTaskHandsUp(int PedIndex, int Time, int PedToFaceIndex, int TimeToFacePed, int Flags)
  239.     {
  240.         if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_HANDS_UP - Time must be -1 for infinite and > 0" ))
  241.         {
  242.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedToFaceIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES_NO_DEAD_CHECK ^ CTheScripts::GUID_ASSERT_FLAG_ENTITY_EXISTS);
  243.             CTask* pTask=rage_new CTaskHandsUp(Time, pPed, TimeToFacePed, Flags);
  244.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_HANDS_UP, "TASK_HANDS_UP");
  245.         }
  246.     }
  247.  
  248.     void CommandUpdateTaskHandsUpDuration(int PedIndex, int Time)
  249.     {
  250.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  251.         if (pPed && pPed->GetPedIntelligence())
  252.         {
  253.             CTaskHandsUp* pTaskHandsUp = static_cast<CTaskHandsUp*>(pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_HANDS_UP));
  254.             if (SCRIPT_VERIFY (pTaskHandsUp, "UPDATE_TASK_HANDS_UP_DURATION - task is not running!"))
  255.             {
  256.                 pTaskHandsUp->SetDuration(Time);
  257.             }
  258.         }
  259.     }
  260.  
  261.     void CommandTaskDuck(int PedIndex, int Time)
  262.     {
  263.         if (SCRIPT_VERIFY(CGameConfig::Get().AllowCrouchedMovement(), "TASK_DUCK - Crouch is disabled" ))
  264.         {
  265.             if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_DUCK - Time must be -1 for infinite and > 0" ))
  266.             {  
  267.                 CTask* pTask;
  268.                
  269.                 if(-1==Time)
  270.                 {
  271.                     pTask=rage_new CTaskCrouch(0);
  272.                 }
  273.                 else
  274.                 {
  275.                     pTask=rage_new CTaskCrouch(Time);
  276.                 }
  277.                 CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_DUCK, "TASK_DUCK");
  278.             }
  279.         }
  280.     }
  281.  
  282.     void ScriptPassengerTask( int iPedID, CVehicle *pVehicle, int iTime, SeatRequestType requestType, int iSeat, int UNUSED_PARAM(EnterStatus), float fMoveBlendRatio, VehicleEnterExitFlags iScriptFlags, fwMvClipSetId overrideClipsetId,  const char* commandName)
  283.     {
  284.         float fTime = (float)iTime;
  285.        
  286.         fTime/=1000.0f;
  287.        
  288.         if( -1==iTime )
  289.         {
  290.             fTime = 0.0f;
  291.         }
  292.         else if( iTime > 0 )
  293.         {
  294.             iScriptFlags.BitSet().Set(CVehicleEnterExitFlags::WarpAfterTime);
  295.         }
  296.  
  297.         // Convert the time into seconds
  298.         CTask* pTask = rage_new CTaskEnterVehicle(pVehicle, requestType, iSeat, iScriptFlags, fTime, fMoveBlendRatio, NULL, overrideClipsetId);
  299.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_ENTER_VEHICLE, commandName);
  300.     }
  301.  
  302.     void ScriptDriverTask( int iPedID, CVehicle *pVehicle, int iTime, int UNUSED_PARAM(EnterStatus), VehicleEnterExitFlags iScriptFlags, float fMoveBlendRatio, fwMvClipSetId overrideClipsetId, const char* commandName)
  303.     {
  304.         s32 seat = pVehicle->GetDriverSeat();
  305.  
  306.         float fTime = (float)iTime;
  307.        
  308.         if( -1==iTime )
  309.         {
  310.             fTime = 0.0f;
  311.         }
  312.         else if( iTime >= 0 )
  313.         {
  314.             iScriptFlags.BitSet().Set(CVehicleEnterExitFlags::WarpAfterTime);
  315.         }
  316.  
  317.         // Convert the time into seconds
  318.         fTime/=1000.0f;
  319.  
  320.         CScriptPeds::GivePedScriptedTask( iPedID, rage_new CTaskEnterVehicle(pVehicle, SR_Specific, seat, iScriptFlags, fTime, fMoveBlendRatio, NULL, overrideClipsetId), SCRIPT_TASK_ENTER_VEHICLE, commandName);
  321.     }
  322.  
  323.     void CommandTaskOpenVehicleDoor( int iPedID, int iVehicleID, int iTime, int iSeat, float fMoveBlendRatio)
  324.     {
  325.         SeatRequestType seatRequestType = SR_Specific;
  326.         s32 iSeatRequest = iSeat+1;
  327.         if( iSeat == -2 )
  328.         {
  329.             seatRequestType = SR_Any;
  330.         }
  331.  
  332.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_OPEN_VEHICLE_DOOR - Time must be -1 for infinite and > 0" ))
  333.         {
  334.             CVehicle *pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  335.             if (pVehicle)
  336.             {  
  337.                 VehicleEnterExitFlags vehicleFlags;
  338.                 vehicleFlags.BitSet().Set(CVehicleEnterExitFlags::JustOpenDoor);
  339.                 if (iSeatRequest != 0)
  340.                 {
  341.                     if (SCRIPT_VERIFY(iSeatRequest < pVehicle->GetSeatManager()->GetMaxSeats(), "TASK_OPEN_VEHICLE_DOOR - seat doesn't exist"))
  342.                     {
  343.                         ScriptPassengerTask(iPedID, pVehicle, iTime, seatRequestType, iSeatRequest, 0, fMoveBlendRatio, vehicleFlags, CLIP_SET_ID_INVALID, "TASK_OPEN_VEHICLE_DOOR");
  344.                     }
  345.                 }
  346.                 else
  347.                 {
  348.                     if (SCRIPT_VERIFY (!pVehicle->GetDriver(), "TASK_OPEN_VEHICLE_DOOR - Vehicle already has a driver"))
  349.                     {
  350.                         ScriptDriverTask(iPedID, pVehicle, iTime, 0, vehicleFlags, fMoveBlendRatio, CLIP_SET_ID_INVALID, "TASK_OPEN_VEHICLE_DOOR");
  351.                     }
  352.                 }
  353.             }
  354.         }
  355.     }
  356.  
  357.  
  358.     void CommandTaskEnterVehicle( int iPedID, int iVehicleID, int iTime, int iSeat, float fMoveBlendRatio, const int iScriptFlags, const char* szOverrideEntryClipsetName )
  359.     {
  360.         VehicleEnterExitFlags iFlags;
  361.         CTaskVehicleFSM::SetScriptedVehicleEntryExitFlags(iFlags, iScriptFlags);
  362.  
  363.         SeatRequestType seatRequestType = SR_Specific;
  364.         s32 iSeatRequest = iSeat+1;
  365.         if( iSeat == -2 )
  366.         {
  367.             seatRequestType = SR_Any;
  368.         }
  369.        
  370.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_ENTER_VEHICLE - Time must be -1 for infinite and > 0" ))
  371.         {
  372.             CVehicle *pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  373.             if (pVehicle)
  374.             {
  375. #if __ASSERT
  376.                 const bool bIsTrailerLarge = MI_TRAILER_TRAILERLARGE.IsValid() && pVehicle->GetModelIndex() == MI_TRAILER_TRAILERLARGE;
  377.                 if (bIsTrailerLarge)
  378.                 {
  379.                     AI_LOG_WITH_ARGS("Ped with index %i is being placed into the trailerlarge from %s", iPedID, CTheScripts::GetCurrentScriptNameAndProgramCounter());
  380.                     AI_LOG_STACK_TRACE(8);
  381.                 }
  382. #endif // __ASSERT
  383.                 fwMvClipSetId overrideClipsetId = CLIP_SET_ID_INVALID;
  384.  
  385.                 //look for an clip set with this name
  386.                 if (szOverrideEntryClipsetName)
  387.                 {
  388.                     if (fwClipSetManager::GetClipSet(fwMvClipSetId(szOverrideEntryClipsetName)))
  389.                     {
  390.                         overrideClipsetId.SetFromString(szOverrideEntryClipsetName);
  391. #if __ASSERT
  392.                         scriptAssertf(fwClipSetManager::IsStreamedIn_DEPRECATED(overrideClipsetId), "TASK_ENTER_VEHICLE - Clip set %s is not loaded yet:", szOverrideEntryClipsetName);
  393. #endif // __ASSERT         
  394.                     }
  395. #if __ASSERT
  396.                     else
  397.                     {
  398.                         scriptAssertf(0, "Couldn't find clipset with name %s", szOverrideEntryClipsetName);
  399.                     }
  400. #endif // __ASSERT
  401.                 }
  402.  
  403.                 if (iSeatRequest != 0)
  404.                 {
  405.                     if (SCRIPT_VERIFY(iSeatRequest < pVehicle->GetSeatManager()->GetMaxSeats(), "TASK_ENTER_VEHICLE - seat doesn't exist"))
  406.                     {
  407.                         ScriptPassengerTask(iPedID, pVehicle, iTime, seatRequestType, iSeatRequest, 0, fMoveBlendRatio, iFlags, overrideClipsetId, "TASK_ENTER_VEHICLE");
  408.                     }
  409.                 }
  410.                 else
  411.                 {
  412.                     // See if the vehicle has a driver already, if they are still running the enter vehicle task then they must be shuffling
  413.                     // so discount them
  414.                     CPed* pDriver = pVehicle->GetDriver();
  415.                     if (pDriver && pDriver->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_ENTER_VEHICLE))
  416.                     {
  417.                         pDriver = NULL;
  418.                     }
  419.  
  420.                     //driver seat
  421.                     if (SCRIPT_VERIFY(!pDriver || (iFlags.BitSet().IsSet(CVehicleEnterExitFlags::JackIfOccupied)), "TASK_ENTER_VEHICLE - Vehicle already has a driver"))
  422.                     {
  423.                         ScriptDriverTask(iPedID, pVehicle, iTime, 0, iFlags, fMoveBlendRatio, overrideClipsetId, "TASK_ENTER_VEHICLE");
  424.                     }
  425.                 }
  426.             }
  427.         }
  428.        
  429.     }
  430.  
  431.     void CommandTaskLeaveVehicle( int iPedID, int iVehicleID, s32 iScriptFlags )
  432.     {
  433.         CVehicle *pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  434.         if (pVehicle)
  435.         {
  436.             VehicleEnterExitFlags vehicleFlags;
  437.             CTaskVehicleFSM::SetScriptedVehicleEntryExitFlags(vehicleFlags, iScriptFlags);
  438.             vehicleFlags.BitSet().Set(CVehicleEnterExitFlags::DontJackAnyone);
  439.             CTask* pTask=rage_new CTaskExitVehicle(pVehicle,vehicleFlags);
  440.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_LEAVE_VEHICLE, "TASK_LEAVE_VEHICLE");
  441.         }  
  442.     }
  443.  
  444.     void CommandTaskVehicleDriveToCoord_Intern( int iPedID, int iVehicleID, const Vector3 &VecCoors_, float CruiseSpeed, int iMode, int UNUSED_PARAM(VehicleModelHashKey), int iDrivingFlags, float TargetRadius, float StraightLineDist)
  445.     {
  446.         Vector3 VecCoors = VecCoors_;
  447.  
  448.         TUNE_GROUP_BOOL(RACING_AI, RACING_actuallyGoFast, false);
  449.         TUNE_GROUP_FLOAT(RACING_AI, RACING_actuallyGoFastSpeed, 50.0f, 0.0, 100.0f, 0.1f);
  450.         if(RACING_actuallyGoFast)
  451.         {
  452.             CruiseSpeed = RACING_actuallyGoFastSpeed;
  453.         }
  454.  
  455.         CTask* pTask = NULL;
  456.         CVehicle *pVehicle = NULL;
  457.  
  458.         pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  459.         if (!pVehicle)
  460.         {
  461.             return;
  462.         }
  463.        
  464.         if (VecCoors.z <= INVALID_MINIMUM_WORLD_Z)
  465.         {
  466.             VecCoors.z = WorldProbe::FindGroundZForCoord(TOP_SURFACE, VecCoors.x, VecCoors.y);
  467.         }
  468.            
  469.         if (StraightLineDist < 0.0f)
  470.         {
  471.             StraightLineDist = sVehicleMissionParams::DEFAULT_SWITCH_TO_STRAIGHT_LINE_DIST;
  472.         }
  473.  
  474.         // The old driving styles are still present in the script headers, until we remove them this will  
  475.         // At least make drivingstyle reversing work.
  476.         if( iMode == 2 )
  477.         {
  478.             iDrivingFlags |= DF_DriveInReverse;
  479.         }
  480.    
  481.         aiTask *pVehicleTask = CVehicleIntelligence::GetGotoTaskForVehicle(pVehicle, NULL, &VecCoors, iDrivingFlags, TargetRadius, StraightLineDist, CruiseSpeed);
  482.         pTask = rage_new CTaskControlVehicle(pVehicle, pVehicleTask );
  483.  
  484.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_DRIVE_TO_COORD, "TASK_VEHICLE_DRIVE_TO_COORD");
  485.     }
  486.  
  487.     void CommandTaskVehicleDriveToCoord( int iPedID, int iVehicleID, const scrVector & scrVecCoors, float CruiseSpeed, int iMode, int VehicleModelHashKey, int iDrivingFlags, float TargetRadius, float StraightLineDist )
  488.     {
  489.         Vector3 VecCoors = Vector3 (scrVecCoors);
  490.  
  491.         CommandTaskVehicleDriveToCoord_Intern( iPedID, iVehicleID, VecCoors, CruiseSpeed, iMode, VehicleModelHashKey, iDrivingFlags, TargetRadius, StraightLineDist );
  492.     }
  493.  
  494.     void CommandTaskVehicleDriveToCoordLongRange(int iPedID, int iVehicleID, const scrVector & scrVecCoors, float CruiseSpeed, int iDrivingFlags, float TargetRadius)
  495.     {
  496.         Vector3 VecCoors = Vector3(scrVecCoors);
  497.  
  498.         CTask* pTask = NULL;
  499.         CVehicle *pVehicle = NULL;
  500.  
  501.         pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  502.         if (!pVehicle)
  503.         {
  504.             return;
  505.         }
  506.  
  507.         if (VecCoors.z <= INVALID_MINIMUM_WORLD_Z)
  508.         {
  509.             VecCoors.z = WorldProbe::FindGroundZForCoord(TOP_SURFACE, VecCoors.x, VecCoors.y);
  510.         }
  511.  
  512.         //aiTask *pVehicleTask = CVehicleIntelligence::GetGotoTaskForVehicle(pVehicle, NULL, &VecCoors, iDrivingFlags, TargetRadius, StraightLineDist, CruiseSpeed);
  513.         sVehicleMissionParams params;
  514.         params.SetTargetPosition(VecCoors);
  515.         params.m_iDrivingFlags = iDrivingFlags;
  516.         params.m_fTargetArriveDist = TargetRadius;
  517.         params.m_fCruiseSpeed = CruiseSpeed;
  518.  
  519.         CTask* pVehicleTask = rage_new CTaskVehicleGotoLongRange(params);
  520.         pTask = rage_new CTaskControlVehicle(pVehicle, pVehicleTask );
  521.  
  522.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, "TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE");
  523.     }
  524.  
  525. #if ENABLE_HORSE
  526.  
  527.     void CommandTaskMountAnimal( int iPedID, int iMountID, int iTime, int iSeat, float fMoveBlendRatio, const int iFlags )
  528.     {
  529.         s32 iSeatRequest = iSeat+1;
  530.  
  531.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_MOUNT_ANIMAL - Time must be -1 for infinite and > 0" ))
  532.         {
  533.             // if this task is being added to a sequence, don't do a clone check on the mount
  534.             unsigned assertFlags = (iPedID == NULL_IN_SCRIPTING_LANGUAGE) ? CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES : CTheScripts::GUID_ASSERT_FLAGS_ALL;
  535.  
  536.             CPed *pMount = CTheScripts::GetEntityToModifyFromGUID<CPed>(iMountID, assertFlags);
  537.             if (pMount)
  538.             {
  539.                 if (iSeatRequest != 0)
  540.                 {
  541.                     scriptAssertf(false, "Non-driver's on mounts not yet supported by TASK_MOUNT_ANIMAL");
  542.                 }
  543.                 else
  544.                 {
  545.                     VehicleEnterExitFlags vehicleFlags;
  546.                     CTaskVehicleFSM::SetScriptedVehicleEntryExitFlags(vehicleFlags, iFlags);
  547.  
  548.                     //driver seat
  549.                     if (SCRIPT_VERIFY(!pMount->GetSeatManager()->GetDriver() || vehicleFlags.BitSet().IsSet(CVehicleEnterExitFlags::JackIfOccupied), "TASK_MOUNT_ANIMAL - Mount already has a driver"))
  550.                     {
  551.                         s32 seat = pMount->GetPedModelInfo()->GetModelSeatInfo()->GetDriverSeat();
  552.    
  553.                         float fTime = (float)iTime;
  554.                         if( -1==iTime )
  555.                         {
  556.                             fTime = 0.0f;
  557.                         }
  558.                         else if( iTime >= 0 )
  559.                         {
  560.                             vehicleFlags.BitSet().Set(CVehicleEnterExitFlags::WarpAfterTime);
  561.                         }
  562.                         // Convert the time into seconds
  563.                         fTime/=1000.0f;
  564.                        
  565.                         CScriptPeds::GivePedScriptedTask( iPedID, rage_new CTaskMountAnimal(pMount, SR_Specific, seat, vehicleFlags, fTime, fMoveBlendRatio), SCRIPT_TASK_MOUNT_ANIMAL, "TASK_MOUNT_ANIMAL");
  566.                     }
  567.                 }
  568.             }
  569.         }
  570.     }
  571.  
  572.     void CommandTaskDismountAnimal( int iPedID, s32 iScriptFlags )
  573.     {
  574.         CPed *pMount = NULL;
  575.         if(iPedID != NULL_IN_SCRIPTING_LANGUAGE) {
  576.             CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  577.             if (pPed)
  578.             {
  579.                 pMount = pPed->GetMyMount();
  580.                 if (!pMount)
  581.                 {
  582.                     return;
  583.                 }              
  584.             }
  585.         }  
  586.  
  587.         VehicleEnterExitFlags vehicleFlags;
  588.         CTaskVehicleFSM::SetScriptedVehicleEntryExitFlags(vehicleFlags, iScriptFlags);
  589.         vehicleFlags.BitSet().Set(CVehicleEnterExitFlags::DontJackAnyone);
  590.         CTask* pTask=rage_new CTaskDismountAnimal(vehicleFlags);
  591.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_DISMOUNT_ANIMAL, "TASK_DISMOUNT_ANIMAL");
  592.     }
  593.  
  594. #else
  595.  
  596.     void CommandTaskMountAnimal( int UNUSED_PARAM(iPedID), int UNUSED_PARAM(iMountID), int UNUSED_PARAM(iTime), int UNUSED_PARAM(iSeat), float UNUSED_PARAM(fMoveBlendRatio), const int UNUSED_PARAM(iFlags) )
  597.     {
  598.     }
  599.  
  600.     void CommandTaskDismountAnimal( int UNUSED_PARAM(iPedID), s32 UNUSED_PARAM(iScriptFlags) )
  601.     {
  602.     }
  603.  
  604. #endif
  605.  
  606.     void CommandTaskVehicleDriveWander( int iPedID, int iVehicleID, float fSpeed, int iDrivingFlags )
  607.     {
  608.         CVehicle *pVehicle = NULL;
  609.         if(iVehicleID != NULL_IN_SCRIPTING_LANGUAGE)
  610.         {
  611.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  612.         }
  613.  
  614.         if (!SCRIPT_VERIFY(pVehicle, "TASK_VEHICLE_DRIVE_WANDER needs a valid vehicle"))
  615.         {
  616.             return;
  617.         }
  618.  
  619.         // cap cruise speed to the maximum
  620.         float fCruiseSpeed = rage::Min(fSpeed, CTaskVehicleMissionBase::MAX_CRUISE_SPEED);
  621.  
  622.         CTask* pTask=rage_new CTaskCarDriveWander(pVehicle, iDrivingFlags, fCruiseSpeed);
  623.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_DRIVE_WANDER, "TASK_VEHICLE_DRIVE_WANDER");
  624.     }
  625.  
  626.     void CommandTaskGoStraightToCoord(int PedIndex, const scrVector &scrVecCoors, float MoveBlendRatio, int Time, const float fTargetHeading, const float fInTargetRadius)
  627.     {
  628.         if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_GO_STRAIGHT_TO_COORD - Time must be -1 for infinite and > 0" ))
  629.         {
  630.             CTask* pTask;
  631.  
  632.             Vector3 vTarget(scrVecCoors);
  633.  
  634.             const float fTargetRadius = fInTargetRadius;//CTaskMoveGoToPointAndStandStill::ms_fTargetRadius;
  635.             const float fSlowDownDistance = CTaskMoveGoToPointAndStandStill::ms_fSlowDownDistance;
  636.             float fMainTaskTimer = 0.0f;
  637.             if(-1==Time)
  638.             {
  639.                 pTask=rage_new CTaskMoveGoToPointAndStandStill(MoveBlendRatio,vTarget,fTargetRadius,fSlowDownDistance,false,true, fTargetHeading<DEFAULT_NAVMESH_FINAL_HEADING ? DtoR * fTargetHeading : fTargetHeading);
  640.             }
  641.             else
  642.             {
  643.                 fMainTaskTimer = (float)Time/1000.0f;
  644.                 if( fMainTaskTimer > 0.0f )
  645.                     fMainTaskTimer += 2.0f;
  646.  
  647.                 int iTime = Max(CTaskComplexGoToPointAndStandStillTimed::ms_iTime, Time);
  648.                 pTask=rage_new CTaskComplexGoToPointAndStandStillTimed(MoveBlendRatio,vTarget,fTargetRadius,fSlowDownDistance, iTime, true, fTargetHeading<DEFAULT_NAVMESH_FINAL_HEADING ? DtoR * fTargetHeading : fTargetHeading);
  649.             }
  650.  
  651.             pTask = rage_new CTaskComplexControlMovement( pTask, NULL, CTaskComplexControlMovement::TerminateOnMovementTask, fMainTaskTimer );
  652.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_GO_STRAIGHT_TO_COORD, "TASK_GO_STRAIGHT_TO_COORD");
  653.         }
  654.     }
  655.  
  656.     void CommandTaskGoStraightToCoordRelativeToEntity(int PedIndex, int EntityIndex, const scrVector & scrVecCoors, float MoveBlendRatio, int Time)
  657.     {
  658.         Vector3 vLocalTarget(scrVecCoors);
  659.         const float fTargetRadius = CTaskMoveGoToPointAndStandStill::ms_fTargetRadius;
  660.        
  661.         if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_GO_STRAIGHT_TO_COORD_RELATIVE_TO_ENTITY - Time must be -1 for infinite and > 0" ))
  662.         {
  663.             const CEntity *pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(EntityIndex);
  664.             if (pEntity)
  665.             {
  666.                 CTaskMoveGoToPointRelativeToEntityAndStandStill * pMoveTask = rage_new CTaskMoveGoToPointRelativeToEntityAndStandStill(
  667.                     pEntity,
  668.                     MoveBlendRatio,
  669.                     vLocalTarget,
  670.                     fTargetRadius,
  671.                     Time
  672.                 );
  673.                
  674.                 CTask * pTask = rage_new CTaskComplexControlMovement( pMoveTask );
  675.                 CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_GO_STRAIGHT_TO_COORD_RELATIVE_TO_ENTITY, "TASK_GO_STRAIGHT_TO_COORD_RELATIVE_TO_ENTITY");
  676.             }
  677.         }
  678.     }
  679.  
  680.     void CommandTaskAchieveHeading(int PedIndex, float fHeadingDegrees, int iTime)
  681.     {
  682.         float fTime;
  683.         if(iTime < 0)
  684.         {
  685.             fTime = -1.0f;
  686.         }
  687.         else if(iTime == 0)
  688.         {
  689.             fTime = 0.0f;
  690.         }
  691.         else
  692.         {
  693.             fTime = ((float)iTime)/1000.0f;
  694.         }
  695.         const float fHeadingRadians=( DtoR * fHeadingDegrees);
  696.         CTask* pTask=rage_new CTaskMoveAchieveHeading(fHeadingRadians, CTaskMoveAchieveHeading::ms_fHeadingChangeRateFrac, CTaskMoveAchieveHeading::ms_fHeadingTolerance, fTime);
  697.         pTask = rage_new CTaskComplexControlMovement( pTask );
  698.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_ACHIEVE_HEADING, "TASK_ACHIEVE_HEADING");
  699.     }
  700.  
  701.     void CommandFlushRoute()
  702.     {
  703.         CTaskMoveFollowPointRoute::ms_pointRoute.Clear();
  704.     }
  705.  
  706.     void CommandExtendRoute(const scrVector & scrVecCoors)
  707.     {
  708.         Vector3 vTarget(scrVecCoors);
  709.         if (CTaskMoveFollowPointRoute::ms_pointRoute.Add(vTarget) == false)
  710.         {
  711.             scriptAssertf(0, "%s:EXTEND_ROUTE - too many points in this route ", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  712.         }
  713.     }
  714.  
  715.     void CommandTaskFollowToOffsetOfEntity(int PedIndex, int EntityIndex, const scrVector & scrVecOffset, float MoveBlendRatio, int Time, float Radius, bool RelativeOffset)
  716.     {
  717.         Vector3 Offset(scrVecOffset);
  718.         const CPhysical* pEntity = CTheScripts::GetEntityToQueryFromGUID<CPhysical>(EntityIndex);
  719.  
  720.         if (pEntity)
  721.         {
  722.             if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_FOLLOW_TO_OFFSET_OF_PED - Time must be -1 for infinite and > 0" ))
  723.             {  
  724.                 CTask* pTask= rage_new CTaskComplexControlMovement(rage_new CTaskMoveFollowEntityOffset(pEntity, MoveBlendRatio, Radius, Offset, Time, RelativeOffset));
  725.                 CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_FOLLOW_TO_OFFSET_OF_ENTITY, "TASK_FOLLOW_TO_OFFSET_OF_ENTITY");
  726.             }
  727.         }
  728.     }
  729.  
  730.  
  731.     void CommandTaskFollowToOffsetOfPickup(int PedIndex, int PickupID, const scrVector & scrVecOffset, float MoveBlendRatio, int Time, float Radius, bool RelativeOffset)
  732.     {
  733.         if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_FOLLOW_TO_OFFSET_OF_PICKUP - Time must be -1 for infinite and > 0" ))
  734.         {
  735.             if (scriptVerify(CTheScripts::GetCurrentGtaScriptHandler()))
  736.             {
  737.                 scriptHandlerObject* pScriptHandlerObject = CTheScripts::GetCurrentGtaScriptHandler()->GetScriptObject(PickupID);
  738.  
  739.                 if (scriptVerifyf(pScriptHandlerObject, "%s: TASK_FOLLOW_TO_OFFSET_OF_PICKUP - failed to find script handler object for pickup ID", CTheScripts::GetCurrentScriptNameAndProgramCounter()))
  740.                 {
  741.                     if (scriptVerifyf(static_cast<CGameScriptHandlerObject*>(pScriptHandlerObject)->GetType() == SCRIPT_HANDLER_OBJECT_TYPE_PICKUP, "%s: TASK_FOLLOW_TO_OFFSET_OF_PICKUP - This is not a pickup id", CTheScripts::GetCurrentScriptNameAndProgramCounter()))
  742.                     {
  743.                         CPickupPlacement* pPlacement = static_cast<CPickupPlacement*>(pScriptHandlerObject);
  744.  
  745.                         if (SCRIPT_VERIFY(pPlacement,"TASK_FOLLOW_TO_OFFSET_OF_PICKUP - Pickup does not exist"))
  746.                         {
  747.                             if (SCRIPT_VERIFY(!pPlacement->GetIsCollected(), "TASK_FOLLOW_TO_OFFSET_OF_PICKUP - pickup has already been collected"))
  748.                             {
  749.                                 if (SCRIPT_VERIFY(!pPlacement->GetHasPickupBeenDestroyed(), "TASK_FOLLOW_TO_OFFSET_OF_PICKUP - pickup has been destroyed"))
  750.                                 {
  751.                                     const CPickup *pPickup = pPlacement->GetPickup();
  752.                                     if (SCRIPT_VERIFY(pPickup, "TASK_FOLLOW_TO_OFFSET_OF_PICKUP - pickup object for this pickup placement is NULL"))
  753.                                     {
  754.                                         Vector3 Offset(scrVecOffset);
  755.                                         CTask* pTask= rage_new CTaskComplexControlMovement(rage_new CTaskMoveFollowEntityOffset(pPickup, MoveBlendRatio, Radius, Offset, Time, RelativeOffset));
  756.                                         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_FOLLOW_TO_OFFSET_OF_PICKUP, "TASK_FOLLOW_TO_OFFSET_OF_PICKUP");
  757.                                     }
  758.                                 }
  759.                             }
  760.                         }
  761.                     }
  762.                 }
  763.             }
  764.         }
  765.     }
  766.  
  767.  
  768.     void CommandTaskFollowPointRoute(int PedIndex, float MoveBlendRatio, int Mode)
  769.     {
  770.         if (SCRIPT_VERIFY (((CTaskMoveFollowPointRoute::TICKET_SINGLE==Mode) ||
  771.         (CTaskMoveFollowPointRoute::TICKET_RETURN==Mode) ||
  772.         (CTaskMoveFollowPointRoute::TICKET_SEASON==Mode) ||
  773.         (CTaskMoveFollowPointRoute::TICKET_LOOP==Mode)),
  774.         "TASK_FOLLOW_POINT_ROUTE - invalid mode"))
  775.         {
  776.             CTask* pTask=rage_new CTaskMoveFollowPointRoute(MoveBlendRatio,CTaskMoveFollowPointRoute::ms_pointRoute,Mode);
  777.             pTask = rage_new CTaskComplexControlMovement( pTask );
  778.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_FOLLOW_POINT_ROUTE, "TASK_FOLLOW_POINT_ROUTE");
  779.         }
  780.     }
  781.  
  782.     // Please keep this in sync with the enumeration in "commands_task.sch"
  783.     enum EGOTO_ENTITY_SCRIPT_FLAGS
  784.     {
  785.         EGOTO_ENTITY_NEVER_SLOW_FOR_PATH_LENGTH = 0x01,
  786.     };
  787.  
  788.     void CommandTaskGoToEntity(int PedIndex, int EntityIndex, int Time, float SeekRadius, float MoveBlendRatio, float fSlowDownDistance, int iFlags)
  789.     {
  790.         const CEntity* pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(EntityIndex);
  791.            
  792.         if (pEntity)
  793.         {
  794.             if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_GOTO_ENTITY - Time must be -1 for infinite and > 0" ))
  795.             {  
  796.                 if (NetworkInterface::IsGameInProgress() && (!pEntity->GetIsDynamic() || !((CDynamicEntity*)pEntity)->GetNetworkObject()))
  797.                 {
  798.                     scriptAssertf(0, "%s:TASK_GOTO_ENTITY; the entity must be networked or this ped will not be able to migrate properly", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  799.                 }
  800.  
  801.                 CTask* pMoveTask=rage_new TTaskMoveSeekEntityStandard(pEntity, Time, TTaskMoveSeekEntityStandard::ms_iPeriod, SeekRadius);
  802.                 ((TTaskMoveSeekEntityStandard*)pMoveTask)->SetMoveBlendRatio(MoveBlendRatio);
  803.                 // scripted seek entity, so we use larger search extents
  804.                 ((TTaskMoveSeekEntityStandard*)pMoveTask)->SetUseLargerSearchExtents(true);
  805.                 ((TTaskMoveSeekEntityStandard*)pMoveTask)->SetUseAdaptiveUpdateFreq(true);
  806.                 ((TTaskMoveSeekEntityStandard*)pMoveTask)->SetSlowDownDistance(fSlowDownDistance);
  807.  
  808.                 if((iFlags & EGOTO_ENTITY_NEVER_SLOW_FOR_PATH_LENGTH)!=0)
  809.                 {
  810.                     ((TTaskMoveSeekEntityStandard*)pMoveTask)->SetNeverSlowDownForPathLength(true);
  811.                 }
  812.  
  813.                 CTask* pTask = rage_new CTaskComplexControlMovement( pMoveTask );
  814.  
  815.                 CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_GO_TO_ENTITY, "TASK_GOTO_ENTITY");
  816.             }
  817.         }
  818.     }
  819.  
  820.     void CommandTaskSmartFleeCoord(int PedIndex, const scrVector & scrVecCoors, float SafeDistance, int Time, bool UNUSED_PARAM(bPreferPavements), bool bQuitIfOutOfRange)
  821.     {
  822.         if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_SMART_FLEE_POINT - Time must be -1 for infinite and > 0" ))
  823.         {
  824.             if (SCRIPT_VERIFY(SafeDistance >= 0.0f ,"TASK_SMART_FLEE_POINT - SafeDistance must be >= 0.0" ))
  825.             {
  826.                 Vector3 vTarget(scrVecCoors);
  827.                 CTaskSmartFlee* pTask = rage_new CTaskSmartFlee(CAITarget(vTarget),SafeDistance,Time);
  828.                 // scripted flee task, so we use larger search extents
  829.                 pTask->SetUseLargerSearchExtents(true);
  830.                 pTask->SetQuitIfOutOfRange(bQuitIfOutOfRange);
  831.  
  832.                 CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_SMART_FLEE_POINT, "TASK_SMART_FLEE_POINT");
  833.             }
  834.         }
  835.     }
  836.  
  837.     void CommandTaskSmartFleePed(int PedIndex, int OtherPedIndex, float SafeDistance, int Time, bool UNUSED_PARAM(bPreferPavements), bool UNUSED_PARAM(bUpdateToNearestHatedPed))
  838.     {
  839.         if (SCRIPT_VERIFY((Time == -1) || (Time > 0) ,"TASK_SMART_FLEE_PED - Time must be -1 for infinite and > 0" ))
  840.         {
  841.             if (SCRIPT_VERIFY(SafeDistance >= 0.0f ,"TASK_SMART_FLEE_PED - SafeDistance must be >= 0.0" ))
  842.             {
  843.                 const CPed* pOtherPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(OtherPedIndex);
  844.                 if (pOtherPed)
  845.                 {              
  846.                     CTaskSmartFlee* pTask = rage_new CTaskSmartFlee(CAITarget(pOtherPed),                           // Target to flee from
  847.                                                             SafeDistance,                                   // Distance to stop at
  848.                                                             Time,                                           // Time to flee for
  849.                                                             CTaskSmartFlee::ms_uiEntityPosCheckPeriod
  850.                                                             0.0f, /*CTaskSmartFlee::ms_fEntityPosChangeThreshold*/
  851.                                                             false);
  852.                    
  853.                     // scripted flee task, so we use larger search extents
  854.                     pTask->SetUseLargerSearchExtents(true);
  855.                     pTask->SetConsiderRunStartForPathLookAhead(true);
  856.  
  857.                     CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_SMART_FLEE_PED, "TASK_SMART_FLEE_PED");
  858.                 }
  859.             }
  860.         }
  861.     }
  862.  
  863.     void CommandTaskReactAndFleeCoord(int PedIndex, const scrVector & scrVecCoors)
  864.     {
  865.         Vector3 vTarget(scrVecCoors);
  866.         CTaskReactAndFlee* pTask = rage_new CTaskReactAndFlee(CAITarget(vTarget), CTaskReactAndFlee::BA_Gunfire);
  867.  
  868.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_REACT_AND_FLEE_COORD, "TASK_REACT_AND_FLEE_COORD");
  869.     }
  870.  
  871.     void CommandTaskReactAndFleePed(int PedIndex, int OtherPedIndex)
  872.     {
  873.         const CPed* pOtherPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(OtherPedIndex);
  874.         if(pOtherPed)
  875.         {
  876.             CTaskReactAndFlee* pTask = rage_new CTaskReactAndFlee(CAITarget(pOtherPed), CTaskReactAndFlee::BA_Gunfire);
  877.  
  878.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_REACT_AND_FLEE_PED, "TASK_REACT_AND_FLEE_PED");
  879.         }
  880.     }
  881.  
  882.     CEventShocking* GetShockingEventFromIDInternal(int EventIndex)
  883.     {
  884.         CEventGroupGlobal& global = *GetEventGlobalGroup();
  885.         int num = global.GetNumEvents();
  886.         for(int j = 0; j < num; j++)
  887.         {
  888.             fwEvent* ev = global.GetEventByIndex(j);
  889.             if(!ev || !static_cast<CEvent*>(ev)->IsShockingEvent())
  890.             {
  891.                 continue;
  892.             }
  893.  
  894.             CEventShocking* pShocking = static_cast<CEventShocking*>(ev);
  895.  
  896.             // Check if we've found the event we're looking for.
  897.             // Note: GetCreatedByScript() is here in case a script-created event timed out by itself,
  898.             // and then a code-created one reused the same ID (which would require a wraparound, so it's
  899.             // unlikely anyway). Since there are currently no commands to give scripts the ID numbers
  900.             // of code-created shocking events, the only valid use of this command is for script-created
  901.             // events.
  902.             if(EventIndex == (int)pShocking->GetId() && pShocking->GetCreatedByScript())
  903.             {
  904.                 return pShocking;
  905.             }
  906.         }
  907.         return NULL;
  908.     }
  909.  
  910.     void CommandTaskShockingEventBackAway(int PedIndex, int EventIndex)
  911.     {
  912.         CEventShocking* pEvent = GetShockingEventFromIDInternal(EventIndex);
  913.  
  914.         if (SCRIPT_VERIFY(pEvent, "Invalid event specified to react to!"))
  915.         {
  916.             const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  917.             if (SCRIPT_VERIFY(pPed, "Invalid PedIndex!"))
  918.             {
  919.                 CTask* pTask = rage_new CTaskShockingEventBackAway(pEvent, CTaskShockingEventBackAway::GetDefaultBackAwayPositionForPed(*pPed));
  920.  
  921.                 CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_SHOCKING_EVENT_BACK_AWAY, "TASK_SHOCKING_EVENT_BACK_AWAY");
  922.             }
  923.         }
  924.     }
  925.  
  926.     void CommandTaskShockingEventHurryAway(int PedIndex, int EventIndex)
  927.     {
  928.         CEventShocking* pEvent = GetShockingEventFromIDInternal(EventIndex);
  929.  
  930.         if (SCRIPT_VERIFY(pEvent, "Invalid event specified to react to!"))
  931.         {
  932.             CTask* pTask = rage_new CTaskShockingEventHurryAway(pEvent);
  933.  
  934.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_SHOCKING_EVENT_HURRY_AWAY, "TASK_SHOCKING_EVENT_HURRY_AWAY");
  935.         }
  936.     }
  937.  
  938.     void CommandTaskShockingEventReact(int PedIndex, int EventIndex)
  939.     {
  940.         CEventShocking* pEvent = GetShockingEventFromIDInternal(EventIndex);
  941.  
  942.         if (SCRIPT_VERIFY(pEvent, "Invalid event specified to react to!"))
  943.         {
  944.             CTask* pTask = rage_new CTaskShockingEventReact(pEvent);
  945.  
  946.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_SHOCKING_EVENT_REACT, "TASK_SHOCKING_EVENT_REACT");
  947.         }
  948.     }
  949.  
  950.     void CommandTaskWanderInArea(int PedIndex, const scrVector & scvCenter, float fRadius, float fMinWaitTime, float fMaxWaitTime)
  951.     {
  952.         if (SCRIPT_VERIFY(fMinWaitTime <= fMaxWaitTime, "MinWaitTime was greater than MaxWaitTime"))
  953.         {
  954.             Vec3V vCenter(scvCenter);
  955.             CTask* pTask = rage_new CTaskWanderInArea(MOVEBLENDRATIO_WALK, fRadius, VEC3V_TO_VECTOR3(vCenter), fMinWaitTime, fMaxWaitTime);
  956.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_WANDER_IN_AREA, "TASK_WANDER_IN_AREA");
  957.         }
  958.     }
  959.    
  960.     void CommandTaskWanderStandard(int PedIndex, float fHeading, int iFlags)
  961.     {
  962.         float fWanderHeading = (IsClose(fHeading, DEFAULT_NAVMESH_FINAL_HEADING, 0.1f) ? fwRandom::GetRandomNumberInRange(0.0f, TWO_PI) : fHeading* DtoR);
  963.         CTaskWander * pTask = rage_new CTaskWander(MOVEBLENDRATIO_WALK, fWanderHeading);
  964.  
  965.         if((iFlags & EWDR_KEEP_MOVING_WHILST_WAITING_FOR_PATH)!=0)
  966.         {
  967.             pTask->KeepMovingWhilstWaitingForFirstPath(NULL);
  968.         }
  969.  
  970.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_WANDER_STANDARD, "TASK_WANDER_STANDARD");
  971.     }
  972.  
  973.     void CommandTaskWanderSpecific(int PedIndex, const char* CondtionalAnimGroupStr, const char* ConditonalAnimStr, float fHeading)
  974.     {
  975.         // Find the conditionalAnimsGroup
  976.         const CConditionalAnimsGroup* pConditionalAnimGroup = CONDITIONALANIMSMGR.GetConditionalAnimsGroup(atHashString(CondtionalAnimGroupStr));
  977.         if (scriptVerifyf(pConditionalAnimGroup, "TASK_WANDER_SPECIFIC called with invalid ConditionalAnimGroup name, (%s)", CondtionalAnimGroupStr))
  978.         {
  979.             // Search for the specified conditionalAnim
  980.             atHashString conditionalAnimHash(ConditonalAnimStr);
  981.             for (int scan = 0; scan < pConditionalAnimGroup->GetNumAnims(); ++scan)
  982.             {
  983.                 const CConditionalAnims* pAnims = pConditionalAnimGroup->GetAnims(scan);
  984.                 if (pAnims && pAnims->GetNameHash() == conditionalAnimHash)
  985.                 {
  986.                     float fWanderHeading = (IsClose(fHeading, DEFAULT_NAVMESH_FINAL_HEADING, 0.1f) ? fwRandom::GetRandomNumberInRange(0.0f, TWO_PI) : fHeading* DtoR);
  987.                     CTask* pTask = rage_new CTaskWander(MOVEBLENDRATIO_WALK, fWanderHeading, pConditionalAnimGroup, scan);
  988.                     CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_WANDER_SPECIFIC, "TASK_WANDER_SPECIFIC");
  989.                     return;
  990.                 }
  991.             }
  992.             // If you get here, we failed to find the specified conditional anim.
  993.             scriptAssertf(0, "TASK_WANDER_SPECIFIC could not find ConditionalAnim name (%s) in ConditionalAnimGroup (%s)", ConditonalAnimStr, CondtionalAnimGroupStr);
  994.         }
  995.     }
  996.  
  997.     void CommandTaskCombat( int iPedID, int iOtherPedID, const int iCombatFlags, const int iThreatResponseFlags )
  998.     {
  999.         // NULL peds are valid since this task can run in a sequence
  1000.         const CPed *pPed = NULL;
  1001.         if(iPedID != NULL_IN_SCRIPTING_LANGUAGE)
  1002.             pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);   
  1003.  
  1004.         const CPed *pSecondPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iOtherPedID); 
  1005.  
  1006.         if (pSecondPed)
  1007.         {
  1008.             SCRIPT_ASSERT((!pPed || !pPed->GetPedIntelligence()->IsFriendlyWith(*pSecondPed)), "TASK_COMBAT_PED - Ped told to attack friendly ped!");
  1009.             SCRIPT_ASSERT(!pSecondPed->GetPedResetFlag(CPED_RESET_FLAG_CannotBeTargeted), "TASK_COMBAT_PED - Ped told to attack ped with flag PRF_CannotBeTargetedByAI!");
  1010.  
  1011.             CTaskThreatResponse* pTask= rage_new CTaskThreatResponse(pSecondPed);
  1012.             pTask->GetConfigFlags().SetAllFlags((u8)iThreatResponseFlags);
  1013.             pTask->GetConfigFlagsForCombat().SetAllFlags(iCombatFlags);
  1014.  
  1015.             CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_COMBAT, "TASK_COMBAT_PED");
  1016.         }
  1017.     }
  1018.  
  1019.  
  1020.     void CommandTaskCombatHatedTargetsInArea( int PedIndex, const scrVector & scvCentre, float Radius, const int iCombatFlags )
  1021.     {
  1022.         if(NetworkInterface::IsGameInProgress())
  1023.         {
  1024.             SCRIPT_ASSERT(Radius < CClonedCombatClosestTargetInAreaInfo::MAX_AREA, "Radius is greater than max allowed (300.0m)");
  1025.             Radius = rage::Clamp( Radius, 0.0f, CClonedCombatClosestTargetInAreaInfo::MAX_AREA );
  1026.         }
  1027.  
  1028.         Vector3 vCentre = scvCentre;
  1029.         CTask* pTask=rage_new CTaskCombatClosestTargetInArea(vCentre,Radius, false, CTaskCombatClosestTargetInArea::INVALID_OVERALL_TIME, iCombatFlags);
  1030.         CScriptPeds::GivePedScriptedTask( PedIndex, pTask, SCRIPT_TASK_COMBAT_HATED_TARGETS_IN_AREA, "TASK_COMBAT_HATED_PED_IN_AREA" );
  1031.     }
  1032.  
  1033.     void CommandTaskCombatHatedTargetsAroundPed( int PedIndex, float Radius, const int iCombatFlags )
  1034.     {
  1035.         if(NetworkInterface::IsGameInProgress())
  1036.         {
  1037.             SCRIPT_ASSERT(Radius < CClonedCombatClosestTargetInAreaInfo::MAX_AREA, "Radius is greater than max allowed (300.0m)");
  1038.             Radius = rage::Clamp( Radius, 0.0f, CClonedCombatClosestTargetInAreaInfo::MAX_AREA );
  1039.         }
  1040.  
  1041.         CTask* pTask=rage_new CTaskCombatClosestTargetInArea(Vector3(0.0f, 0.0f, 0.0f),Radius, true, CTaskCombatClosestTargetInArea::INVALID_OVERALL_TIME, iCombatFlags);
  1042.         CScriptPeds::GivePedScriptedTask( PedIndex, pTask, SCRIPT_TASK_COMBAT_HATED_TARGETS_AROUND_PED, "TASK_COMBAT_HATED_TARGETS_AROUND_PED" );
  1043.     }
  1044.  
  1045.     void CommandTaskCombatHatedTargetsAroundPedTimed( int PedIndex, float Radius, int iTime, const int iCombatFlags )
  1046.     {
  1047.         if(NetworkInterface::IsGameInProgress())
  1048.         {
  1049.             SCRIPT_ASSERT(Radius < CClonedCombatClosestTargetInAreaInfo::MAX_AREA, "Radius is greater than max allowed (300.0m)");
  1050.             Radius = rage::Clamp( Radius, 0.0f, CClonedCombatClosestTargetInAreaInfo::MAX_AREA );
  1051.         }
  1052.  
  1053.         float fTime = ((float) iTime) / 1000.0f ;
  1054.        
  1055.         CTask* pTask=rage_new CTaskCombatClosestTargetInArea(Vector3(0.0f, 0.0f, 0.0f),Radius, true, fTime, iCombatFlags );
  1056.         CScriptPeds::GivePedScriptedTask( PedIndex, pTask, SCRIPT_TASK_COMBAT_HATED_TARGETS_AROUND_PED_TIMED, "TASK_COMBAT_HATED_TARGETS_AROUND_PED_TIMED" );
  1057.     }
  1058.  
  1059.     void CommandTaskCombatTimed( int PedIndex, int iOtherPedID, s32 iTime, const int iFlags )
  1060.     {
  1061.         CPed *pSecondPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iOtherPedID);
  1062.         if (pSecondPed)
  1063.         {
  1064.             if(NULL_IN_SCRIPTING_LANGUAGE!=PedIndex)
  1065.             {
  1066.                 const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  1067.                 if( pPed )
  1068.                 {
  1069.                     if(!SCRIPT_VERIFY(!pPed->GetPedIntelligence()->IsFriendlyWith(*pSecondPed), "TASK_COMBAT_TIMED - Ped told to attack friendly ped!"))
  1070.                         return;    
  1071.                 }
  1072.             }
  1073.            
  1074.             float fTime = ((float) iTime) / 1000.0f ;
  1075.             CTaskThreatResponse* pTask=rage_new CTaskThreatResponse(pSecondPed, fTime);
  1076.             pTask->GetConfigFlags().SetFlag(CTaskThreatResponse::CF_CanFightArmedPedsWhenNotArmed);
  1077.             pTask->GetConfigFlagsForCombat().SetAllFlags(iFlags);
  1078.  
  1079.             CScriptPeds::GivePedScriptedTask( PedIndex, pTask, SCRIPT_TASK_COMBAT_TIMED, "TASK_COMBAT_TIMED" );
  1080.         }
  1081.     }
  1082.  
  1083.     void CommandTaskThrowProjectile( int PedIndex, const scrVector & scrVecTarget, int IgnoreCollisionEntityIndex, bool CreateInvincibleProjectile)
  1084.     {
  1085.         CEntity* pIgnoreCollisionEntity = NULL;
  1086.        
  1087.         if (IgnoreCollisionEntityIndex != NULL_IN_SCRIPTING_LANGUAGE)
  1088.         {
  1089.             pIgnoreCollisionEntity = CTheScripts::GetEntityToModifyFromGUID<CEntity>(IgnoreCollisionEntityIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES_NO_DEAD_CHECK);
  1090.  
  1091. #if __BANK
  1092.             if (!pIgnoreCollisionEntity)
  1093.             {
  1094.                 scriptAssertf(0,"TASK_THROW_PROJECTILE - IgnoreCollisionEntityIndex is not null (%i), but could not find the entity in the world!", IgnoreCollisionEntityIndex);
  1095.             }
  1096. #endif
  1097.         }
  1098.  
  1099.         // Create vectors needed for getting the start position, trajectory, velocity.
  1100.         CTaskAimAndThrowProjectile* pTask = rage_new CTaskAimAndThrowProjectile( CWeaponTarget( scrVecTarget ), pIgnoreCollisionEntity, CreateInvincibleProjectile );      
  1101.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_THROW_PROJECTILE, "TASK_THROW_PROJECTILE");
  1102.     }
  1103.  
  1104.     //*************************************************************************************************************************
  1105.  
  1106.  
  1107.  
  1108.     CTaskMoveFollowNavMesh * CreateNavigateTask(const int iPedIndex, const Vector3 &vTarget, const float fMoveBlendRatio, int iTime, const float fTargetRadius, const float fTargetHeading = DEFAULT_NAVMESH_FINAL_HEADING)
  1109.     {
  1110.         //*************************************************************
  1111.         // Assert that scripters aren't trying to do "crazy shit"(tm)
  1112.  
  1113.         if(iPedIndex != NULL_IN_SCRIPTING_LANGUAGE)
  1114.         {
  1115.             CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1116.  
  1117.             if (!pPed)
  1118.                 return NULL;
  1119.         }
  1120.  
  1121.         //********************************
  1122.         // Sanity-check for comedy values
  1123.  
  1124.         ASSERT_ONLY(static const float fStupidlyLargeValue = 10000.0f);
  1125.         scriptAssertf(rage::FPIsFinite(vTarget.x) && rage::FPIsFinite(vTarget.y) && rage::FPIsFinite(vTarget.z), "script \'%s\'\nNAVIGATE_TO_COORD - Ped %i's target (%.2f, %.2f, %.2f) is duff.", CTheScripts::GetCurrentScriptNameAndProgramCounter(), iPedIndex, vTarget.x, vTarget.y, vTarget.z);
  1126.         scriptAssertf((vTarget.x > -fStupidlyLargeValue && vTarget.y > -fStupidlyLargeValue && vTarget.z > -fStupidlyLargeValue && vTarget.x < fStupidlyLargeValue && vTarget.y < fStupidlyLargeValue && vTarget.z < fStupidlyLargeValue), "script \'%s\'\nNAVIGATE_TO_COORD - Ped %i's target (%.2f, %.2f, %.2f) is outside of the world.", CTheScripts::GetCurrentScriptNameAndProgramCounter(), iPedIndex, vTarget.x, vTarget.y, vTarget.z);
  1127.  
  1128.         //***************************************************************
  1129.         // Translate iTime into a value meaningful to the navmesh task
  1130.  
  1131.         //-1 is assumed as to be infinite -2, will assert legacy used to be infinite
  1132.  
  1133.         //*********************************************************
  1134.         // Create the CTaskMoveFollowNavMesh task
  1135.         // Set up the task according to the passed-in parameters
  1136.        
  1137.         CTaskMoveFollowNavMesh* pTaskFollowNavMesh = rage_new CTaskMoveFollowNavMesh(
  1138.             fMoveBlendRatio,
  1139.             vTarget,
  1140.             fTargetRadius,
  1141.             CTaskMoveFollowNavMesh::ms_fSlowDownDistance,
  1142.             iTime,
  1143.             true,
  1144.             false,
  1145.             NULL,
  1146.             fTargetRadius);
  1147.  
  1148.         //***********************************************
  1149.         // This is always set for scripted navmesh tasks
  1150.  
  1151.         pTaskFollowNavMesh->SetIsScriptedRoute(true);
  1152.  
  1153.         pTaskFollowNavMesh->SetTargetStopHeading(fTargetHeading);
  1154.  
  1155.         return pTaskFollowNavMesh;
  1156.     }
  1157.  
  1158.     void CommandTaskFollowNavMeshToCoord(const int iPedIndex, const scrVector & vScrTarget, const float fMoveBlendRatio, const int iTime, const float fTargetRadius, const int iFlags, const float fTargetHeading)
  1159.     {
  1160.         Assertf(fMoveBlendRatio >= MOVEBLENDRATIO_STILL && fMoveBlendRatio <= MOVEBLENDRATIO_SPRINT, "Invalid 'fMoveBlendRatio' specified in TASK_FOLLOW_NAVMESH_TO_COORD.  Must be in range (%.1f to %.1f) inclusive.  You've passed in %.1f", MOVEBLENDRATIO_STILL, MOVEBLENDRATIO_SPRINT, fMoveBlendRatio);
  1161.  
  1162.         CTaskMoveFollowNavMesh * pTaskFollowNavMesh = CreateNavigateTask(iPedIndex, vScrTarget, fMoveBlendRatio, iTime, fTargetRadius, fTargetHeading<DEFAULT_NAVMESH_FINAL_HEADING ? DtoR * fTargetHeading : fTargetHeading);
  1163.        
  1164.         if (iTime < -1)
  1165.         {
  1166.             scriptAssertf(0, "%s:TASK_FOLLOW_NAVMESH_TO_COORD - Time must be -1 for infinite ", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  1167.             return;
  1168.         }
  1169.         else if (iTime == 0)
  1170.         {
  1171.             scriptAssertf(0, "%s:TASK_FOLLOW_NAVMESH_TO_COORD - You cannot give a task 0 time", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  1172.             return;
  1173.         }
  1174.        
  1175.         if(!pTaskFollowNavMesh)
  1176.             return;
  1177.  
  1178. #if __ASSERT
  1179.         if (fTargetHeading<DEFAULT_NAVMESH_FINAL_HEADING && ((iFlags & ENAV_SUPPRESS_EXACT_STOP)!=0))
  1180.         {
  1181.             Assertf(false, "You cannot specify 'ENAV_SUPPRESS_EXACT_STOP' and have a target-heading");
  1182.         }
  1183. #endif
  1184.  
  1185.         pTaskFollowNavMesh->SetScriptBehaviourFlags(iFlags, NULL);
  1186.  
  1187.         //*****************************************************************************************************
  1188.         // The 'fMainTaskTimer' value is used to warp the ped via the parent CTaskComplexControlMovement task
  1189.  
  1190.         float fMainTaskTimer = ((float)iTime)/1000.0f;
  1191.         if(fMainTaskTimer > 0.0f)
  1192.             fMainTaskTimer += 2.0f;
  1193.  
  1194.         //**********************************************************************************
  1195.         // Now wrap the task in the CTaskComplexControlMovement parent, and give to the ped
  1196.  
  1197.         CTask * pTask = rage_new CTaskComplexControlMovement( pTaskFollowNavMesh, NULL, CTaskComplexControlMovement::TerminateOnMovementTask, fMainTaskTimer );
  1198.         CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_FOLLOW_NAV_MESH_TO_COORD, "TASK_FOLLOW_NAVMESH_TO_COORD");
  1199.     }
  1200.  
  1201.     void CommandTaskFollowNavMeshToCoordAdvanced(const int iPedIndex, const Vector3 &vTarget, const float fMoveBlendRatio, const int iTime, const float fTargetRadius, const int iFlags, TNavMeshScriptStruct * pNavData, const float fTargetHeading )
  1202.     {
  1203.         Assertf(fMoveBlendRatio >= MOVEBLENDRATIO_STILL && fMoveBlendRatio <= MOVEBLENDRATIO_SPRINT, "Invalid 'fMoveBlendRatio' specified in TASK_FOLLOW_NAVMESH_TO_COORD_ADVANCED.  Must be in range (%.1f to %.1f) inclusive.  You've passed in %.1f", MOVEBLENDRATIO_STILL, MOVEBLENDRATIO_SPRINT, fMoveBlendRatio);
  1204.  
  1205.         //********************
  1206.         // Create the task
  1207.  
  1208.         if (iTime < -1)
  1209.         {
  1210.             scriptAssertf(0, "%s:TASK_FOLLOW_NAVMESH_TO_COORD_ADVANCED - Time must be -1 for infinite ", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  1211.             return;
  1212.         }
  1213.         else if (iTime == 0)
  1214.         {
  1215.             scriptAssertf(0, "%s:TASK_FOLLOW_NAVMESH_TO_COORD_ADVANCED - You cannot give a task 0 time", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  1216.             return;
  1217.         }
  1218.  
  1219.  
  1220.         CTaskMoveFollowNavMesh * pTaskFollowNavMesh = CreateNavigateTask(iPedIndex, vTarget, fMoveBlendRatio, iTime, fTargetRadius, fTargetHeading<DEFAULT_NAVMESH_FINAL_HEADING ? DtoR * fTargetHeading: fTargetHeading);
  1221.  
  1222.         if(!pTaskFollowNavMesh)
  1223.             return;
  1224.  
  1225.         pTaskFollowNavMesh->SetScriptBehaviourFlags(iFlags, pNavData);
  1226.  
  1227.         //*****************************************************************************************************
  1228.         // The 'fMainTaskTimer' value is used to warp the ped via the parent CTaskComplexControlMovement task
  1229.  
  1230.         float fMainTaskTimer = ((float)iTime)/1000.0f;
  1231.         if(fMainTaskTimer > 0.0f)
  1232.             fMainTaskTimer += 2.0f;
  1233.  
  1234.         //**********************************************************************************
  1235.         // Now wrap the task in the CTaskComplexControlMovement parent, and give to the ped
  1236.  
  1237.         CTask * pTask = rage_new CTaskComplexControlMovement( pTaskFollowNavMesh, NULL, CTaskComplexControlMovement::TerminateOnMovementTask, fMainTaskTimer);
  1238.         CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_FOLLOW_NAVMESH_TO_COORD_ADVANCED, "TASK_FOLLOW_NAVMESH_TO_COORD_ADVANCED");
  1239.     }
  1240.  
  1241.     //***********************************************************
  1242.     // CommandTaskNavigateToCoordAdvanced - parameter list:
  1243.     //
  1244.     // int iPedIndex
  1245.     // const scrVector & vScrTarget
  1246.     // float fMoveBlendRatio
  1247.     // int iTime
  1248.     // float fTargetRadius
  1249.     // int iFlags
  1250.     // TNavMeshScriptStruct navStruct
  1251.     //
  1252.  
  1253.     void CommandTaskFollowNavMeshToCoordAdvanced_ScrStruct(scrThread::Info & info)
  1254.     {
  1255.         //**********************************************************************
  1256.         // Extract the parameters from the scrThread::Info structure.  This
  1257.         // is necessary as the way of passing structures into script functions
  1258.  
  1259.         ASSERT_ONLY(static const int iNumParams = 12);
  1260.         scriptAssertf(info.ParamCount == iNumParams, "script \'%s\'\nTASK_FOLLOW_NAV_MESH_TO_COORD_ADVANCED - You have passed in the wrong num arguments (%i instead of %i)", CTheScripts::GetCurrentScriptNameAndProgramCounter(), info.ParamCount, iNumParams);
  1261.  
  1262.         // Get the ped index
  1263.         const int iPedIndex = info.Params[0].Int;
  1264.         // Get the target position
  1265.         //const float * pFloat = &info.Params[1].Reference->Float;
  1266.         const Vector3 vTarget(info.Params[1].Float, info.Params[2].Float, info.Params[3].Float);
  1267.         // Get the move blend ratio
  1268.         const float fMoveBlendRatio = info.Params[4].Float;
  1269.         // Get the time
  1270.         int iTime = info.Params[5].Int;
  1271.         // Get the target radius
  1272.         const float fTargetRadius = info.Params[6].Float;
  1273.         // Get the bit-flags
  1274.         const int iFlags = info.Params[7].Int;
  1275.         // Get the nav data structure
  1276.         //void * pStructData = info.Params[6].Reference;
  1277.         //TNavMeshScriptStruct * pNavStruct = (TNavMeshScriptStruct*)pStructData;
  1278.         TNavMeshScriptStruct NavStruct;
  1279.         NavStruct.m_fSlideToCoordHeading = info.Params[8].Float;
  1280.         NavStruct.m_fMaxSlopeNavigable = info.Params[9].Float;
  1281.         NavStruct.m_fClampMaxSearchDistance = info.Params[10].Float;
  1282.  
  1283.         // Final heading
  1284.         const float fTargetHeading = info.Params[11].Float;
  1285.        
  1286.         CommandTaskFollowNavMeshToCoordAdvanced(iPedIndex, vTarget, fMoveBlendRatio, iTime, fTargetRadius, iFlags, &NavStruct, fTargetHeading);
  1287.     }
  1288.  
  1289.     // Sets the path-style for this ped, so that they will use climb-overs or not during pathfinding
  1290.     void CommandSetPedPathCanUseClimbOvers(int PedIndex, bool Flag)
  1291.     {
  1292.         CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  1293.         if (pPed)
  1294.         {
  1295.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1296.             pPedAI->GetNavCapabilities().SetFlag(CPedNavCapabilityInfo::FLAG_MAY_CLIMB, Flag);
  1297.         }
  1298.     }
  1299.  
  1300.     // Sets the path-style for this ped, so that they will use ladders or not during pathfinding
  1301.     void CommandSetPedPathCanUseLadders(int PedIndex, bool Flag)
  1302.     {
  1303.         CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  1304.         if (pPed)
  1305.         {
  1306.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1307.             pPedAI->GetNavCapabilities().SetFlag(CPedNavCapabilityInfo::FLAG_MAY_USE_LADDERS, Flag);
  1308.         }
  1309.     }
  1310.  
  1311.     // Sets the path-style for this ped, so that they will use high drop-downs or not during pathfinding
  1312.     void CommandSetPedPathCanDropFromHeight(int PedIndex, bool Flag)
  1313.     {
  1314.         CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  1315.         if (pPed)
  1316.         {
  1317.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1318.             pPedAI->GetNavCapabilities().SetFlag(CPedNavCapabilityInfo::FLAG_MAY_DROP, Flag);
  1319.         }
  1320.     }
  1321.  
  1322.     // Sets the path-style for this ped, so designers can modify how likely it is for a ped to use a climb during navigation
  1323.     void CommandSetPedPathClimbCostModifier(int PedIndex, float fModifier)
  1324.     {
  1325.         fModifier = Clamp(fModifier, 0.0f, 10.0f);
  1326.  
  1327.         CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  1328.         if (pPed)
  1329.         {
  1330.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1331.             pPedAI->GetNavCapabilities().SetClimbCostModifier(fModifier);
  1332.         }
  1333.     }
  1334.  
  1335.     //
  1336.     void CommandSetPedToMayEnterWater(int PedIndex, bool Flag)
  1337.     {
  1338.         CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  1339.         if (pPed)
  1340.         {
  1341.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1342.             pPedAI->GetNavCapabilities().SetFlag(CPedNavCapabilityInfo::FLAG_MAY_ENTER_WATER, Flag);
  1343.         }
  1344.     }
  1345.  
  1346.     // Sets the path-style for this ped, so that they will use prefer to avoid water or not during pathfinding
  1347.     void CommandSetPedPreferToAvoidWater(int PedIndex, bool Flag)
  1348.     {
  1349.         CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  1350.         if (pPed)
  1351.         {
  1352.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1353.             pPedAI->GetNavCapabilities().SetFlag(CPedNavCapabilityInfo::FLAG_PREFER_TO_AVOID_WATER, Flag);
  1354.         }
  1355.     }
  1356.  
  1357.     // Sets the path-style for this ped, so that they will use prefer to avoid fire during pathfinding
  1358.     void CommandSetPedPathAvoidFire(int PedIndex, bool Flag)
  1359.     {
  1360.         CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  1361.         if (pPed)
  1362.         {
  1363.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1364.             pPedAI->GetNavCapabilities().SetFlag(CPedNavCapabilityInfo::FLAG_AVOID_FIRE, Flag);
  1365.         }
  1366.     }
  1367.  
  1368.     // Needs to be called each frame or it will reset.
  1369.     void CommandSetGlobalMinBirdFlightHeight(float fHeight)
  1370.     {
  1371.         CWildlifeManager::GetInstance().SetScriptMinBirdHeight(fHeight);
  1372.     }
  1373.  
  1374.     //****************************************************************************
  1375.     //  Retrieves the remaining distance to the target, if a ped is following
  1376.     //  a navmesh route in their primary slot.  Returns enumeration value to
  1377.     //  indicate whether the navmesh task was found.
  1378.  
  1379.     int CommandGetNavMeshRouteDistanceRemaining(int PedIndex, float & fOutDistanceRemaining, int & bThisIsLastRouteSection)
  1380.     {
  1381.         fOutDistanceRemaining = 0.0f;
  1382.         bThisIsLastRouteSection = false;
  1383.  
  1384.         const CPed * pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  1385.         if(pPed)
  1386.         {
  1387.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1388.             aiTask * pTask = pPedAI->FindTaskActiveMovementByType(CTaskTypes::TASK_MOVE_FOLLOW_NAVMESH);
  1389.             if(pTask)
  1390.             {
  1391.                 CTaskMoveFollowNavMesh * pNavTask = (CTaskMoveFollowNavMesh*)pTask;
  1392.  
  1393.                 bThisIsLastRouteSection = pNavTask->GetLastRoutePointIsTarget();
  1394.  
  1395.                 if(pNavTask->IsFollowingNavMeshRoute() && !pNavTask->GetIsFleeing())
  1396.                 {
  1397.                     fOutDistanceRemaining = pNavTask->GetDistanceLeftOnCurrentRouteSection(pPed);
  1398.                     return NAVMESHROUTE_ROUTE_FOUND;
  1399.                 }
  1400.                 else
  1401.                 {
  1402.                     return NAVMESHROUTE_ROUTE_NOT_FOUND;
  1403.                 }
  1404.             }
  1405.         }
  1406.         return NAVMESHROUTE_TASK_NOT_FOUND;
  1407.     }
  1408.  
  1409.  
  1410.     int CommandGetNavMeshRouteResult(int PedIndex)
  1411.     {
  1412.         const CPed * pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  1413.         if(pPed)
  1414.         {
  1415.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1416.  
  1417.             // Script task priority must be active
  1418.             if(pPedAI->GetTaskManager()->GetTree(PED_TASK_TREE_PRIMARY)->GetActiveTaskPriority()==PED_TASK_PRIORITY_PRIMARY)
  1419.             {
  1420.                 // The movement task tree must be running its general movement task
  1421.                 if(pPedAI->GetTaskManager()->GetTree(PED_TASK_TREE_MOVEMENT)->GetActiveTaskPriority()==PED_TASK_MOVEMENT_GENERAL)
  1422.                 {
  1423.                     // A control movement task must be found
  1424.                     CTaskComplexControlMovement * pControlMovementTask = (CTaskComplexControlMovement*) pPedAI->FindTaskPrimaryByType(CTaskTypes::TASK_COMPLEX_CONTROL_MOVEMENT);
  1425.                     // The control movement must have a running movement task
  1426.                     if(pControlMovementTask && pControlMovementTask->GetRunningMovementTask(pPed))
  1427.                     {
  1428.                         CTaskMoveFollowNavMesh * pNavTask = (CTaskMoveFollowNavMesh*)pPedAI->GetTaskManager()->GetTree(PED_TASK_TREE_MOVEMENT)->FindTaskByTypeActive(CTaskTypes::TASK_MOVE_FOLLOW_NAVMESH);
  1429.                         if(pNavTask)
  1430.                         {
  1431.                             if(pNavTask->GetState()==CTaskNavBase::NavBaseState_FollowingPath)
  1432.                             {
  1433.                                 return NAVMESHROUTE_ROUTE_FOUND;
  1434.                             }
  1435.                             else if(pNavTask->IsUnableToFindRoute())
  1436.                             {
  1437.                                 return NAVMESHROUTE_ROUTE_NOT_FOUND;
  1438.                             }
  1439.                             else
  1440.                             {
  1441.                                 return NAVMESHROUTE_ROUTE_NOT_YET_TRIED;
  1442.                             }
  1443.                         }
  1444.                     }
  1445.                 }
  1446.             }
  1447.         }
  1448.         return NAVMESHROUTE_TASK_NOT_FOUND;
  1449.     }
  1450.  
  1451.     bool CommandIsControlledVehicleUnableToGetToRoad(int PedIndex)
  1452.     {
  1453.         const CPed * pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  1454.         if(pPed)
  1455.         {
  1456.             CPedIntelligence * pPedAI = pPed->GetPedIntelligence();
  1457.  
  1458.             // Script task priority must be active
  1459.             if(pPedAI->GetTaskManager()->GetTree(PED_TASK_TREE_PRIMARY)->GetActiveTaskPriority()==PED_TASK_PRIORITY_PRIMARY)
  1460.             {
  1461.                 // A control vehicle task must be found
  1462.                 CTaskControlVehicle* pControlVehicleTask = (CTaskControlVehicle*) pPedAI->FindTaskPrimaryByType(CTaskTypes::TASK_CONTROL_VEHICLE);
  1463.                 if(pControlVehicleTask)
  1464.                 {
  1465.                     return pControlVehicleTask->IsVehicleTaskUnableToGetToRoad();
  1466.                 }
  1467.             }
  1468.         }
  1469.  
  1470.         return false;
  1471.     }
  1472.  
  1473.     void CommandTaskGoToCoordAnyMeans( int PedIndex, const scrVector & scrVecCoors, float fMoveBlendRatio, int iVehicleID, bool bUseLongRangeVehiclePathing, s32 iDrivingFlags, float fMaxRangeToShootTargets)
  1474.     {
  1475.         Vector3 vTarget(scrVecCoors);
  1476.         CVehicle *pVehicle=NULL;
  1477.         if(iVehicleID != NULL_IN_SCRIPTING_LANGUAGE)
  1478.         {
  1479.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1480.             if(!pVehicle)
  1481.                 return;
  1482.         }
  1483.         CTask* pTask=rage_new CTaskGoToPointAnyMeans(fMoveBlendRatio,vTarget,pVehicle, CTaskGoToPointAnyMeans::ms_fTargetRadius, -1, bUseLongRangeVehiclePathing, iDrivingFlags, fMaxRangeToShootTargets);
  1484.         CScriptPeds::GivePedScriptedTask( PedIndex, pTask, SCRIPT_TASK_GO_TO_COORD_ANY_MEANS, "TASK_GO_TO_COORD_ANY_MEANS");
  1485.     }
  1486.  
  1487.     void CommandTaskGoToCoordAnyMeansExtraParams( int PedIndex, const scrVector & scrVecCoors, float fMoveBlendRatio, int iVehicleID, bool bUseLongRangeVehiclePathing, s32 iDrivingFlags, float fMaxRangeToShootTargets, float fExtraVehToTargetDistToPreferVe, float fDriveStraightLineDistance, s32 iExtraFlags, float fWarpTimerMS)
  1488.     {
  1489.         Vector3 vTarget(scrVecCoors);
  1490.         CVehicle *pVehicle=NULL;
  1491.         if(iVehicleID != NULL_IN_SCRIPTING_LANGUAGE)
  1492.         {
  1493.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1494.             if(!pVehicle)
  1495.                 return;
  1496.         }
  1497.         CTask* pTask=rage_new CTaskGoToPointAnyMeans(fMoveBlendRatio,vTarget,pVehicle, CTaskGoToPointAnyMeans::ms_fTargetRadius, -1, bUseLongRangeVehiclePathing, iDrivingFlags, fMaxRangeToShootTargets, fExtraVehToTargetDistToPreferVe, fDriveStraightLineDistance, static_cast<u16>(iExtraFlags), -1.0f, fWarpTimerMS);
  1498.         CScriptPeds::GivePedScriptedTask( PedIndex, pTask, SCRIPT_TASK_GO_TO_COORD_ANY_MEANS_EXTRA_PARAMS, "SCRIPT_TASK_GO_TO_COORD_ANY_MEANS_EXTRA_PARAMS");
  1499.     }
  1500.  
  1501.     void CommandTaskGoToCoordAnyMeansExtraParamsWithCruiseSpeed( int PedIndex, const scrVector & scrVecCoors, float fMoveBlendRatio, int iVehicleID, bool bUseLongRangeVehiclePathing, s32 iDrivingFlags, float fMaxRangeToShootTargets, float fExtraVehToTargetDistToPreferVe, float fDriveStraightLineDistance, s32 iExtraFlags, float fCruiseSpeed, float fTargetArriveDist)
  1502.     {
  1503.         Vector3 vTarget(scrVecCoors);
  1504.         CVehicle *pVehicle=NULL;
  1505.         if(iVehicleID != NULL_IN_SCRIPTING_LANGUAGE)
  1506.         {
  1507.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1508.             if(!pVehicle)
  1509.                 return;
  1510.         }
  1511.         CTask* pTask=rage_new CTaskGoToPointAnyMeans(fMoveBlendRatio,vTarget,pVehicle, CTaskGoToPointAnyMeans::ms_fTargetRadius, -1, bUseLongRangeVehiclePathing, iDrivingFlags, fMaxRangeToShootTargets, fExtraVehToTargetDistToPreferVe, fDriveStraightLineDistance, static_cast<u16>(iExtraFlags), fCruiseSpeed, -1.0f, fTargetArriveDist);
  1512.         CScriptPeds::GivePedScriptedTask( PedIndex, pTask, SCRIPT_TASK_GO_TO_COORD_ANY_MEANS_EXTRA_PARAMS_WITH_CRUISE_SPEED, "TASK_GO_TO_COORD_ANY_MEANS_EXTRA_PARAMS_WITH_CRUISE_SPEED");
  1513.     }
  1514.  
  1515. #if __BANK
  1516.     bool VerifyDictAndAnim(atHashString dictionaryHash, atHashString animHash, const char * ASSERT_ONLY(scriptName))
  1517.     {
  1518.         strLocalIndex dictIndex = fwAnimManager::FindSlotFromHashKey(dictionaryHash.GetHash());
  1519.  
  1520.         if (scriptVerifyf(dictIndex.Get()>-1, "%s - The dictionary name '%s' is not recognised.", scriptName, dictionaryHash.TryGetCStr()))
  1521.         {
  1522.             strIndex index = strStreamingEngine::GetInfo().GetModuleMgr().GetModule(fwAnimManager::GetStreamingModuleId())->GetStreamingIndex(dictIndex);
  1523.             if (scriptVerifyf(strStreamingEngine::GetInfo().GetStreamingInfo(index)->GetStatus() == STRINFO_LOADED, "%s - The dictionary '%s' is not streamed in.",  scriptName, dictionaryHash.TryGetCStr()))
  1524.             {
  1525.                 const crClip* pClip = fwAnimManager::GetClipIfExistsByDictIndex(dictIndex.Get(), animHash.GetHash());
  1526.                
  1527.                 if (scriptVerifyf(pClip, "%s - The clip '%s' does not exist in dictionary '%s'", scriptName, animHash.TryGetCStr(), dictionaryHash.TryGetCStr()))
  1528.                 {
  1529.                     return true;
  1530.                 }
  1531.             }
  1532.         }
  1533.  
  1534.         return false;
  1535.     }
  1536.  
  1537. #endif //__BANK
  1538.  
  1539.     CTaskScriptedAnimation::ePlaybackPriority GetPriorityFromControlFlags(s32 nControlFlags)
  1540.     {
  1541.         // TODO - convert to support the new anim priority flags
  1542.         CTaskScriptedAnimation::ePlaybackPriority priority = CTaskScriptedAnimation::kPriorityLow;
  1543.        
  1544.         if (nControlFlags == AF_PRIORITY_MEDIUM)
  1545.         {
  1546.             priority = CTaskScriptedAnimation::kPriorityMid;
  1547.         }
  1548.         else if (nControlFlags == AF_PRIORITY_HIGH)
  1549.         {
  1550.             priority = CTaskScriptedAnimation::kPriorityHigh;
  1551.         }
  1552.         return priority;
  1553.     }
  1554.  
  1555.     void PlayAnimScriptCommand(int CurrCommand, int PedIndex, const char *pAnimName, const char *pAnimDictNameStr, float fBlendInDelta, float fBlendOutDelta, int nTimeToPlay, int nControlFlags, int nIkFlags, bool bAdvanced, const Vector3 &initialPosition, const Vector3 &initialOrientation, float fStartPhase, EulerAngleOrder RotationOrder, bool phaseControlled, bool bAllowOverrideCloneUpdate)
  1556.     {
  1557.         eScriptedAnimFlagsBitSet flags;
  1558.         flags.BitSet().SetBits(nControlFlags);
  1559.  
  1560.         if(!SCRIPT_VERIFY(pAnimName, "TASK_PLAY_ANIM - Animation name is null"))
  1561.         {          
  1562.             return;
  1563.         }
  1564.  
  1565.         if(!SCRIPT_VERIFY(pAnimDictNameStr, "TASK_PLAY_ANIM - Animation dictionary name is null"))
  1566.         {          
  1567.             return;
  1568.         }
  1569.  
  1570.         if (bAllowOverrideCloneUpdate && !NetworkInterface::IsGameInProgress())
  1571.         {
  1572.             bAllowOverrideCloneUpdate = false;
  1573.             SCRIPT_ASSERT(0, "Don't expect bAllowOverrideCloneUpdate to be set true in SP. Clearing this bool.");
  1574.         }
  1575.  
  1576.         const strStreamingObjectName    pAnimDictName( pAnimDictNameStr );
  1577.  
  1578.         CPed *pPed = NULL;
  1579.         if(NULL_IN_SCRIPTING_LANGUAGE!=PedIndex)
  1580.         {
  1581.             pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1582.             if(!pPed)
  1583.             {          
  1584.                 return;
  1585.             }
  1586.  
  1587.             if(pPed->GetIsAttached())
  1588.             {
  1589.                 SCRIPT_ASSERT(!flags.BitSet().IsSet(AF_OVERRIDE_PHYSICS), "TASK_PLAY_ANIM - Cannot use AF_OVERRIDE_PHYSICS when ped is attached!");
  1590.                 SCRIPT_ASSERT(!flags.BitSet().IsSet(AF_TURN_OFF_COLLISION), "TASK_PLAY_ANIM - Cannot set CTaskScriptedAnimation::AF_TURN_OFF_COLLISION when ped is attached!");
  1591.                 SCRIPT_ASSERT(!flags.BitSet().IsSet(AF_IGNORE_GRAVITY), "TASK_PLAY_ANIM - Cannot set CTaskScriptedAnimation::AF_IGNORE_GRAVITY when ped is attached!");
  1592.             }
  1593.         }
  1594.         else if(bAllowOverrideCloneUpdate)
  1595.         {
  1596.             SCRIPT_ASSERT(0, "In MP don't expect bAllowOverrideCloneUpdate to be set true with null PedIndex!");
  1597.             return;
  1598.         }
  1599.  
  1600.         bool bPartOfASequence = (PedIndex == NULL_IN_SCRIPTING_LANGUAGE);
  1601.  
  1602.         //scriptAssertf(strlen(pAnimName)<ANIM_NAMELEN, "%s:TASK_PLAY_ANIM - Animation name is null : %s", CTheScripts::GetCurrentScriptNameAndProgramCounter(), pAnimName);
  1603.  
  1604.         if(!bPartOfASequence)
  1605.         {
  1606.             BANK_ONLY(VerifyDictAndAnim(pAnimDictName, pAnimName, "TASK_PLAY_ANIM");)
  1607.         }
  1608.  
  1609.         u32 iBoneMask = BONEMASK_ALL;
  1610.  
  1611.         eIkControlFlagsBitSet& ikFlags = reinterpret_cast<eIkControlFlagsBitSet&>(nIkFlags);
  1612.  
  1613.         if (flags.BitSet().IsSet(AF_UPPERBODY))
  1614.         {
  1615.             iBoneMask = BONEMASK_UPPERONLY;
  1616.         }
  1617.        
  1618.         // Currently, always extract the mover and the initial offset when using override physics mode
  1619.         if (flags.BitSet().IsSet(AF_OVERRIDE_PHYSICS) )
  1620.         {
  1621.             flags.BitSet().Set(AF_USE_MOVER_EXTRACTION, true);
  1622.             flags.BitSet().Set(AF_EXTRACT_INITIAL_OFFSET, true);
  1623.         }
  1624.  
  1625.         CTask* pTask;
  1626.  
  1627.         if (nTimeToPlay<0)
  1628.             nTimeToPlay = -1;
  1629.  
  1630.         if (bAdvanced)
  1631.         {
  1632.             Quaternion rotationQuaternion;
  1633.             CScriptEulers::QuaternionFromEulers(rotationQuaternion, initialOrientation, RotationOrder);
  1634.             pTask = rage_new CTaskScriptedAnimation(pAnimDictName, pAnimName, CTaskScriptedAnimation::kPriorityLow, iBoneMask, fwAnimHelpers::CalcBlendDuration(fBlendInDelta), fwAnimHelpers::CalcBlendDuration(fBlendOutDelta), nTimeToPlay, flags, fStartPhase, initialPosition, rotationQuaternion, false, phaseControlled, ikFlags, bAllowOverrideCloneUpdate, bPartOfASequence);
  1635.         }
  1636.         else
  1637.         {
  1638.             pTask = rage_new CTaskScriptedAnimation(pAnimDictName, pAnimName, CTaskScriptedAnimation::kPriorityLow, iBoneMask, fwAnimHelpers::CalcBlendDuration(fBlendInDelta), fwAnimHelpers::CalcBlendDuration(fBlendOutDelta), nTimeToPlay, flags, fStartPhase, false, phaseControlled, ikFlags, bAllowOverrideCloneUpdate, bPartOfASequence);
  1639.         }
  1640.  
  1641. #if !__FINAL
  1642.         if(NetworkInterface::IsGameInProgress())
  1643.         {
  1644.             scriptDebugf1("PlayAnimScriptCommand PedIndex %d, pPed %s, pAnimName %s, pAnimDictNameStr %s nControlFlags 0x%x, pTask [ %p ]",
  1645.                 PedIndex,
  1646.                 pPed?(pPed->GetNetworkObject()?pPed->GetNetworkObject()->GetLogName():pPed->GetModelName() ):"Null pPed",
  1647.                 pAnimName,
  1648.                 pAnimDictNameStr,
  1649.                 nControlFlags,
  1650.                 pTask);
  1651.         }
  1652. #endif
  1653.  
  1654.         if (flags.BitSet().IsSet(AF_USE_ALTERNATIVE_FP_ANIM))
  1655.         {
  1656.             static const char * s_fpsClipSuffixHash = "_FP";
  1657.             u32 fpsClipHash = atPartialStringHash(s_fpsClipSuffixHash, atPartialStringHash(pAnimName));
  1658.             atHashString finalFpsHash(atFinalizeHash(fpsClipHash));
  1659.             static_cast<CTaskScriptedAnimation*>(pTask)->SetFPSClipHash(finalFpsHash);
  1660.             if(!bPartOfASequence)
  1661.             {
  1662.                 BANK_ONLY(VerifyDictAndAnim(pAnimDictName, finalFpsHash, "TASK_PLAY_ANIM");)
  1663.             }
  1664.         }
  1665.  
  1666.         if(bAllowOverrideCloneUpdate)
  1667.         {
  1668.             scriptAssertf( !flags.BitSet().IsSet(AF_LOOPING) && !flags.BitSet().IsSet(AF_HOLD_LAST_FRAME), "Don't support AF_LOOPING or AF_HOLD_LAST_FRAME with bAllowOverrideCloneUpdate %d",nControlFlags);
  1669.  
  1670.             CTaskScriptedAnimation* pTaskScriptedAnimation = static_cast<CTaskScriptedAnimation*>(pTask);
  1671.             if(pPed->IsNetworkClone())
  1672.             {
  1673.                 pPed->GetPedIntelligence()->AddLocalCloneTask(pTaskScriptedAnimation, PED_TASK_PRIORITY_PRIMARY);
  1674.             }
  1675.             else
  1676.             {
  1677.                 int iEventPriority = E_PRIORITY_GIVE_PED_TASK;
  1678.                 CEventGivePedTask event(PED_TASK_PRIORITY_PRIMARY,pTaskScriptedAnimation,false,iEventPriority);
  1679.                 pPed->GetPedIntelligence()->AddEvent(event);
  1680.             }
  1681.             return;
  1682.         }
  1683.  
  1684.         // Nb/ PedIndex == NULL_IN_SCRIPTING_LANGUAGE if the task is part of a sequence
  1685.         bool bSecondary                 = flags.BitSet().IsSet(AF_SECONDARY);
  1686.  
  1687.         if ( bPartOfASequence && bSecondary )
  1688.         {
  1689.             CTask* pTaskSecond=pTask;
  1690.             pTask=rage_new CTaskAffectSecondaryBehaviour(true,PED_TASK_SECONDARY_PARTIAL_ANIM,pTaskSecond);
  1691.         }
  1692.         else if (bSecondary)
  1693.         {
  1694.             if(SCRIPT_VERIFY( !bPartOfASequence, "TASK_PLAY_ANIM_SECONDARY* Cant be used in a sequence!" ))
  1695.             {
  1696.                 CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  1697.                 if(pPed)
  1698.                 {
  1699.                     pPed->GetPedIntelligence()->AddTaskSecondary( pTask, PED_TASK_SECONDARY_PARTIAL_ANIM );
  1700.                 }
  1701.             }
  1702.             return;
  1703.         }
  1704.  
  1705.         if (!bPartOfASequence && flags.BitSet().IsSet(AF_OVERRIDE_PHYSICS))
  1706.         {
  1707.             //force an ai update post camera so that the anim will be visible next frame (rather than waiting for the next task update)
  1708.             CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  1709.             if(pPed)
  1710.             {
  1711.                 pPed->SetPedResetFlag( CPED_RESET_FLAG_ForcePostCameraAIUpdate, true );
  1712.             }
  1713.         }
  1714.  
  1715.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, CurrCommand, "TASK_PLAY_ANIM");
  1716.     }
  1717.  
  1718.     CTaskScriptedAnimation* FindPrimaryScriptedAnimTask(const CPed* pPed)
  1719.     {
  1720.         CTaskScriptedAnimation* pTask = static_cast<CTaskScriptedAnimation*>(pPed->GetPedIntelligence()->FindTaskPrimaryByType(CTaskTypes::TASK_SCRIPTED_ANIMATION));
  1721.         return pTask;
  1722.     }
  1723.  
  1724.     CTaskScriptedAnimation* FindSecondaryScriptedAnimTask(const CPed* pPed)
  1725.     {
  1726.         CTask* pTask = pPed->GetPedIntelligence()->GetTaskSecondaryPartialAnim();
  1727.         if (pTask && pTask->GetTaskType()==CTaskTypes::TASK_SCRIPTED_ANIMATION)
  1728.         {
  1729.             return static_cast<CTaskScriptedAnimation*>(pTask);
  1730.         }
  1731.         return NULL;
  1732.     }
  1733.  
  1734.     const crClip* FindClipForScriptCommand(const char * pDictName, const char * pClipName, const char * ASSERT_ONLY(pScriptName))
  1735.     {
  1736.         const crClip* pClip = fwAnimManager::GetClipIfExistsByName(pDictName, pClipName);
  1737.  
  1738. #if __ASSERT
  1739.         if (!pClip)
  1740.         {
  1741.             const char * pFailReason;
  1742.             strLocalIndex dictIndex = strLocalIndex(fwAnimManager::FindSlot(pDictName));
  1743.             if (dictIndex.Get()<0)
  1744.             {
  1745.                 pFailReason = " The dictionary does not exist.";
  1746.             }
  1747.             else
  1748.             {
  1749.                 fwClipDictionaryDef* pDictDef = fwAnimManager::GetSlot(dictIndex);
  1750.                 if ( !pDictDef)
  1751.                 {
  1752.                     pFailReason = " The dictionary is not in the image!";
  1753.                 }
  1754.                 else if (!GET_OBJECT(pDictDef))
  1755.                 {
  1756.                     pFailReason = " The dictionary is not streamed in.";
  1757.                 }
  1758.                 else
  1759.                 {
  1760.                     pFailReason = " The clip is not in the dictionary";
  1761.                 }
  1762.             }
  1763.             animAssertf (pClip, "(%s) Unable to retrieve clip '%s' from dictionary '%s'.%s", pScriptName, pClipName, pDictName, pFailReason);
  1764.         }
  1765. #endif // __ASSERT
  1766.         return pClip;
  1767.     }
  1768.  
  1769.     void CommandTaskPlayAnim(int PedIndex, const char *pAnimDictName, const char *pAnimName, float fBlendInDelta, float fBlendOutDelta, int nTimeToPlay, int nFlags, float startPhase, bool phaseControlled, int ikFlags, bool bAllowOverrideCloneUpdate)
  1770.     {
  1771.         if (SCRIPT_VERIFY((nTimeToPlay == -1) || (nTimeToPlay > 0) ,"TASK_PLAY_ANIM - Time must be -1 for infinite or > 0" ))
  1772.         {
  1773.             PlayAnimScriptCommand(SCRIPT_TASK_PLAY_ANIM, PedIndex, pAnimName, pAnimDictName, fBlendInDelta, fBlendOutDelta, nTimeToPlay, nFlags, ikFlags, false, VEC3_ZERO, VEC3_ZERO, startPhase, EULER_YXZ, phaseControlled, bAllowOverrideCloneUpdate);
  1774.         }
  1775.     }
  1776.  
  1777. #if __BANK
  1778.     void VerifySlotData(CTaskScriptedAnimation::ScriptInitSlotData* pData)
  1779.     {
  1780.         if (pData)
  1781.         {
  1782.             switch(pData->state.Int)
  1783.             {
  1784.             case CTaskScriptedAnimation::kStateSingleClip:
  1785.                 {
  1786.                     VerifyDictAndAnim(scrDecodeString(pData->dict0.String), scrDecodeString(pData->clip0.String), "TASK_SCRIPTED_ANIMATION");
  1787.                 }
  1788.                 break;
  1789.             case CTaskScriptedAnimation::kStateBlend:
  1790.                 {
  1791.                     VerifyDictAndAnim(scrDecodeString(pData->dict0.String), scrDecodeString(pData->clip0.String), "TASK_SCRIPTED_ANIMATION");
  1792.                     VerifyDictAndAnim(scrDecodeString(pData->dict1.String), scrDecodeString(pData->clip1.String), "TASK_SCRIPTED_ANIMATION");
  1793.                     VerifyDictAndAnim(scrDecodeString(pData->dict2.String), scrDecodeString(pData->clip2.String), "TASK_SCRIPTED_ANIMATION");
  1794.                 }
  1795.                 break;
  1796.             default:
  1797.                 {
  1798.                    
  1799.                 }
  1800.                 break;
  1801.             }
  1802.         }
  1803.     }
  1804. #endif //__BANK
  1805.  
  1806.     void CommandTaskScriptedAnimation(int pedIndex, int& priorityLowData, int& priorityMidData, int& priorityHighData, float blendInDelta, float BlendOutDelta)
  1807.     {
  1808.         CTaskScriptedAnimation::ScriptInitSlotData* priorityLow = reinterpret_cast<CTaskScriptedAnimation::ScriptInitSlotData*>(&priorityLowData);
  1809.         CTaskScriptedAnimation::ScriptInitSlotData* priorityMid = reinterpret_cast<CTaskScriptedAnimation::ScriptInitSlotData*>(&priorityMidData);
  1810.         CTaskScriptedAnimation::ScriptInitSlotData* priorityHigh = reinterpret_cast<CTaskScriptedAnimation::ScriptInitSlotData*>(&priorityHighData);
  1811.  
  1812. #if __BANK
  1813.         // verify the clips exist, etc
  1814.         VerifySlotData(priorityLow);
  1815.         VerifySlotData(priorityMid);
  1816.         VerifySlotData(priorityHigh);
  1817. #endif //__BANK
  1818.  
  1819.         bool bSecondaryTask = false;
  1820.         u32 combinedBits = priorityLow->flags.Int | priorityMid->flags.Int | priorityHigh->flags.Int;
  1821.         eScriptedAnimFlagsBitSet& combinedFlags = reinterpret_cast<eScriptedAnimFlagsBitSet&>(combinedBits);
  1822.  
  1823.         if ( combinedFlags.BitSet().IsSet(AF_SECONDARY) )
  1824.         {
  1825.             bSecondaryTask = true;
  1826.         }
  1827.  
  1828. #if __ASSERT
  1829.         if (NetworkInterface::IsGameInProgress() )
  1830.         {
  1831.             if( (priorityMid->state.Int!=CTaskScriptedAnimation::kStateEmpty) || (priorityHigh->state.Int!=CTaskScriptedAnimation::kStateEmpty) )
  1832.             {
  1833.                 scriptAssertf(false,"TASK_SCRIPTED_ANIMATION:: Network implementation only handles one slot data in ANIM_DATA& priorityLow.  priorityMid %s, priorityHigh %s",
  1834.                     (priorityMid->state.Int!=CTaskScriptedAnimation::kStateEmpty)?"Valid":"Empty",
  1835.                     (priorityHigh->state.Int!=CTaskScriptedAnimation::kStateEmpty)?"Valid":"Empty");
  1836.             }
  1837.             scriptAssertf( (priorityLow->clip2.String==NULL || priorityLow->weight2.Float==0.0f),"TASK_SCRIPTED_ANIMATION:: Network blended anim implementation only handles first 2 weighted anims. weight2 = %.5f, clip =%s",
  1838.                             priorityLow->weight2.Float,
  1839.                             priorityLow->clip2.String?priorityLow->clip2.String:"Null clip string");
  1840.         }
  1841. #endif
  1842.         // Start the new task
  1843.         CTask* pTask = rage_new CTaskScriptedAnimation(*priorityLow, *priorityMid, *priorityHigh, blendInDelta, BlendOutDelta);
  1844.  
  1845.         // handle the automated FPS alternative clip
  1846.         if (combinedFlags.BitSet().IsSet(AF_USE_ALTERNATIVE_FP_ANIM))
  1847.         {
  1848.             if (pTask && priorityLow->state.Int==CTaskScriptedAnimation::kStateSingleClip)
  1849.             {
  1850.                 static const char * s_fpsClipSuffixHash = "_FP";
  1851.                 u32 fpsClipHash = atPartialStringHash(s_fpsClipSuffixHash, atPartialStringHash(priorityLow->clip0.String));
  1852.                 atHashString finalFpsHash(atFinalizeHash(fpsClipHash));
  1853.                 static_cast<CTaskScriptedAnimation*>(pTask)->SetFPSClipHash(finalFpsHash);
  1854.                 BANK_ONLY(VerifyDictAndAnim(scrDecodeString(priorityLow->dict0.String), finalFpsHash, "TASK_SCRIPTED_ANIMATION");)
  1855.             }
  1856.         }
  1857.  
  1858.         bool bPartOfASequence = (pedIndex == NULL_IN_SCRIPTING_LANGUAGE);
  1859.  
  1860.         if ( bPartOfASequence && bSecondaryTask )
  1861.         {
  1862.             CTask* pTaskSecond=pTask;
  1863.             pTask=rage_new CTaskAffectSecondaryBehaviour(true,PED_TASK_SECONDARY_PARTIAL_ANIM,pTaskSecond);
  1864.         }
  1865.         else if (bSecondaryTask)
  1866.         {
  1867.             CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(pedIndex, bSecondaryTask ? CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES : CTheScripts::GUID_ASSERT_FLAGS_ALL);
  1868.             if(pPed)
  1869.             {
  1870.                 pPed->GetPedIntelligence()->AddTaskSecondary( pTask, PED_TASK_SECONDARY_PARTIAL_ANIM );
  1871.             }
  1872.             return;
  1873.         }
  1874.  
  1875.         if (!bPartOfASequence && combinedFlags.BitSet().IsSet(AF_OVERRIDE_PHYSICS))
  1876.         {
  1877.             //force an ai update post camera so that the anim will be visible next frame (rather than waiting for the next task update)
  1878.             CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(pedIndex, bSecondaryTask ? CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES : CTheScripts::GUID_ASSERT_FLAGS_ALL);
  1879.             if(pPed)
  1880.             {
  1881.                 pPed->SetPedResetFlag( CPED_RESET_FLAG_ForcePostCameraAIUpdate, true );
  1882.             }
  1883.         }
  1884.  
  1885.         CScriptPeds::GivePedScriptedTask(pedIndex, pTask, SCRIPT_TASK_PLAY_ANIM, "TASK_SCRIPTED_ANIMATION");
  1886.     }
  1887.  
  1888.     void CommandPlayEntityScriptedAnimation(int EntityIndex, int& priorityLowData, int& priorityMidData, int& priorityHighData, float blendInDelta, float BlendOutDelta)
  1889.     {
  1890.         CTaskScriptedAnimation::ScriptInitSlotData* priorityLow = reinterpret_cast<CTaskScriptedAnimation::ScriptInitSlotData*>(&priorityLowData);
  1891.         CTaskScriptedAnimation::ScriptInitSlotData* priorityMid = reinterpret_cast<CTaskScriptedAnimation::ScriptInitSlotData*>(&priorityMidData);
  1892.         CTaskScriptedAnimation::ScriptInitSlotData* priorityHigh = reinterpret_cast<CTaskScriptedAnimation::ScriptInitSlotData*>(&priorityHighData);
  1893.  
  1894. #if __BANK
  1895.         // verify the clips exist, etc
  1896.         VerifySlotData(priorityLow);
  1897.         VerifySlotData(priorityMid);
  1898.         VerifySlotData(priorityHigh);
  1899. #endif //__BANK
  1900.  
  1901.         // Start the new task
  1902.         CPhysical *pEntity = CTheScripts::GetEntityToModifyFromGUID< CPhysical >(EntityIndex);
  1903.         if(pEntity)
  1904.         {
  1905.             CTask* pTask = rage_new CTaskScriptedAnimation(*priorityLow, *priorityMid, *priorityHigh, blendInDelta, BlendOutDelta);
  1906.             if (pEntity->GetIsTypeObject())
  1907.             {
  1908.                 CObject *pObject = static_cast<CObject*>(pEntity);
  1909.                 pObject->SetTask(pTask, CObjectIntelligence::OBJECT_TASK_TREE_SECONDARY, CObjectIntelligence::OBJECT_TASK_SECONDARY_ANIM);
  1910.             }
  1911.             else if(pEntity->GetIsTypeVehicle())
  1912.             {
  1913.                 CVehicle *pVehicle = static_cast<CVehicle*>(pEntity);
  1914.                 pVehicle->GetIntelligence()->AddTask(VEHICLE_TASK_TREE_SECONDARY, pTask, VEHICLE_TASK_SECONDARY_ANIM, true);
  1915.             }
  1916.             else
  1917.             {
  1918.                 delete pTask;
  1919.             }
  1920.         }
  1921.     }
  1922.  
  1923.     void CommandTaskPlayPhoneGestureAnimation(int PedIndex, const char* pAnimDictHash, const char* pAnimName, const char *pFilterName, float fBlendInDuration, float fBlendOutDuration, bool bIsLooping, bool bHoldLastFrame)
  1924.     {
  1925.         const CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1926.         if (SCRIPT_VERIFY(pPed && pPed->GetAnimDirector(), "TASK_PLAY_PHONE_GESTURE_ANIMATION - Invalid ped or ped has no anim director."))
  1927.         {
  1928.             // Look to see if secondary/phone task is running
  1929.             CTaskMobilePhone *pTaskMobilePhone = static_cast<CTaskMobilePhone*>(pPed->GetPedIntelligence()->FindTaskSecondaryByType(CTaskTypes::TASK_MOBILE_PHONE));
  1930.             if (SCRIPT_VERIFY(pTaskMobilePhone, "TASK_PLAY_PHONE_GESTURE_ANIMATION - Ped is not running mobile phone task."))
  1931.             {
  1932.                 // Check if clip actually exists
  1933.                 u32 uDictHashkey = atHashString(pAnimDictHash);
  1934.                 s32 sAnimDictIndex = fwAnimManager::FindSlotFromHashKey(uDictHashkey).Get();
  1935.                 u32 uAnimHashKey = atHashString(pAnimName);
  1936.                 const crClip* pClip = fwAnimManager::GetClipIfExistsByDictIndex(sAnimDictIndex, uAnimHashKey);
  1937.                 scriptAssertf(pClip, "TASK_PLAY_PHONE_GESTURE_ANIMATION - Animation does not exist. Please ensure dictionary is streamed in! sAnimDictIndex: %d, uAnimHashKey: %d", sAnimDictIndex, uAnimHashKey);
  1938.                
  1939.                 if (pClip)
  1940.                 {
  1941.                     pTaskMobilePhone->RequestAdditionalSecondaryAnims(pAnimDictHash, pAnimName, pFilterName, fBlendInDuration, fBlendOutDuration, bIsLooping, bHoldLastFrame);
  1942.                 }
  1943.             }
  1944.         }
  1945.     }
  1946.    
  1947.     void CommandTaskStopPhoneGestureAnimation(int PedIndex, float fBlendOutOverride)
  1948.     {
  1949.         const CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1950.         if (SCRIPT_VERIFY(pPed && pPed->GetAnimDirector(), "TASK_STOP_PHONE_GESTURE_ANIMATION - Invalid ped or ped has no anim director."))
  1951.         {
  1952.             CTaskMobilePhone *pTaskMobilePhone = static_cast<CTaskMobilePhone*>(pPed->GetPedIntelligence()->FindTaskSecondaryByType(CTaskTypes::TASK_MOBILE_PHONE));
  1953.             if (SCRIPT_VERIFY(pTaskMobilePhone, "TASK_STOP_PHONE_GESTURE_ANIMATION - Ped is not running mobile phone task."))
  1954.             {
  1955.                 pTaskMobilePhone->ClearAdditionalSecondaryAnimation(fBlendOutOverride);
  1956.             }
  1957.         }
  1958.     }
  1959.  
  1960.     bool CommandIsPlayingPhoneGestureAnim(int PedIndex)
  1961.     {
  1962.         const CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1963.         if (SCRIPT_VERIFY(pPed && pPed->GetAnimDirector(), "(IS_PLAYING_PHONE_GESTURE_ANIM - Invalid ped or ped has no anim director."))
  1964.         {
  1965.             CTaskMobilePhone *pTaskMobilePhone = static_cast<CTaskMobilePhone*>(pPed->GetPedIntelligence()->FindTaskSecondaryByType(CTaskTypes::TASK_MOBILE_PHONE));
  1966.             if (SCRIPT_VERIFY(pTaskMobilePhone, "(IS_PLAYING_PHONE_GESTURE_ANIM - Ped is not running mobile phone task."))
  1967.             {
  1968.                 return pTaskMobilePhone->GetIsPlayingAdditionalSecondaryAnim();
  1969.             }
  1970.         }
  1971.         return false;
  1972.     }
  1973.  
  1974.     float CommandGetPhoneGestureAnimCurrentTime(int PedIndex)
  1975.     {
  1976.         const CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1977.         if (SCRIPT_VERIFY(pPed && pPed->GetAnimDirector(), "GET_PHONE_GESTURE_ANIM_CURRENT_TIME - Invalid ped or ped has no anim director."))
  1978.         {
  1979.             CTaskMobilePhone *pTaskMobilePhone = static_cast<CTaskMobilePhone*>(pPed->GetPedIntelligence()->FindTaskSecondaryByType(CTaskTypes::TASK_MOBILE_PHONE));
  1980.             if (SCRIPT_VERIFY(pTaskMobilePhone, "GET_PHONE_GESTURE_ANIM_CURRENT_TIME - Ped is not running mobile phone task."))
  1981.             {
  1982.                 return pTaskMobilePhone->GetAdditionalSecondaryAnimPhase();
  1983.             }
  1984.         }
  1985.         return -1.0f;
  1986.     }
  1987.  
  1988.     float CommandGetPhoneGestureAnimTotalTime(int PedIndex)
  1989.     {
  1990.         const CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  1991.         if (SCRIPT_VERIFY(pPed && pPed->GetAnimDirector(), "GET_PHONE_GESTURE_ANIM_TOTAL_TIME - Invalid ped or ped has no anim director."))
  1992.         {
  1993.             CTaskMobilePhone *pTaskMobilePhone = static_cast<CTaskMobilePhone*>(pPed->GetPedIntelligence()->FindTaskSecondaryByType(CTaskTypes::TASK_MOBILE_PHONE));
  1994.             if (SCRIPT_VERIFY(pTaskMobilePhone, "GET_PHONE_GESTURE_ANIM_TOTAL_TIME - Ped is not running mobile phone task."))
  1995.             {
  1996.                 return pTaskMobilePhone->GetAdditionalSecondaryAnimDuration();
  1997.             }
  1998.         }
  1999.         return -1.0f;
  2000.     }
  2001.  
  2002.     void CommandStartAnimPlayback(int EntityIndex, int& data, s32 priority)
  2003.     {
  2004.         CTaskScriptedAnimation::ScriptInitSlotData* slotData = reinterpret_cast<CTaskScriptedAnimation::ScriptInitSlotData*>(&data);
  2005.  
  2006.         CPhysical *pPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(EntityIndex);
  2007.         if(pPhysical)
  2008.         {
  2009.             // look for an existing scripted animation task running on the ped
  2010.             CTaskScriptedAnimation* pTask = NULL;
  2011.                
  2012.             if (slotData->flags.Int & BIT(AF_SECONDARY))
  2013.             {
  2014.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true, false);
  2015.             }
  2016.             else
  2017.             {
  2018.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true);
  2019.             }
  2020.  
  2021.             if (SCRIPT_VERIFY(pTask, "START_ANIM_PLAYBACK: Anim task is not playing. Use TASK_SCRIPTED_ANIMATION to begin the task."))
  2022.             {
  2023.                 CTaskScriptedAnimation::InitSlotData data(*slotData);
  2024.                 pTask->StartPlayback(data, GetPriorityFromControlFlags(priority));
  2025.             }
  2026.         }
  2027.     }
  2028.  
  2029.     void CommandStopAnimPlayback(int EntityIndex, s32 priority, bool secondary = false)
  2030.     {
  2031.         CPhysical *pPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(EntityIndex);
  2032.         if(pPhysical)
  2033.         {
  2034.             // look for an existing scripted animation task running on the ped
  2035.             CTaskScriptedAnimation* pTask = NULL;
  2036.  
  2037.             if (secondary)
  2038.             {
  2039.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true, false);
  2040.             }
  2041.             else
  2042.             {
  2043.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true);
  2044.             }
  2045.  
  2046.             if (SCRIPT_VERIFY(pTask, "STOP_ANIM_PLAYBACK: Anim task is not playing."))
  2047.             {
  2048.                 pTask->StopPlayback(GetPriorityFromControlFlags(priority));
  2049.             }
  2050.         }
  2051.     }
  2052.  
  2053.     void CommandTaskClipSetClip(int EntityIndex, const char * pAnimDictName, const char * pAnimName, s32 priority, s32 index, bool secondary = false)
  2054.     {
  2055.         CPhysical *pPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(EntityIndex);
  2056.         if(pPhysical)
  2057.         {
  2058.             // look for an existing scripted animation task running on the ped
  2059.             CTaskScriptedAnimation* pTask = NULL;
  2060.  
  2061.             if (secondary)
  2062.             {
  2063.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true, false);
  2064.             }
  2065.             else
  2066.             {
  2067.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true);
  2068.             }
  2069.  
  2070.             if (SCRIPT_VERIFY(pTask, "TASK_CLIP_SET_CLIP: Anim task is not playing. Use TASK_ANIM_START_CLIP or TASK_ANIM_START_BLEND to begin the task."))
  2071.             {
  2072.                 const crClip* pClip = FindClipForScriptCommand(pAnimDictName, pAnimName, "TASK_CLIP_SET_CLIP");
  2073.  
  2074.                 if (pClip)
  2075.                 {
  2076.                     pTask->SetClip(pClip, GetPriorityFromControlFlags(priority), (u8)index);
  2077.                 }
  2078.             }
  2079.         }
  2080.     }
  2081.  
  2082.     void CommandTaskClipSetBlendWeight(int EntityIndex, float weight, s32 priority, s32 index, bool secondary = false)
  2083.     {
  2084.         CPhysical *pPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(EntityIndex);
  2085.         if(pPhysical)
  2086.         {
  2087.             // look for an existing scripted animation task running on the ped
  2088.             CTaskScriptedAnimation* pTask = NULL;
  2089.  
  2090.             if (secondary)
  2091.             {
  2092.                 pTask = pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true, false);
  2093.             }
  2094.             else
  2095.             {
  2096.                 pTask = pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true);
  2097.             }
  2098.  
  2099.             if (SCRIPT_VERIFY(pTask, "TASK_CLIP_SET_BLEND_WEIGHT: Anim task is not playing. Use TASK_ANIM_START_BLEND to begin the task."))
  2100.             {
  2101.                  
  2102.                 pTask->SetBlend(weight, GetPriorityFromControlFlags(priority) , (u8)index);
  2103.             }
  2104.         }
  2105.     }
  2106.  
  2107.     void CommandTaskClipSetFilter(int EntityIndex, const char * pFilterName, s32 priority, bool secondary =  false)
  2108.     {
  2109.         CPhysical *pPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(EntityIndex);
  2110.         if(pPhysical)
  2111.         {
  2112.             // look for an existing scripted animation task running on the ped
  2113.             CTaskScriptedAnimation* pTask = NULL;
  2114.  
  2115.             if (secondary)
  2116.             {
  2117.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true, false);
  2118.             }
  2119.             else
  2120.             {
  2121.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true);
  2122.             }
  2123.  
  2124.             if (SCRIPT_VERIFY(pTask, "TASK_CLIP_SET_FILTER: Anim task is not playing. Use TASK_ANIM_START_CLIP or TASK_ANIM_START_BLEND to begin the task."))
  2125.             {
  2126.                 pTask->SetFilter(pFilterName, GetPriorityFromControlFlags(priority));
  2127.             }
  2128.         }
  2129.     }
  2130.  
  2131.     void CommandTaskClipSetPhase(int EntityIndex, float phase, s32 priority, bool secondary = false)
  2132.     {
  2133.         CPhysical *pPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(EntityIndex);
  2134.         if(pPhysical)
  2135.         {
  2136.             // look for an existing scripted animation task running on the ped
  2137.             CTaskScriptedAnimation* pTask = NULL;
  2138.  
  2139.             if (secondary)
  2140.             {
  2141.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true, false);
  2142.             }
  2143.             else
  2144.             {
  2145.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true);
  2146.             }
  2147.  
  2148.             if (SCRIPT_VERIFY(pTask, "TASK_CLIP_SET_PHASE: Anim task is not playing. Use TASK_ANIM_START_CLIP or TASK_ANIM_START_BLEND to begin the task."))
  2149.             {
  2150.                 pTask->SetPhase(phase, GetPriorityFromControlFlags(priority));
  2151.             }
  2152.         }
  2153.     }
  2154.  
  2155.     void CommandTaskClipSetRate(int EntityIndex, float rate, s32 priority, bool secondary = false)
  2156.     {
  2157.         CPhysical *pPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(EntityIndex);
  2158.         if(pPhysical)
  2159.         {
  2160.             // look for an existing scripted animation task running on the ped
  2161.             CTaskScriptedAnimation* pTask = NULL;
  2162.  
  2163.             if (secondary)
  2164.             {
  2165.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true, false);
  2166.             }
  2167.             else
  2168.             {
  2169.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true);
  2170.             }
  2171.  
  2172.             if (SCRIPT_VERIFY(pTask, "TASK_CLIP_SET_RATE: Anim task is not playing. Use TASK_ANIM_START_CLIP or TASK_ANIM_START_BLEND to begin the task."))
  2173.             {
  2174.                 pTask->SetRate(rate, GetPriorityFromControlFlags(priority));
  2175.             }
  2176.         }
  2177.     }
  2178.  
  2179.     void CommandTaskClipSetLooped(int EntityIndex, bool looped, s32 priority, bool secondary = false)
  2180.     {
  2181.         CPhysical *pPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(EntityIndex);
  2182.         if(pPhysical)
  2183.         {
  2184.             // look for an existing scripted animation task running on the ped
  2185.             CTaskScriptedAnimation* pTask = NULL;
  2186.  
  2187.             if (secondary)
  2188.             {
  2189.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true, false);
  2190.             }
  2191.             else
  2192.             {
  2193.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true);
  2194.             }
  2195.  
  2196.             if (SCRIPT_VERIFY(pTask, "TASK_CLIP_SET_LOOPED: Anim task is not playing. Use TASK_ANIM_START_CLIP or TASK_ANIM_START_BLEND to begin the task."))
  2197.             {
  2198.                 pTask->SetLooped(looped, GetPriorityFromControlFlags(priority));
  2199.             }
  2200.         }
  2201.     }
  2202.  
  2203.     void CommandTaskPlayAnimAdvanced(int PedIndex, const char *pAnimDictName, const char *pAnimName, const scrVector & pos, const scrVector & rot, float fBlendInDelta, float fBlendOutDelta, int nTimeToPlay, int nFlags, float startPhase, int RotOrder, int ikFlags)
  2204.     {
  2205.         if (SCRIPT_VERIFY((nTimeToPlay == -1) || (nTimeToPlay > 0) ,"TASK_PLAY_ANIM - Time must be -1 for infinite or > 0" ))
  2206.         {
  2207.             // Transform the rotation into x = yaw, y = pitch, z = roll
  2208.             // Convert from degrees to radians
  2209.             Vector3 axisRot(DtoR*rot.x, DtoR*rot.y, DtoR*rot.z);
  2210.  
  2211. #if GTA_REPLAY
  2212.             CPed *pPed = NULL;
  2213.             if(NULL_IN_SCRIPTING_LANGUAGE!=PedIndex)
  2214.             {
  2215.                 pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  2216.                 if(pPed)
  2217.                 {
  2218.                     CReplayMgr::RecordWarpedEntity(pPed);
  2219.                 }
  2220.             }
  2221. #endif
  2222.  
  2223.             PlayAnimScriptCommand(SCRIPT_TASK_PLAY_ANIM, PedIndex, pAnimName, pAnimDictName, fBlendInDelta, fBlendOutDelta, nTimeToPlay, nFlags, ikFlags, true, Vector3(pos), axisRot, startPhase, static_cast<EulerAngleOrder>(RotOrder), false, false);
  2224.         }
  2225.     }
  2226.  
  2227.     void CommandStopAnimTask(int EntityIndex, const char *pAnimDictName, const char *pAnimName, float fBlendDelta)
  2228.     {
  2229.         // Check the object
  2230.         CPhysical *pPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(EntityIndex);
  2231.         if(pPhysical)
  2232.         {
  2233.             // look for an existing scripted animation task running on the ped
  2234.             CTaskScriptedAnimation* pTask = NULL;
  2235.  
  2236.             pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true);
  2237.  
  2238.             if (pTask && pTask->IsPlayingClip(pAnimDictName, pAnimName))
  2239.             {
  2240.                 // nothing to see here
  2241.             }
  2242.             else
  2243.             {
  2244.                 //check the secondary task tree
  2245.                 pTask = entity_commands::FindScriptedAnimTask(EntityIndex, true, false);
  2246.                 if (pTask && !pTask->IsPlayingClip(pAnimDictName,pAnimName))
  2247.                 {
  2248.                     pTask = NULL;
  2249.                 }
  2250.             }
  2251.  
  2252.             const CTaskSynchronizedScene* pTaskSynchronizedScene = NULL;
  2253.             if (!pTask)
  2254.             {
  2255.                 pTaskSynchronizedScene = entity_commands::FindSynchronizedSceneTask(EntityIndex, pAnimDictName, pAnimName);
  2256.                 if (!SCRIPT_VERIFY(pTaskSynchronizedScene == NULL, "STOP_ANIM_TASK - Entity is playing the anim through a synced scene, use STOP_SYNCHRONIZED_ENTITY_ANIM instead!"))
  2257.                 {
  2258.                     pTaskSynchronizedScene = NULL;
  2259.                 }
  2260.             }
  2261.             if(!pTaskSynchronizedScene)
  2262.             {
  2263.                 if (SCRIPT_VERIFY(pTask, "STOP_ANIM_TASK - Entity isn't running the anim"))
  2264.                 {
  2265.                     scriptAssertf(fBlendDelta<0.0f, "Blend out delta must be less than 0.0");
  2266.                     pTask->BlendOut(fwAnimHelpers::CalcBlendDuration(fBlendDelta));
  2267.                 }
  2268.             }
  2269.         }
  2270.     }
  2271.  
  2272.     void CommandTaskSynchronizedScene(int PedIndex, int sceneId, const char *pAnimDictName, const char *pAnimName, float blendIn, float blendOut, int flags, int ragdollBlockingFlags, float moverBlendDelta, int ikFlags)
  2273.     {
  2274.         if (SCRIPT_VERIFY(PedIndex!=NULL_IN_SCRIPTING_LANGUAGE, "TASK_SYNCHRONIZED_SCENE cannot be used in a sequence!"))
  2275.         {
  2276.             if (SCRIPT_VERIFY(fwAnimDirectorComponentSyncedScene::IsValidSceneId((fwSyncedSceneId)sceneId), "TASK_SYNCHRONIZED_SCENE: Invalid scene id!"))
  2277.             {
  2278.                 // Get the ped
  2279.                 CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  2280.                 if(pPed)
  2281.                 {
  2282.                     scriptAssertf(blendIn>0.0f ,"TASK_SYNCHRONIZED_SCENE: blend in delta is (%f) should be > 0.0f. Changing to INSTANT_BLEND_IN_DELTA.", blendIn);
  2283.                     if (blendIn<=0.0f)
  2284.                         blendIn = INSTANT_BLEND_IN_DELTA;
  2285.  
  2286.                     scriptAssertf(blendOut<0.0f ,"TASK_SYNCHRONIZED_SCENE: blend out delta (%f) should be < 0.0. Changing to INSTANT_BLEND_OUT_DELTA.", blendOut);
  2287.                     if (blendOut>=0.0f)
  2288.                         blendOut = INSTANT_BLEND_OUT_DELTA;
  2289.  
  2290.                     scriptAssertf(moverBlendDelta>0.0f ,"TASK_SYNCHRONIZED_SCENE: mover blend delta (%f) should be > 0.0f. Changing to INSTANT_BLEND_IN_DELTA!", moverBlendDelta);
  2291.                     if (moverBlendDelta<=0.0f)
  2292.                         moverBlendDelta = INSTANT_BLEND_IN_DELTA;
  2293.  
  2294.  
  2295.                     if(pPed->GetIsAttached())
  2296.                     {
  2297.                         // If we are using CTaskUseScenario, it's probably not a problem if we are attached, because it's likely
  2298.                         // the task itself that has attached the ped.
  2299.                         CTaskUseScenario* pScenarioTask = static_cast<CTaskUseScenario*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_USE_SCENARIO));
  2300.                         if(pScenarioTask)
  2301.                         {
  2302.                             // It would have been expected to me that the running CTaskUseScenario would be aborted and
  2303.                             // clean up the detachment before CTaskSynchronizedScene starts, so that we would just need
  2304.                             // to find a way to bypass the attachment check below. For some reason, that doesn't seem to happen,
  2305.                             // but by calling MakeAbortable(), the task seems to clean up the attachment (and we can still
  2306.                             // check GetIsAttached() below), in case the abort failed or if there was some other reason the
  2307.                             // ped was attached. /FF
  2308.                             pScenarioTask->MakeAbortable(CTask::ABORT_PRIORITY_IMMEDIATE, NULL);
  2309.                         }
  2310.                     }
  2311.  
  2312.                     if (pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle ))
  2313.                     {
  2314.  
  2315.                         // Added by sorr in CL 6438528
  2316.                         if(pPed->IsLocalPlayer() && pPed->GetPedAudioEntity())
  2317.                         {
  2318.                             u32 animDictNameHash = atStringHash(pAnimDictName);
  2319.                             if(animDictNameHash == ATSTRINGHASH("mini@prostitutes@sexlow_veh_first_person", 0x3A68E23A) ||
  2320.                                 animDictNameHash == ATSTRINGHASH("mini@prostitutes@sexnorm_veh_first_person", 0xF72790A8))
  2321.                             {
  2322.                                 pPed->GetPedAudioEntity()->SetCachedBJVehicle(pPed->GetMyVehicle());
  2323.                             }
  2324.                         }
  2325.                         // Added by sorr in CL 6438528
  2326.  
  2327.                         Warningf("TASK_SYNCHRONIZED_SCENE: Ped was in vehicle, setting them out of it.");
  2328.                         pPed->SetPedOutOfVehicle(CPed::PVF_IgnoreSafetyPositionCheck|CPed::PVF_Warp);
  2329.                     }
  2330.  
  2331.                     const fwAttachmentEntityExtension *pExtension = pPed->GetAttachmentExtension();
  2332.                     if (pExtension)
  2333.                     {
  2334.                         fwEntity *entity = pExtension->GetAttachParent();
  2335.                         if (entity)
  2336.                         {
  2337.                             Warningf("TASK_SYNCHRONIZED_SCENE: Ped was attached.  Detaching them.");
  2338.                             pPed->DetachFromParent(DETACH_FLAG_IGNORE_SAFE_POSITION_CHECK|DETACH_FLAG_SKIP_CURRENT_POSITION_CHECK);
  2339.                         }
  2340.                     }
  2341.                     scriptAssertf(!pPed->GetIsAttached(), "TASK_SYNCHRONIZED_SCENE: Ped is attached.");
  2342.  
  2343.                     const crClip* pClip = FindClipForScriptCommand(pAnimDictName, pAnimName, "TASK_SYNCHRONIZED_SCENE");
  2344.                     if (pClip)
  2345.                     {
  2346.                         eSyncedSceneFlagsBitSet& sceneFlags = reinterpret_cast<eSyncedSceneFlagsBitSet&>(flags);
  2347.                         eRagdollBlockingFlagsBitSet& ragdollFlags = reinterpret_cast<eRagdollBlockingFlagsBitSet&>(ragdollBlockingFlags);
  2348.                         eIkControlFlagsBitSet& ikControlFlags = reinterpret_cast<eIkControlFlagsBitSet&>(ikFlags);
  2349.  
  2350.                         CTaskSynchronizedScene* pTask = rage_new CTaskSynchronizedScene(static_cast<fwSyncedSceneId>(sceneId), atPartialStringHash(pAnimName), pAnimDictName, blendIn, blendOut, sceneFlags, ragdollFlags, moverBlendDelta, -1, ikControlFlags);
  2351.  
  2352. #if __DEV
  2353.                         fwAnimDirectorComponentSyncedScene::RegisterWithSyncedScene(static_cast<fwSyncedSceneId>(sceneId), pPed);
  2354. #endif //__DEV
  2355.                        
  2356.                         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_SYNCHRONIZED_SCENE, "TASK_SYNCHRONIZED_SCENE");
  2357.                         animEntityDebugf(pPed, "TASK_SYNCHRONIZED_SCENE - %s starting synced scene task", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  2358.  
  2359.                         // make sure we do an ai update now to sync up next frame
  2360.                         pPed->SetPedResetFlag( CPED_RESET_FLAG_ForcePostCameraAIUpdate, true );
  2361.                         pPed->SetPedResetFlag( CPED_RESET_FLAG_AllowUpdateIfNoCollisionLoaded, true);
  2362.                         if (blendIn==INSTANT_BLEND_IN_DELTA)
  2363.                         {
  2364.                             animDebugf3("[%u:%u] TASK_SYNCHRONIZED_SCENE: forcing a post camera anim update ped %s(%p) for instant blend in of synced scene", fwTimer::GetTimeInMilliseconds(), fwTimer::GetFrameCount(), pPed->GetModelName(), pPed);
  2365.                             pPed->SetPedResetFlag( CPED_RESET_FLAG_ForcePostCameraAnimUpdate, true );
  2366.                         }
  2367.                     }
  2368.                 }
  2369.             }
  2370.         }
  2371.     }
  2372.  
  2373.     int GetActualSequenceId(int Sequence)
  2374.     {
  2375.         return CTheScripts::GetCurrentGtaScriptHandler()->GetResourceReferenceFromId(Sequence);
  2376.     }
  2377.  
  2378.     void CommandOpenSequenceTask(int &Sequence)
  2379.     {
  2380.         CScriptResource_SequenceTask sequenceResource;
  2381.  
  2382.         Sequence = CTheScripts::GetCurrentGtaScriptHandler()->RegisterScriptResourceAndGetId(sequenceResource);
  2383.     }
  2384.  
  2385.     void CommandCloseSequenceTask(int Sequence)
  2386.     {
  2387.         const int iTaskID = GetActualSequenceId(Sequence);
  2388.         if(SCRIPT_VERIFY(iTaskID>=0, "CLOSE_SEQUENCE_TASK - No free sequences left."))
  2389.         {
  2390.             if(SCRIPT_VERIFY(iTaskID<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "CLOSE_SEQUENCE_TASK - Sequence task ID too big"))
  2391.             {  
  2392.                 if(SCRIPT_VERIFY(CTaskSequences::ms_bIsOpened[iTaskID], "CLOSE_SEQUENCE_TASK - Sequence task is already closed"))
  2393.                 {
  2394.                     SCRIPT_ASSERT(!CTaskSequences::ms_TaskSequenceLists[iTaskID].IsEmpty(), "CLOSE_SEQUENCE_TASK - sequence is empty");
  2395.  
  2396.                     CTaskSequences::ms_bIsOpened[iTaskID]=false;
  2397.                     CTaskSequences::ms_iActiveSequence=-1;
  2398.                 }
  2399.             }
  2400.         }
  2401.     }
  2402.  
  2403.     void CommandTaskPerformSequence(int PedIndex, int Sequence)
  2404.     {
  2405.         const int iTaskID = GetActualSequenceId(Sequence);
  2406.         if(SCRIPT_VERIFY(iTaskID >= 0 && iTaskID<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "TASK_PERFORM_SEQUENCE - not a valid Sequence task ID"))
  2407.         {
  2408.             if (SCRIPT_VERIFY(!CTaskSequences::ms_bIsOpened[iTaskID], "TASK_PERFORM_SEQUENCE - Sequence task is still open"))
  2409.             {
  2410.                 if (SCRIPT_VERIFY(!CTaskSequences::ms_TaskSequenceLists[iTaskID].IsEmpty(), "TASK_PERFORM_SEQUENCE - sequence task empty"))
  2411.                 {
  2412.                     CTaskUseSequence* pSequenceTask=rage_new CTaskUseSequence(iTaskID, Sequence);
  2413.                    
  2414. #if __ASSERT
  2415.                     //If assigning a sequence with a prop task in it, make sure the ped has an inventory.
  2416.  
  2417.                     CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  2418.  
  2419.                     const CTaskList& taskList = pSequenceTask->GetTaskSequenceList()->GetTaskList();
  2420.                     for (int seqIndex = 0; seqIndex < taskList.GetNumTasks(); ++seqIndex)
  2421.                     {
  2422.                         const CTask* pTask = static_cast<const CTask*>(taskList.GetTask(seqIndex));
  2423.                         if (pTask && pTask->GetTaskType() == CTaskTypes::TASK_USE_SCENARIO)
  2424.                         {
  2425.                             const CTaskUseScenario* pScenarioTask = static_cast<const CTaskUseScenario*>(pTask);
  2426.                             scriptAssertf(!pScenarioTask->GetScenarioInfo().HasProp() || pPed->GetInventory(), "%s: Attempting to assign a ped a task sequence that includes a prop scenario (%s), but the ped(%s) has no inventory", CTheScripts::GetCurrentScriptNameAndProgramCounter(), pScenarioTask->GetScenarioInfo().GetName(), pPed->GetModelName());
  2427.                         }
  2428.                     }
  2429. #endif
  2430.                     CScriptPeds::GivePedScriptedTask(PedIndex, pSequenceTask, SCRIPT_TASK_PERFORM_SEQUENCE, "TASK_PERFORM_SEQUENCE");
  2431.                 }
  2432.             }
  2433.         }
  2434.     }
  2435.  
  2436.     void CommandTaskPerformSequenceLocally(int PedIndex, int Sequence)
  2437.     {
  2438.         const int iTaskID = GetActualSequenceId(Sequence);
  2439.         if(SCRIPT_VERIFY(iTaskID >= 0 && iTaskID<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "TASK_PERFORM_SEQUENCE_LOCALLY - not a valid Sequence task ID"))
  2440.         {
  2441.             if(SCRIPT_VERIFY(!CTaskSequences::ms_bIsOpened[iTaskID], "TASK_PERFORM_SEQUENCE_LOCALLY - Sequence task is still open"))
  2442.             {
  2443.                 if(SCRIPT_VERIFY(!CTaskSequences::ms_TaskSequenceLists[iTaskID].IsEmpty(), "TASK_PERFORM_SEQUENCE_LOCALLY - sequence task empty"))
  2444.                 {
  2445.                     CTaskUseSequence* pTask=rage_new CTaskUseSequence(iTaskID);
  2446.                     CScriptPeds::GivePedScriptedTask(PedIndex,pTask, SCRIPT_TASK_PERFORM_SEQUENCE_LOCALLY, "TASK_PERFORM_SEQUENCE_LOCALLY");
  2447.                 }
  2448.             }
  2449.         }
  2450.     }
  2451.  
  2452.     void CommandClearSequenceTask(int &Sequence)
  2453.     {
  2454.         CTheScripts::GetCurrentGtaScriptHandler()->RemoveScriptResource(Sequence, false, true, CGameScriptResource::SCRIPT_RESOURCE_SEQUENCE_TASK);
  2455.         Sequence = 0;
  2456.     }
  2457.  
  2458.  
  2459.     void CommandSetSequenceToRepeat(int Sequence, int repeat)
  2460.     {
  2461.         const int iSequenceTaskID = GetActualSequenceId(Sequence);
  2462.         const int iRepeatMode=repeat;
  2463.  
  2464.         if(SCRIPT_VERIFY(iSequenceTaskID==CTaskSequences::ms_iActiveSequence, "SET_SEQUENCE_TO_REPEAT - Using wrong sequence ID"))
  2465.         {
  2466.             if(SCRIPT_VERIFY (iSequenceTaskID>=0 && iSequenceTaskID<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "SET_SEQUENCE_TO_REPEAT - Sequence task ID out of range"))
  2467.             {
  2468.                 if(SCRIPT_VERIFY (CTaskSequences::ms_bIsOpened[iSequenceTaskID], "SET_SEQUENCE_TO_REPEAT - Sequence task needs to be open"))
  2469.                 {
  2470.                     CTaskSequences::ms_TaskSequenceLists[CTaskSequences::ms_iActiveSequence].SetRepeatMode(iRepeatMode);
  2471.                 }
  2472.             }
  2473.         }
  2474.     }
  2475.  
  2476.     void CommandSetSequencePreventMigration(int Sequence)
  2477.     {
  2478.         const int iSequenceTaskID = GetActualSequenceId(Sequence);
  2479.  
  2480.         if(SCRIPT_VERIFY(iSequenceTaskID==CTaskSequences::ms_iActiveSequence, "SET_SEQUENCE_PREVENT_MIGRATION - Using wrong sequence ID"))
  2481.         {
  2482.             if(SCRIPT_VERIFY (iSequenceTaskID>=0 && iSequenceTaskID<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "SET_SEQUENCE_TO_REPEAT - Sequence task ID out of range"))
  2483.             {
  2484.                 if(SCRIPT_VERIFY (CTaskSequences::ms_bIsOpened[iSequenceTaskID], "SET_SEQUENCE_PREVENT_MIGRATION - Sequence task needs to be open"))
  2485.                 {
  2486.                     CTaskSequences::ms_TaskSequenceLists[CTaskSequences::ms_iActiveSequence].PreventMigration();
  2487.                 }
  2488.             }
  2489.         }
  2490.     }
  2491.  
  2492.     int CommandGetSequenceProgress(int PedIndex)
  2493.     {
  2494.         int iProgress=-1;
  2495.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  2496.         if (pPed)
  2497.         {
  2498.             if (SCRIPT_VERIFY(CPedScriptedTaskRecord::GetStatus(pPed, SCRIPT_TASK_PERFORM_SEQUENCE)>=0 ||
  2499.                 CPedScriptedTaskRecord::GetStatus(pPed, SCRIPT_TASK_PERFORM_SEQUENCE_FROM_PROGRESS)>=0,
  2500.                 "GET_SEQUENCE_PROGRESS - Ped isn't performing sequence"))
  2501.             {
  2502.                 bool b=false;
  2503.  
  2504.                 const int iStage1=CPedScriptedTaskRecord::GetStatus(pPed, SCRIPT_TASK_PERFORM_SEQUENCE);
  2505.                 if(CPedScriptedTaskRecordData::EVENT_STAGE==iStage1)
  2506.                 {
  2507.                     b=true;
  2508.                     iProgress=-1;
  2509.                 }
  2510.  
  2511.                 const int iStage2=CPedScriptedTaskRecord::GetStatus(pPed, SCRIPT_TASK_PERFORM_SEQUENCE_FROM_PROGRESS);
  2512.                 if(CPedScriptedTaskRecordData::EVENT_STAGE==iStage2)
  2513.                 {
  2514.                     b=true;
  2515.                     iProgress=-1;
  2516.                 }
  2517.  
  2518.                 if(!b)
  2519.                 {
  2520.                     if( pPed->GetPedIntelligence()->GetQueriableInterface()->IsTaskPresentAtPriority( CTaskTypes::TASK_USE_SEQUENCE, PED_TASK_PRIORITY_PRIMARY ) )
  2521.                     {
  2522.                         iProgress = pPed->GetPedIntelligence()->GetQueriableInterface()->GetSequenceProgressForTaskType( 0, CTaskTypes::TASK_USE_SEQUENCE, PED_TASK_PRIORITY_PRIMARY );
  2523.                     }
  2524.                     else
  2525.                     {
  2526.                         scriptAssertf(false, "GET_SEQUENCE_PROGRESS- Ped doesn't have a the correct primary task");
  2527.                     }
  2528.                 }
  2529.             }
  2530.         }
  2531.         return iProgress;
  2532.     }
  2533.  
  2534.  
  2535.     void CommandTaskGetOffBoat( int iPedID, int iTime )
  2536.     {
  2537.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_GET_OFF_BOAT - Time must be -1 for infinite and > 0" ))
  2538.         {
  2539.             CTaskComplexGetOffBoat * pTaskGetOffBoat = rage_new CTaskComplexGetOffBoat(iTime);
  2540.             CScriptPeds::GivePedScriptedTask( iPedID, pTaskGetOffBoat, SCRIPT_TASK_GET_OFF_BOAT, "TASK_GET_OFF_BOAT");
  2541.         }
  2542.     }
  2543.  
  2544.     bool CommandGetIsTaskActive( int iPedID, int iCommandType )
  2545.     {
  2546.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  2547.         if (pPed)
  2548.         {
  2549.             if(pPed->GetPedIntelligence()->GetQueriableInterface()->IsTaskCurrentlyRunning(iCommandType, true))
  2550.             {
  2551.                 return true;
  2552.             }
  2553.         }
  2554.         return false;
  2555.     }
  2556.  
  2557.     int CommandGetActiveVehicleMissionType(int iVehID)
  2558.     {
  2559.         const CVehicle *pVehicle = CTheScripts::GetEntityToQueryFromGUID<CVehicle>(iVehID);
  2560.         if (pVehicle)
  2561.         {
  2562.             sVehicleMissionParams params;
  2563.             s32 iTaskType = CTaskTypes::TASK_INVALID_ID;
  2564.             pVehicle->GetIntelligence()->GetActiveTaskInfo(iTaskType, params);
  2565.  
  2566.             return CVehicleIntelligence::GetMissionIdentifierFromTaskType(iTaskType, params);
  2567.         }
  2568.  
  2569.         return MISSION_NONE;
  2570.     }
  2571.  
  2572.     int CommandGetScriptTaskStatus( int iPedID, int iCommandType)
  2573.     {
  2574. #if __ASSERT
  2575.         scriptAssertf(CTheScripts::GetScriptTaskName(iCommandType), "%s GET_SCRIPT_TASK_STATUS: Unknown command type (%d)", CTheScripts::GetCurrentScriptNameAndProgramCounter(), iCommandType);
  2576. #endif // __ASSERT
  2577.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  2578.         if (pPed)
  2579.         {
  2580.             int iTaskStatus=CPedScriptedTaskRecord::GetStatus(pPed,iCommandType);
  2581.             if (iTaskStatus == -1)
  2582.             {
  2583.                 iTaskStatus = CPedScriptedTaskRecordData::MAX_NUM_STAGES;
  2584.             }
  2585.             return iTaskStatus;
  2586.         }
  2587.          return (CPedScriptedTaskRecordData::MAX_NUM_STAGES);
  2588.     }
  2589.  
  2590.     void CommandTaskLeaveAnyVehicle( int iPedID, int iDelayTime, int iFlags)
  2591.     {
  2592.         VehicleEnterExitFlags vehicleFlags;
  2593.         CTaskVehicleFSM::SetScriptedVehicleEntryExitFlags(vehicleFlags, iFlags);
  2594.         if (!vehicleFlags.BitSet().IsSet(CVehicleEnterExitFlags::DontDefaultWarpIfDoorBlocked))
  2595.         {
  2596.             vehicleFlags.BitSet().Set(CVehicleEnterExitFlags::WarpIfDoorBlocked);
  2597.         }
  2598.         CTask* pTask=rage_new CTaskLeaveAnyCar(iDelayTime, vehicleFlags);
  2599.         AI_LOG_WITH_ARGS("[Script] - Script %s has created CTaskLeaveAnyCar from SCRIPT_TASK_LEAVE_ANY_VEHICLE at 0x%p for ped with id %i\n", CTheScripts::GetCurrentScriptName(), pTask, iPedID);
  2600.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_LEAVE_ANY_VEHICLE, "TASK_LEAVE_ANY_VEHICLE");
  2601.     }
  2602.  
  2603.     void CommandTaskAimGunScripted(int iPedID, int iGunTaskType, bool bDisableBlockingClip, bool bInstantBlendToAim)
  2604.     {
  2605.         const CScriptedGunTaskInfo* pScriptedGunTaskInfo = CScriptedGunTaskMetadataMgr::GetScriptedGunTaskInfoByHash((u32)iGunTaskType);
  2606.  
  2607.         if (scriptVerifyf(pScriptedGunTaskInfo, "TASK_AIM_GUN_SCRIPTED - scripted gun task info (%u) didn't exist, check metadata", iGunTaskType))
  2608.         {
  2609.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  2610.             if (pPed)
  2611.             {
  2612.                 SCRIPT_ASSERT(pPed->IsLocalPlayer(), "TASK_AIM_GUN_SCRIPTED - Only supported on the player ped");
  2613.                 //Position the default target position ahead of the player
  2614.                 Vector3 targetPos = VEC3V_TO_VECTOR3(pPed->GetTransform().GetPosition()) + (VEC3V_TO_VECTOR3(pPed->GetTransform().GetForward()) * 3.0f);
  2615.                 CTaskGun* pGunTask = rage_new CTaskGun(CWeaponController::WCT_Player, CTaskTypes::TASK_AIM_GUN_SCRIPTED, CWeaponTarget(targetPos));
  2616.  
  2617.                 if( bDisableBlockingClip )
  2618.                     pGunTask->GetGunFlags().SetFlag(GF_DisableBlockingClip);
  2619.  
  2620.                 if( bInstantBlendToAim )
  2621.                     pGunTask->GetGunFlags().SetFlag(GF_InstantBlendToAim);
  2622.  
  2623.                 pGunTask->GetGunFlags().SetFlag(GF_ForceAimState);
  2624.                 pGunTask->GetGunFlags().SetFlag(GF_DisableTorsoIk);
  2625.                 pGunTask->SetScriptedGunTaskInfoHash(pScriptedGunTaskInfo->GetName().GetHash());
  2626.                 CScriptPeds::GivePedScriptedTask( iPedID, pGunTask, SCRIPT_TASK_AIM_GUN_SCRIPTED, "TASK_AIM_GUN_SCRIPTED");
  2627.             }
  2628.         }
  2629.     }
  2630.  
  2631.     void CommandTaskAimGunScriptedWithTarget(int iPedID, int iTargetPedID, const scrVector & scrVecTargetOrOffset, int iGunTaskType, bool bDisableBlockingClip, bool bForceAim)
  2632.     {
  2633.         const CScriptedGunTaskInfo* pScriptedGunTaskInfo = CScriptedGunTaskMetadataMgr::GetScriptedGunTaskInfoByHash((u32)iGunTaskType);
  2634.  
  2635.         if (scriptVerifyf(pScriptedGunTaskInfo, "TASK_AIM_GUN_SCRIPTED_WITH_TARGET - scripted gun task info (%u) didn't exist, check metadata", iGunTaskType))
  2636.         {
  2637.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  2638.             if (pPed)
  2639.             {
  2640.                 CTaskGun* pGunTask;
  2641.                 Vec3V vTargetOrOffset(scrVecTargetOrOffset);
  2642.                 const CPed* pTargetPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iTargetPedID, CTheScripts::GUID_ASSERT_FLAG_DEAD_CHECK);
  2643.                
  2644.                 CWeaponController::WeaponControllerType controllerType = CWeaponController::WCT_Fire;
  2645.                 if(bForceAim)
  2646.                 {
  2647.                     controllerType = CWeaponController::WCT_Aim;
  2648.                 }
  2649.  
  2650.                 if(pTargetPed)
  2651.                 {
  2652.                     pGunTask = rage_new CTaskGun(controllerType, CTaskTypes::TASK_AIM_GUN_SCRIPTED, CWeaponTarget(pTargetPed, VEC3V_TO_VECTOR3(vTargetOrOffset)));
  2653.                 }
  2654.                 else
  2655.                 {
  2656.                     pGunTask = rage_new CTaskGun(controllerType, CTaskTypes::TASK_AIM_GUN_SCRIPTED, CWeaponTarget(VEC3V_TO_VECTOR3(vTargetOrOffset)));
  2657.                 }
  2658.  
  2659.                 if(pPed->IsLocalPlayer())
  2660.                 {
  2661.                     pGunTask->SetFiringPatternHash(FIRING_PATTERN_FULL_AUTO);
  2662.                 }
  2663.  
  2664.                 if( bDisableBlockingClip )
  2665.                     pGunTask->GetGunFlags().SetFlag(GF_DisableBlockingClip);
  2666.    
  2667.                 pGunTask->GetGunFlags().SetFlag(GF_ForceAimState);
  2668.                 pGunTask->SetScriptedGunTaskInfoHash(pScriptedGunTaskInfo->GetName().GetHash());
  2669.                 CScriptPeds::GivePedScriptedTask( iPedID, pGunTask, SCRIPT_TASK_AIM_GUN_SCRIPTED, "TASK_AIM_GUN_SCRIPTED_WITH_TARGET");
  2670.             }
  2671.         }
  2672.     }
  2673.  
  2674.     void CommmandUpdateTaskAimGunScriptedTarget(int iPedID, int iTargetPedID, const scrVector & scrVecTargetOrOffset, bool bDisableBlockingClip)
  2675.     {
  2676.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  2677.         if (pPed)
  2678.         {
  2679.             CTaskAimGunScripted* pAimGunTask = static_cast<CTaskAimGunScripted*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_AIM_GUN_SCRIPTED));
  2680.  
  2681.             if(SCRIPT_VERIFY(pAimGunTask, "UPDATE_TASK_AIM_GUN_SCRIPTED_TARGET - Ped must be running TASK_AIM_GUN_SCRIPTED"))
  2682.             {
  2683.                 if( bDisableBlockingClip )
  2684.                 {
  2685.                     pAimGunTask->GetGunFlags().SetFlag(GF_DisableBlockingClip);
  2686.                 }
  2687.  
  2688.                 pAimGunTask->GetGunFlags().SetFlag(GF_ForceAimState);
  2689.  
  2690.                 //Update the target on the gun task
  2691.                 CTaskGun* pGunTask = static_cast<CTaskGun*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_GUN));
  2692.                 if(SCRIPT_VERIFY(pGunTask, "UPDATE_TASK_AIM_GUN_SCRIPTED_TARGET - Ped must be running CTaskGun"))
  2693.                 {
  2694.                     Vec3V vTargetOrOffset(scrVecTargetOrOffset);
  2695.                     const CPed* pTargetPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iTargetPedID, CTheScripts::GUID_ASSERT_FLAG_DEAD_CHECK);
  2696.  
  2697.                     if(pTargetPed)
  2698.                     {
  2699.                         pGunTask->SetTarget( CWeaponTarget(pTargetPed, VEC3V_TO_VECTOR3(vTargetOrOffset)));
  2700.                     }
  2701.                     else
  2702.                     {
  2703.                         pGunTask->SetTarget( CWeaponTarget(VEC3V_TO_VECTOR3(vTargetOrOffset)));
  2704.                     }
  2705.                 }
  2706.             }
  2707.         }
  2708.     }
  2709.  
  2710.     const char * CommandGetClipSetForScriptedGunTask(s32 iGunTaskType)
  2711.     {
  2712.         const CScriptedGunTaskInfo* pScriptedGunTaskInfo = CScriptedGunTaskMetadataMgr::GetScriptedGunTaskInfoByHash((u32)iGunTaskType);
  2713.         if (scriptVerifyf(pScriptedGunTaskInfo, "GET_CLIP_SET_FOR_SCRIPTED_GUN_TASK - Scripted gun task info %u didn't exist, check metadata", (u32)iGunTaskType))
  2714.         {
  2715.             return pScriptedGunTaskInfo->GetClipSetName().GetCStr();
  2716.         }
  2717.  
  2718.         return NULL;
  2719.     }
  2720.  
  2721.     void CommandSetRopeTrackEntityForGunTask(int iPedID, int iEntityID)
  2722.     {
  2723.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  2724.         if(SCRIPT_VERIFY(pPed, "SET_ROPE_TRACK_ENTITY_FOR_SCRIPTED_GUN_TASK - Invalid ped"))
  2725.         {
  2726.             CEntity* pEntity = const_cast<CEntity*>(CTheScripts::GetEntityToQueryFromGUID<CEntity>(iEntityID));
  2727.             if(SCRIPT_VERIFY(pEntity, "SET_ROPE_TRACK_ENTITY_FOR_SCRIPTED_GUN_TASK - Invalid entity"))
  2728.             {
  2729.                 CTaskAimGunScripted* pAimTask = static_cast<CTaskAimGunScripted*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_AIM_GUN_SCRIPTED));
  2730.  
  2731.                 if(SCRIPT_VERIFY(pAimTask, "SET_ROPE_TRACK_ENTITY_FOR_SCRIPTED_GUN_TASK - Ped must be running TASK_AIM_GUN_SCRIPTED"))
  2732.                 {
  2733.                     pAimTask->SetRopeOrientationEntity(pEntity);
  2734.                 }
  2735.             }
  2736.         }
  2737.     }
  2738.  
  2739.     void CommandTaskAimGunAtEntity(int iPedID, int iEntityID, int iTime, bool bInstantBlendToAim )
  2740.     {
  2741.         if (SCRIPT_VERIFY((iTime == -1) || (iTime >= 0) ,"TASK_AIM_GUN_AT_ENTITY - Time must be -1 for infinite" ))
  2742.         {
  2743.             const CEntity  *pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iEntityID);
  2744.             if (pEntity)
  2745.             {
  2746.                 CTaskGun* pTaskGun = rage_new CTaskGun(CWeaponController::WCT_Aim, CTaskTypes::TASK_AIM_GUN_ON_FOOT, CWeaponTarget(pEntity), ((float) iTime) / 1000.0f);
  2747.    
  2748.                 if(iTime == -1)
  2749.                 {
  2750.                     pTaskGun->GetGunFlags().SetFlag(GF_InfiniteDuration);
  2751.                 }
  2752.                 else if (iTime == 0)
  2753.                 {
  2754.                     pTaskGun->GetGunFlags().SetFlag(GF_DisableAiming);
  2755.                 }
  2756.  
  2757.                 if(bInstantBlendToAim)
  2758.                 {
  2759.                     pTaskGun->GetGunFlags().SetFlag(GF_InstantBlendToAim);
  2760.                 }
  2761.  
  2762.                 CScriptPeds::GivePedScriptedTask( iPedID, pTaskGun, SCRIPT_TASK_AIM_GUN_AT_ENTITY, "TASK_AIM_GUN_AT_ENTITY");
  2763.             }
  2764.         }
  2765.     }
  2766.  
  2767.     void CommandTaskTurnPedToFaceEntity( int iPedID, int iEntityID, int iTime )
  2768.     {
  2769.         const CEntity* pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iEntityID, CTheScripts::GUID_ASSERT_FLAGS_NO_DEAD_CHECK);
  2770.         if (pEntity)
  2771.         {
  2772.             float fTime;
  2773.             if(iTime < 0)
  2774.             {
  2775.                 fTime = -1.0f;
  2776.             }
  2777.             else if(iTime == 0)
  2778.             {
  2779.                 fTime = 0.0f;
  2780.             }
  2781.             else
  2782.             {
  2783.                 fTime = ((float)iTime)/1000.0f;
  2784.             }
  2785.             CTask* pTask=rage_new CTaskTurnToFaceEntityOrCoord(pEntity, CTaskMoveAchieveHeading::ms_fHeadingChangeRateFrac, CTaskMoveAchieveHeading::ms_fHeadingTolerance, fTime);
  2786.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_TURN_PED_TO_FACE_ENTITY, "TASK_TURN_PED_TO_FACE_ENTITY");
  2787.         }
  2788.     }
  2789.  
  2790.     void CommandTaskAimGunAtCoord( int iPedID, const scrVector & scrVecCoors, int iTime, bool bInstantBlendToAim, bool bPlayAimIntro )
  2791.     {
  2792.         if (SCRIPT_VERIFY((iTime == -1) || (iTime >= 0) ,"TASK_AIM_GUN_AT_COORD - Time must be -1 for infinite and >= 0" ))
  2793.         {
  2794.             Vector3 vecAimTarget(scrVecCoors);
  2795.             CTaskGun* pTaskGun = rage_new CTaskGun(CWeaponController::WCT_Aim, CTaskTypes::TASK_AIM_GUN_ON_FOOT, CWeaponTarget(vecAimTarget), ((float) iTime) / 1000.0f);
  2796.        
  2797.             if(iTime == -1)
  2798.             {
  2799.                 pTaskGun->GetGunFlags().SetFlag(GF_InfiniteDuration);
  2800.             }
  2801.             else if(iTime == 0)
  2802.             {
  2803.                 pTaskGun->GetGunFlags().SetFlag(GF_DisableAiming);
  2804.             }
  2805.        
  2806.             if(bInstantBlendToAim)
  2807.             {
  2808.                 pTaskGun->GetGunFlags().SetFlag(GF_InstantBlendToAim);
  2809.             }
  2810.  
  2811.             if(bPlayAimIntro)
  2812.             {
  2813.                 pTaskGun->SetPlayAimIntro(true);
  2814.             }
  2815.  
  2816.             CScriptPeds::GivePedScriptedTask(iPedID, pTaskGun, SCRIPT_TASK_AIM_GUN_AT_COORD,  "TASK_AIM_GUN_AT_COORD");
  2817.         }
  2818.     }
  2819.  
  2820.     void CommandTaskShootAtCoord( int iPedID, const scrVector & scrVecCoors, int iTime, int iFiringPatternHash )
  2821.     {
  2822.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_SHOOT_GUN_AT_COORD - Time must be -1 for infinite and > 0" ))
  2823.         {
  2824.             Vector3 TempCoors( scrVecCoors);
  2825.             CTask* pTask = NULL;
  2826.  
  2827.             if(iPedID != NULL_IN_SCRIPTING_LANGUAGE)
  2828.             {
  2829.                 CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  2830.                 if (pPed)
  2831.                 {
  2832.                     if(scriptVerifyf(pPed->GetWeaponManager(), "%s:TASK_SHOOT_GUN_AT_COORD - ped requires a weapon manager", CTheScripts::GetCurrentScriptNameAndProgramCounter()))
  2833.                     {
  2834.                         const CWeaponInfo* pWeaponInfo = CWeaponInfoManager::GetInfo<CWeaponInfo>(pPed->GetWeaponManager()->GetEquippedWeaponHash());
  2835.                        
  2836.                         if(scriptVerifyf(pWeaponInfo, "%s:TASK_SHOOT_GUN_AT_COORD - pWeaponInfo NULL - ped has no equiped weapon info", CTheScripts::GetCurrentScriptNameAndProgramCounter())
  2837.                            && pWeaponInfo->GetIsThrownWeapon())
  2838.                         {                                  
  2839.                             pTask = rage_new CTaskAimAndThrowProjectile( CWeaponTarget( TempCoors ) );
  2840.                         }
  2841.                     }
  2842.                 }
  2843.                 else
  2844.                 {
  2845.                     return;
  2846.                 }
  2847.             }
  2848.             if(pTask==NULL)
  2849.             {
  2850.                 pTask = rage_new CTaskGun(CWeaponController::WCT_Fire, CTaskTypes::TASK_AIM_GUN_ON_FOOT, CWeaponTarget(TempCoors), ((float) iTime) / 1000.0f);
  2851.  
  2852.                 if(iFiringPatternHash)
  2853.                 {
  2854.                     static_cast<CTaskGun*>(pTask)->SetFiringPatternHash(iFiringPatternHash);
  2855.                 }
  2856.        
  2857.                 if(iTime == -1)
  2858.                 {
  2859.                     static_cast<CTaskGun*>(pTask)->GetGunFlags().SetFlag(GF_InfiniteDuration);
  2860.                 }
  2861.  
  2862.             }
  2863.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_SHOOT_AT_COORD, "TASK_SHOOT_GUN_AT_COORD");
  2864.         }
  2865.     }
  2866.  
  2867.     void CommandTaskShuffleToNextVehicleSeat( int iPedID, int iVehicleID, bool bUseAlternateShuffle)
  2868.     {
  2869.         CVehicle *pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  2870.         CPed* pPed = NULL;
  2871.         if(iPedID != NULL_IN_SCRIPTING_LANGUAGE)
  2872.         {
  2873.             pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  2874.             if (pPed)
  2875.             {
  2876.                 if (!SCRIPT_VERIFY(pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle ) && pPed->GetMyVehicle(), "Ped isn't in a vehicle, need to call IS_PED_IN_ANY_VEHICLE to verify ped is in one") ||
  2877.                     !SCRIPT_VERIFY(pPed->GetMyVehicle() == pVehicle, "Ped is not in the given vehicle - TASK_SHUFFLE_TO_NEXT_VEHICLE_SEAT"))
  2878.                 {
  2879.                     return;
  2880.                 }
  2881.             }
  2882.         }
  2883.  
  2884.         if (pVehicle)
  2885.         {
  2886.             s32 iTargetSeatIndex = -1;
  2887.             if (pPed && bUseAlternateShuffle && pVehicle->GetSeatManager() && pVehicle->GetVehicleModelInfo() && pVehicle->GetVehicleModelInfo()->GetModelSeatInfo())
  2888.             {
  2889.                 const s32 iCurrentSeatIndex = pVehicle->GetSeatManager()->GetPedsSeatIndex(pPed);
  2890.                 const s32 iCurrentEntryPointIndex = pVehicle->GetVehicleModelInfo()->GetModelSeatInfo()->GetEntryPointIndexForSeat(iCurrentSeatIndex, pVehicle);
  2891.                 iTargetSeatIndex = pVehicle->GetVehicleModelInfo()->GetModelSeatInfo()->GetShuffleSeatForSeat(iCurrentEntryPointIndex, iCurrentSeatIndex, true);
  2892.             }
  2893.  
  2894.             CTask* pTask = rage_new CTaskInVehicleSeatShuffle(pVehicle,NULL, true, iTargetSeatIndex);
  2895.             CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_SHUFFLE_TO_NEXT_VEHICLE_SEAT, "TASK_SHUFFLE_TO_NEXT_VEHICLE_SEAT");
  2896.         }
  2897.     }
  2898.  
  2899.     void CommandClearPedTasks(int iPedID)
  2900.     {
  2901.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  2902.         if (pPed)
  2903.         {
  2904.             if (SCRIPT_VERIFY(!pPed->IsInjured(), "Ped is injured, cannot clear all tasks!"))
  2905.             {
  2906.                 if(pPed->IsNetworkClone())
  2907.                 {
  2908.                     bool bClearTasksImmediately = false;
  2909.                     CClearPedTasksEvent::Trigger(pPed, bClearTasksImmediately);
  2910.                 }
  2911.                 else
  2912.                 {
  2913.                     AI_LOG_WITH_ARGS_IF_SCRIPT_OR_PLAYER_PED(pPed, "[Script] - Ped %s has had tasks cleared by script %s\n", AILogging::GetDynamicEntityNameSafe(pPed), CTheScripts::GetCurrentScriptName());
  2914.                     pPed->GetPedIntelligence()->ClearTasks();
  2915.                     pPed->SetIsCrouching(false);
  2916.                 }
  2917. #if __DEV
  2918.                 // Record the task in the debug list
  2919.                 static char stringName[] = "CLEAR_PED_TASKS";
  2920.                 pPed->GetPedIntelligence()->AddScriptHistoryString(stringName, stringName, CTheScripts::GetCurrentScriptName(), CTheScripts::GetCurrentGtaScriptThread()->GetThreadPC());
  2921. #endif
  2922.             }
  2923.         }
  2924.     }
  2925.  
  2926.     void CommandClearPedScriptTaskIfRunningThreatResponseNonTempTask(int iPedID)
  2927.     {
  2928.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  2929.         if (pPed)
  2930.         {
  2931.             // If this ped is running a non temporary threat response task, clear their primary (script) task which is dormant
  2932.             // [GTAV] B*1605087
  2933.             CTask* pNonTempTask = pPed->GetPedIntelligence()->GetTaskAtPriority(PED_TASK_PRIORITY_EVENT_RESPONSE_NONTEMP);
  2934.             if (pNonTempTask && pNonTempTask->GetTaskType() == CTaskTypes::TASK_THREAT_RESPONSE)
  2935.             {
  2936.                 pPed->GetPedIntelligence()->ClearPrimaryTaskAtPriority(PED_TASK_PRIORITY_PRIMARY);
  2937.             }
  2938.         }
  2939.     }
  2940.  
  2941.     void CommandClearPedSecondaryTask(int iPedID)
  2942.     {
  2943.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  2944.         if (pPed)
  2945.         {
  2946.             pPed->GetPedIntelligence()->ClearTasks( false, true );
  2947.         }
  2948.     }
  2949.  
  2950.     void CommandTaskEveryoneLeaveVehicle(int iVehicleID)
  2951.     {
  2952.         // this script command is not approved for use in network scripts
  2953.         if (SCRIPT_VERIFY(!NetworkInterface::IsGameInProgress(), "%TASK_EVERYONE_LEAVE_VEHICLE - This script command is not allowed in network game scripts!"))
  2954.         {
  2955.             CVehicle *pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID);
  2956.             if (SCRIPT_VERIFY(pVehicle, "TASK_EVERYONE_LEAVE_VEHICLE - Vehicle doesn't exist"))
  2957.             {
  2958.                 for(int loop = 0;loop < pVehicle->GetSeatManager()->GetMaxSeats(); loop++)
  2959.                 {
  2960.                     CPed* pPedInSeat = pVehicle->GetSeatManager()->GetPedInSeat(loop);
  2961.                     if(pPedInSeat && !pPedInSeat->IsInjured() )
  2962.                     {
  2963.                         const int iDelay=(loop+1)*500+fwRandom::GetRandomNumberInRange(-100,100);
  2964.                         CTask* pTask=rage_new CTaskLeaveAnyCar(iDelay);
  2965.                         AI_LOG_WITH_ARGS("[Script] - Script %s has created CTaskLeaveAnyCar from SCRIPT_TASK_EVERYONE_LEAVE_VEHICLE at 0x%p for ped %s\n", CTheScripts::GetCurrentScriptName(), pTask, AILogging::GetDynamicEntityNameSafe(pPedInSeat));
  2966.                         const int iPedID=CTheScripts::GetGUIDFromEntity(*pPedInSeat);
  2967.                         CScriptPeds::GivePedScriptedTask( iPedID,pTask, SCRIPT_TASK_EVERYONE_LEAVE_VEHICLE, "TASK_EVERYONE_LEAVE_VEHICLE");
  2968.                     }
  2969.                 }
  2970.             }
  2971.         }
  2972.     }
  2973.  
  2974.     // Please keep this in sync with the enumeration in "commands_task.sch"
  2975.     enum ESEEK_ENTITY_OFFSET_FLAGS
  2976.     {
  2977.         ESEEK_OFFSET_ORIENTATES_WITH_ENTITY = 0x01,
  2978.         ESEEK_KEEP_TO_PAVEMENTS             = 0x02
  2979.     };
  2980.  
  2981.     void CommandTaskGotoEntityOffset( int iPedID, int iEntityID, int iTime, float fSeekRadius, float fSeekAngleDeg, float fMoveBlendRatio, int iGotoEntityOffsetFlags )
  2982.     {
  2983.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0), "TASK_GOTO_ENTITY_OFFSET - Time must be -1 for infinite and > 0" ))
  2984.         {      
  2985.             const float fSeekAngle=( DtoR * fSeekAngleDeg);
  2986.             const CEntity* pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iEntityID);
  2987.             if (pEntity)
  2988.             {
  2989.                 if (NetworkInterface::IsGameInProgress() && (!pEntity->GetIsDynamic() || !((CDynamicEntity*)pEntity)->GetNetworkObject()))
  2990.                 {
  2991.                     scriptAssertf(0, "%s:TASK_GOTO_ENTITY_OFFSET; the entity must be networked or this ped will not be able to migrate properly", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  2992.                 }
  2993.  
  2994.                 CTask* pTask=rage_new TTaskMoveSeekEntityRadiusAngleOffset(pEntity,iTime);
  2995.                
  2996.                 CEntitySeekPosCalculatorRadiusAngleOffset seekPosCalculator(fSeekRadius,fSeekAngle);
  2997.                 ((TTaskMoveSeekEntityRadiusAngleOffset*)pTask)->SetEntitySeekPosCalculator(seekPosCalculator);
  2998.                 ((TTaskMoveSeekEntityRadiusAngleOffset*)pTask)->SetMoveBlendRatio(fMoveBlendRatio);
  2999.  
  3000.                 Assertf( (iGotoEntityOffsetFlags & ESEEK_OFFSET_ORIENTATES_WITH_ENTITY)==0, "Can't specify 'ESEEK_OFFSET_ORIENTATES_WITH_ENTITY' with TASK_GOTO_ENTITY_OFFSET, this task always orientates offset with target entity.");
  3001.  
  3002.                 if((iGotoEntityOffsetFlags & ESEEK_KEEP_TO_PAVEMENTS)!=0)
  3003.                     ((TTaskMoveSeekEntityRadiusAngleOffset*)pTask)->SetPreferPavements(true);
  3004.  
  3005.                 ((TTaskMoveSeekEntityRadiusAngleOffset*)pTask)->SetUseLargerSearchExtents(true);
  3006.  
  3007.                 CTaskComplexControlMovement* pSimpleControlMovement = rage_new CTaskComplexControlMovement(pTask);
  3008.                 CScriptPeds::GivePedScriptedTask( iPedID, pSimpleControlMovement, SCRIPT_TASK_GOTO_ENTITY_OFFSET, "TASK_GOTO_ENTITY_OFFSET");
  3009.             }
  3010.         }
  3011.     }
  3012.  
  3013.     void CommandTaskGotoEntityOffsetXY( int iPedID, int iEntityID, int iTime, float fTargetRadius, float fOffsetX, float fOffsetY, float fMoveBlendRatio, int iGotoEntityOffsetFlags )
  3014.     {
  3015.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0), "TASK_GOTO_ENTITY_OFFSET_XY - Time must be -1 for infinite and > 0" ))
  3016.         {      
  3017.             const CEntity* pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iEntityID);
  3018.             if (pEntity)
  3019.             {
  3020.                 if (NetworkInterface::IsGameInProgress() && (!pEntity->GetIsDynamic() || !((CDynamicEntity*)pEntity)->GetNetworkObject()))
  3021.                 {
  3022.                     scriptAssertf(0, "%s:TASK_GOTO_ENTITY_OFFSET_XY; the entity must be networked or this ped will not be able to migrate properly", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3023.                 }
  3024.  
  3025.                 CTask * pTask;
  3026.  
  3027.                 if( (iGotoEntityOffsetFlags & ESEEK_OFFSET_ORIENTATES_WITH_ENTITY) != 0 )
  3028.                 {
  3029.                     pTask = rage_new TTaskMoveSeekEntityXYOffsetRotated(pEntity, iTime);
  3030.                     CEntitySeekPosCalculatorXYOffsetRotated seekPosCalculator( Vector3(fOffsetX, fOffsetY, 0.0f) );
  3031.                     ((TTaskMoveSeekEntityXYOffsetRotated*)pTask)->SetEntitySeekPosCalculator(seekPosCalculator);
  3032.  
  3033.                     ((TTaskMoveSeekEntityXYOffsetRotated*)pTask)->SetMoveBlendRatio(fMoveBlendRatio);
  3034.                     ((TTaskMoveSeekEntityXYOffsetRotated*)pTask)->SetTargetRadius(fTargetRadius);
  3035.                     if((iGotoEntityOffsetFlags & ESEEK_KEEP_TO_PAVEMENTS)!=0)
  3036.                         ((TTaskMoveSeekEntityXYOffsetRotated*)pTask)->SetPreferPavements(true);
  3037.                     ((TTaskMoveSeekEntityXYOffsetRotated*)pTask)->SetUseLargerSearchExtents(true);
  3038.                 }
  3039.                 else
  3040.                 {
  3041.                     pTask = rage_new TTaskMoveSeekEntityXYOffsetFixed(pEntity, iTime);
  3042.                     CEntitySeekPosCalculatorXYOffsetFixed seekPosCalculator( Vector3(fOffsetX, fOffsetY, 0.0f) );
  3043.                     ((TTaskMoveSeekEntityXYOffsetFixed*)pTask)->SetEntitySeekPosCalculator(seekPosCalculator);
  3044.  
  3045.                     ((TTaskMoveSeekEntityXYOffsetFixed*)pTask)->SetMoveBlendRatio(fMoveBlendRatio);
  3046.                     ((TTaskMoveSeekEntityXYOffsetFixed*)pTask)->SetTargetRadius(fTargetRadius);
  3047.                     if((iGotoEntityOffsetFlags & ESEEK_KEEP_TO_PAVEMENTS)!=0)
  3048.                         ((TTaskMoveSeekEntityXYOffsetFixed*)pTask)->SetPreferPavements(true);
  3049.                     ((TTaskMoveSeekEntityXYOffsetFixed*)pTask)->SetUseLargerSearchExtents(true);
  3050.                 }
  3051.            
  3052.                 CTaskComplexControlMovement* pSimpleControlMovement = rage_new CTaskComplexControlMovement(pTask);
  3053.                 CScriptPeds::GivePedScriptedTask( iPedID, pSimpleControlMovement, SCRIPT_TASK_GOTO_ENTITY_OFFSET, "TASK_GOTO_ENTITY_OFFSET_XY");
  3054.             }
  3055.         }
  3056.     }
  3057.  
  3058.     // Remember to update eScriptInvestigateFlags in commands_task.sch
  3059.     enum eScriptInvestigateFlags
  3060.     {
  3061.         SIF_DONT_RETURN_TO_ORIGINAL_POSITION = 1,
  3062.     };
  3063.    
  3064.     void CommandTaskInvestigateCoords (int iPedID, const scrVector & vCoords, int timeToSpendAtSearchPointInMS, int investigateFlags)
  3065.     {
  3066.         Vector3 vInvestigationPosition(vCoords);
  3067.  
  3068.         // As there's only one flag right now, I'm just passing in a bool to the constructor of CTaskInvestigate. [1/9/2013 mdawe]
  3069.         const bool bReturnToPosition = !(investigateFlags & SIF_DONT_RETURN_TO_ORIGINAL_POSITION);
  3070.         CTask* pTask = rage_new CTaskInvestigate(vInvestigationPosition, NULL, EVENT_SUSPICIOUS_ACTIVITY, timeToSpendAtSearchPointInMS, bReturnToPosition);
  3071.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_INVESTIGATE_COORDS, "TASK_INVESTIGATE");
  3072.     }
  3073.  
  3074.  
  3075.     // Remember to update the scripts if you change these flags
  3076.     // eScriptLookAtFlags in commands_task.sch
  3077.     // Please leave as numbers so its easy to compare with the flags in commands_task.sch
  3078.     // i.e dont change 4 to (1<<2)
  3079.     enum eScriptLookatFlags
  3080.     {
  3081.         SLF_SLOW_TURN_RATE          = 1,    // turn the head toward the target slowly
  3082.         SLF_FAST_TURN_RATE          = 2,    // turn the head toward the target quickly
  3083.         SLF_EXTEND_YAW_LIMIT        = 4,    // wide yaw head limits
  3084.         SLF_EXTEND_PITCH_LIMIT      = 8,    // wide pitch head limit
  3085.         SLF_WIDEST_YAW_LIMIT        = 16,   // widest yaw head limit
  3086.         SLF_WIDEST_PITCH_LIMIT      = 32,   // widest pitch head limit
  3087.         SLF_NARROW_YAW_LIMIT        = 64,   // narrow yaw head limits
  3088.         SLF_NARROW_PITCH_LIMIT      = 128,  // narrow pitch head limit
  3089.         SLF_NARROWEST_YAW_LIMIT     = 256,  // narrowest yaw head limit
  3090.         SLF_NARROWEST_PITCH_LIMIT   = 512,  // narrowest pitch head limit
  3091.         SLF_USE_TORSO               = 1024, // use the torso aswell as the neck and head (currently disabled)
  3092.         SLF_WHILE_NOT_IN_FOV        = 2048, // keep tracking the target even if they are not in the hard coded FOV
  3093.         SLF_USE_CAMERA_FOCUS        = 4096, // use the camera as the target
  3094.         SLF_USE_EYES_ONLY           = 8192, // only track the target with the eyes  
  3095.         SLF_USE_LOOK_DIR            = 16384, // use information in look dir DOF
  3096.         SLF_FROM_SCRIPT             = 32768, // internal use only
  3097.         SLF_USE_REF_DIR_ABSOLUTE    = 65536  // use absolute reference direction mode for solver
  3098.     };
  3099.  
  3100.     int ConvertScriptLookatFlags(int scriptFlags)
  3101.     {
  3102.         int lookatFlags = LF_FROM_SCRIPT;
  3103.         scriptFlags & SLF_SLOW_TURN_RATE        ? lookatFlags |= LF_SLOW_TURN_RATE          : 0;
  3104.         scriptFlags & SLF_FAST_TURN_RATE        ? lookatFlags |= LF_FAST_TURN_RATE          : 0;
  3105.         scriptFlags & SLF_EXTEND_YAW_LIMIT      ? lookatFlags |= LF_WIDEST_YAW_LIMIT        : 0;
  3106.         scriptFlags & SLF_EXTEND_PITCH_LIMIT    ? lookatFlags |= LF_WIDEST_PITCH_LIMIT      : 0;
  3107.         scriptFlags & SLF_WIDEST_YAW_LIMIT      ? lookatFlags |= LF_WIDEST_YAW_LIMIT        : 0;
  3108.         scriptFlags & SLF_WIDEST_PITCH_LIMIT    ? lookatFlags |= LF_WIDEST_PITCH_LIMIT      : 0;
  3109.         scriptFlags & SLF_NARROW_YAW_LIMIT      ? lookatFlags |= LF_NARROW_YAW_LIMIT        : 0;
  3110.         scriptFlags & SLF_NARROW_PITCH_LIMIT    ? lookatFlags |= LF_NARROW_PITCH_LIMIT      : 0;
  3111.         scriptFlags & SLF_NARROWEST_YAW_LIMIT   ? lookatFlags |= LF_NARROWEST_YAW_LIMIT     : 0;
  3112.         scriptFlags & SLF_NARROWEST_PITCH_LIMIT ? lookatFlags |= LF_NARROWEST_PITCH_LIMIT   : 0;
  3113.         scriptFlags & SLF_USE_TORSO             ? lookatFlags |= LF_USE_TORSO               : 0;
  3114.         scriptFlags & SLF_WHILE_NOT_IN_FOV      ? lookatFlags |= LF_WHILE_NOT_IN_FOV        : 0;
  3115.         scriptFlags & SLF_USE_CAMERA_FOCUS      ? lookatFlags |= LF_USE_CAMERA_FOCUS        : 0;
  3116.         scriptFlags & SLF_USE_EYES_ONLY         ? lookatFlags |= LF_USE_EYES_ONLY           : 0;
  3117.         scriptFlags & SLF_USE_LOOK_DIR          ? lookatFlags |= LF_USE_LOOK_DIR            : 0;
  3118.         scriptFlags & SLF_USE_REF_DIR_ABSOLUTE  ? lookatFlags |= LF_USE_REF_DIR_ABSOLUTE    : 0;
  3119.         return lookatFlags;
  3120.     }
  3121.  
  3122.     void CommandTaskLookAtCoord(int iPedID, const scrVector & scrVecCoors, int iTime, int flags, int priority)
  3123.     {      
  3124.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0), "TASK_LOOK_AT_COORD - Time must be -1 for infinite and > 0" ))
  3125.         {
  3126.             int lookatFlags = ConvertScriptLookatFlags(flags);
  3127.  
  3128.             if(NULL_IN_SCRIPTING_LANGUAGE!=iPedID)
  3129.             {
  3130.                 if (SCRIPT_VERIFY(-1==CTaskSequences::ms_iActiveSequence, "TASK_LOOK_AT_COORD - Sequence opened unexpectedly"))
  3131.                 {      
  3132.                     CPed *pPed=CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  3133.                     if (pPed)
  3134.                     {  
  3135.                         ikDebugf3("%u TASK_LOOK_AT_COORD(pPed %p %s, scrVecCoors %.3f,%.3f,%.3f, iTime %i, flags %i, priority %i) LookAt",
  3136.                             fwTimer::GetFrameCount(), pPed, pPed->GetModelName(), scrVecCoors.x, scrVecCoors.y, scrVecCoors.z, iTime, flags, priority);
  3137.  
  3138.                         // this script command is not approved for use in network scripts
  3139.                         Vector3 offset(scrVecCoors);
  3140.                         pPed->GetIkManager().LookAt(0, 0, iTime, BONETAG_INVALID, &offset, lookatFlags, 500, 500, (CIkManager::eLookAtPriority)priority);
  3141.                     }
  3142.                     else
  3143.                     {
  3144.                         ikDebugf3("%u TASK_LOOK_AT_COORD(iPedID %i, scrVecCoors %.3f,%.3f,%.3f, iTime %i, flags %i, priority %i) Could not find ped!\n%s",
  3145.                             fwTimer::GetFrameCount(), iPedID, scrVecCoors.x, scrVecCoors.y, scrVecCoors.z, iTime, flags, priority,
  3146.                             CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3147.                     }
  3148.                 }
  3149.                 else
  3150.                 {
  3151.                     ikDebugf3("%u TASK_LOOK_AT_COORD(iPedID %i, scrVecCoors %.3f,%.3f,%.3f, iTime %i, flags %i, priority %i) Sequence opened unexpectedly!\n%s",
  3152.                         fwTimer::GetFrameCount(), iPedID, scrVecCoors.x, scrVecCoors.y, scrVecCoors.z, iTime, flags, priority,
  3153.                         CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3154.                 }
  3155.             }
  3156.             else
  3157.             {
  3158.                 Vector3 offset(scrVecCoors);
  3159.                
  3160.                 if (SCRIPT_VERIFY(CTaskSequences::ms_iActiveSequence >=0 && CTaskSequences::ms_iActiveSequence<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "TASK_LOOK_AT_COORD - Sequence task closed"))
  3161.                 {  
  3162.                     if (SCRIPT_VERIFY(CTaskSequences::ms_bIsOpened[CTaskSequences::ms_iActiveSequence], "TASK_LOOK_AT_COORD - sequence task closed"))
  3163.                     {  
  3164.                         ikDebugf3("%u TASK_LOOK_AT_COORD(iPedID %i, scrVecCoors %.3f,%.3f,%.3f, iTime %i, flags %i, priority %i) CTaskTriggerLookAt",
  3165.                             fwTimer::GetFrameCount(), iPedID, scrVecCoors.x, scrVecCoors.y, scrVecCoors.z, iTime, flags, priority);
  3166.  
  3167.                         CTask* pTask = rage_new CTaskTriggerLookAt(NULL, iTime, BONETAG_INVALID, offset, lookatFlags);
  3168.                         CTaskSequences::ms_TaskSequenceLists[CTaskSequences::ms_iActiveSequence].AddTask(pTask);
  3169.                     }
  3170.                     else
  3171.                     {
  3172.                         ikDebugf3("%u TASK_LOOK_AT_COORD(iPedID %i, scrVecCoors %.3f,%.3f,%.3f, iTime %i, flags %i, priority %i) Sequence task closed!\n%s",
  3173.                             fwTimer::GetFrameCount(), iPedID, scrVecCoors.x, scrVecCoors.y, scrVecCoors.z, iTime, flags, priority,
  3174.                             CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3175.                     }
  3176.                 }
  3177.                 else
  3178.                 {
  3179.                     ikDebugf3("%u TASK_LOOK_AT_COORD(iPedID %i, scrVecCoors %.3f,%.3f,%.3f, iTime %i, flags %i, priority %i) Sequence task closed!\n%s",
  3180.                         fwTimer::GetFrameCount(), iPedID, scrVecCoors.x, scrVecCoors.y, scrVecCoors.z, iTime, flags, priority,
  3181.                         CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3182.                 }
  3183.             }
  3184.         }
  3185.     }
  3186.  
  3187.     void CommandTaskLookAtEntity(int iPedID, int iEntityID, int iTime, int flags, int priority)
  3188.     {
  3189.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0), "TASK_LOOK_AT_ENTITY - Time must be -1 for infinite and > 0" ))
  3190.         {
  3191.             int lookatFlags = ConvertScriptLookatFlags(flags);
  3192.  
  3193.             const CEntity* pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iEntityID, CTheScripts::GUID_ASSERT_FLAGS_NO_DEAD_CHECK);
  3194.             if (pEntity)
  3195.             {
  3196.                 eAnimBoneTag boneTag = BONETAG_INVALID;
  3197.  
  3198.                 // Use the head bone as the target (if possible)
  3199.                 if ( pEntity->GetIsTypePed() )
  3200.                 {
  3201.                     // Some animals e.g A_C_Stingray dont have a head fall back to the entity position
  3202.                     s32 boneIdx = -1;
  3203.                     if  ( pEntity->GetSkeletonData().ConvertBoneIdToIndex((u16)BONETAG_HEAD, boneIdx) )
  3204.                     {
  3205.                         boneTag = BONETAG_HEAD;
  3206.                     }
  3207.                 }
  3208.  
  3209.                 if(NULL_IN_SCRIPTING_LANGUAGE!=iPedID)
  3210.                 {
  3211.                     if (SCRIPT_VERIFY(-1==CTaskSequences::ms_iActiveSequence, "TASK_LOOK_AT_ENTITY - Sequence opened unexpectedly"))
  3212.                     {
  3213.                         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_NO_DEAD_CHECK & CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3214.                         if(pPed)
  3215.                         {
  3216.                             scriptAssertf(pPed != pEntity, "TASK_LOOK_AT_ENTITY - Target and source entities are the same (entityId = %d)", iPedID);
  3217.                             if(NetworkUtils::IsNetworkCloneOrMigrating(pPed))
  3218.                             {
  3219.                                 if(SCRIPT_VERIFY(pEntity->GetIsDynamic(), "TASK_LOOK_AT_ENTITY - Entity for clone is not dynamic!"))
  3220.                                 {
  3221.                                     netObject* pNetObj = static_cast<const CDynamicEntity*>(pEntity)->GetNetworkObject();
  3222.                                     if(SCRIPT_VERIFY(pNetObj, "TASK_LOOK_AT_ENTITY - Entity for clone is not networked!"))
  3223.                                     {
  3224.                                         ikDebugf3("%u TASK_LOOK_AT_ENTITY(pPed %p %s, pEntity %p %s, iTime %i, flags %i, priority %i) CSettingOfLookAtEntity",
  3225.                                             fwTimer::GetFrameCount(), pPed, pPed->GetModelName(), pEntity, pEntity->GetModelName(), iTime, flags, priority);
  3226.  
  3227.                                         CScriptEntityStateChangeEvent::CSettingOfLookAtEntity parameters(pNetObj, lookatFlags, iTime);
  3228.                                         CScriptEntityStateChangeEvent::Trigger(pPed->GetNetworkObject(), parameters);          
  3229.                                     }
  3230.                                     else
  3231.                                     {
  3232.                                         ikDebugf3("%u TASK_LOOK_AT_ENTITY(pPed %p %s, pEntity %p %s, iTime %i, flags %i, priority %i) Entity for clone is not networked!\n%s",
  3233.                                             fwTimer::GetFrameCount(), pPed, pPed->GetModelName(), pEntity, pEntity->GetModelName(), iTime, flags, priority,
  3234.                                             CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3235.                                     }
  3236.                                 }
  3237.                                 else
  3238.                                 {
  3239.                                     ikDebugf3("%u TASK_LOOK_AT_ENTITY(pPed %p %s, pEntity %p %s, iTime %i, flags %i, priority %i) Entity for clone is not dynamic!\n%s",
  3240.                                         fwTimer::GetFrameCount(), pPed, pPed->GetModelName(), pEntity, pEntity->GetModelName(), iTime, flags, priority,
  3241.                                         CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3242.                                 }
  3243.                             }
  3244.                             else
  3245.                             {
  3246.                                 ikDebugf3("%u TASK_LOOK_AT_ENTITY(pPed %p %s, pEntity %p %s, iTime %i, flags %i, priority %i) LookAt",
  3247.                                     fwTimer::GetFrameCount(), pPed, pPed->GetModelName(), pEntity, pEntity->GetModelName(), iTime, flags, priority);
  3248.  
  3249.                                 pPed->GetIkManager().LookAt(0, pEntity, iTime, boneTag, NULL, lookatFlags, 500, 500, (CIkManager::eLookAtPriority)priority);
  3250.                             }
  3251.                         }  
  3252.                         else
  3253.                         {
  3254.                             ikDebugf3("%u TASK_LOOK_AT_ENTITY(iPedID %i, pEntity %p %s, iTime %i, flags %i, priority %i) Entity for clone is not dynamic!\n%s",
  3255.                                 fwTimer::GetFrameCount(), iPedID, pEntity, pEntity->GetModelName(), iTime, flags, priority,
  3256.                                 CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3257.                         }
  3258.                     }
  3259.                 }
  3260.                 else
  3261.                 {
  3262.                     Vector3 offset(0,0,0);
  3263.                     if (SCRIPT_VERIFY(CTaskSequences::ms_iActiveSequence >=0 && CTaskSequences::ms_iActiveSequence<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "TASK_LOOK_AT_ENTITY - Sequence task closed"))
  3264.                     {
  3265.                         if (SCRIPT_VERIFY(CTaskSequences::ms_bIsOpened[CTaskSequences::ms_iActiveSequence], "TASK_LOOK_AT_ENTITY - sequence task closed"))
  3266.                         {
  3267.                             ikDebugf3("%u TASK_LOOK_AT_ENTITY(iPedID %i, pEntity %p %s, iTime %i, flags %i, priority %i) CTaskTriggerLookAt",
  3268.                                 fwTimer::GetFrameCount(), iPedID, pEntity, pEntity->GetModelName(), iTime, flags, priority);
  3269.  
  3270.                             CTask* pTask = rage_new CTaskTriggerLookAt(pEntity, iTime, boneTag, offset, lookatFlags);
  3271.                             CTaskSequences::ms_TaskSequenceLists[CTaskSequences::ms_iActiveSequence].AddTask(pTask);
  3272.                         }
  3273.                         else
  3274.                         {
  3275.                             ikDebugf3("%u TASK_LOOK_AT_ENTITY(iPedID %i, pEntity %p %s, iTime %i, flags %i, priority %i) Sequence task closed!\n%s",
  3276.                                 fwTimer::GetFrameCount(), iPedID, pEntity, pEntity->GetModelName(), iTime, flags, priority,
  3277.                                 CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3278.                         }
  3279.                     }
  3280.                     else
  3281.                     {
  3282.                         ikDebugf3("%u TASK_LOOK_AT_ENTITY(iPedID %i, pEntity %p %s, iTime %i, flags %i, priority %i) Sequence task closed!\n%s",
  3283.                             fwTimer::GetFrameCount(), iPedID, pEntity, pEntity->GetModelName(), iTime, flags, priority,
  3284.                             CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3285.                     }
  3286.                 }
  3287.             }
  3288.             else
  3289.             {
  3290.                 ikDebugf3("%u TASK_LOOK_AT_ENTITY(iPedID %i, iEntityID %i, iTime %i, flags %i, priority %i) Could not find entity!\n%s",
  3291.                     fwTimer::GetFrameCount(), iPedID, iEntityID, iTime, flags, priority,
  3292.                     CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3293.             }
  3294.         }
  3295.         else
  3296.         {
  3297.             ikDebugf3("%u TASK_LOOK_AT_ENTITY(iPedID %i, iEntityID %i, iTime %i, flags %i, priority %i) Time must be -1 for infinite and > 0!\n%s",
  3298.                 fwTimer::GetFrameCount(), iPedID, iEntityID, iTime, flags, priority,
  3299.                 CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3300.         }
  3301.     }
  3302.  
  3303.     void CommandClearLookAt(int iPedID)
  3304.     {
  3305.         if(NULL_IN_SCRIPTING_LANGUAGE!=iPedID)
  3306.         {
  3307.             if(SCRIPT_VERIFY(-1==CTaskSequences::ms_iActiveSequence, "TASK_CLEAR_LOOK_AT - Sequence opened unexpectedly"))
  3308.             {
  3309.                 CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  3310.                 if(pPed)
  3311.                 {
  3312.                     if(pPed->GetIkManager().IsLooking())
  3313.                     {
  3314.                         ikDebugf3("%u CLEAR_LOOK_AT(pPed %p %s) AbortLookAt(500)",
  3315.                             fwTimer::GetFrameCount(), pPed, pPed->GetModelName());
  3316.  
  3317.                         pPed->GetIkManager().AbortLookAt(500);
  3318.                     }
  3319.                     else
  3320.                     {
  3321.                         ikDebugf3("%u CLEAR_LOOK_AT(pPed %p %s) Ped is not looking!\n%s",
  3322.                             fwTimer::GetFrameCount(), pPed, pPed->GetModelName(),
  3323.                             CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3324.                     }
  3325.                 }
  3326.                 else
  3327.                 {
  3328.                     ikDebugf3("%u CLEAR_LOOK_AT(iPedID %i) Could not find ped!\n%s",
  3329.                         fwTimer::GetFrameCount(), iPedID,
  3330.                         CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3331.                 }
  3332.             }
  3333.             else
  3334.             {
  3335.                 ikDebugf3("%u CLEAR_LOOK_AT(iPedID %i) Sequence opened unexpectedly!\n%s",
  3336.                     fwTimer::GetFrameCount(), iPedID,
  3337.                     CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3338.             }
  3339.         }
  3340.         else
  3341.         {
  3342.             if(SCRIPT_VERIFY(CTaskSequences::ms_iActiveSequence >=0 && CTaskSequences::ms_iActiveSequence<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "CLEAR_LOOK_AT - Sequence task closed"))
  3343.             {
  3344.                 if(SCRIPT_VERIFY(CTaskSequences::ms_bIsOpened[CTaskSequences::ms_iActiveSequence], "TASK_CLEAR_LOOK_AT - sequence task closed"))
  3345.                 {
  3346.                     ikDebugf3("%u CLEAR_LOOK_AT(iPedID %i) CTaskClearLookAt",
  3347.                         fwTimer::GetFrameCount(), iPedID);
  3348.  
  3349.                     CTask* pTask = rage_new CTaskClearLookAt();
  3350.                     CTaskSequences::ms_TaskSequenceLists[CTaskSequences::ms_iActiveSequence].AddTask(pTask);
  3351.                 }
  3352.                 else
  3353.                 {
  3354.                     ikDebugf3("%u CLEAR_LOOK_AT(iPedID %i) Sequence task closed!\n%s",
  3355.                         fwTimer::GetFrameCount(), iPedID,
  3356.                         CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3357.                 }
  3358.             }
  3359.             else
  3360.             {
  3361.                 ikDebugf3("%u CLEAR_LOOK_AT(iPedID %i) Sequence task closed!\n%s",
  3362.                     fwTimer::GetFrameCount(), iPedID,
  3363.                     CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3364.             }
  3365.         }
  3366.     }
  3367.  
  3368.     static u32 giSearchModelIndex = fwModelId::MI_INVALID;
  3369.     static CEntity* gpClosestEntity = NULL;
  3370.     static float gfClosestDistSq = 0.0f;
  3371.     static Vector3 gvSearchPos;
  3372.  
  3373.     bool    FindNearestEntityCB (CEntity* pEntity, void* UNUSED_PARAM(pData) )
  3374.     {
  3375.         C2dEffect* pSpawnPoint = pEntity->GetClosest2dEffect(ET_SPAWN_POINT, gvSearchPos);
  3376.  
  3377.         if(!pSpawnPoint)
  3378.         {
  3379.             return true;
  3380.         }
  3381.  
  3382.         if( pEntity->GetModelIndex() == giSearchModelIndex ||
  3383.             !CModelInfo::IsValidModelInfo(giSearchModelIndex))
  3384.         {
  3385.             float fDistSq = DistSquared(pEntity->GetTransform().GetPosition(), RCC_VEC3V(gvSearchPos)).Getf();
  3386.  
  3387.             if(gpClosestEntity == NULL ||
  3388.                 gfClosestDistSq > fDistSq )
  3389.             {
  3390.                 gpClosestEntity = pEntity;
  3391.                 gfClosestDistSq = fDistSq;
  3392.             }
  3393.         }
  3394.         return true;
  3395.     }
  3396.  
  3397.     bool CommandIsPedInvestigatingWhistlingEvent( int iPedID )
  3398.     {
  3399.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  3400.         if(pPed)
  3401.         {
  3402.             CTaskInvestigate* pInvestigateTask = (CTaskInvestigate*) pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_INVESTIGATE);
  3403.             if (pInvestigateTask && pInvestigateTask->IsInvestigatingWhistlingEvent())
  3404.             {
  3405.                 return true;
  3406.             }
  3407.         }
  3408.         return false;
  3409.     }
  3410.  
  3411.     void CommandSetInvestigationPosition( int iPedID, const scrVector & scrVecInvestigationPosition)
  3412.     {
  3413.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  3414.         if(pPed)
  3415.         {
  3416.             CTaskInvestigate* pInvestigateTask = (CTaskInvestigate*) pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_INVESTIGATE);
  3417.             if (pInvestigateTask)
  3418.             {
  3419.                 pInvestigateTask->SetInvestigationPos(scrVecInvestigationPosition);
  3420.             }
  3421.         }
  3422.     }
  3423.  
  3424.     void CommandTaskTurnPedToFaceCoord( int iPedID, const scrVector & scrVecCoors, int iTime )
  3425.     {
  3426.         float fTime;
  3427.         if(iTime < 0)
  3428.         {
  3429.             fTime = -1.0f;
  3430.         }
  3431.         else if(iTime == 0)
  3432.         {
  3433.             fTime = 0.0f;
  3434.         }
  3435.         else
  3436.         {
  3437.             fTime = ((float)iTime)/1000.0f;
  3438.         }
  3439.         CTask* pTask = rage_new CTaskTurnToFaceEntityOrCoord(Vector3(scrVecCoors), CTaskMoveAchieveHeading::ms_fHeadingChangeRateFrac, CTaskMoveAchieveHeading::ms_fHeadingTolerance, fTime);
  3440.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_TURN_PED_TO_FACE_COORD,  "TASK_TURN_PED_TO_FACE_COORD");
  3441.     }
  3442.  
  3443.     void CommandTaskDrivePointRoute( int iPedID, int iVehicleID, float fCruiseSpeed )
  3444.     {
  3445.         if(SCRIPT_VERIFY(CTaskMoveFollowPointRoute::ms_pointRoute.GetSize() > 0,"TASK_DRIVE_POINT_ROUTE: Point route didn't have any points in it."))
  3446.         {
  3447.             CTask* pTask;
  3448.             CVehicle *pVehicle = NULL;
  3449.             if(iVehicleID>=0)
  3450.             {
  3451.                 pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3452.                 if(!pVehicle)
  3453.                     return;
  3454.             }
  3455.             pTask=rage_new CTaskDrivePointRoute(pVehicle,CTaskMoveFollowPointRoute::ms_pointRoute, fCruiseSpeed);
  3456.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_DRIVE_POINT_ROUTE, "TASK_DRIVE_POINT_ROUTE");
  3457.         }
  3458.     }
  3459.  
  3460.     void GivePedGoToPointAimingTask(
  3461.         int iPedID, const CAITarget& goToTarget, const CAITarget& aimAtTarget, float fMoveBlendRatio,
  3462.         float TargetRadius, float SlowDistance, bool bShoot, bool bUseNavmesh, int iNavFlags, bool bInstantBlendToAim, int iFiringPatternHash,
  3463.         int iScriptTaskType, const char* commandName, const int iTime )
  3464.     {
  3465. #if __ASSERT
  3466.         Vector3 vGoToPosition;
  3467.         Vector3 vAimAtPosition;
  3468.  
  3469.         if(goToTarget.GetPosition(vGoToPosition))
  3470.         {
  3471.             scriptAssertf(!vGoToPosition.IsClose(VEC3_ZERO, SMALL_FLOAT), "%s - Goto position is too close to the origin. %s", commandName, CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3472.         }
  3473.  
  3474.         if(aimAtTarget.GetPosition(vAimAtPosition))
  3475.         {
  3476.             scriptAssertf(!vAimAtPosition.IsClose(VEC3_ZERO, SMALL_FLOAT), "%s - Aim at position is too close to the origin. %s", commandName, CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3477.         }
  3478. #endif
  3479.  
  3480.         CTaskGoToPointAiming* pTask = rage_new CTaskGoToPointAiming(goToTarget, aimAtTarget, fMoveBlendRatio, bShoot, iTime);
  3481.         pTask->SetTargetRadius(TargetRadius);
  3482.         pTask->SetSlowDownDistance(SlowDistance);
  3483.         pTask->SetUseNavmesh(bUseNavmesh);
  3484.         pTask->SetScriptNavFlags(iNavFlags);
  3485.         pTask->SetInstantBlendToAim(bInstantBlendToAim);
  3486.        
  3487.         if(bShoot)
  3488.         {
  3489.             pTask->SetFiringPattern(iFiringPatternHash);
  3490.         }
  3491.  
  3492.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, iScriptTaskType, commandName);
  3493.     }
  3494.  
  3495.     void CommandTaskGoToCoordWhileAimingAtCoord(
  3496.         int iPedID, const scrVector & scrVecGoToCoord, const scrVector & scrVecAimAtCoord, float fMoveBlendRatio,
  3497.         bool bShoot, float TargetRadius, float SlowDistance, bool bUseNavmesh, int iNavFlags, bool bInstantBlendToAim, int iFiringPatternHash )
  3498.     {
  3499.         GivePedGoToPointAimingTask(
  3500.             iPedID, CAITarget(Vector3(scrVecGoToCoord)), CAITarget(Vector3(scrVecAimAtCoord)), fMoveBlendRatio,
  3501.             TargetRadius, SlowDistance, bShoot, bUseNavmesh, iNavFlags, bInstantBlendToAim, iFiringPatternHash, SCRIPT_TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD,
  3502.             "TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD", -1);
  3503.     }
  3504.  
  3505.     void CommandTaskGoToCoordWhileAimingAtEntity(
  3506.         int iPedID, const scrVector & scrVecGoToCoord, int iAimAtEntityID, float fMoveBlendRatio,
  3507.         bool bShoot, float TargetRadius, float SlowDistance, bool bUseNavmesh, int iNavFlags, bool bInstantBlendToAim, int iFiringPatternHash, const int iTime )
  3508.     {
  3509.         const CEntity* pAimAtEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iAimAtEntityID);
  3510.         if(pAimAtEntity)
  3511.         {
  3512.             GivePedGoToPointAimingTask(
  3513.                 iPedID, CAITarget(Vector3(scrVecGoToCoord)), CAITarget(pAimAtEntity), fMoveBlendRatio,
  3514.                 TargetRadius, SlowDistance, bShoot, bUseNavmesh, iNavFlags, bInstantBlendToAim, iFiringPatternHash, SCRIPT_TASK_GO_TO_COORD_WHILE_AIMING_AT_ENTITY,
  3515.                 "TASK_GO_TO_COORD_WHILE_AIMING_AT_ENTITY", iTime);
  3516.         }
  3517.     }
  3518.  
  3519.     void CommandTaskGoToCoordAndAimAtHatedEntitiesNearCoord(
  3520.         int iPedID, const scrVector & scrVecGoToCoord, const scrVector & scrAimNearCoord, float fMoveBlendRatio,
  3521.         bool bShoot, float TargetRadius, float SlowDistance, bool bUseNavmesh, int iNavFlags, int iTaskFlags, int iFiringPatternHash )
  3522.     {
  3523.         Vector3 vGoToPosition(scrVecGoToCoord);
  3524.         scriptAssertf(!vGoToPosition.IsClose(VEC3_ZERO, SMALL_FLOAT), "TASK_GO_TO_COORD_AND_AIM_AT_HATED_ENTITIES_NEAR_COORD - Go to position is too close to the origin. %s", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3525.  
  3526.         Vector3 vAimNearPosition(scrAimNearCoord);
  3527.         scriptAssertf(!vAimNearPosition.IsClose(VEC3_ZERO, SMALL_FLOAT), "TASK_GO_TO_COORD_AND_AIM_AT_HATED_ENTITIES_NEAR_COORD - Aim near position is too close to the origin. %s", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  3528.        
  3529.         CTaskGoToPointAiming* pTask = rage_new CTaskGoToPointAiming(CAITarget(vGoToPosition), CAITarget(vAimNearPosition), fMoveBlendRatio, bShoot);
  3530.         pTask->SetTargetRadius(TargetRadius);
  3531.         pTask->SetSlowDownDistance(SlowDistance);
  3532.         pTask->SetUseNavmesh(bUseNavmesh);
  3533.         pTask->SetAimAtHatedEntitiesNearAimCoord(true);
  3534.         pTask->SetScriptNavFlags(iNavFlags);
  3535.         pTask->SetConfigFlags(iTaskFlags);
  3536.  
  3537.         if(bShoot)
  3538.         {
  3539.             pTask->SetFiringPattern(iFiringPatternHash);
  3540.         }
  3541.  
  3542.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_GO_TO_COORD_AND_AIM_AT_HATED_ENTITIES_NEAR_COORD,
  3543.                                         "TASK_GO_TO_COORD_AND_AIM_AT_HATED_ENTITIES_NEAR_COORD");
  3544.     }
  3545.  
  3546.     void CommandTaskGoToEntityWhileAimingAtCoord(
  3547.         int iPedID, int iEntityID, const scrVector & scrVecAimAtCoord, float fMoveBlendRatio,
  3548.         bool bShoot, float TargetRadius, float SlowDistance, bool bUseNavmesh, bool bInstantBlendToAim, int iFiringPatternHash )
  3549.     {
  3550.         const CEntity* pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iEntityID);
  3551.         if(pEntity)
  3552.         {
  3553.             GivePedGoToPointAimingTask(
  3554.                 iPedID, CAITarget(pEntity), CAITarget(Vector3(scrVecAimAtCoord)), fMoveBlendRatio,
  3555.                 TargetRadius, SlowDistance, bShoot, bUseNavmesh, 0, bInstantBlendToAim, iFiringPatternHash, SCRIPT_TASK_GO_TO_ENTITY_WHILE_AIMING_AT_COORD,
  3556.                 "TASK_GO_TO_ENTITY_WHILE_AIMING_AT_COORD", -1);
  3557.         }
  3558.     }
  3559.  
  3560.     void CommandTaskGoToEntityWhileAimingAtEntity(
  3561.         int iPedID, int iGoToEntityID, int iAimAtEntityID, float fMoveBlendRatio,
  3562.         bool bShoot, float TargetRadius, float SlowDistance, bool bUseNavmesh, bool bInstantBlendToAim, int iFiringPatternHash )
  3563.     {
  3564.         const CEntity* pGoToEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iGoToEntityID);
  3565.         const CEntity* pAimAtEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iAimAtEntityID);
  3566.  
  3567.         if(pGoToEntity && pAimAtEntity)
  3568.         {
  3569.             GivePedGoToPointAimingTask(
  3570.                 iPedID, CAITarget(pGoToEntity), CAITarget(pAimAtEntity), fMoveBlendRatio,
  3571.                 TargetRadius, SlowDistance, bShoot, bUseNavmesh, 0, bInstantBlendToAim, iFiringPatternHash, SCRIPT_TASK_GO_TO_ENTITY_WHILE_AIMING_AT_ENTITY,
  3572.                 "TASK_GO_TO_ENTITY_WHILE_AIMING_AT_ENTITY", -1);
  3573.         }
  3574.     }
  3575.  
  3576.     void CommandTaskVehicleTempAction( int iPedID, int iVehicleID, int iAction, int iTime )
  3577.     {
  3578.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_VEHICLE_TEMP_ACTION - Time must be -1 for infinite and > 0" ))
  3579.         {
  3580.             CVehicle *pVehicle = 0;
  3581.             CTask* pTask;
  3582.             {
  3583.                 if(iVehicleID!=NULL_IN_SCRIPTING_LANGUAGE)
  3584.                 {
  3585.                     pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3586.                     if(!pVehicle)
  3587.                         return;
  3588.                 }
  3589.  
  3590.                 if(pVehicle)
  3591.                 {
  3592.                     if(iPedID!=NULL_IN_SCRIPTING_LANGUAGE)
  3593.                     {
  3594.                         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_NO_DEAD_CHECK & CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3595.                         if(pPed && NetworkUtils::IsNetworkCloneOrMigrating(pPed))
  3596.                         {
  3597.                             netObject* pNetObj = pPed->GetNetworkObject();
  3598.                             if(pNetObj)
  3599.                             {
  3600.                                 CScriptEntityStateChangeEvent::CSettingOfTaskVehicleTempAction parameters(pVehicle->GetNetworkObject(),iAction,iTime);
  3601.                                 CScriptEntityStateChangeEvent::Trigger(pNetObj, parameters);
  3602.                             }
  3603.                         }
  3604.                         else
  3605.                         {
  3606.                             if (NetworkInterface::IsGameInProgress() && iPedID==NULL_IN_SCRIPTING_LANGUAGE)
  3607.                             {
  3608.                                 scriptAssertf(0, "TASK_VEHICLE_TEMP_ACTION - temp actions cannot be added to a sequence in MP");
  3609.                                 return;
  3610.                             }
  3611.  
  3612.                             pTask=rage_new CTaskCarSetTempAction(pVehicle,iAction,iTime);
  3613.                             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_TEMP_ACTION, "TASK_VEHICLE_TEMP_ACTION");
  3614.                         }
  3615.                     }
  3616.                 }
  3617.             }
  3618.         }
  3619.     }
  3620.  
  3621.  
  3622.     void CommandTaskVehicleMission_Internal( int iPedID, int iVehicleID, int iTargetVehicleID,
  3623.         int iMission, float fCruiseSpeed, int iDrivingStyle, float fTargetReached, float fStraightLineDistance, bool bAllowedToGoAgainstTraffic, Vector3* vTarget)
  3624.     {
  3625.         CVehicle *pVehicle=0;
  3626.         if(NULL_IN_SCRIPTING_LANGUAGE!=iVehicleID)
  3627.         {
  3628.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3629.         }
  3630.  
  3631.         if(!SCRIPT_VERIFY(pVehicle, "TASK_VEHICLE_MISSION needs a valid vehicle!"))
  3632.             return;
  3633.  
  3634.         CVehicle *pTargetVehicle = NULL;
  3635.         if (NULL_IN_SCRIPTING_LANGUAGE!=iTargetVehicleID)
  3636.         {
  3637.             pTargetVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iTargetVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3638.             if(!pTargetVehicle)
  3639.                 return;
  3640.         }
  3641.  
  3642.         if (fStraightLineDistance < 0.0f)
  3643.         {
  3644.             fStraightLineDistance = sVehicleMissionParams::DEFAULT_SWITCH_TO_STRAIGHT_LINE_DIST;
  3645.         }
  3646.         fStraightLineDistance = MIN(255.0f, fStraightLineDistance);
  3647.  
  3648.         if (fTargetReached < 0.0f)
  3649.         {
  3650.             fTargetReached = sVehicleMissionParams::DEFAULT_TARGET_REACHED_DIST;
  3651.         }
  3652.  
  3653. #if __ASSERT
  3654.         if (iMission == MISSION_CRASH)
  3655.         {
  3656.             VehicleType vehicleType = pVehicle->GetVehicleType();
  3657.             if (vehicleType != VEHICLE_TYPE_PLANE
  3658.                 && vehicleType != VEHICLE_TYPE_HELI
  3659.                 && vehicleType != VEHICLE_TYPE_BLIMP
  3660.                 && vehicleType != VEHICLE_TYPE_AUTOGYRO)
  3661.             {
  3662.                 scriptErrorf("%s:%s Non PLANE, HELI, BLIMP or AUTOGYRO has been told to crash", CTheScripts::GetCurrentScriptNameAndProgramCounter(), "TASK_VEHICLE_MISSION");
  3663.             }
  3664.         }
  3665. #endif  //__ASSERT
  3666.  
  3667.         aiTask *pCarTask = CVehicleIntelligence::GetTaskFromMissionIdentifier(pVehicle, iMission, pTargetVehicle, vTarget, iDrivingStyle, fTargetReached, fStraightLineDistance, fCruiseSpeed, bAllowedToGoAgainstTraffic);
  3668.            
  3669.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pCarTask);
  3670.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_VEHICLE_MISSION");
  3671.     }
  3672.  
  3673.  
  3674.  
  3675.     void CommandTaskVehicleMission( int iPedID, int iVehicleID, int iTargetVehicleID,
  3676.                 int iMission, float fCruiseSpeed, int iDrivingStyle, float fTargetReached, float fStraightLineDistance, bool bDriveAgainstTraffic)
  3677.     {
  3678.         CommandTaskVehicleMission_Internal(iPedID, iVehicleID, iTargetVehicleID, iMission, fCruiseSpeed, iDrivingStyle, fTargetReached, fStraightLineDistance, bDriveAgainstTraffic, NULL);
  3679.     }
  3680.  
  3681.  
  3682.     void CommandTaskVehicleMissionPedTarget_Internal( int iPedID, int iVehicleID, int iTargetPedID,
  3683.         int iMission, float fCruiseSpeed, int iDrivingStyle, float fTargetReached, float fStraightLineDistance, bool bAllowedToGoAgainstTraffic)
  3684.     {
  3685.         CVehicle *pVehicle=0;
  3686.         if(NULL_IN_SCRIPTING_LANGUAGE!=iVehicleID)
  3687.         {
  3688.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3689.             if(!pVehicle)
  3690.                 return;
  3691.         }
  3692.  
  3693.         CPed *pTargetPed = NULL;
  3694.         if (NULL_IN_SCRIPTING_LANGUAGE!=iTargetPedID)
  3695.         {
  3696.             pTargetPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iTargetPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3697.             if(!pTargetPed)
  3698.                 return;
  3699.         }
  3700.  
  3701.         if (fStraightLineDistance < 0.0f)
  3702.         {
  3703.             fStraightLineDistance = sVehicleMissionParams::DEFAULT_SWITCH_TO_STRAIGHT_LINE_DIST;
  3704.         }
  3705.         fStraightLineDistance = MIN(255.0f, fStraightLineDistance);
  3706.  
  3707.         if (fTargetReached < 0.0f)
  3708.         {
  3709.             fTargetReached = sVehicleMissionParams::DEFAULT_TARGET_REACHED_DIST;
  3710.         }
  3711.  
  3712. #if __ASSERT
  3713.         if (iMission == MISSION_CRASH)
  3714.         {
  3715.             VehicleType vehicleType = pVehicle->GetVehicleType();
  3716.             if (vehicleType != VEHICLE_TYPE_PLANE
  3717.                 && vehicleType != VEHICLE_TYPE_HELI
  3718.                 && vehicleType != VEHICLE_TYPE_BLIMP
  3719.                 && vehicleType != VEHICLE_TYPE_AUTOGYRO)
  3720.             {
  3721.                 scriptErrorf("%s:%s Non PLANE, HELI, BLIMP or AUTOGYRO has been told to crash", CTheScripts::GetCurrentScriptNameAndProgramCounter(), "TASK_VEHICLE_MISSION_PED_TARGET");
  3722.             }
  3723.         }
  3724. #endif  //__ASSERT
  3725.  
  3726.         aiTask *pCarTask = CVehicleIntelligence::GetTaskFromMissionIdentifier(pVehicle, iMission, pTargetPed, NULL, iDrivingStyle, fTargetReached, fStraightLineDistance, fCruiseSpeed, bAllowedToGoAgainstTraffic);
  3727.  
  3728.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pCarTask);
  3729.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_VEHICLE_MISSION_PED_TARGET");
  3730.     }
  3731.  
  3732.  
  3733.     void CommandTaskVehicleMissionPedTarget( int iPedID, int iVehicleID, int iTargetPedID,
  3734.         int iMission, float fCruiseSpeed, int iDrivingStyle, float fTargetReached, float fStraightLineDistance, bool bDriveAgainstTraffic)
  3735.     {
  3736.         CommandTaskVehicleMissionPedTarget_Internal( iPedID, iVehicleID, iTargetPedID,
  3737.                     iMission, fCruiseSpeed, iDrivingStyle, fTargetReached, fStraightLineDistance, bDriveAgainstTraffic);
  3738.     }
  3739.  
  3740.     void CommandTaskVehicleMissionCoorsTarget( int iPedID, int iVehicleID, const scrVector & scrVecCoors,
  3741.         int iMission, float fCruiseSpeed, int iDrivingStyle, float fTargetReached, float fStraightLineDistance, bool bDriveAgainstTraffic)
  3742.     {
  3743.         Vector3 VecCoors = Vector3 (scrVecCoors);
  3744.  
  3745.         CommandTaskVehicleMission_Internal( iPedID, iVehicleID, NULL_IN_SCRIPTING_LANGUAGE,
  3746.             iMission, fCruiseSpeed, iDrivingStyle, fTargetReached, fStraightLineDistance, bDriveAgainstTraffic, &VecCoors);
  3747.     }
  3748.  
  3749.     void AddVehicleSubtaskInternal(int iPedID, CTask* pSubTask, const char* ASSERT_ONLY(szTaskName))
  3750.     {
  3751.         if(NULL_IN_SCRIPTING_LANGUAGE!=iPedID)
  3752.         {
  3753.             CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  3754.             if( !pPed )
  3755.             {
  3756.                 delete pSubTask;
  3757.                 return;
  3758.             }
  3759.  
  3760.             CEventScriptCommand* pEvent = static_cast<CEventScriptCommand*>(pPed->GetPedIntelligence()->GetEventOfType(EVENT_SCRIPT_COMMAND));
  3761.             if( !scriptVerifyf(pEvent, "%s:%s - You must have previously given the ped a valid driving task!", CTheScripts::GetCurrentScriptNameAndProgramCounter(), szTaskName) )
  3762.             {
  3763.                 delete pSubTask;
  3764.                 return;
  3765.             }              
  3766.  
  3767.             aiTask* pTask = pEvent->GetTask();
  3768.  
  3769.             if( !scriptVerifyf(pTask && (pTask->GetTaskType() == CTaskTypes::TASK_CONTROL_VEHICLE || pTask->GetTaskType() == CTaskTypes::TASK_CAR_DRIVE_POINT_ROUTE), "%s:%s - You must have previously given the ped a valid driving task!", CTheScripts::GetCurrentScriptNameAndProgramCounter(), szTaskName) )
  3770.             {
  3771.                 delete pSubTask;
  3772.                 return;
  3773.             }
  3774.             if( pTask->GetTaskType() == CTaskTypes::TASK_CONTROL_VEHICLE )
  3775.             {
  3776.                 CTaskControlVehicle* pVehicleTask = static_cast<CTaskControlVehicle*>(pTask);
  3777.                 pVehicleTask->SetDesiredSubtask(pSubTask);
  3778.             }
  3779.             else if( pTask->GetTaskType() == CTaskTypes::TASK_CAR_DRIVE_POINT_ROUTE )
  3780.             {
  3781.                 CTaskDrivePointRoute* pVehicleTask = static_cast<CTaskDrivePointRoute*>(pTask);
  3782.                 pVehicleTask->SetDesiredSubtask(pSubTask);
  3783.             }
  3784.             else
  3785.             {
  3786. #if __ASSERT
  3787.                 scriptErrorf( "%s:%s unknown task type", CTheScripts::GetCurrentScriptNameAndProgramCounter(), szTaskName);
  3788. #endif
  3789.                 delete pSubTask;
  3790.                 return;
  3791.             }
  3792.  
  3793.         }
  3794.         // Add task to last sequence thats open
  3795.         else
  3796.         {
  3797.             if( !scriptVerifyf(CTaskSequences::ms_iActiveSequence >=0 && CTaskSequences::ms_iActiveSequence<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "%s:%s Sequence task closed", CTheScripts::GetCurrentScriptNameAndProgramCounter(), szTaskName))
  3798.             {
  3799.                 delete pSubTask;
  3800.                 return;
  3801.             }
  3802.             // Add task to sequence
  3803.             if( !scriptVerifyf(CTaskSequences::ms_bIsOpened[CTaskSequences::ms_iActiveSequence], "%s:%s Sequence task closed", CTheScripts::GetCurrentScriptNameAndProgramCounter(), szTaskName) )
  3804.             {
  3805.                 delete pSubTask;
  3806.                 return;
  3807.             }
  3808.  
  3809.             aiTask* pTask = CTaskSequences::ms_TaskSequenceLists[CTaskSequences::ms_iActiveSequence].GetLastAddedTask();
  3810.             if( scriptVerifyf(pTask && (pTask->GetTaskType() == CTaskTypes::TASK_CONTROL_VEHICLE || pTask->GetTaskType() == CTaskTypes::TASK_CAR_DRIVE_POINT_ROUTE), "%s:%s Last task added to sequence not a valid driving task", CTheScripts::GetCurrentScriptNameAndProgramCounter(), szTaskName ) )
  3811.             {
  3812.                 if( pTask->GetTaskType() == CTaskTypes::TASK_CONTROL_VEHICLE )
  3813.                 {
  3814.                     CTaskControlVehicle* pVehicleTask = static_cast<CTaskControlVehicle*>(pTask);
  3815.                     pVehicleTask->SetDesiredSubtask(pSubTask);
  3816.                 }
  3817.                 else if( pTask->GetTaskType() == CTaskTypes::TASK_CAR_DRIVE_POINT_ROUTE )
  3818.                 {
  3819.                     CTaskDrivePointRoute* pVehicleTask = static_cast<CTaskDrivePointRoute*>(pTask);
  3820.                     pVehicleTask->SetDesiredSubtask(pSubTask);
  3821.                 }
  3822.                 else
  3823.                 {
  3824. #if __ASSERT
  3825.                     scriptErrorf( "%s:%s unknown task type", CTheScripts::GetCurrentScriptNameAndProgramCounter(), szTaskName);
  3826. #endif
  3827.                     delete pSubTask;
  3828.                     return;
  3829.                 }
  3830.             }
  3831.             else
  3832.             {
  3833.                 delete pSubTask;
  3834.             }
  3835.         }
  3836.     }
  3837.  
  3838.     void CommandAddVehicleSubtaskAttackCoord( int iPedID, const scrVector & scrVecCoors )
  3839.     {
  3840.         Vector3 vTarget(scrVecCoors);
  3841.         CAITarget target(vTarget);
  3842.         AddVehicleSubtaskInternal(iPedID, rage_new CTaskVehicleCombat(&target), "ADD_VEHICLE_SUBTASK_ATTACK_COORD");
  3843.     }
  3844.  
  3845.     void CommandAddVehicleSubtaskAttackPed( int iPedID, int iOtherPedID )
  3846.     {
  3847.         CPed* pOtherPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iOtherPedID);
  3848.         if( !pOtherPed )
  3849.         {
  3850.             return;
  3851.         }
  3852.         CAITarget target(pOtherPed);
  3853.         AddVehicleSubtaskInternal(iPedID, rage_new CTaskVehicleCombat(&target), "ADD_VEHICLE_SUBTASK_ATTACK_PED");
  3854.     }
  3855.  
  3856.  
  3857.     void CommandTaskHeliMission( int iPedID, int iVehicleID, int iTargetVehicleID, int iTargetPedID, const scrVector & scrVecCoors,
  3858.         int iMission, float fCruiseSpeed, float fTargetReached, float fHeliOrientation, int iFlightHeight, int iMinHeightAboveTerrain, float fSlowDownDistance, int iHeliFlags)
  3859.     {
  3860.         CVehicle *pVehicle=0;
  3861.         Vector3 VecTargetCoors = Vector3 (scrVecCoors);
  3862.  
  3863.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE!=iVehicleID, "TASK_HELI_MISSION - You must specify a heli to be flown"))
  3864.         {
  3865.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3866.             if(!pVehicle)
  3867.                 return;
  3868.  
  3869.             if(!SCRIPT_VERIFY(pVehicle->GetVehicleType() == VEHICLE_TYPE_HELI, "TASK_HELI_MISSION - Vehicle to be used (2nd parameter) is not actually a heli"))
  3870.                 return;
  3871.         }
  3872.         else
  3873.         {
  3874.             return;
  3875.         }
  3876.  
  3877.         CPhysical* pPhysical = NULL;
  3878.         const CVehicle *pTargetVehicle = NULL;
  3879.         if (NULL_IN_SCRIPTING_LANGUAGE!=iTargetVehicleID)
  3880.         {
  3881.             pTargetVehicle = CTheScripts::GetEntityToQueryFromGUID<CVehicle>(iTargetVehicleID);
  3882.             if(!pTargetVehicle)
  3883.                 return;
  3884.  
  3885.             pPhysical = const_cast<CVehicle*>(pTargetVehicle);
  3886.         }
  3887.         const CPed *pTargetPed = NULL;
  3888.         if (NULL_IN_SCRIPTING_LANGUAGE!=iTargetPedID)
  3889.         {
  3890.             pTargetPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iTargetPedID);
  3891.             if(!pTargetPed)
  3892.                 return;
  3893.  
  3894.             pPhysical = const_cast<CPed*>(pTargetPed);
  3895.         }
  3896.  
  3897.         if (fTargetReached < 0.0f)
  3898.         {
  3899.             fTargetReached = sVehicleMissionParams::DEFAULT_TARGET_REACHED_DIST;
  3900.         }
  3901.  
  3902.         if (fHeliOrientation < 0.0f)
  3903.         {
  3904.             fHeliOrientation = -1.0f;
  3905.         }
  3906.         else
  3907.         {
  3908.             fHeliOrientation = ( DtoR * fHeliOrientation);
  3909.  
  3910.             // For whatever reason the helicopter AI treats the X axis as 0, so we have to rotate a Y axis heading request by 90
  3911.             fHeliOrientation += 90.0f*DtoR;
  3912.         }
  3913.  
  3914.         aiTask *pHeliTask = CVehicleIntelligence::GetHeliTaskFromMissionIdentifier(pVehicle, iMission, pPhysical, &VecTargetCoors, fTargetReached, fCruiseSpeed, fHeliOrientation, iFlightHeight, iMinHeightAboveTerrain, fSlowDownDistance, iHeliFlags);
  3915.  
  3916.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pHeliTask);
  3917.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_HELI_MISSION");
  3918.     }
  3919.  
  3920.     void CommandTaskHeliEscort( int iPedID, int iVehicleID, int iTargetVehicleID, const scrVector & offsetVec)
  3921.     {
  3922.         CVehicle *pVehicle=0;
  3923.         CVehicle *pTargetVehicle=0;
  3924.  
  3925.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE!=iVehicleID, "TASK_HELI_ESCORT_HELI - You must specify a heli to be flown"))
  3926.         {
  3927.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3928.             if(!pVehicle)
  3929.                 return;
  3930.  
  3931.             if(!SCRIPT_VERIFY(pVehicle->GetVehicleType() == VEHICLE_TYPE_HELI, "TASK_HELI_ESCORT_HELI - Vehicle to be used (2nd parameter) is not actually a heli"))
  3932.                 return;
  3933.         }
  3934.         else
  3935.         {
  3936.             return;
  3937.         }
  3938.  
  3939.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE!=iTargetVehicleID, "TASK_HELI_ESCORT_HELI - You must specify a heli to be targetted"))
  3940.         {
  3941.             pTargetVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iTargetVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3942.             if(!pTargetVehicle)
  3943.                 return;
  3944.  
  3945.             if(!SCRIPT_VERIFY(pTargetVehicle->GetVehicleType() == VEHICLE_TYPE_HELI, "TASK_HELI_ESCORT_HELI - Vehicle to be targetted (2nd parameter) is not actually a heli"))
  3946.                 return;
  3947.         }
  3948.         else
  3949.         {
  3950.             return;
  3951.         }
  3952.  
  3953.         Vector3 vOffset(offsetVec);
  3954.  
  3955.         sVehicleMissionParams params;
  3956.         params.SetTargetEntity(pTargetVehicle);
  3957.         params.SetTargetPosition(vOffset);
  3958.  
  3959.         CTaskVehicleEscort *pHeliTask = rage_new CTaskVehicleEscort(params, CTaskVehicleEscort::VEHICLE_ESCORT_HELI);
  3960.  
  3961.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pHeliTask);
  3962.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_HELI_ESCORT_HELI");
  3963.     }
  3964.  
  3965.     void CommandTaskPlaneMission( int iPedID, int iVehicleID, int iTargetVehicleID, int iTargetPedID, const scrVector & scrVecCoors,
  3966.         int iMission, float fCruiseSpeed, float fTargetReached, float fOrientation, int iFlightHeight, int iMinHeightAboveTerrain, bool bPrecise)
  3967.     {
  3968.         CVehicle *pVehicle=0;
  3969.         Vector3 VecTargetCoors = Vector3 (scrVecCoors);
  3970.  
  3971.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE!=iVehicleID, "TASK_PLANE_MISSION - You must specify a plane to be flown"))
  3972.         {
  3973.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  3974.             if(!pVehicle)
  3975.                 return;
  3976.  
  3977.             if(!SCRIPT_VERIFY(pVehicle->GetVehicleType() == VEHICLE_TYPE_PLANE, "TASK_PLANE_MISSION - Vehicle to be used (2nd parameter) is not actually a plane"))
  3978.                 return;
  3979.         }
  3980.         else
  3981.         {
  3982.             return;
  3983.         }
  3984.  
  3985.         CPhysical* pPhysical = NULL;
  3986.         const CVehicle *pTargetVehicle = NULL;
  3987.         if (NULL_IN_SCRIPTING_LANGUAGE!=iTargetVehicleID)
  3988.         {
  3989.             pTargetVehicle = CTheScripts::GetEntityToQueryFromGUID<CVehicle>(iTargetVehicleID);
  3990.             if(!pTargetVehicle)
  3991.                 return;
  3992.  
  3993.             pPhysical = const_cast<CVehicle*>(pTargetVehicle);
  3994.         }
  3995.         const CPed *pTargetPed = NULL;
  3996.         if (NULL_IN_SCRIPTING_LANGUAGE!=iTargetPedID)
  3997.         {
  3998.             pTargetPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iTargetPedID);
  3999.             if(!pTargetPed)
  4000.                 return;
  4001.  
  4002.             pPhysical = const_cast<CPed*>(pTargetPed);
  4003.         }
  4004.  
  4005.         if (fTargetReached < 0.0f)
  4006.         {
  4007.             fTargetReached = sVehicleMissionParams::DEFAULT_TARGET_REACHED_DIST;
  4008.         }
  4009.  
  4010.         if (fOrientation < 0.0f)
  4011.         {
  4012.             fOrientation = -1.0f;
  4013.         }
  4014.         else
  4015.         {
  4016.             fOrientation = ( DtoR * fOrientation);
  4017.             // For whatever reason the helicopter AI treats the X axis as 0, so we have to rotate a Y axis heading request by 90
  4018.             fOrientation += 90.0f*DtoR;
  4019.         }
  4020.        
  4021.         aiTask *pPlaneTask = CVehicleIntelligence::GetPlaneTaskFromMissionIdentifier(pVehicle, iMission, pPhysical, &VecTargetCoors, fTargetReached, fCruiseSpeed, fOrientation, iFlightHeight, iMinHeightAboveTerrain, bPrecise);
  4022.         if( pPlaneTask )
  4023.         {
  4024.             CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pPlaneTask);
  4025.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_PLANE_MISSION");
  4026.         }
  4027.     }
  4028.  
  4029.     void CommandTaskPlaneTaxi(int iPedID, int iVehicleID, const scrVector& scrVecCoors, float fCruiseSpeed, float fTargetReached)
  4030.     {
  4031.         CVehicle *pVehicle=0;
  4032.         Vector3 VecTargetCoors = Vector3 (scrVecCoors);
  4033.  
  4034.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE!=iVehicleID, "TASK_PLANE_TAXI - You must specify a plane to taxi"))
  4035.         {
  4036.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4037.             if(!pVehicle)
  4038.                 return;
  4039.  
  4040.             if(!SCRIPT_VERIFY(pVehicle->GetVehicleType() == VEHICLE_TYPE_PLANE, "TASK_PLANE_TAXI - Vehicle to be used (2nd parameter) is not actually a plane"))
  4041.                 return;
  4042.         }
  4043.         else
  4044.         {
  4045.             return;
  4046.         }
  4047.  
  4048.         if (fTargetReached < 0.0f)
  4049.         {
  4050.             fTargetReached = sVehicleMissionParams::DEFAULT_TARGET_REACHED_DIST;
  4051.         }
  4052.  
  4053.         sVehicleMissionParams params;
  4054.         params.SetTargetPosition(VecTargetCoors);
  4055.         params.m_fTargetArriveDist = fTargetReached;
  4056.         params.m_fCruiseSpeed = fCruiseSpeed;
  4057.  
  4058.         aiTask* pGotoTask = rage_new CTaskVehicleGoToPointAutomobile(params);
  4059.  
  4060.         if( pGotoTask )
  4061.         {
  4062.             CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pGotoTask);
  4063.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_PLANE_TAXI");
  4064.         }
  4065.     }
  4066.  
  4067.     void CommandTaskBoatMission( int iPedID, int iVehicleID, int iTargetVehicleID, int iTargetPedID, const scrVector & scrVecCoors,
  4068.         int iMission, float fCruiseSpeed, int iDrivingStyle, float fTargetReached, int iBoatFlags)
  4069.     {
  4070.         CVehicle *pVehicle=0;
  4071.         Vector3 VecTargetCoors = Vector3 (scrVecCoors);
  4072.  
  4073.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE!=iVehicleID, "TASK_BOAT_MISSION - You must specify a boat"))
  4074.         {
  4075.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4076.             if(!pVehicle)
  4077.                 return;
  4078.  
  4079.             if(!SCRIPT_VERIFY(pVehicle->GetVehicleType() == VEHICLE_TYPE_BOAT, "TASK_BOAT_MISSION - Vehicle to be used (2nd parameter) is not actually a boat"))
  4080.                 return;
  4081.         }
  4082.         else
  4083.         {
  4084.             return;
  4085.         }
  4086.  
  4087.         CPhysical* pPhysical = NULL;
  4088.         const CVehicle *pTargetVehicle = NULL;
  4089.         if (NULL_IN_SCRIPTING_LANGUAGE!=iTargetVehicleID)
  4090.         {
  4091.             pTargetVehicle = CTheScripts::GetEntityToQueryFromGUID<CVehicle>(iTargetVehicleID);
  4092.             if(!pTargetVehicle)
  4093.                 return;
  4094.  
  4095.             pPhysical = const_cast<CVehicle*>(pTargetVehicle);
  4096.         }
  4097.         const CPed *pTargetPed = NULL;
  4098.         if (NULL_IN_SCRIPTING_LANGUAGE!=iTargetPedID)
  4099.         {
  4100.             pTargetPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iTargetPedID);
  4101.             if(!pTargetPed)
  4102.                 return;
  4103.  
  4104.             pPhysical = const_cast<CPed*>(pTargetPed);
  4105.         }
  4106.  
  4107.         if (fTargetReached < 0.0f)
  4108.         {
  4109.             fTargetReached = sVehicleMissionParams::DEFAULT_TARGET_REACHED_DIST;
  4110.         }
  4111.  
  4112.         aiTask *pBoatTask = CVehicleIntelligence::GetBoatTaskFromMissionIdentifier(pVehicle, iMission, pPhysical, &VecTargetCoors, iDrivingStyle, fTargetReached, fCruiseSpeed, iBoatFlags);
  4113.         if( pBoatTask )
  4114.         {
  4115.             CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pBoatTask);
  4116.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_BOAT_MISSION");
  4117.         }
  4118.     }
  4119.  
  4120.  
  4121.     void CommandTaskVehiclePark( int iPedID, int iVehicleID, const scrVector & vecMoveTarget, float HeadingDegrees, int ParkType, float ToleranceDegrees, bool bKeepLightsOn)
  4122.     {
  4123.         CVehicle* pVehicle = NULL;
  4124.         Vector3 VecTargetCoors = Vector3 (vecMoveTarget);
  4125.  
  4126.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iVehicleID, "TASK_VEHICLE_PARK - You must specify a vehicle to be parked"))
  4127.         {
  4128.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4129.         }
  4130.  
  4131.         if(!pVehicle)
  4132.         {
  4133.             return;
  4134.         }
  4135.  
  4136.         const float HeadingRadians = HeadingDegrees*DtoR;
  4137.         Vector3 direction;
  4138.  
  4139.         direction.x = -rage::Sinf(HeadingRadians);
  4140.         direction.y = rage::Cosf(HeadingRadians);
  4141.         direction.z = 0.0f;
  4142.  
  4143.         sVehicleMissionParams params;
  4144.         params.SetTargetPosition(VecTargetCoors);
  4145.  
  4146.         CTaskVehicleParkNew* pParkTask = rage_new CTaskVehicleParkNew(params, direction, (CTaskVehicleParkNew::ParkType)ParkType, ToleranceDegrees*DtoR, bKeepLightsOn);
  4147.  
  4148.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pParkTask);
  4149.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_PARK, "TASK_VEHICLE_PARK");
  4150.     }
  4151.  
  4152.     void CommandTaskStealthKill( int iPedID, int iTargetPedID, int iStealthKillActionResultId, float fDesiredMoveBlendRatio, int iStealthFlags )
  4153.     {
  4154.         if( iPedID != NULL_IN_SCRIPTING_LANGUAGE )
  4155.         {
  4156.             // Apparently sequence tasks rely on the iPedID to be NULL
  4157.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  4158.             if( pPed )
  4159.             {
  4160.                 // Check to make sure the ped has a weapon equipped
  4161.                 const CWeaponInfo* pEquippedWeaponInfo = pPed->GetWeaponManager()->GetEquippedWeaponInfo();
  4162.                 if( !SCRIPT_VERIFY( pEquippedWeaponInfo, "TASK_STEALTH_KILL - The ped doesn't have a weapon equipped. Please use GIVE_WEAPON_TO_PED" ) )
  4163.                 {
  4164.                     return;
  4165.                 }
  4166.             }
  4167.         }
  4168.  
  4169.         // Ensure target ped is valid
  4170.         CPed* pTargetPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iTargetPedID);
  4171.         if( !SCRIPT_VERIFY( pTargetPed, "TASK_STEALTH_KILL - The target ped is invalid." ) )
  4172.         {
  4173.             return;
  4174.         }
  4175.  
  4176.         // Check to make sure the ped has a weapon equipped
  4177.         const CWeaponInfo* pTargetEquippedWeaponInfo = pTargetPed->GetWeaponManager()->GetEquippedWeaponInfo();
  4178.         if( !SCRIPT_VERIFY( pTargetEquippedWeaponInfo, "TASK_STEALTH_KILL - The target ped doesn't have a weapon equipped. Please use GIVE_WEAPON_TO_PED" ) )
  4179.         {
  4180.             return;
  4181.         }
  4182.  
  4183.         // Ensure the stealth kill id is valid
  4184.         u32 uActionIdx = 0;
  4185.         const CActionResult* pStealthKillActionResult = ACTIONMGR.FindActionResult( uActionIdx, (u32)iStealthKillActionResultId );
  4186.         if( !SCRIPT_VERIFY( pStealthKillActionResult, "TASK_STEALTH_KILL - Invalid stealth kill action." ) )
  4187.         {
  4188.             return;
  4189.         }
  4190.  
  4191.         CTask* pTask = rage_new CTaskStealthKill( pTargetPed, pStealthKillActionResult, fDesiredMoveBlendRatio, iStealthFlags );
  4192.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_STEALTH_KILL, "TASK_STEALTH_KILL" );
  4193.     }
  4194.  
  4195.     void CommandTaskPlantBomb( int iPedID, const scrVector &, float )
  4196.     {
  4197.         if( iPedID != NULL_IN_SCRIPTING_LANGUAGE )
  4198.         {
  4199.             // Apparently sequence tasks rely on the iPedID to be NULL
  4200.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  4201.             if( pPed )
  4202.             {
  4203.                 // Check to make sure the ped has a weapon equipped
  4204.                 const CWeaponInfo* pEquippedWeaponInfo = pPed->GetWeaponManager()->GetEquippedWeaponInfo();
  4205.                 if( !SCRIPT_VERIFY( pEquippedWeaponInfo && pEquippedWeaponInfo->GetProjectileCanBePlaced(), "TASK_PLANT_BOMB - The ped doesn't have a weapon that can be placed. Please use GIVE_WEAPON_TO_PED" ) )
  4206.                 {
  4207.                     return;
  4208.                 }
  4209.             }
  4210.         }
  4211.  
  4212.         CTask* pTask = rage_new CTaskBomb();
  4213.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_PLANT_BOMB, "TASK_PLANT_BOMB" );
  4214.     }
  4215.  
  4216.     void CommandTaskSharkCircleCoord(int iPedID, const scrVector & vCoord, float fMBR, float fRadius)
  4217.     {
  4218.         CAITarget aiTarget;
  4219.         aiTarget.SetPosition(vCoord);
  4220.         float fSpeed = CTaskSharkAttack::GetTunables().m_CirclingAngularSpeed;
  4221.         CTask* pTask = rage_new CTaskComplexControlMovement(rage_new CTaskSharkCircle(fMBR, aiTarget, fRadius, fSpeed));
  4222.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_SHARK_CIRCLE_COORD, "TASK_SHARK_CIRCLE_COORD");
  4223.     }
  4224.  
  4225.     void CommandTaskSharkCirclePed(int iPedID, int iOtherPedID, float fMBR, float fRadius)
  4226.     {
  4227.         CAITarget aiTarget;
  4228.         const CPed* pOtherPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iOtherPedID);
  4229.         aiTarget.SetEntity(pOtherPed);
  4230.         float fSpeed = CTaskSharkAttack::GetTunables().m_CirclingAngularSpeed;
  4231.         CTask* pTask = rage_new CTaskComplexControlMovement(rage_new CTaskSharkCircle(fMBR, aiTarget, fRadius, fSpeed));
  4232.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_SHARK_CIRCLE_PED, "TASK_SHARK_CIRCLE_COORD");
  4233.     }
  4234.  
  4235.     void CommandTaskPlaneGotoPreciseVtol(int iPedID, int iVehicleID, const scrVector & vecMoveTarget, int iFlightHeight, int iMinHeightAboveTerrain, bool bUseDesiredOrientation, float fDesiredOrientation, bool bAutoPilot)
  4236.     {
  4237.         CVehicle* pVehicle = NULL;
  4238.         Vector3 VecTargetCoors = Vector3 (vecMoveTarget);
  4239.  
  4240.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iVehicleID, "TASK_PLANE_GOTO_PRECISE_VTOL - You must specify a vehicle to be parked"))
  4241.         {
  4242.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID);
  4243.         }
  4244.  
  4245.         if(!pVehicle)
  4246.         {
  4247.             return;
  4248.         }
  4249.  
  4250.         if (!SCRIPT_VERIFY(pVehicle->InheritsFromPlane(), "TASK_PLANE_GOTO_PRECISE_VTOL - Must be used on a plane"))
  4251.         {
  4252.             return;
  4253.         }
  4254.  
  4255.         CPlane* pPlane = static_cast<CPlane*>(pVehicle);
  4256.         if (!SCRIPT_VERIFY(pPlane->GetVerticalFlightModeAvaliable(), "TASK_PLANE_GOTO_PRECISE_VTOL - Plane must support VTOL (vertical takeoff and landing)"))
  4257.         {
  4258.             return;
  4259.         }
  4260.  
  4261.         sVehicleMissionParams params;
  4262.         params.SetTargetPosition(VecTargetCoors);
  4263.  
  4264.         fDesiredOrientation *= DtoR;
  4265.         fDesiredOrientation += 90.0f*DtoR;
  4266.  
  4267.         fDesiredOrientation = fwAngle::LimitRadianAngleSafe(fDesiredOrientation);
  4268.  
  4269.         if (bAutoPilot)
  4270.         {
  4271.             params.m_iDrivingFlags.SetFlag(DF_DontTerminateTaskWhenAchieved);
  4272.         }
  4273.  
  4274.         CTaskVehicleGoToPlane* pPlaneTask = rage_new CTaskVehicleGoToPlane(params, iFlightHeight, iMinHeightAboveTerrain, true, bUseDesiredOrientation, fDesiredOrientation);
  4275.  
  4276.         if (bAutoPilot)
  4277.         {
  4278.             // Apply task directly to the vehicle
  4279.             pVehicle->GetIntelligence()->GetTaskManager()->SetTask(VEHICLE_TASK_TREE_PRIMARY, pPlaneTask, VEHICLE_TASK_PRIORITY_PRIMARY, false);
  4280.             pVehicle->GetIntelligence()->SetUsingScriptAutopilot(true);
  4281.  
  4282.             CVehicleNodeList * pNodeList = pVehicle->GetIntelligence()->GetNodeList();
  4283.             if(pNodeList)
  4284.             {  
  4285.                 pNodeList->ClearPathNodes();
  4286.             }
  4287.  
  4288.             pVehicle->SwitchEngineOn(true);
  4289.         }
  4290.  
  4291.         else
  4292.         {
  4293.             // Apply task to the ped as part of CTaskControlVehicle
  4294.             CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pPlaneTask);
  4295.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_PLANE_GOTO_PRECISE_VTOL");
  4296.         }
  4297.     }
  4298.  
  4299.     void CommandTaskSubmarineGotoAndStop(int iPedID, int iVehicleID, const scrVector & vecMoveTarget, bool bAutoPilot)
  4300.     {
  4301.         CVehicle* pVehicle = NULL;
  4302.         Vector3 VecTargetCoors = Vector3 (vecMoveTarget);
  4303.  
  4304.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iVehicleID, "TASK_PLANE_GOTO_PRECISE_VTOL - You must specify a vehicle to be parked"))
  4305.         {
  4306.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID);
  4307.         }
  4308.  
  4309.         if(!pVehicle)
  4310.         {
  4311.             return;
  4312.         }
  4313.  
  4314.         sVehicleMissionParams params;
  4315.         params.SetTargetPosition(VecTargetCoors);
  4316.  
  4317.         s32 subFlags = 0;
  4318.         if (bAutoPilot)
  4319.         {
  4320.             params.m_iDrivingFlags.SetFlag(DF_DontTerminateTaskWhenAchieved);
  4321.             subFlags = CTaskVehicleGoToSubmarine::SF_HoverAtEnd;
  4322.             params.m_fTargetArriveDist = 30.0f;
  4323.         }
  4324.  
  4325.         CTaskVehicleGoToSubmarine* pSubTask = rage_new CTaskVehicleGoToSubmarine(params, subFlags);
  4326.  
  4327.         if (bAutoPilot)
  4328.         {
  4329.             // Apply task directly to the vehicle
  4330.             pVehicle->GetIntelligence()->GetTaskManager()->SetTask(VEHICLE_TASK_TREE_PRIMARY, pSubTask, VEHICLE_TASK_PRIORITY_PRIMARY, false);
  4331.             pVehicle->GetIntelligence()->SetUsingScriptAutopilot(true);
  4332.  
  4333.             CVehicleNodeList * pNodeList = pVehicle->GetIntelligence()->GetNodeList();
  4334.             if(pNodeList)
  4335.             {  
  4336.                 pNodeList->ClearPathNodes();
  4337.             }
  4338.  
  4339.             pVehicle->SwitchEngineOn(true);
  4340.         }
  4341.  
  4342.         else
  4343.         {
  4344.             // Apply task to the ped as part of CTaskControlVehicle
  4345.             CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pSubTask);
  4346.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_SUBMARINE_GOTO_AND_STOP");
  4347.         }
  4348.     }
  4349.  
  4350.     void CommandClearDefaultPrimaryTask(int iPedID)
  4351.     {
  4352.         if (SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iPedID, "CLEAR_DEFAULT_PRIMARY_TASK - Can't have a NULL ped"))
  4353.         {
  4354.             if (CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID))
  4355.             {
  4356.                 AI_LOG_WITH_ARGS("[Script] - Script %s has restarted the default primary task for ped %s", CTheScripts::GetCurrentScriptName(), AILogging::GetDynamicEntityNameSafe(pPed));
  4357.                 pPed->GetPedIntelligence()->AddTaskDefault(pPed->ComputeDefaultTask(*pPed));
  4358.             }
  4359.         }
  4360.     }
  4361.  
  4362.     void CommandClearPrimaryVehicleTask( int iVehicleID )
  4363.     {
  4364.         CVehicle* pVehicle = NULL;
  4365.         pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID);
  4366.  
  4367.         if (SCRIPT_VERIFYF(pVehicle, "CLEAR_PRIMARY_VEHICLE_TASK - Could not find vehicle with provided ID %i", iVehicleID))
  4368.         {
  4369.             if (pVehicle->GetIntelligence() && pVehicle->GetIntelligence()->GetTaskManager())
  4370.             {
  4371.                 pVehicle->GetIntelligence()->GetTaskManager()->ClearTask(VEHICLE_TASK_TREE_PRIMARY, VEHICLE_TASK_PRIORITY_PRIMARY);
  4372.             }
  4373.         }
  4374.     }
  4375.  
  4376.     void CommandClearVehicleCrashTask( int iVehicleID )
  4377.     {
  4378.         CVehicle* pVehicle = NULL;
  4379.         pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID);
  4380.  
  4381.         if (SCRIPT_VERIFYF(pVehicle, "CLEAR_VEHICLE_CRASH_TASK - Could not find vehicle with provided ID %i", iVehicleID))
  4382.         {
  4383.             if (pVehicle->GetIntelligence() && pVehicle->GetIntelligence()->GetTaskManager())
  4384.             {
  4385.                 pVehicle->GetIntelligence()->GetTaskManager()->ClearTask(VEHICLE_TASK_TREE_PRIMARY, VEHICLE_TASK_PRIORITY_CRASH);
  4386.             }
  4387.         }
  4388.     }
  4389.  
  4390.     void CommandTaskVehicleEscort( int iPedID, int iVehicleID, int iEscortEntityID, int iEscortType, float fCruiseSpeed, int iDrivingFlags, float fCustomOffset, int iMinHeightAboveTerrain, float fStraightLineDist)
  4391.     {
  4392.         CVehicle* pVehicle = NULL;
  4393.  
  4394.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iVehicleID, "TASK_VEHICLE_ESCORT - You must specify a vehicle to drive"))
  4395.         {
  4396.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4397.         }
  4398.  
  4399.         if(!pVehicle)
  4400.         {
  4401.             return;
  4402.         }
  4403.  
  4404.         CEntity *pEntity = CTheScripts::GetEntityToModifyFromGUID<CEntity>(iEscortEntityID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4405.         if (!pEntity)
  4406.         {
  4407.             return;
  4408.         }
  4409.  
  4410.         sVehicleMissionParams params;
  4411.         params.m_iDrivingFlags = iDrivingFlags;
  4412.         params.SetTargetEntity(pEntity);
  4413.         params.m_fCruiseSpeed = fCruiseSpeed;
  4414.  
  4415.         if (iMinHeightAboveTerrain < 0)
  4416.         {
  4417.             iMinHeightAboveTerrain = CTaskVehicleGoToHelicopter::DEFAULT_MIN_HEIGHT_ABOVE_TERRAIN;
  4418.         }
  4419.         CTaskVehicleEscort* pEscortTask = rage_new CTaskVehicleEscort(params, (CTaskVehicleEscort::VehicleEscortType)iEscortType, fCustomOffset, iMinHeightAboveTerrain, fStraightLineDist);
  4420.  
  4421.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pEscortTask);
  4422.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_VEHICLE_ESCORT");
  4423.     }
  4424.  
  4425.     void CommandTaskVehicleFollow( int iPedID, int iVehicleID, int iFollowEntityID, float fCruiseSpeed, int iDrivingFlags, int iFollowDistance)
  4426.     {
  4427.         CVehicle* pVehicle = NULL;
  4428.  
  4429.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iVehicleID, "TASK_VEHICLE_FOLLOW - You must specify a vehicle to drive"))
  4430.         {
  4431.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4432.         }
  4433.  
  4434.         if(!pVehicle)
  4435.         {
  4436.             return;
  4437.         }
  4438.  
  4439.         CEntity *pEntity = CTheScripts::GetEntityToModifyFromGUID<CEntity>(iFollowEntityID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4440.         if (!pEntity)
  4441.         {
  4442.             return;
  4443.         }
  4444.  
  4445.         sVehicleMissionParams params;
  4446.         params.m_iDrivingFlags = iDrivingFlags;
  4447.         params.SetTargetEntity(pEntity);
  4448.         params.m_fCruiseSpeed = fCruiseSpeed;
  4449.  
  4450.         CTaskVehicleFollow* pFollowTask = rage_new CTaskVehicleFollow(params, iFollowDistance);
  4451.  
  4452.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pFollowTask);
  4453.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_VEHICLE_FOLLOW");
  4454.     }
  4455.  
  4456.     void CommandTaskHeliProtect( int iPedID, int iVehicleID, int iEscortEntityID, float fCruiseSpeed, int iDrivingFlags, float fCustomOffset, int iMinHeightAboveTerrain, int iHeliFlags)
  4457.     {
  4458.         CVehicle* pVehicle = NULL;
  4459.  
  4460.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iVehicleID, "TASK_VEHICLE_HELI_PROTECT - You must specify a vehicle to drive"))
  4461.         {
  4462.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4463.         }
  4464.  
  4465.         if(!pVehicle)
  4466.         {
  4467.             return;
  4468.         }
  4469.  
  4470.         CEntity *pEntity = CTheScripts::GetEntityToModifyFromGUID<CEntity>(iEscortEntityID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4471.         if (!pEntity)
  4472.         {
  4473.             return;
  4474.         }
  4475.  
  4476.         sVehicleMissionParams params;
  4477.         params.m_iDrivingFlags = iDrivingFlags;
  4478.         params.SetTargetEntity(pEntity);
  4479.         params.m_fCruiseSpeed = fCruiseSpeed;
  4480.  
  4481.         if (iMinHeightAboveTerrain < 0)
  4482.         {
  4483.             iMinHeightAboveTerrain = CTaskVehicleGoToHelicopter::DEFAULT_MIN_HEIGHT_ABOVE_TERRAIN;
  4484.         }
  4485.         CTask* pHeliTask = rage_new CTaskVehicleHeliProtect(params, fCustomOffset, iMinHeightAboveTerrain, iHeliFlags);
  4486.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pHeliTask);
  4487.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_VEHICLE_MISSION, "TASK_VEHICLE_HELI_PROTECT");
  4488.     }
  4489.        
  4490.     void CommandTaskVehicleChase(int iPedID, int iTargetID)
  4491.     {
  4492.         //Ensure the ped is valid.
  4493.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  4494.         if(!SCRIPT_VERIFY(pPed, "TASK_VEHICLE_CHASE - The ped is invalid."))
  4495.         {
  4496.             return;
  4497.         }
  4498.        
  4499.         //Ensure the ped is in a vehicle.
  4500.         if(!SCRIPT_VERIFY(pPed->GetVehiclePedInside(), "TASK_VEHICLE_CHASE - The ped is not in a vehicle."))
  4501.         {
  4502.             return;
  4503.         }
  4504.        
  4505.         //Ensure the target is valid.
  4506.         CPed* pTarget = CTheScripts::GetEntityToModifyFromGUID<CPed>(iTargetID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4507.         if(!SCRIPT_VERIFY(pTarget, "TASK_VEHICLE_CHASE - The target is invalid."))
  4508.         {
  4509.             return;
  4510.         }
  4511.  
  4512.         //Ensure the target is in a vehicle.
  4513.         if(!SCRIPT_VERIFY(pTarget->GetVehiclePedInside(), "TASK_VEHICLE_CHASE - The target is not in a vehicle."))
  4514.         {
  4515.             return;
  4516.         }
  4517.        
  4518.         //Create the task.
  4519.         CTask* pTask = rage_new CTaskVehicleChase(pTarget);
  4520.        
  4521.         //Give the task to the ped.
  4522.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_VEHICLE_CHASE, "TASK_VEHICLE_CHASE");
  4523.     }
  4524.    
  4525.     void CommandSetTaskVehicleChaseBehaviorFlag(int iPedID, int iFlag, bool bValue)
  4526.     {
  4527.         //Ensure the ped is valid.
  4528.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  4529.         if(!SCRIPT_VERIFY(pPed, "SET_TASK_VEHICLE_CHASE_BEHAVIOR_FLAG - The ped is invalid."))
  4530.         {
  4531.             return;
  4532.         }
  4533.        
  4534.         //Ensure the vehicle chase task is valid.
  4535.         CTaskVehicleChase* pTask = static_cast<CTaskVehicleChase *>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_VEHICLE_CHASE));
  4536.         if(!SCRIPT_VERIFY(pTask, "SET_TASK_VEHICLE_CHASE_BEHAVIOR_FLAG - The task is invalid."))
  4537.         {
  4538.             return;
  4539.         }
  4540.        
  4541.         //Change the behavior flag.
  4542.         pTask->ChangeBehaviorFlag(CTaskVehicleChase::Overrides::Script, (CTaskVehicleChase::BehaviorFlags)iFlag, bValue);
  4543.     }
  4544.    
  4545.     void CommandSetTaskVehicleChaseIdealPursuitDistance(int iPedID, float fIdealPursuitDistance)
  4546.     {
  4547.         //Ensure the ped is valid.
  4548.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  4549.         if(!SCRIPT_VERIFY(pPed, "SET_TASK_VEHICLE_CHASE_IDEAL_PURSUIT_DISTANCE - The ped is invalid."))
  4550.         {
  4551.             return;
  4552.         }
  4553.  
  4554.         //Ensure the vehicle chase task is valid.
  4555.         CTaskVehicleChase* pTask = static_cast<CTaskVehicleChase *>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_VEHICLE_CHASE));
  4556.         if(!SCRIPT_VERIFY(pTask, "SET_TASK_VEHICLE_CHASE_IDEAL_PURSUIT_DISTANCE - The task is invalid."))
  4557.         {
  4558.             return;
  4559.         }
  4560.  
  4561.         //Set the ideal distance.
  4562.         pTask->SetIdealDistanceForPursue(CTaskVehicleChase::Overrides::Script, fIdealPursuitDistance);
  4563.     }
  4564.    
  4565.  
  4566.     void CommandTaskPlaneChase(int iPedID, int iTargetID, const scrVector & vTargetOffset)
  4567.     {
  4568.         //Ensure the ped is valid.
  4569.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4570.         if(!SCRIPT_VERIFY(pPed, "TASK_PLANE_CHASE - The ped is invalid."))
  4571.         {
  4572.             return;
  4573.         }
  4574.  
  4575.         //Ensure the target is valid.
  4576.         CEntity const* pTarget = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iTargetID);
  4577.         if(!SCRIPT_VERIFY(pTarget, "TASK_PLANE_CHASE - The target is invalid."))
  4578.         {
  4579.             return;
  4580.         }
  4581.  
  4582.         CAITarget target;
  4583.         target.SetEntityAndOffsetUnlimited(pTarget, vTargetOffset);
  4584.         CTask* pTask = rage_new CTaskPlaneChase(target);
  4585.  
  4586.         //Give the task to the ped.
  4587.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_PLANE_CHASE, "TASK_PLANE_CHASE");
  4588.     }
  4589.  
  4590.  
  4591.     void CommandTaskPlaneLand(int iPedID, int iVehicleID, const scrVector & vRunWayStart, const scrVector & vRunWayEnd)
  4592.     {
  4593.         //Ensure the ped is valid.
  4594.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  4595.         if(!SCRIPT_VERIFY(pPed, "TASK_PLANE_LAND - The ped is invalid."))
  4596.         {
  4597.             return;
  4598.         }
  4599.  
  4600.         CVehicle* pVehicle = NULL;
  4601.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iVehicleID, "TASK_PLANE_LAND - You must specify a vehicle!"))
  4602.         {
  4603.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID);
  4604.         }
  4605.  
  4606.         if(!pVehicle)
  4607.         {
  4608.             return;
  4609.         }
  4610.  
  4611.         //Create the task.
  4612.         CTask* pTaskVehicleLandPlane = rage_new CTaskVehicleLandPlane((Vec3V)vRunWayStart, (Vec3V)vRunWayEnd);
  4613.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pTaskVehicleLandPlane);
  4614.  
  4615.         //Give the task to the ped.
  4616.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_PLANE_LAND, "TASK_PLANE_CHASE");
  4617.     }
  4618.  
  4619.  
  4620.  
  4621.     void CommandTaskHeliChase(int iPedID, int iTargetID, const scrVector & vTargetOffset)
  4622.     {
  4623.         //Ensure the ped is valid.
  4624.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4625.         if(!SCRIPT_VERIFY(pPed, "TASK_HELI_CHASE - The ped is invalid."))
  4626.         {
  4627.             return;
  4628.         }
  4629.        
  4630.         //Ensure the target is valid.
  4631.         const CEntity* pTarget = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iTargetID);
  4632.         if(!SCRIPT_VERIFY(pTarget, "TASK_HELI_CHASE - The target is invalid."))
  4633.         {
  4634.             return;
  4635.         }
  4636.        
  4637.         //Create the task.
  4638.         CTask* pTask = rage_new CTaskHeliChase(CAITarget(pTarget), (Vec3V)vTargetOffset);
  4639.        
  4640.         //Give the task to the ped.
  4641.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_HELI_CHASE, "TASK_HELI_CHASE");
  4642.     }
  4643.    
  4644.     void CommandSetTaskHeliChaseTargetOffset(int iPedID, const scrVector & vTargetOffset)
  4645.     {
  4646.         //Ensure the ped is valid.
  4647.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4648.         if(!SCRIPT_VERIFY(pPed, "SET_TASK_HELI_CHASE_TARGET_OFFSET - The ped is invalid."))
  4649.         {
  4650.             return;
  4651.         }
  4652.        
  4653.         //Ensure the vehicle chase task is valid.
  4654.         CTaskHeliChase* pTask = static_cast<CTaskHeliChase *>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_HELI_CHASE));
  4655.         if(!SCRIPT_VERIFY(pTask, "SET_TASK_HELI_CHASE_TARGET_OFFSET - The task is invalid."))
  4656.         {
  4657.             return;
  4658.         }
  4659.        
  4660.         //Set the target offset.
  4661.         pTask->SetTargetOffset((Vec3V)vTargetOffset);
  4662.     }
  4663.  
  4664.     void CommandSetTaskHeliChaseTargetOffsetWorldSpace(int iPedID, bool bTargetOffsetWorldSpace)
  4665.     {
  4666.         //Ensure the ped is valid.
  4667.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4668.         if(!SCRIPT_VERIFY(pPed, "SET_TASK_HELI_CHASE_TARGET_OFFSET_WORLD_SPACE - The ped is invalid."))
  4669.         {
  4670.             return;
  4671.         }
  4672.  
  4673.         //Ensure the vehicle chase task is valid.
  4674.         CTaskHeliChase* pTask = static_cast<CTaskHeliChase *>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_HELI_CHASE));
  4675.         if(!SCRIPT_VERIFY(pTask, "SET_TASK_HELI_CHASE_TARGET_OFFSET_WORLD_SPACE - The task is invalid."))
  4676.         {
  4677.             return;
  4678.         }
  4679.  
  4680.         //Set the target offset.
  4681.         pTask->SetTargetOffsetRelative(bTargetOffsetWorldSpace ? CTaskHeliChase::OffsetRelative_World : CTaskHeliChase::OffsetRelative_Local );
  4682.     }
  4683.  
  4684.     void CommandSetTaskHeliChaseOrientation(int iPedID, int iOrientationMode, int iOrientationRelative, float in_orientation)
  4685.     {
  4686.         //Ensure the ped is valid.
  4687.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  4688.         if(!SCRIPT_VERIFY(pPed, "SET_TASK_HELI_CHASE_ORIENTATION - The ped is invalid."))
  4689.         {
  4690.             return;
  4691.         }
  4692.  
  4693.         //Ensure the vehicle chase task is valid.
  4694.         CTaskHeliChase* pTask = static_cast<CTaskHeliChase *>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_HELI_CHASE));
  4695.         if(!SCRIPT_VERIFY(pTask, "SET_TASK_HELI_CHASE_ORIENTATION - The task is invalid."))
  4696.         {
  4697.             return;
  4698.         }
  4699.  
  4700.         pTask->SetOrientationMode(static_cast<CTaskHeliChase::OrientationMode>(iOrientationMode));
  4701.         pTask->SetOrientationRelative(static_cast<CTaskHeliChase::OrientationRelative>(iOrientationRelative));
  4702.         pTask->SetOrientationOffset(in_orientation);
  4703.     }
  4704.  
  4705.     void CommandTaskWeaponRoll( int UNUSED_PARAM(iPedID), bool UNUSED_PARAM(bRight))
  4706.     {
  4707.         Assertf(false, "unsupported command TASK_WEAPON_ROLL");
  4708.         MUST_FIX_THIS(anim missing);
  4709.     }
  4710.  
  4711.     bool CommandControlMountedWeapon( int iPedID )
  4712.     {
  4713.         if( SCRIPT_VERIFY( NULL_IN_SCRIPTING_LANGUAGE != iPedID, "CONTROL_MOUNTED_WEAPON - Can't have a NULL ped" ))
  4714.         {
  4715.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  4716.             if(pPed)
  4717.             {
  4718.                 bool inVehicle = pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle );
  4719.                 if(SCRIPT_VERIFY(inVehicle , "CONTROL_MOUNTED_WEAPON: ped is not in vehicle!"))
  4720.                 {
  4721.                     if(CTaskVehicleMountedWeapon::IsTaskValid(pPed))
  4722.                     {
  4723.                         CTask* pControlVehicleTask = pPed->GetPedIntelligence()->FindTaskPrimaryByType( CTaskTypes::TASK_CONTROL_VEHICLE );
  4724.                         if( pControlVehicleTask )
  4725.                         {
  4726.                             CTaskControlVehicle* pTaskControlVehicle=static_cast<CTaskControlVehicle*>(pControlVehicleTask);
  4727.                             pTaskControlVehicle->SetDesiredSubtask(NULL);
  4728.                             return true;
  4729.                         }
  4730.                     }
  4731.                 }
  4732.             }
  4733.         }
  4734.         return false;
  4735.     }
  4736.  
  4737.     void CommandSetMountedWeaponTarget(int iPedID, int iOtherPedID, int iTargetVehicleID, const scrVector & scrVecCoors, int TaskMode, bool bIgnoreTargetVehDeadCheck)
  4738.     {
  4739.         if( SCRIPT_VERIFY( NULL_IN_SCRIPTING_LANGUAGE != iPedID, "SET_MOUNTED_WEAPON_TARGET - Can't have a NULL ped" ) )
  4740.         {
  4741.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>( iPedID );
  4742.             if( pPed )
  4743.             {
  4744.                 // Determine the type of target to updateSET_MOUNTED_WEAPON_TARGET
  4745.                 const CEntity *pTargetEntity = NULL;
  4746.  
  4747.                 // Ped target
  4748.                 if( iOtherPedID != NULL_IN_SCRIPTING_LANGUAGE )
  4749.                 {
  4750.                     if( !SCRIPT_VERIFY( iTargetVehicleID == NULL_IN_SCRIPTING_LANGUAGE, "SET_MOUNTED_WEAPON_TARGET - Can't have a target ped and a target car" ) )
  4751.                         return;
  4752.  
  4753.                     const CPed* pTargetPed = CTheScripts::GetEntityToQueryFromGUID<CPed>( iOtherPedID );
  4754.                     if( !SCRIPT_VERIFY( pTargetPed, "SET_MOUNTED_WEAPON_TARGET - Target ped doesn't exist" ) )
  4755.                         return;
  4756.  
  4757.                     pTargetEntity = pTargetPed;
  4758.                 }
  4759.  
  4760.                 // Vehicle target
  4761.                 if( iTargetVehicleID != NULL_IN_SCRIPTING_LANGUAGE )
  4762.                 {
  4763.                     const CVehicle *pTargetVehicle = CTheScripts::GetEntityToQueryFromGUID<CVehicle>( iTargetVehicleID, bIgnoreTargetVehDeadCheck ? CTheScripts::GUID_ASSERT_FLAGS_NO_DEAD_CHECK : CTheScripts::GUID_ASSERT_FLAGS_ALL );
  4764.                     if( !SCRIPT_VERIFY( pTargetVehicle, "SET_MOUNTED_WEAPON_TARGET - Target vehicle doesn't exist" ) )
  4765.                         return;
  4766.  
  4767.                     pTargetEntity = pTargetVehicle;
  4768.                 }
  4769.  
  4770.                 // Set the target
  4771.                 const Vector3 vTargetCoords( scrVecCoors );
  4772.  
  4773.                 aiTask* pMountedWeaponBase = pPed->GetPedIntelligence()->FindTaskActiveByType( CTaskTypes::TASK_VEHICLE_MOUNTED_WEAPON );
  4774.                 if( pMountedWeaponBase )
  4775.                 {
  4776.                     //Updated the mode
  4777.                     static_cast<CTaskVehicleMountedWeapon*>(pMountedWeaponBase)->SetMode((CTaskVehicleMountedWeapon::eTaskMode)TaskMode);
  4778.  
  4779.                     //Set the target
  4780.                     if( pTargetEntity )
  4781.                         static_cast<CTaskVehicleMountedWeapon*>(pMountedWeaponBase)->SetTarget( pTargetEntity, &vTargetCoords );
  4782.                     else
  4783.                         static_cast<CTaskVehicleMountedWeapon*>(pMountedWeaponBase)->SetTargetPosition( vTargetCoords );
  4784.                 }
  4785.  
  4786.                 Assertf( pMountedWeaponBase, "SET_MOUNTED_WEAPON_TARGET - Native function invoked but ped has no gun or vehicle gun task." );
  4787.             }
  4788.         }
  4789.     }
  4790.  
  4791.  
  4792.     void CommandClearMountedWeaponTaskUnderneathDrivingTask(int iPedID)
  4793.     {
  4794.  
  4795.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  4796.         if(pPed)
  4797.         {
  4798.             bool inVehicle = pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle );
  4799.             if(SCRIPT_VERIFY(inVehicle , "CLEAR_MOUNTED_WEAPON_TASK_UNDERNEATH_DRIVING_TASK: ped is not in vehicle!"))
  4800.             {
  4801.                 CTask* pCurrent=pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CONTROL_VEHICLE );
  4802.                 if( pCurrent )
  4803.                 {
  4804.                     CTaskControlVehicle* pTaskControlVehicle=static_cast<CTaskControlVehicle*>(pCurrent);
  4805.                     if( scriptVerifyf( pTaskControlVehicle->GetDesiredSubtask() && pTaskControlVehicle->GetDesiredSubtask()->GetTaskType() == CTaskTypes::TASK_VEHICLE_MOUNTED_WEAPON, "CLEAR_MOUNTED_WEAPON_TASK_UNDERNEATH_DRIVING_TASK no mounted weapon task running, use IS_MOUNTED_WEAPON_TASK_UNDERNEATH_DRIVING_TASK" ) )
  4806.                     {
  4807.                         pTaskControlVehicle->SetDesiredSubtask(NULL);
  4808.                     }
  4809.                 }
  4810.             }
  4811.         }
  4812.     }
  4813.  
  4814.     bool CommandIsMountedWeaponTaskUnderneathDrivingTask(int iPedID)
  4815.     {
  4816.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  4817.         if(pPed)
  4818.         {
  4819.             bool inVehicle = pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle );
  4820.             if(SCRIPT_VERIFY(inVehicle, "IS_MOUNTED_WEAPON_TASK_UNDERNEATH_DRIVING_TASK: ped is not in vehicle or on a mount!"))
  4821.             {
  4822.                 CTask* pCurrent = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_VEHICLE_MOUNTED_WEAPON);
  4823.                 if( pCurrent )
  4824.                 {
  4825.                     return true;                   
  4826.                 }
  4827.             }
  4828.         }
  4829.         return false;
  4830.     }
  4831.  
  4832.  
  4833.     void CommandTaskDriveBy( int iPedID, int iOtherPedID, int iTargetVehicleID,
  4834.         const scrVector & scrVecCoors, float fAbortRange, int iFrequencyPercentage, bool bPushUnderneathDrivingTaskIfDriving, int iFiringPatternHash )
  4835.     {
  4836.         Vector3 TempVec, CentreVec, VecDiff;
  4837.         CPed *pPed;
  4838.         const CPed *pSecondPed;
  4839.         const CVehicle *pSecondVehicle;
  4840.         CTask* pTask;
  4841.  
  4842.         TempVec = Vector3(scrVecCoors);
  4843.  
  4844.         if(!SCRIPT_VERIFY( (iFrequencyPercentage >= 0) && (iFrequencyPercentage <= 100), "TASK_DRIVE_BY - Frequency should be between 0 and 100"))
  4845.             return;
  4846.        
  4847.         const CEntity *pTargetEntity = NULL;
  4848.         if (iOtherPedID != NULL_IN_SCRIPTING_LANGUAGE)  //  >= 0)
  4849.         {
  4850.             if(SCRIPT_VERIFY(iTargetVehicleID == NULL_IN_SCRIPTING_LANGUAGE, "TASK_DRIVE_BY - Can't have a target ped and a target car"))
  4851.             {
  4852.                 pSecondPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iOtherPedID);
  4853.                 if(!pSecondPed)
  4854.                     return;
  4855.  
  4856.                 pTargetEntity = pSecondPed;
  4857.             }
  4858.             else
  4859.             {
  4860.                 return;
  4861.             }
  4862.         }
  4863.         else
  4864.         {
  4865.             pSecondPed = NULL;
  4866.         }
  4867.         if (iTargetVehicleID != NULL_IN_SCRIPTING_LANGUAGE) //  >= 0)
  4868.         {
  4869.             if(SCRIPT_VERIFY(iOtherPedID == NULL_IN_SCRIPTING_LANGUAGE, "TASK_DRIVE_BY - Can't have a target ped and a target car"))
  4870.             {
  4871.                 pSecondVehicle = CTheScripts::GetEntityToQueryFromGUID<CVehicle>(iTargetVehicleID);
  4872.                 if(!SCRIPT_VERIFY(pSecondVehicle, "TASK_DRIVE_BY - Target vehicle doesn't exist"))
  4873.                     return;
  4874.  
  4875.                 pTargetEntity = pSecondVehicle;
  4876.             }
  4877.             else
  4878.             {
  4879.                 return;
  4880.             }
  4881.         }
  4882.         else
  4883.         {
  4884.             pSecondVehicle = NULL;
  4885.         }
  4886.  
  4887.         // Set up the arguments
  4888.         CAITarget target;
  4889.         if( pTargetEntity )
  4890.         {
  4891.             target.SetEntityAndOffset(pTargetEntity,TempVec);
  4892.         }
  4893.         else
  4894.         {
  4895.             target.SetPosition(TempVec);
  4896.         }
  4897.         const u32 uFiringPattern = iFiringPatternHash != 0  ? (u32)iFiringPatternHash : ATSTRINGHASH("FIRING_PATTERN_BURST_FIRE_DRIVEBY", 0x0d31265f2);    
  4898.  
  4899.         bool bAlreadydoingDriveBy=false;
  4900.         if(NULL_IN_SCRIPTING_LANGUAGE!=iPedID)
  4901.         {
  4902.             pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  4903.             if(pPed)
  4904.             {
  4905.                 bool inVehicle = pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle );
  4906.                 bool onMount = (pPed->GetMyMount() != NULL);
  4907.                 if(SCRIPT_VERIFY(inVehicle || onMount, "TASK_DRIVE_BY: char is not in vehicle or on a mount!"))
  4908.                 {
  4909.                     CTask* pControlVehicleTask = pPed->GetPedIntelligence()->FindTaskPrimaryByType( CTaskTypes::TASK_CONTROL_VEHICLE );
  4910.                     CTask* pCurrent=pPed->GetPedIntelligence()->GetTaskAtPriority(PED_TASK_PRIORITY_PRIMARY);
  4911.                     if(pCurrent && pCurrent->GetTaskType()==CTaskTypes::TASK_VEHICLE_GUN)
  4912.                     {
  4913.                         CTaskVehicleGun* pTaskDriveBy=(CTaskVehicleGun*)pCurrent;
  4914.                         if(pTaskDriveBy->GetTarget().GetEntity()==pSecondPed)
  4915.                         {
  4916.                             bAlreadydoingDriveBy=true;
  4917.                         }
  4918.                     }
  4919.                     else if( bPushUnderneathDrivingTaskIfDriving && pControlVehicleTask )
  4920.                     {
  4921.                         CTaskControlVehicle* pTaskControlVehicle=static_cast<CTaskControlVehicle*>(pControlVehicleTask);
  4922.                         pTask = rage_new CTaskVehicleGun(CTaskVehicleGun::Mode_Fire,uFiringPattern,&target,((float)iFrequencyPercentage)/100.0f,fAbortRange);          
  4923.                         pTaskControlVehicle->SetDesiredSubtask(pTask);
  4924.                         bAlreadydoingDriveBy=true;
  4925.                     }
  4926.                     else if(onMount && bPushUnderneathDrivingTaskIfDriving)
  4927.                     {
  4928.                         CTaskComplexControlMovement* pControlTask = static_cast<CTaskComplexControlMovement*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_COMPLEX_CONTROL_MOVEMENT));
  4929.                         if(pControlTask)
  4930.                         {
  4931.                             const int existingSubTask = pControlTask->GetMainSubTaskType();
  4932.                             if(existingSubTask == CTaskTypes::TASK_NONE || existingSubTask == CTaskTypes::TASK_VEHICLE_GUN)
  4933.                             {
  4934.                                 pTask = rage_new CTaskVehicleGun(CTaskVehicleGun::Mode_Fire,uFiringPattern,&target,((float)iFrequencyPercentage)/100.0f,fAbortRange);          
  4935.                                 pControlTask->SetNewMainSubtask(pTask);
  4936.                                 bAlreadydoingDriveBy=true;
  4937.                             }
  4938.                             // Note: not entirely sure what to do in the case of there being a subtask that's something
  4939.                             // else than CTaskVehicleGun. Now, it would still give you the driveby task, but running as the
  4940.                             // main task. This seems consistent with the vehicle case and is probably acceptable.
  4941.                         }
  4942.                     }
  4943.                 }
  4944.             }
  4945.         }
  4946.  
  4947.         if(!bAlreadydoingDriveBy)
  4948.         {  
  4949.             pTask = rage_new CTaskVehicleGun(CTaskVehicleGun::Mode_Fire,uFiringPattern,&target,((float)iFrequencyPercentage)/100.0f,fAbortRange);          
  4950.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_DRIVE_BY, "TASK_DRIVE_BY");
  4951.         }
  4952.     }
  4953.  
  4954.     void CommandSetDriveByTarget(int iPedID, int iOtherPedID, int iTargetVehicleID, const scrVector & scrVecCoors)
  4955.     {
  4956.         if( SCRIPT_VERIFY( NULL_IN_SCRIPTING_LANGUAGE != iPedID, "SET_DRIVERBY_TASK_TARGET - Can't have a NULL ped" ) )
  4957.         {
  4958.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>( iPedID );
  4959.             if( pPed )
  4960.             {
  4961.                 // Determine the type of target to update
  4962.                 const CEntity *pTargetEntity = NULL;
  4963.  
  4964.                 // Ped target
  4965.                 if( iOtherPedID != NULL_IN_SCRIPTING_LANGUAGE )
  4966.                 {
  4967.                     if( !SCRIPT_VERIFY( iTargetVehicleID == NULL_IN_SCRIPTING_LANGUAGE, "SET_DRIVERBY_TASK_TARGET - Can't have a target ped and a target car" ) )
  4968.                         return;
  4969.  
  4970.                     const CPed* pTargetPed = CTheScripts::GetEntityToQueryFromGUID<CPed>( iOtherPedID );
  4971.                     if( !SCRIPT_VERIFY( pTargetPed, "SET_DRIVERBY_TASK_TARGET - Target ped doesn't exist" ) )
  4972.                         return;
  4973.  
  4974.                     pTargetEntity = pTargetPed;
  4975.                 }
  4976.  
  4977.                 // Vehicle target
  4978.                 if( iTargetVehicleID != NULL_IN_SCRIPTING_LANGUAGE )
  4979.                 {
  4980.                     const CVehicle *pTargetVehicle = CTheScripts::GetEntityToQueryFromGUID<CVehicle>( iTargetVehicleID );
  4981.                     if( !SCRIPT_VERIFY( pTargetVehicle, "SET_DRIVERBY_TASK_TARGET - Target vehicle doesn't exist" ) )
  4982.                         return;
  4983.  
  4984.                     pTargetEntity = pTargetVehicle;
  4985.                 }
  4986.  
  4987.                 // Set the target
  4988.                 const Vector3 vTargetCoords( scrVecCoors );
  4989.  
  4990.                 // Check the gun task
  4991.                 aiTask* pGunTaskBase = pPed->GetPedIntelligence()->FindTaskActiveByType( CTaskTypes::TASK_GUN );
  4992.                 if( pGunTaskBase )
  4993.                 {
  4994.                     CWeaponTarget target;
  4995.                     if( pTargetEntity )
  4996.                         target.SetEntityAndOffset( pTargetEntity, vTargetCoords );
  4997.                     else
  4998.                         target.SetPosition( vTargetCoords );
  4999.  
  5000.                     static_cast<CTaskGun*>(pGunTaskBase)->SetTarget( target );
  5001.                 }
  5002.  
  5003.                 // Check vehicle gun task just in case
  5004.                 aiTask* pVehicleGunTaskBase = pPed->GetPedIntelligence()->FindTaskActiveByType( CTaskTypes::TASK_VEHICLE_GUN );
  5005.                 if( pVehicleGunTaskBase )
  5006.                 {
  5007.                     if( pTargetEntity )
  5008.                         static_cast<CTaskVehicleGun*>(pVehicleGunTaskBase)->SetTarget( pTargetEntity, &vTargetCoords );
  5009.                     else
  5010.                         static_cast<CTaskVehicleGun*>(pVehicleGunTaskBase)->SetTargetPosition( vTargetCoords );
  5011.                 }
  5012.  
  5013.                 Assertf( pGunTaskBase || pVehicleGunTaskBase, "SET_DRIVERBY_TASK_TARGET - Native function invoked but ped has no gun or vehicle gun task." );
  5014.             }
  5015.         }
  5016.     }
  5017.  
  5018.     void CommandClearDrivebyTaskUnderneathDrivingTask(int iPedID)
  5019.     {
  5020.        
  5021.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  5022.         if(pPed)
  5023.         {
  5024.             bool inVehicle = pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle );
  5025.             bool onMount = (pPed->GetMyMount() != NULL);
  5026.             if(SCRIPT_VERIFY(inVehicle || onMount, "CLEAR_DRIVEBY_TASK_UNDERNEATH_DRIVING_TASK: char is not in vehicle or on a mount!"))
  5027.             {
  5028.                 CTask* pCurrent=pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CONTROL_VEHICLE );
  5029.                 if( pCurrent )
  5030.                 {
  5031.                     CTaskControlVehicle* pTaskControlVehicle=static_cast<CTaskControlVehicle*>(pCurrent);
  5032.                     if( scriptVerifyf( pTaskControlVehicle->GetDesiredSubtask() && pTaskControlVehicle->GetDesiredSubtask()->GetTaskType() == CTaskTypes::TASK_VEHICLE_GUN, "CLEAR_DRIVEBY_TASK_UNDERNEATH_DRIVING_TASK no driveby task running, use IS_DRIVEBY_TASK_UNDERNEATH_DRIVING_TASK" ) )
  5033.                     {
  5034.                         pTaskControlVehicle->SetDesiredSubtask(NULL);
  5035.                     }
  5036.                 }
  5037.                 else if(onMount)
  5038.                 {
  5039.                     CTaskComplexControlMovement* pControlTask = static_cast<CTaskComplexControlMovement*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_COMPLEX_CONTROL_MOVEMENT));
  5040.                     if(pControlTask)
  5041.                     {
  5042.                         const int existingSubTask = pControlTask->GetMainSubTaskType();
  5043.                         if(existingSubTask == CTaskTypes::TASK_VEHICLE_GUN)
  5044.                         {
  5045.                             pControlTask->SetNewMainSubtask(NULL);
  5046.                         }
  5047.                     }
  5048.                 }
  5049.             }
  5050.         }
  5051.     }
  5052.  
  5053.     bool CommandIsDrivebyTaskUnderneathDrivingTask(int iPedID)
  5054.     {
  5055.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  5056.         if(pPed)
  5057.         {
  5058.             bool inVehicle = pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle );
  5059.             bool onMount = (pPed->GetMyMount() != NULL);
  5060.             if(SCRIPT_VERIFY(inVehicle || onMount, "IS_DRIVEBY_TASK_UNDERNEATH_DRIVING_TASK: char is not in vehicle or on a mount!"))
  5061.             {
  5062.                 CTask* pCurrent=pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CONTROL_VEHICLE);
  5063.                 if( pCurrent )
  5064.                 {
  5065.                     CTaskControlVehicle* pTaskControlVehicle=static_cast<CTaskControlVehicle*>(pCurrent);
  5066.                     return (pTaskControlVehicle->GetDesiredSubtask() && pTaskControlVehicle->GetDesiredSubtask()->GetTaskType() == CTaskTypes::TASK_VEHICLE_GUN);
  5067.                 }
  5068.                 else if(onMount)
  5069.                 {
  5070.                     CTaskComplexControlMovement* pControlTask = static_cast<CTaskComplexControlMovement*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_COMPLEX_CONTROL_MOVEMENT));
  5071.                     if(pControlTask)
  5072.                     {
  5073.                         const int existingSubTask = pControlTask->GetMainSubTaskType();
  5074.                         return existingSubTask == CTaskTypes::TASK_VEHICLE_GUN;
  5075.                     }
  5076.                 }
  5077.             }
  5078.         }
  5079.         return false;
  5080.     }
  5081.  
  5082.     void CommandTaskUseMobilePhone( int iPedID, bool bUsePhone, int eDesiredPhoneMode )
  5083.     {
  5084.         if (bUsePhone)
  5085.         {
  5086.             if (NULL_IN_SCRIPTING_LANGUAGE != iPedID)
  5087.             {
  5088.                 // pulled inside due to the NULL check
  5089.                 bool bShouldCreatePhoneTask = true;
  5090.                 CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  5091.                 if (pPed)
  5092.                 {
  5093.                     CTask* pTask = (bShouldCreatePhoneTask ? pPed->GetPedIntelligence()->FindTaskActiveByTreeAndType(PED_TASK_TREE_SECONDARY, CTaskTypes::TASK_MOBILE_PHONE) : NULL);
  5094.                     if (pTask)
  5095.                     {
  5096.                         CTaskMobilePhone* pTaskMobilePhone = static_cast<CTaskMobilePhone*>(pTask);
  5097.                         pTaskMobilePhone->PutUpToEar();
  5098.                         bShouldCreatePhoneTask = false;
  5099.                     }
  5100.  
  5101.                     pTask = (bShouldCreatePhoneTask ? pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_MOTION_IN_COVER) : NULL);
  5102.                     if (pTask && pTask->GetTaskType() == CTaskTypes::TASK_MOTION_IN_COVER)
  5103.                     {
  5104.                         CTaskMotionInCover* pTaskCover = (CTaskMotionInCover*)pTask;
  5105.                         pTaskCover->ProcessUseMobilePhone(true);    // Pick up phone
  5106.                         bShouldCreatePhoneTask = false;
  5107.                     }
  5108.                 }
  5109.                 if (bShouldCreatePhoneTask)
  5110.                 {
  5111.                     CTask* pTask = rage_new CTaskMobilePhone(CTaskMobilePhone::PhoneMode(eDesiredPhoneMode));
  5112.                     pPed->GetPedIntelligence()->AddTaskSecondary(pTask, PED_TASK_SECONDARY_PARTIAL_ANIM);
  5113.                 }
  5114.             }
  5115.             else
  5116.             {
  5117.                 // We still have to try and send the task if this is called from script in a sequence.
  5118.                 CTask* pTask = rage_new CTaskMobilePhone(CTaskMobilePhone::PhoneMode(eDesiredPhoneMode), -1, false);
  5119.                 CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_USE_MOBILE_PHONE, "TASK_USE_MOBILE_PHONE");
  5120.             }
  5121.         }
  5122.         else
  5123.         {
  5124.             if(SCRIPT_VERIFY( NULL_IN_SCRIPTING_LANGUAGE != iPedID, "TASK_USE_MOBILE_PHONE( ped, FALSE ) Cannot be used in a sequence"))
  5125.             {
  5126.                 CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  5127.                 if (pPed)
  5128.                 {
  5129.                     CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByTreeAndType(PED_TASK_TREE_SECONDARY, CTaskTypes::TASK_MOBILE_PHONE);
  5130.                     if (pTask)
  5131.                     {
  5132.                         CTaskMobilePhone* pTaskPhone = (CTaskMobilePhone*)pTask;
  5133.                         pTaskPhone->PutDownToPrevState();
  5134.                     }
  5135.  
  5136.                     // Make sure any mobile phone tasks in the event queue are removed.
  5137.                     for (s32 i = 0; i < pPed->GetPedIntelligence()->GetNumEventsInQueue(); i++)
  5138.                     {
  5139.                         CEvent* pEvent = pPed->GetPedIntelligence()->GetEventByIndex(i);
  5140.                         if (pEvent && pEvent->GetEventType() == EVENT_SCRIPT_COMMAND)
  5141.                         {
  5142.                             CEventScriptCommand* pEventScript = static_cast<CEventScriptCommand*>(pEvent);
  5143.                             if (pEventScript->GetTask() && pEventScript->GetTask()->GetTaskType() == CTaskTypes::TASK_MOBILE_PHONE)
  5144.                             {
  5145.                                 pPed->GetPedIntelligence()->RemoveEvent(pEvent);
  5146.                             }
  5147.                         }
  5148.                     }
  5149.                 }
  5150.             }
  5151.         }
  5152.     }
  5153.  
  5154.     void CommandAddFollowNavmeshToPhoneTask( int iPedID, const scrVector & svTargetPos, float fMoveBlendRatio )
  5155.     {
  5156.         Assert(fMoveBlendRatio >= MOVEBLENDRATIO_WALK && fMoveBlendRatio <= MOVEBLENDRATIO_SPRINT);
  5157.  
  5158.         Vector3 vTargetPos = svTargetPos;
  5159.  
  5160.         if(SCRIPT_VERIFY( NULL_IN_SCRIPTING_LANGUAGE != iPedID, "ADD_FOLLOW_NAVMESH_TO_PHONE_TASK Cannot be used in a sequence"))
  5161.         {
  5162.             CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  5163.             if (pPed)
  5164.             {
  5165.                 CTask* pTaskSecondary = pPed->GetPedIntelligence()->FindTaskActiveByTreeAndType(PED_TASK_TREE_SECONDARY, CTaskTypes::TASK_MOBILE_PHONE);
  5166.                 if(pTaskSecondary)
  5167.                 {
  5168.                     CTaskComplexControlMovement* pControlTask = static_cast<CTaskComplexControlMovement*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_COMPLEX_CONTROL_MOVEMENT));
  5169.                     if(pControlTask)
  5170.                     {
  5171.                         CTaskMoveFollowNavMesh * pNavMeshTask = rage_new CTaskMoveFollowNavMesh(fMoveBlendRatio, vTargetPos);
  5172.                         pNavMeshTask->SetIsScriptedRoute(true);
  5173.                         pControlTask->SetNewMoveTask(pNavMeshTask);
  5174.                     }
  5175.                 }
  5176.             }
  5177.         }
  5178.     }
  5179.  
  5180.     void CommandTaskUseMobilePhoneTimed( int iPedID, int iTime )
  5181.     {
  5182.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_USE_MOBILE_PHONE_TIMED - Time must be -1 for infinite and > 0" ))
  5183.         {
  5184.             if (NULL_IN_SCRIPTING_LANGUAGE != iPedID)
  5185.             {
  5186.                 CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  5187.  
  5188.                 CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByTreeAndType(PED_TASK_TREE_SECONDARY, CTaskTypes::TASK_MOBILE_PHONE);
  5189.                 if (!pTask)
  5190.                 {
  5191.                     pTask = rage_new CTaskMobilePhone(CTaskMobilePhone::Mode_ToCall, iTime);
  5192.                     pPed->GetPedIntelligence()->AddTaskSecondary(pTask, PED_TASK_SECONDARY_PARTIAL_ANIM);
  5193.                 }
  5194.                 else
  5195.                 {
  5196.                     // we already have one, just reset it
  5197.                     CTaskMobilePhone* pTaskMobilePhone = static_cast<CTaskMobilePhone*>(pTask);
  5198.                     pTaskMobilePhone->ResetTaskMobilePhone(CTaskMobilePhone::Mode_ToCall, iTime);
  5199.                 }
  5200.             }
  5201.             else
  5202.             {
  5203.                 // We still have to try and send the task if this is called from script in a sequence.
  5204.                 CTask* pTask = rage_new CTaskMobilePhone(CTaskMobilePhone::Mode_ToCall, iTime, false);
  5205.                 CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_USE_MOBILE_PHONE, "TASK_USE_MOBILE_PHONE_TIMED");
  5206.             }
  5207.         }          
  5208.     }
  5209.  
  5210.     void CommandTaskUseWalkieTalkie( int UNUSED_PARAM(iPedID), const char* UNUSED_PARAM(szContext) )
  5211.     {
  5212.         scriptAssertf(0, "TASK_USE_WALKIE_TALKIE has been deprecated");
  5213.     }
  5214.  
  5215.     void CommandTaskCapturePed(int UNUSED_PARAM(iPedID), int UNUSED_PARAM(iOtherPedID), float UNUSED_PARAM(fCaptureTime), float UNUSED_PARAM(fTimeToQuestion))
  5216.     {
  5217.         scriptAssertf(0, "TASK_CAPTURE_PED is deprecated");
  5218.     }
  5219.  
  5220.     void CommandTaskAdvanceToTargetInLine(int iPedID, int iOtherPedID, const scrVector & svTargetLocation, float fDesiredDist, float fTimeToHoldAtEnd, int iFlags)
  5221.     {
  5222.         // If we aren't running this in a sequence, assert on the peds group
  5223.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  5224.         if(pPed)
  5225.         {
  5226.             Assertf(pPed->GetPedsGroup(), "Ped running TASK_ADVANCE_TO_TARGET_IN_LINE must have a valid group");
  5227.         }
  5228.  
  5229.         // Get the other ped or location or both to determine the target type
  5230.         CPed* pOtherPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iOtherPedID);
  5231.         Vector3 vTargetLoc = svTargetLocation;
  5232.  
  5233.         Assertf(pOtherPed || vTargetLoc.IsNonZero(), "Target must be a valid ped or a non-origin position");
  5234.  
  5235.         CAITarget target;
  5236.         if(pOtherPed)
  5237.         {
  5238.             target = vTargetLoc.IsZero() ? CAITarget(pOtherPed) : CAITarget(pOtherPed, vTargetLoc);
  5239.         }
  5240.         else
  5241.         {
  5242.             target = CAITarget(vTargetLoc);
  5243.         }
  5244.  
  5245.         // Create our new task and give it to the ped
  5246.         CTask* pTask = rage_new CTaskSwatFollowInLine(target, fDesiredDist, fTimeToHoldAtEnd, iFlags);
  5247.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_ADVANCE_TO_TARGET_IN_LINE, "TASK_ADVANCE_TO_TARGET_IN_LINE");
  5248.     }
  5249.  
  5250.     void CommandSetChargeTargetEnabled(bool bEnabled)
  5251.     {
  5252.         CTaskCombat::ms_Tunables.m_ChargeTuning.m_bChargeTargetEnabled = bEnabled;
  5253.     }
  5254.  
  5255.     void CommandSetMaxNumActiveChargers(int iMaxActiveChargers)
  5256.     {
  5257.         if( SCRIPT_VERIFY(iMaxActiveChargers >= 0, "SET_MAX_NUM_ACTIVE_CHARGERS -- negative MAX_NUM_ACTIVE_CHARGERS requested") )
  5258.         {
  5259.             CTaskCombat::ms_Tunables.m_ChargeTuning.m_uMaxNumActiveChargers = (u8)iMaxActiveChargers;
  5260.         }
  5261.     }
  5262.  
  5263.     void CommandSetMinTimeBetweenChargesAtSameTarget(float fMinTimeSeconds)
  5264.     {
  5265.         if( SCRIPT_VERIFY(fMinTimeSeconds >= 0.0f, "SET_MIN_TIME_BETWEEN_CHARGES_AT_SAME_TARGET -- negative MIN_TIME_SECONDS requested") )
  5266.         {
  5267.             CTaskCombat::ms_Tunables.m_ChargeTuning.m_uMinTimeBetweenChargesAtSameTargetMS = (u32)(fMinTimeSeconds * 1000.0f);
  5268.         }
  5269.     }
  5270.  
  5271.     void CommandTaskChatToPed(int iPedID, int iOtherPedID, int iFlags, const scrVector & vGoToPos, float fHeadingDegs, float fIdleTime)
  5272.     {
  5273.         CPed* pOtherPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iOtherPedID);
  5274.         if (pOtherPed)
  5275.         {
  5276.             // Convert the heading to radians, in the -PI..PI range.
  5277.             float fHeading = CanonicalizeAngle(fHeadingDegs*DtoR);
  5278.  
  5279.             CTask* pTask = rage_new CTaskChat(pOtherPed, iFlags, vGoToPos, fHeading, fIdleTime);
  5280.             CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_CHAT_TO_PED, "TASK_CHAT_TO_PED");
  5281.         }
  5282.     }
  5283.  
  5284.     bool CommandIsChattingPedInPosition(int iPedID)
  5285.     {
  5286.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  5287.  
  5288.         if(pPed)
  5289.         {
  5290.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CHAT);
  5291.             if (pTask && static_cast<CTaskChat*>(pTask)->IsInPosition())
  5292.             {
  5293.                 return true;
  5294.             }
  5295.         }
  5296.         return false;
  5297.     }
  5298.  
  5299.     bool CommandIsChattingPedPlayingAnim(int iPedID)
  5300.     {
  5301.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  5302.  
  5303.         if(pPed)
  5304.         {
  5305.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CHAT);
  5306.             if (pTask && static_cast<CTaskChat*>(pTask)->IsPlayingClip())
  5307.             {
  5308.                 return true;
  5309.             }
  5310.         }
  5311.         return false;
  5312.     }
  5313.  
  5314.     void CommandMakeChattingPedPlayAnim(int UNUSED_PARAM(iPedID), const char *UNUSED_PARAM(pAnimDictName), const char *UNUSED_PARAM(pAnimName), float UNUSED_PARAM(fBlendInDelta), int UNUSED_PARAM(nTimeToPlay), int UNUSED_PARAM(nControlFlags))
  5315.     {
  5316.         // GSALES - killing this so I can get rid of the old anim control flag stuff. It doesn't seem to be used anywhere any more.
  5317.         scriptAssertf(0, "MAKE_CHATTING_PED_PLAY_ANIM - This command is deprecated. See an animation programmer.");
  5318.     }
  5319.  
  5320.     void CommandMakeChattingPedLeave(int iPedID, bool bPlayGoodByeGestures)
  5321.     {
  5322.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  5323.  
  5324.         if(pPed)
  5325.         {
  5326.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CHAT);
  5327.             if (pTask)
  5328.             {
  5329.                 static_cast<CTaskChat*>(pTask)->LeaveChat(bPlayGoodByeGestures);
  5330.             }
  5331.         }
  5332.     }
  5333.  
  5334.     enum {
  5335.         MOBILE_SUB_TASK_PHONE_IN,
  5336.         MOBILE_SUB_TASK_PHONE_TALK,
  5337.         MOBILE_SUB_TASK_PHONE_OUT,
  5338.         MOBILE_SUB_TASK_PHONE_OTHER
  5339.     };
  5340.  
  5341.     bool CommandGetMobilePhoneTaskSubTask( int iPedID, int &ReturnSubTask)
  5342.     {
  5343.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  5344.         if(pPed)
  5345.         {
  5346.             ReturnSubTask = MOBILE_SUB_TASK_PHONE_IN;
  5347.             CTaskComplexUseMobilePhone *pTaskUseMobile = (CTaskComplexUseMobilePhone*)pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_COMPLEX_USE_MOBILE_PHONE);
  5348.  
  5349.             //  Assertf(pTaskUseMobile, "%s:GET_MOBILE_PHONE_TASK_SUB_TASK - ped is not performing the mobile phone task", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  5350.             if (pTaskUseMobile)
  5351.             {
  5352.                 CTask *pSubTask = pTaskUseMobile->GetSubTask();
  5353.  
  5354.                 if (pSubTask)
  5355.                 {
  5356.                     switch (pSubTask->GetTaskType())
  5357.                     {
  5358.                     case CTaskTypes::TASK_SIMPLE_PHONE_IN:
  5359.                         ReturnSubTask = MOBILE_SUB_TASK_PHONE_IN;
  5360.                         break;
  5361.                     case CTaskTypes::TASK_SIMPLE_PHONE_TALK:
  5362.                         ReturnSubTask = MOBILE_SUB_TASK_PHONE_TALK;
  5363.                         break;
  5364.                     case CTaskTypes::TASK_SIMPLE_PHONE_OUT:
  5365.                         ReturnSubTask = MOBILE_SUB_TASK_PHONE_OUT;
  5366.                         break;
  5367.                     default:    //  return the same value for all other sub task types?
  5368.                         ReturnSubTask = MOBILE_SUB_TASK_PHONE_OTHER;
  5369.                         break;
  5370.                     }
  5371.                 }
  5372.  
  5373.                 return true;
  5374.             }
  5375.  
  5376.         //  if the ped isn't performing TASK_COMPLEX_USE_MOBILE_PHONE then ReturnSubTask will be MOBILE_SUB_TASK_PHONE_IN
  5377.         }
  5378.         return false;
  5379.     }
  5380.  
  5381.     void CommandTaskWarpPedIntoVehicle( int iPedID, int iVehicleID, int iSeat )
  5382.     {
  5383.         scriptAssertf(!NetworkInterface::IsGameInProgress(), "%s:TASK_WARP_PED_INTO_VEHICLE is not safe in network games! Use TASK_ENTER_VEHICLE with the warp flag set instead!", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  5384.  
  5385.         CVehicle *pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID);
  5386.  
  5387.         if(pVehicle)
  5388.         {
  5389.             s32 iSeatIndex = iSeat+1;
  5390.  
  5391.             if( iSeatIndex == -1 )
  5392.             {
  5393.                 // If -2 is passed in, we should put the ped into any passenger seat
  5394.                 for (s32 seatIndex=1; seatIndex<pVehicle->GetSeatManager()->GetMaxSeats(); seatIndex++)
  5395.                 {
  5396.                     if (!pVehicle->GetSeatManager()->GetPedInSeat(seatIndex))
  5397.                     {
  5398.                         iSeatIndex = seatIndex;
  5399.                         break;
  5400.                     }
  5401.                 }
  5402.  
  5403.                 if (!SCRIPT_VERIFY(iSeatIndex != -1, "TASK_WARP_PED_INTO_VEHICLE - Couldn't find free passenger seat to put ped in"))
  5404.                     return;
  5405.             }
  5406.  
  5407.             if( iSeatIndex != -1 )
  5408.             {
  5409.                 if(!SCRIPT_VERIFY((iSeatIndex < pVehicle->GetSeatManager()->GetMaxSeats()), "TASK_WARP_PED_INTO_VEHICLE - Seat number is too large"))
  5410.                     return;
  5411.  
  5412.                 if(!SCRIPT_VERIFY(!pVehicle->GetSeatManager()->GetPedInSeat(iSeatIndex), "TASK_WARP_PED_INTO_VEHICLE - Vehicle already has a passenger in the specified seat"))
  5413.                     return;
  5414.             }
  5415.  
  5416.             CTaskSetPedInVehicle* pTask=rage_new CTaskSetPedInVehicle(pVehicle, iSeatIndex, CPed::PVF_Warp);
  5417.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_WARP_PED_INTO_VEHICLE, "TASK_WARP_PED_INTO_VEHICLE"); 
  5418.         }
  5419.     }
  5420.  
  5421.     // Warps a ped to a position on an entity with defined combination of limbs attached and sets the ped to ragdoll.
  5422.     void CommandTaskNMAttachPedToEntity(int iPedID, int iEntityID,  int iAttachParentBone, const scrVector & vOffset, const scrVector & vRotation, int iAttachFlags, const char* pAnimDict, const char * pGetOnAnimName, const char* pIdleAnimName, int RotOrder)
  5423.     {
  5424.         s32 animDictIndex;
  5425.  
  5426.         CPhysical* pEntity = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(iEntityID);
  5427.  
  5428.         if(scriptVerifyf(!NetworkInterface::IsGameInProgress(), "TASK_NM_ATTACH_PED_TO_ENTITY - This script command is not allowed in network game scripts!"))
  5429.         {
  5430.             if(pEntity)
  5431.             {
  5432.                 if(scriptVerifyf(fwAnimManager::GetClipIfExistsByName(pAnimDict, pGetOnAnimName), "Check that the dictionary: %s is loaded and the anim: %s is contained with the dictionary",pAnimDict ,pGetOnAnimName ))
  5433.                 {
  5434.                     if(scriptVerifyf(fwAnimManager::GetClipIfExistsByName(pAnimDict, pIdleAnimName), "Check that the dictionary: %s is loaded and the anim: %s is contained with the dictionary",pAnimDict ,pIdleAnimName))
  5435.                     {
  5436.                         animDictIndex = fwAnimManager::FindSlot(pAnimDict).Get();
  5437.  
  5438.                         Quaternion rotationQuaternion;
  5439.                         CScriptEulers::QuaternionFromEulers(rotationQuaternion, vRotation, static_cast<EulerAngleOrder>(RotOrder));
  5440.  
  5441.                         CTaskAnimatedAttach* pTaskAttach=rage_new CTaskAnimatedAttach(pEntity, iAttachParentBone, vOffset, rotationQuaternion, iAttachFlags, animDictIndex, atStringHash(pGetOnAnimName), atStringHash(pIdleAnimName) );
  5442.                         CScriptPeds::GivePedScriptedTask( iPedID, pTaskAttach, SCRIPT_TASK_NM_ATTACH_TO_VEHICLE, "TASK_NM_ATTACH_PED_TO_ENTITY");
  5443.                     }
  5444.                 }
  5445.             }
  5446.         }
  5447.     }
  5448.  
  5449.     void CommandTaskShootAtEntity( int iPedID, int iEntityID, int iTime, int iFiringPatternHash )
  5450.     {
  5451.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_SHOOT_AT_ENTITY - Time must be -1 for infinite and > 0" ))
  5452.         {
  5453.             const CEntity  *pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iEntityID);
  5454.             if(pEntity)
  5455.             {
  5456.                 CTaskGun* pTaskGun = rage_new CTaskGun(CWeaponController::WCT_Fire, CTaskTypes::TASK_AIM_GUN_ON_FOOT, CWeaponTarget(pEntity), ((float) iTime) / 1000.0f);
  5457.                 pTaskGun->SetAllowRestartAfterAbort(true);
  5458.                 if(iFiringPatternHash)
  5459.                 {
  5460.                     pTaskGun->SetFiringPatternHash(iFiringPatternHash);
  5461.                 }
  5462.                 CScriptPeds::GivePedScriptedTask(iPedID, pTaskGun, SCRIPT_TASK_SHOOT_AT_ENTITY, "TASK_SHOOT_AT_ENTITY");
  5463.  
  5464. #if 0
  5465.                 // This block of code is an attempt to make this task work for a mounted ped, left in
  5466.                 // for reference. Was hoping that we could just use CTaskGun with CTaskAimGunVehicleDriveBy,
  5467.                 // but there were some complications. Basically, if we bypass CTaskVehicleGun, there is nothing
  5468.                 // streaming in the animations that CTaskAimGunVehicleDriveBy needs. If on the other hand
  5469.                 // we create a CTaskVehicleGun instead of CTaskGun, we probably won't have support for
  5470.                 // the time parameter. /FF
  5471.  
  5472.                 CTaskTypes::eTaskType aimTaskType = CTaskTypes::TASK_AIM_GUN_ON_FOOT;
  5473.                 const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  5474.                 if(pPed && pPed->GetMyMount())
  5475.                 {
  5476.                     aimTaskType = CTaskTypes::TASK_AIM_GUN_VEHICLE_DRIVE_BY;
  5477.                 }
  5478.  
  5479.                 CTaskGun* pTaskGun = rage_new CTaskGun(CWeaponController::WCT_Fire, aimTaskType, CWeaponTarget(pEntity), ((float) iTime) / 1000.0f);
  5480.  
  5481.                 if(aimTaskType == CTaskTypes::TASK_AIM_GUN_VEHICLE_DRIVE_BY)
  5482.                 {
  5483.                     const CVehicleDriveByInfo* pDrivebyInfo = CVehicleMetadataMgr::GetVehicleDriveByInfoFromPed(pPed);
  5484.                     taskAssert(pDrivebyInfo);
  5485.                     const CVehicleDriveByAnimInfo* pAnimInfo = CVehicleMetadataMgr::GetDriveByAnimInfoForWeapon(pPed, pPed->GetWeaponManager()->GetEquippedWeaponHash());
  5486.                     pTaskGun->SetOverrideClipSetId(pAnimInfo->GetClipSet());
  5487.                 }
  5488. #endif
  5489.             }
  5490.         }
  5491.     }
  5492.  
  5493.     void CommandTaskClimb( int iPedID, bool UNUSED_PARAM(bUsePlayerLaunchForce) )
  5494.     {
  5495.         CTask* pTask = rage_new CTaskJumpVault(JF_ForceVault);
  5496.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_CLIMB, "TASK_CLIMB" );
  5497.     }
  5498.  
  5499.     void CommandTaskClimbLadder( int iPedID, bool bFast )
  5500.     {
  5501.         CTask *pTask=rage_new CTaskClimbLadderFully(bFast);
  5502.         CScriptPeds::GivePedScriptedTask( iPedID,pTask, SCRIPT_TASK_CLIMB_LADDER, "TASK_CLIMB_LADDER");
  5503.     }
  5504.  
  5505.     void CommandTaskRappelDownWall( int iPedID, const scrVector & scrVecStartPos, const scrVector & scrVecRopeAnchorPos, float fDestinationHeight, int ropeID )
  5506.     {
  5507.         ropeManager* pRopeManager = CPhysics::GetRopeManager();
  5508.         if( SCRIPT_VERIFY(pRopeManager, "Rope Manager doesn't exist or is damaged!") )
  5509.         {
  5510.             ropeInstance* pRope = pRopeManager->FindRope( ropeID );
  5511.             if( scriptVerifyf(pRope, "Rope with ID: %d, doesn't exist or is damaged!", ropeID) )
  5512.             {
  5513.                 Vector3 vStartPos(scrVecStartPos);
  5514.                 Vector3 vAnchorPos(scrVecRopeAnchorPos);
  5515.                 CTask *pTask = rage_new CTaskRappel(fDestinationHeight, vStartPos, vAnchorPos, ropeID, CLIP_SET_ID_INVALID);
  5516.                 CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_RAPPEL_DOWN_WALL, "TASK_RAPPEL_DOWN_WALL");
  5517.             }
  5518.         }
  5519.     }
  5520.  
  5521.     void CommandTaskRappelDownWallUsingClipsetOverride(int iPedID, const scrVector & scrVecStartPos, const scrVector & scrVecRopeAnchorPos, float fDestinationHeight, int ropeID, const char* szOverrideRappelClipset, bool bSkipClimbOverWall)
  5522.     {
  5523.         ropeManager* pRopeManager = CPhysics::GetRopeManager();
  5524.         if (SCRIPT_VERIFY(pRopeManager, "Rope Manager doesn't exist or is damaged!"))
  5525.         {
  5526.             ropeInstance* pRope = pRopeManager->FindRope(ropeID);
  5527.             if (scriptVerifyf(pRope, "Rope with ID: %d, doesn't exist or is damaged!", ropeID))
  5528.             {
  5529.                 if (szOverrideRappelClipset)
  5530.                 {
  5531.                     fwMvClipSetId setId(szOverrideRappelClipset);
  5532.                     if (SCRIPT_VERIFYF(fwClipSetManager::GetClipSet(setId) != NULL, "ClipSet %s did not exist.  Are you sure it is in clip_sets.xml?", szOverrideRappelClipset))
  5533.                     {
  5534.                         Vector3 vStartPos(scrVecStartPos);
  5535.                         Vector3 vAnchorPos(scrVecRopeAnchorPos);
  5536.                         CTask *pTask = rage_new CTaskRappel(fDestinationHeight, vStartPos, vAnchorPos, ropeID, setId, bSkipClimbOverWall);
  5537.                         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_RAPPEL_DOWN_WALL, "TASK_RAPPEL_DOWN_WALL");
  5538.                     }
  5539.                 }
  5540.             }
  5541.         }
  5542.     }
  5543.  
  5544.     int CommandsGetTaskRappelDownWallState( int iPedID )
  5545.     {
  5546.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  5547.         if(pPed && pPed->GetPedIntelligence()->GetQueriableInterface()->IsTaskCurrentlyRunning(CTaskTypes::TASK_RAPPEL))
  5548.         {
  5549.             return pPed->GetPedIntelligence()->GetQueriableInterface()->GetStateForTaskType(CTaskTypes::TASK_RAPPEL);
  5550.         }
  5551.  
  5552.         return -1;
  5553.     }
  5554.  
  5555.     void CommandClearPedTasksImmediately(int iPedID)
  5556.     {
  5557.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  5558.  
  5559.         if(pPed)
  5560.         {
  5561.             pPed->SetPedResetFlag(CPED_RESET_FLAG_ScriptClearingPedTasks, true);
  5562.             if(pPed->IsNetworkClone())
  5563.             {
  5564.                 bool bClearTasksImmediately = true;
  5565.                 CClearPedTasksEvent::Trigger(pPed, bClearTasksImmediately);
  5566.             }
  5567.             else
  5568.             {
  5569.                 AI_LOG_WITH_ARGS_IF_SCRIPT_OR_PLAYER_PED(pPed, "[Script] - Ped %s has had tasks cleared immediately by script %s\n", AILogging::GetDynamicEntityNameSafe(pPed), CTheScripts::GetCurrentScriptName());
  5570.  
  5571.                 // instantly blend out any remaining animation before the flush
  5572.                 pPed->GetMovePed().SwitchToAnimated(0, false, true);
  5573.  
  5574.                 pPed->GetPedIntelligence()->FlushImmediately(true);
  5575.                 pPed->SetIsCrouching(false);
  5576.                 pPed->StopAllMotion(true);
  5577.  
  5578.                 // B*2979918 - too late to change for SP, but don't clear the helmet in MP when clearing tasks. It should be managed separately
  5579.                 if (!NetworkInterface::IsGameInProgress())
  5580.                 {
  5581.                     if (pPed->GetHelmetComponent())
  5582.                         pPed->GetHelmetComponent()->DisableHelmet();
  5583.                 }
  5584.  
  5585.                 pPed->SetPedResetFlag( CPED_RESET_FLAG_IsDrowning, false );
  5586.             }
  5587.             pPed->SetTimeSincePedInWater(60.0f); //B* 1150689
  5588.  
  5589. #if __DEV
  5590.             // Record the task in the debug list
  5591.             static char stringName[] = "CLEAR_PED_TASKS_IMMEDIATELY";
  5592.             pPed->GetPedIntelligence()->AddScriptHistoryString(stringName, stringName, CTheScripts::GetCurrentScriptName(), CTheScripts::GetCurrentGtaScriptThread()->GetThreadPC());
  5593. #endif
  5594.         }
  5595.     }
  5596.  
  5597.     void CommandTaskPerformSequenceFromProgress( int iPedID, int iTaskIndex, int iProgress1, int iProgress2 )
  5598.     {
  5599.         const int iTaskID = GetActualSequenceId(iTaskIndex);
  5600.         if(SCRIPT_VERIFY(iTaskID>=0 && iTaskID<CTaskSequences::MAX_NUM_SEQUENCE_TASKS, "TASK_PERFORM_SEQUENCE_FROM_PROGRESS - Sequence task ID too big"))
  5601.         {
  5602.             if(SCRIPT_VERIFY(!CTaskSequences::ms_bIsOpened[iTaskID], "TASK_PERFORM_SEQUENCE_FROM_PROGRESS - Sequence task is still open"))
  5603.             {
  5604.                 if(SCRIPT_VERIFY(!CTaskSequences::ms_TaskSequenceLists[iTaskID].IsEmpty(), "TASK_PERFORM_SEQUENCE_FROM_PROGRESS - sequence task empty"))
  5605.                 {
  5606.                     if(SCRIPT_VERIFY(iProgress1>=0 && iProgress1<CTaskList::MAX_LIST_SIZE, "TASK_PERFORM_SEQUENCE_FROM_PROGRESS - Sequence task ID too big"))
  5607.                     {
  5608.                         if(SCRIPT_VERIFY(iProgress2<CTaskList::MAX_LIST_SIZE, "TASK_PERFORM_SEQUENCE_FROM_PROGRESS - Sequence task ID too big"))
  5609.                         {
  5610.                             CTaskUseSequence* pTask=rage_new CTaskUseSequence(iTaskID, iTaskIndex);
  5611.                             pTask->SetProgress((u32)iProgress1,iProgress2);
  5612.                             CScriptPeds::GivePedScriptedTask( iPedID,pTask, SCRIPT_TASK_PERFORM_SEQUENCE_FROM_PROGRESS, "TASK_PERFORM_SEQUENCE_FROM_PROGRESS");
  5613.                         }
  5614.                     }
  5615.                 }
  5616.             }
  5617.         }
  5618.     }
  5619.  
  5620.     float CommandGetPedDesiredMoveBlendRatio( int iPedIndex )
  5621.     {
  5622.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex);
  5623.  
  5624.         if (pPed)
  5625.         {
  5626.             return pPed->GetMotionData()->GetDesiredMbrY();
  5627.         }
  5628.         return 0;
  5629.     }
  5630.  
  5631.     void CommandSetNextDesiredMoveState( float /*NextMoveState*/ )
  5632.     {
  5633.         scriptAssertf(0, "%s:SET_NEXT_DESIRED_MOVE_STATE - Function is deprecated - do not use anymore", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  5634.     }
  5635.  
  5636.     void CommandSetPedDesiredMoveBlendRatio( int iPedID, float fNewMoveBlendRatio )
  5637.     {
  5638.         if(!scriptVerifyf(fNewMoveBlendRatio >= MOVEBLENDRATIO_STILL && fNewMoveBlendRatio <= MOVEBLENDRATIO_SPRINT, "SET_PED_DESIRED_MOVE_BLEND_RATIO - move blend ratio %f out of range (%.2f:%.2f)", fNewMoveBlendRatio, MOVEBLENDRATIO_STILL, MOVEBLENDRATIO_SPRINT))
  5639.         {
  5640.             fNewMoveBlendRatio = Clamp(fNewMoveBlendRatio, MOVEBLENDRATIO_STILL, MOVEBLENDRATIO_SPRINT);
  5641.         }
  5642.  
  5643.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  5644.  
  5645.         if(pPed)
  5646.         {
  5647.             //Assertf(fMoveBlendRatio >= MOVEBLENDRATIO_STILL && fMoveBlendRatio <= MOVEBLENDRATIO_SPRINT, "MODIFY_PED_MOVE_BLEND_RATIO - Ratio must be between 0..3 inclusive");
  5648.  
  5649.             // Generally speaking we will want to look for the control-movement task in the primary (script) slot.
  5650.             // However there's an exception to this rule : if the ped is in a group, they may be entering a vehicle
  5651.             // via a task which has been given them in response to CEventLeaderEnteredCarAsDriver (etc), in which
  5652.             // case we will want to find the control movement in the TASK_PRIORITY_EVENT_RESPONSE_NONTEMP slot.
  5653.             CTaskComplexControlMovement * pCtrlMove = NULL;
  5654.  
  5655.             CPedIntelligence * pPedAi = pPed->GetPedIntelligence();
  5656.             const int iTaskPriority = pPedAi->GetTaskManager()->GetActiveTaskPriority(PED_TASK_TREE_PRIMARY);
  5657.  
  5658.             if(pPed->GetPedsGroup()!=NULL && iTaskPriority==PED_TASK_PRIORITY_EVENT_RESPONSE_NONTEMP
  5659.                 && pPedAi->GetCurrentEventType()==EVENT_LEADER_ENTERED_CAR_AS_DRIVER)
  5660.             {
  5661.                 pCtrlMove = (CTaskComplexControlMovement*)pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_COMPLEX_CONTROL_MOVEMENT);
  5662.             }
  5663.             else
  5664.             {
  5665.                 pCtrlMove = (CTaskComplexControlMovement*)pPed->GetPedIntelligence()->FindTaskPrimaryByType(CTaskTypes::TASK_COMPLEX_CONTROL_MOVEMENT);
  5666.             }
  5667.             if(!pCtrlMove)
  5668.             {
  5669.                 return;
  5670.             }
  5671.  
  5672.             CTask * pRunningMoveTask = pCtrlMove->GetRunningMovementTask(pPed);
  5673.             CTask * pBackUpMoveTask = pCtrlMove->GetBackupCopyOfMovementSubtask();
  5674.  
  5675.             if(pRunningMoveTask)
  5676.             {
  5677.                 Assert(pRunningMoveTask->IsMoveTask());
  5678.                 pRunningMoveTask->PropagateNewMoveSpeed(fNewMoveBlendRatio);
  5679.             }
  5680.             if(pBackUpMoveTask)
  5681.             {
  5682.                 Assert(pBackUpMoveTask->IsMoveTask());
  5683.                 pBackUpMoveTask->PropagateNewMoveSpeed(fNewMoveBlendRatio);
  5684.             }
  5685.         }
  5686.     }
  5687.  
  5688.     void CommandTaskGotoEntityAiming( int iPedID, int iEntityID, float fSeekRadius, float fAimRadius )
  5689.     {
  5690.         CTask *pTask;
  5691.         const CEntity* pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(iEntityID);
  5692.         if(pEntity)
  5693.         {
  5694.             Assert(fAimRadius>=fSeekRadius);
  5695.             pTask=rage_new CTaskSeekEntityAiming(pEntity,fSeekRadius,fAimRadius);
  5696.             CScriptPeds::GivePedScriptedTask( iPedID,pTask, SCRIPT_TASK_GOTO_ENTITY_AIMING, "TASK_GOTO_ENTITY_AIMING");
  5697.         }
  5698.     }
  5699.  
  5700.     void CommandTaskSetDecisionMaker( int iPedID, int iDecisionMakerId )
  5701.     {
  5702.         if(SCRIPT_VERIFY(iDecisionMakerId != NULL_IN_SCRIPTING_LANGUAGE, "TASK_SET_DECISION_MAKER -  NULL passed for decision maker, or variable not initialised"))
  5703.         {
  5704.             if(NULL_IN_SCRIPTING_LANGUAGE!=iPedID)
  5705.             {
  5706.                 CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  5707.                 if(pPed)
  5708.                 {
  5709.                     if(SCRIPT_VERIFY(pPed->IsPlayer() == false, "TASK_SET_PED_DECISION_MAKER - Can't change a player's decision maker"))
  5710.                     {
  5711.                         pPed->GetPedIntelligence()->SetDecisionMakerId(iDecisionMakerId);
  5712.                     }
  5713.                 }
  5714.             }
  5715.             else
  5716.             {
  5717.                 CTask* pTask=rage_new CTaskSetCharDecisionMaker(iDecisionMakerId);
  5718.                 CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_SET_PED_DECISION_MAKER, "TASK_SET_DECISION_MAKER");
  5719.             }
  5720.         }
  5721.     }
  5722.  
  5723.     void SetPedDefensiveIfNeeded( CPed* pPed )
  5724.     {
  5725.         if(pPed)
  5726.         {
  5727.             // If our ped is set as will advance movement then change it to defensive
  5728.             CCombatBehaviour& pedCombatBehaviour = pPed->GetPedIntelligence()->GetCombatBehaviour();
  5729.             if(pedCombatBehaviour.GetCombatMovement() == CCombatData::CM_WillAdvance)
  5730.             {
  5731.                 pedCombatBehaviour.SetCombatMovement(CCombatData::CM_Defensive);
  5732.             }
  5733.         }
  5734.     }
  5735.  
  5736.     void CommandTaskSetSphereDefensiveArea(int iPedID, const scrVector & scrVecCenter, float fRadius )
  5737.     {
  5738.         Vector3 vCenter(scrVecCenter);
  5739.  
  5740.         if(NULL_IN_SCRIPTING_LANGUAGE != iPedID)
  5741.         {
  5742.             CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  5743.             if (pPed)
  5744.             {
  5745.                 pPed->GetPedIntelligence()->GetDefensiveAreaManager()->GetPrimaryDefensiveArea()->SetAsSphere( vCenter, fRadius, NULL );
  5746.                 SetPedDefensiveIfNeeded(pPed);
  5747.             }
  5748.         }
  5749.         else
  5750.         {
  5751.             CTask* pTask = rage_new CTaskSetPedDefensiveArea(vCenter, fRadius);
  5752.             CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_SET_PED_DEFENSIVE_AREA, "TASK_SET_PED_SPHERE_DEFENSIVE_AREA");
  5753.         }
  5754.     }
  5755.  
  5756.     void CommandTaskClearDefensiveArea(int iPedID)
  5757.     {
  5758.         bool bGivePedTask = true;
  5759.  
  5760.         if(NULL_IN_SCRIPTING_LANGUAGE != iPedID)
  5761.         {
  5762.             CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  5763.             if (pPed && !pPed->IsNetworkClone())
  5764.             {
  5765.                 pPed->GetPedIntelligence()->GetDefensiveAreaManager()->GetPrimaryDefensiveArea()->Reset();
  5766.                 bGivePedTask = false;
  5767.             }
  5768.         }
  5769.  
  5770.         if(bGivePedTask)
  5771.         {
  5772.             CTask* pTask = rage_new CTaskSetPedDefensiveArea();
  5773.             CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_SET_PED_DEFENSIVE_AREA, "TASK_CLEAR_DEFENSIVE_AREA");
  5774.         }
  5775.     }
  5776.  
  5777.     void CommandTaskPedSlideToCoordWithHeadingChangeRate(int iPedID, const scrVector & scrVecCoors, float fHeadingDegs, float fSpeed, float fHdgChangeRate)
  5778.     {
  5779.         while(fHeadingDegs < 0.0f) fHeadingDegs += 360.0f;
  5780.         while(fHeadingDegs >= 360.0f) fHeadingDegs -= 360.0f;
  5781.         const float heading=( DtoR * fHeadingDegs);
  5782.         float speed=fSpeed;
  5783.         if(speed<0)
  5784.         {
  5785.             speed=0.1f;
  5786.         }
  5787.         Vector3 v(scrVecCoors);
  5788.  
  5789. #if __DEV
  5790.         if(NULL_IN_SCRIPTING_LANGUAGE != iPedID)
  5791.         {
  5792.             const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  5793.             if(pPed)
  5794.                 scriptAssertf(DistSquared(RCC_VEC3V(v), pPed->GetTransform().GetPosition()).Getf() < 100.0f, "TASK_PED_SLIDE_TO_COORD_HDG_RATE is moving a ped over 10m.");
  5795.         }
  5796. #endif
  5797.  
  5798.         static dev_float fTargetRadius = 0.125f;    //CTaskMoveGoToPointAndStandStill::ms_fTargetRadius;
  5799.  
  5800.         CTaskSequenceList* pTaskList = rage_new CTaskSequenceList();
  5801.         CTaskMoveGoToPointAndStandStill * pGotoTask = rage_new CTaskMoveGoToPointAndStandStill(MOVEBLENDRATIO_WALK, v, fTargetRadius);
  5802.         pTaskList->AddTask(rage_new CTaskComplexControlMovement(pGotoTask));
  5803.  
  5804.         CTaskSlideToCoord * pTaskSlide = rage_new CTaskSlideToCoord(v,heading,speed);
  5805.         pTaskSlide->SetHeadingIncrement( ( DtoR * fHdgChangeRate) );
  5806.         pTaskList->AddTask(pTaskSlide);
  5807.         CScriptPeds::GivePedScriptedTask( iPedID, pTaskList, SCRIPT_TASK_PED_SLIDE_TO_COORD, "TASK_PED_SLIDE_TO_COORD_HDG_RATE");
  5808.     }
  5809.  
  5810.     void CommandTaskPedSlideToCoord(int iPedID, const scrVector & scrVecCoors, float fHeadingDegs, float fSpeed)
  5811.     {
  5812.         CommandTaskPedSlideToCoordWithHeadingChangeRate(iPedID, scrVecCoors, fHeadingDegs, fSpeed, 0.0f);
  5813.     }
  5814.    
  5815.     //This command is not called by any include_command.sch but needs to be incorporated into CommandTaskPedSlideToCoordAndPlayAnim
  5816.     void CommandTaskPedSlideToCoordAndPlayAnimWithHeadingChangeRate( int iPedID,
  5817.         const scrVector & scrVecCoors,
  5818.         float fHeadingDegrees, float fSpeed,
  5819.         const char* AnimName, const char* AnimDictName,
  5820.         float fBlendDelta,
  5821.         bool bLooped, bool bExtractBackwardsVelocity, bool bExtractSidewaysVelocity, bool bHoldOnLastFrame,
  5822.         int iTime, float fHdgChangeRate)
  5823.     {
  5824.         while(fHeadingDegrees < 0.0f) fHeadingDegrees += 360.0f;
  5825.         while(fHeadingDegrees >= 360.0f) fHeadingDegrees -= 360.0f;
  5826.         const float heading=( DtoR * fHeadingDegrees);
  5827.         float speed=fSpeed;
  5828.         if(speed<0)
  5829.         {
  5830.             speed=0.1f;
  5831.         }
  5832.         s32 flags = 0;
  5833.         if ( bLooped || (iTime > 0) )
  5834.         {
  5835.             flags |= APF_ISLOOPED;
  5836.         }
  5837.         if (bExtractBackwardsVelocity)
  5838.         {
  5839.             //flags |= APF_CANEXTRACTYVELOCITY; //These flags no longer exist: GS 09/12/2009
  5840.         }
  5841.         if (bHoldOnLastFrame == false)
  5842.         {
  5843.             flags |= APF_ISFINISHAUTOREMOVE;
  5844.         }
  5845.         if (bExtractSidewaysVelocity)
  5846.         {
  5847.             //scriptAssertf(bExtractBackwardsVelocity, "%s:TASK_PLAY_ANIM - If you want to extract sideways velocity you have to extract forwards velocity too", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  5848.             //flags |= APF_CANEXTRACTXVELOCITY; //These flags no longer exist: GS 09/12/2009
  5849.         }
  5850.         bool bRunInSequence=false;
  5851.         if(CTaskSequences::ms_iActiveSequence>=0)
  5852.         {
  5853.             bRunInSequence=true;
  5854.         }
  5855.         Vector3 v(scrVecCoors);
  5856.  
  5857. #if __DEV
  5858.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  5859.         if(pPed)
  5860.             scriptAssertf(DistSquared(RCC_VEC3V(v), pPed->GetTransform().GetPosition()).Getf() < 100.0f, "TASK_PED_SLIDE_TO_COORD_HDG_RATE is moving a ped over 10m.");
  5861. #endif
  5862.  
  5863.         static dev_float fTargetRadius = 0.125f;    //CTaskMoveGoToPointAndStandStill::ms_fTargetRadius;
  5864.  
  5865.         CTaskSequenceList* pTaskList = rage_new CTaskSequenceList();
  5866.  
  5867.         // JB: Slightly larger target radius, since peds were occasionally overshooting their target & then sliding back
  5868.         CTaskMoveGoToPointAndStandStill * pTaskGoto = rage_new CTaskMoveGoToPointAndStandStill(MOVEBLENDRATIO_WALK, v, fTargetRadius);
  5869.         pTaskList->AddTask(rage_new CTaskComplexControlMovement(pTaskGoto) );
  5870.  
  5871.         CTaskSlideToCoord * pTaskSlide;
  5872.  
  5873.         if (iTime > 0)
  5874.         {
  5875.             pTaskSlide = rage_new CTaskSlideToCoord(v,heading,speed,AnimName,AnimDictName,flags,fBlendDelta,bRunInSequence,iTime);
  5876.         }
  5877.         else
  5878.         {
  5879.             pTaskSlide = rage_new CTaskSlideToCoord(v,heading,speed,AnimName,AnimDictName,flags,fBlendDelta,bRunInSequence);
  5880.         }
  5881.         pTaskSlide->SetHeadingIncrement( ( DtoR * fHdgChangeRate) );
  5882.  
  5883.         pTaskList->AddTask(pTaskSlide);
  5884.  
  5885.         CScriptPeds::GivePedScriptedTask( iPedID, pTaskList, SCRIPT_TASK_PED_SLIDE_TO_COORD_AND_PLAY_ANIM, "TASK_PED_SLIDE_TO_COORD_AND_PLAY_ANIM_HDG_RATE");
  5886.     }
  5887.  
  5888.     void CommandTaskPedSlideToCoordAndPlayAnim(
  5889.         int iPedID,
  5890.         const scrVector & scrVecCoors,
  5891.         float fHeadingDegrees, float fSpeed,
  5892.         const char* AnimName, const char* AnimDictName,
  5893.         float fBlendDelta,
  5894.         bool bLooped, bool bExtractBackwardsVelocity, bool bExtractSidewaysVelocity, bool bHoldOnLastFrame,
  5895.         int iTime)
  5896.     {
  5897.         CommandTaskPedSlideToCoordAndPlayAnimWithHeadingChangeRate(
  5898.             iPedID, scrVecCoors, fHeadingDegrees, fSpeed, AnimName, AnimDictName, fBlendDelta, bLooped,
  5899.             bExtractBackwardsVelocity, bExtractSidewaysVelocity, bHoldOnLastFrame, iTime, 0.0f);
  5900.     }
  5901.  
  5902.     void CommandTaskDrivePointRouteAdvanced( int iPedID, int iVehicleID, float fCruiseSpeed, int iMode, int VehicleModelHashKey, int iDrivingStyle)
  5903.     {
  5904.         CVehicle* pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  5905.        
  5906.         if(pVehicle)
  5907.         {
  5908.             fwModelId VehicleModelId;
  5909.             if (VehicleModelHashKey != DUMMY_ENTRY_IN_MODEL_ENUM_FOR_SCRIPTING_LANGUAGE)
  5910.             {
  5911.                 CModelInfo::GetBaseModelInfoFromHashKey((u32) VehicleModelHashKey, &VehicleModelId);        //  ignores return value
  5912.                 scriptAssertf( VehicleModelId.IsValid(), "%s:TASK_DRIVE_POINT_ROUTE_ADVANCED - this is not a valid model index", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  5913.             }
  5914.             CTask* pTask=rage_new CTaskDrivePointRoute(pVehicle,CTaskMoveFollowPointRoute::ms_pointRoute,fCruiseSpeed,iMode,VehicleModelId.GetModelIndex(),7.0f,iDrivingStyle); // 7.0 was -1.0 (finished radius)
  5915.             CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_DRIVE_POINT_ROUTE_ADVANCED, "TASK_DRIVE_POINT_ROUTE_ADVANCED");
  5916.         }
  5917.     }
  5918.  
  5919.  
  5920.     void CommandTaskGuardAssignedDefensiveArea(int iPedIndex, const scrVector & vDefendPosition, float fHeading, float fMaxPatrolProximity, int nTimer)
  5921.     {
  5922.         if (SCRIPT_VERIFY((nTimer == -1) || (nTimer > 0) ,"TASK_GUARD_ASSIGNED_DEFENSIVE_AREA - Time must be -1 for infinite and > 0" ))
  5923.         {
  5924.             Vector3 vDefendPosV3    = vDefendPosition;
  5925.             float fNewPedHeading    = fHeading;
  5926.             float fTimer            = ((float) nTimer)/1000.0f;
  5927.  
  5928.             while (fNewPedHeading < 0.0f)
  5929.             {
  5930.                 fNewPedHeading += 360.0f;
  5931.             }
  5932.             while (fNewPedHeading > 360.0f)
  5933.             {
  5934.                 fNewPedHeading -= 360.0f;
  5935.             }
  5936.  
  5937.             CTask* pTask = rage_new CTaskStandGuard( vDefendPosV3, ( DtoR * fNewPedHeading), fMaxPatrolProximity, GM_PatrolDefensiveArea, fTimer);
  5938.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_GUARD_DEFENSIVE_AREA, "TASK_GUARD_ASSIGNED_DEFENSIVE_AREA");
  5939.         }
  5940.     }
  5941.  
  5942.  
  5943.     void CommandTaskGuardAngledDefensiveArea(int iPedIndex, const scrVector & vDefendPosition, float fHeading, float fMaxPatrolProximity, int iTime, const scrVector & sv1, const scrVector & sv2, float fDefensiveAreaWidth)
  5944.     {
  5945.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_GUARD_ANGLED_DEFENSIVE_AREA - Time must be -1 for infinite and > 0" ))
  5946.         {
  5947.             scriptAssertf(fDefensiveAreaWidth >= CDefensiveArea::GetMinRadius(), "TASK_GUARD_ANGLED_DEFENSIVE_AREA - defensive area radius should be at least %.2f, but passed in - %.2f",CDefensiveArea::GetMinRadius(),fDefensiveAreaWidth);
  5948.            
  5949.             Vector3 vDefendPosV3    = vDefendPosition;
  5950.             float fNewPedHeading    = fHeading;
  5951.             float fTimer            = ((float) iTime)/1000.0f;
  5952.  
  5953.             if (fNewPedHeading < 0.0f)
  5954.             {
  5955.                 fNewPedHeading += 360.0f;
  5956.             }
  5957.             if (fNewPedHeading > 360.0f)
  5958.             {
  5959.                 fNewPedHeading -= 360.0f;
  5960.             }
  5961.  
  5962.             Vector3 v1 = sv1;
  5963.             Vector3 v2 = sv2;
  5964.  
  5965.             CDefensiveArea area;
  5966.             area.Set(v1, v2, fDefensiveAreaWidth);
  5967.  
  5968.             CTask* pTask = rage_new CTaskSetAndGuardArea( vDefendPosV3, ( DtoR * fNewPedHeading), fMaxPatrolProximity, GM_PatrolDefensiveArea, fTimer, area );
  5969.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_GUARD_ANGLED_DEFENSIVE_AREA, "TASK_GUARD_ANGLED_DEFENSIVE_AREA");
  5970.         }
  5971.     }
  5972.  
  5973.     void CommandTaskGuardSphereDefensiveArea(int iPedIndex, const scrVector & vDefendPosition, float fHeading, float fMaxPatrolProximity, int iTime, const scrVector & sv1, float fDefensiveAreaRadius)
  5974.     {
  5975.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_GUARD_SPHERE_DEFENSIVE_AREA - Time must be -1 for infinite and > 0" ))
  5976.         {
  5977.             Vector3 v1 = sv1;
  5978.  
  5979.             Vector3 vDefendPosV3    = vDefendPosition;
  5980.             float fNewPedHeading    = fHeading;
  5981.             float fTimer            = ((float) iTime)/1000.0f;
  5982.  
  5983.             scriptAssertf(!vDefendPosV3.IsClose(VEC3_ZERO, SMALL_FLOAT), "TASK_GUARD_SPHERE_DEFENSIVE_AREA is tasking a ped to defend the origin.  This is is very likely an error.");
  5984.  
  5985.             scriptAssertf(fDefensiveAreaRadius >= CDefensiveArea::GetMinRadius(),"TASK_GUARD_SPHERE_DEFENSIVE_AREA - defensive area radius should be at least %.2f, but passed in - %.2f",CDefensiveArea::GetMinRadius(),fDefensiveAreaRadius);
  5986.  
  5987.             if (fNewPedHeading < 0.0f)
  5988.             {
  5989.                 fNewPedHeading += 360.0f;
  5990.             }
  5991.             if (fNewPedHeading > 360.0f)
  5992.             {
  5993.                 fNewPedHeading -= 360.0f;
  5994.             }
  5995.  
  5996.             CDefensiveArea area;
  5997.             area.SetAsSphere(v1, fDefensiveAreaRadius);
  5998.  
  5999.             CTask* pTask = rage_new CTaskSetAndGuardArea( vDefendPosV3, ( DtoR * fNewPedHeading), fMaxPatrolProximity, GM_PatrolDefensiveArea, fTimer, area );
  6000.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_GUARD_SPHERE_DEFENSIVE_AREA, "TASK_GUARD_SPHERE_DEFENSIVE_AREA");
  6001.         }
  6002.     }
  6003.  
  6004.     void CommandTaskGuardCurrentPosition(int iPedIndex, float fMaxPatrolProximity, float fDefensiveAreaRadius, bool bSetDefensiveArea)
  6005.     {
  6006.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex);
  6007.  
  6008.         if (SCRIPT_VERIFY(pPed, "Invalid ped tasked with TASK_GUARD_CURRENT_POSITION"))
  6009.         {
  6010.             scriptAssertf(fDefensiveAreaRadius >= CDefensiveArea::GetMinRadius(),"TASK_GUARD_CURRENT_POSITION - defensive area radius should be at least %.2f, but passed in - %.2f",CDefensiveArea::GetMinRadius(),fDefensiveAreaRadius);
  6011.            
  6012.             Vector3 vDefendPosV3 = VEC3V_TO_VECTOR3(pPed->GetTransform().GetPosition());
  6013.             CDefensiveArea area;
  6014.             area.SetAsSphere(vDefendPosV3, fDefensiveAreaRadius);
  6015.             float fTimer = -1.0f;
  6016.  
  6017.             eGuardMode guardMode = bSetDefensiveArea ? GM_PatrolDefensiveArea : GM_PatrolProximity;
  6018.  
  6019.             CTask* pTask = rage_new CTaskSetAndGuardArea( vDefendPosV3, pPed->GetCurrentHeading(), fMaxPatrolProximity, guardMode, fTimer, area, true, bSetDefensiveArea );
  6020.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_GUARD_CURRENT_POSITION, "TASK_GUARD_CURRENT_POSITION");
  6021.         }
  6022.     }
  6023.  
  6024.     // Stand guard at a position
  6025.     void CommandTaskStandGuard(int iPedIndex, const scrVector & vDefendPosition, float fHeading, const char* szContext)
  6026.     {
  6027.         Vector3 vDefendPosV3    = vDefendPosition;
  6028.         float fNewPedHeading    = fHeading;
  6029.  
  6030.         fwAngle::LimitDegreeAngle(fNewPedHeading);
  6031.  
  6032.         if (strcmp(szContext,"Default") == 0)
  6033.         {
  6034.             CTask* pTask = rage_new CTaskStandGuardFSM( vDefendPosV3, ( DtoR * fNewPedHeading));
  6035.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_STAND_GUARD, "TASK_STAND_GUARD");
  6036.         }
  6037.         else
  6038.         {
  6039.  
  6040.             s32 scenarioType = CScenarioManager::GetScenarioTypeFromHashKey(atStringHash(szContext));
  6041.             CTask* pTask = rage_new CTaskStandGuardFSM( vDefendPosV3, ( DtoR * fNewPedHeading),scenarioType);
  6042.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_STAND_GUARD, "TASK_STAND_GUARD");
  6043.         }
  6044.     }
  6045.  
  6046.     // Add a scripted cover point
  6047.     int CommandAddCoverPoint( const scrVector & scrVecCoors, float fDirection, s32 iUsage, s32 iHeight, s32 iArc, bool bIsPriority)
  6048.     {
  6049.         AI_LOG_WITH_ARGS("[Script] - Script %s is adding a coverpoint at position (%.2f, %.2f, %.2f)", CTheScripts::GetCurrentScriptName(), scrVecCoors.x, scrVecCoors.y, scrVecCoors.z);
  6050.         AI_LOG_STACK_TRACE(8);
  6051.  
  6052.         CScriptResource_Coverpoint coverPoint(Vector3(scrVecCoors), fDirection, iUsage, iHeight, iArc, bIsPriority);
  6053.  
  6054.         return CTheScripts::GetCurrentGtaScriptHandler()->RegisterScriptResourceAndGetRef(coverPoint);
  6055.     }
  6056.  
  6057.     // Remove a scripted cover point
  6058.     void CommandRemoveCoverPoint( int iIdentifier )
  6059.     {
  6060.         AI_LOG_WITH_ARGS("[Script] - Script %s is removing a cover point with ID %d", CTheScripts::GetCurrentScriptName(), iIdentifier);
  6061.         AI_LOG_STACK_TRACE(8);
  6062.  
  6063.         CTheScripts::GetCurrentGtaScriptHandler()->RemoveScriptResource(CGameScriptResource::SCRIPT_RESOURCE_COVERPOINT, iIdentifier);
  6064.     }
  6065.  
  6066.     bool CommandDoesScriptedCoverPointExistAtCoords( const scrVector & scrVecCoors )
  6067.     {
  6068.         CCoverPoint* pOverlappingCoverPoint = NULL;
  6069.         if (!CCoverPointsContainer::CheckIfNoOverlapAndGetGridCell(scrVecCoors, CCoverPoint::COVTYPE_SCRIPTED, NULL, pOverlappingCoverPoint, false))
  6070.         {
  6071.             return true;
  6072.         }
  6073.         else
  6074.         {
  6075.             return false;
  6076.         }
  6077.     }
  6078.  
  6079.     scrVector CommandGetScriptedCoverPointCoords( int iIdentifier )
  6080.     {
  6081.         CScriptedCoverPoint* pScriptedCoverPoint = CTheScripts::GetScriptedCoverPointToModifyFromGUID(iIdentifier);
  6082.         if (SCRIPT_VERIFY(pScriptedCoverPoint ,"GET_SCRIPTED_COVER_POINT_COORDS - Identifier is invalid" ))
  6083.         {
  6084.             CCoverPoint* pCoverPoint = CCover::FindCoverPointWithIndex(pScriptedCoverPoint->GetScriptIndex());
  6085.             if (scriptVerifyf(pCoverPoint, "GET_SCRIPTED_COVER_POINT_COORDS - Cover Point %i Doesn't Exist", iIdentifier))
  6086.             {
  6087.                 Vector3 vCoverPos(Vector3::ZeroType);
  6088.                 if (scriptVerifyf(pCoverPoint->GetCoverPointPosition(vCoverPos), "GET_SCRIPTED_COVER_POINT_COORDS - Couldn't get cover point coords for cover point with index %i", iIdentifier))
  6089.                 {
  6090.                     return vCoverPos;
  6091.                 }
  6092.             }
  6093.         }
  6094.         return VEC3_ZERO;
  6095.     }
  6096.  
  6097.     // Add a scripted cover area which will be appended to the streamed cover area array
  6098.     void CommandAddScriptedCoverArea(const scrVector & scrVecCoors, const float fRadius)
  6099.     {
  6100.         if (CPed* pPlayer = CGameWorld::FindLocalPlayer())
  6101.         {
  6102.             Vector3 vFrom(scrVecCoors);
  6103.  
  6104.             Vector3 vDistance = VEC3V_TO_VECTOR3(pPlayer->GetTransformPtr()->GetPosition()) - vFrom;
  6105.             float fDistance2 = vDistance.Mag2();
  6106.  
  6107.             if (scriptVerifyf(fDistance2 < rage::square(200), "ADD_SCRIPTED_COVER_AREA - Scripted Area Cover distance from player is %fm, it must be within 200m to add.", vDistance.Mag()))
  6108.             {
  6109.                 AI_LOG_WITH_ARGS("[Script] - Script %s is adding a scripted cover area at position (%.2f, %.2f, %.2f) with a radius of %.2f", CTheScripts::GetCurrentScriptName(), scrVecCoors.x, scrVecCoors.y, scrVecCoors.z, fRadius);
  6110.  
  6111.                 CCover::AddNewScriptedCoverArea(scrVecCoors, fRadius);
  6112.             }
  6113.         }
  6114.     }
  6115.  
  6116.     /*int CommandGetScriptedCoverPointStatus( int iIdentifier )
  6117.     {
  6118.         CScriptedCoverPoint* pScriptedCoverPoint = CTheScripts::GetScriptedCoverPointToModifyFromGUID(iIdentifier);
  6119.         if (scriptVerifyf(pScriptedCoverPoint, "GET_SCRIPTED_COVER_POINT_STATUS - Cover Point %i Doesn't Exist", iIdentifier))
  6120.         {
  6121.             CCoverPoint* pCoverPoint = CCover::FindCoverPointWithIndex(pScriptedCoverPoint->GetScriptIndex());
  6122.             if (scriptVerifyf(pCoverPoint, "GET_SCRIPTED_COVER_POINT_STATUS - Cover Point %i Doesn't Exist", iIdentifier))
  6123.             {
  6124.                 return pCoverPoint->GetStatus();
  6125.             }
  6126.         }
  6127.         return CCoverPoint::COVSTATUS_Invalid;
  6128.     }*/
  6129.  
  6130.     // Seek cover from the given position
  6131.     void CommandTaskSeekCoverFromPos( int PedIndex, const scrVector & scrVecCoors, int iTime, bool bAllowPeekingAndFiring )
  6132.     {
  6133.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_SEEK_COVER_FROM_POS - Time must be -1 for infinite and > 0" ))
  6134.         {
  6135.             float fTime = ( ( float )iTime ) / 1000.0f;
  6136.            
  6137.             Vector3 vFrom(scrVecCoors);
  6138.  
  6139.             CTaskCover* pCoverTask = rage_new CTaskCover(CAITarget(vFrom), bAllowPeekingAndFiring ? 0 : CTaskCover::CF_DisableAimingAndPeeking);
  6140.             pCoverTask->SetSearchFlags(CTaskCover::CF_SeekCover | CTaskCover::CF_CoverSearchAny | CTaskCover::CF_ScriptedSeekCover);
  6141.             pCoverTask->SetTimeInCover(fTime);
  6142.  
  6143.             CScriptPeds::GivePedScriptedTask(PedIndex, pCoverTask, SCRIPT_TASK_SEEK_COVER_FROM_POS, "TASK_SEEK_COVER_FROM_POS");
  6144.         }
  6145.     }
  6146.  
  6147.     // Seek cover from the given ped
  6148.     void CommandTaskSeekCoverFromPed( int iPedIndex, int iOtherPedIndex, int iTime, bool bAllowPeekingAndFiring )
  6149.     {
  6150.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_SEEK_COVER_FROM_PED - Time must be -1 for infinite and > 0" ))
  6151.         {
  6152.             float fTime = ( ( float )iTime ) / 1000.0f;
  6153.  
  6154.             const CPed *pOtherPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iOtherPedIndex);
  6155.  
  6156.             if(!pOtherPed)
  6157.                 return;
  6158.  
  6159.             CTaskCover* pCoverTask = rage_new CTaskCover(CAITarget(pOtherPed), bAllowPeekingAndFiring ? 0 : CTaskCover::CF_DisableAimingAndPeeking);
  6160.             pCoverTask->SetSearchFlags(CTaskCover::CF_SeekCover | CTaskCover::CF_CoverSearchAny | CTaskCover::CF_ScriptedSeekCover);
  6161.             pCoverTask->SetTimeInCover(fTime);
  6162.  
  6163.             CScriptPeds::GivePedScriptedTask(iPedIndex, pCoverTask, SCRIPT_TASK_SEEK_COVER_FROM_PED, "TASK_SEEK_COVER_FROM_PED");
  6164.         }
  6165.     }
  6166.  
  6167.     // Seek cover to the given cover point, away from the position specified
  6168.     void CommandTaskSeekCoverToCoverPoint( int iPedIndex, int iIdentifier, const scrVector & scrVecCoors, int iTime, bool bAllowPeekingAndFiring )
  6169.     {
  6170.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_SEEK_COVER_TO_COVER_POINT - Time must be -1 for infinite and > 0" ))
  6171.         {
  6172.  
  6173.             float fTime = ( ( float )iTime ) / 1000.0f;
  6174.  
  6175.             CScriptedCoverPoint* pScriptedCoverPoint = CTheScripts::GetScriptedCoverPointToModifyFromGUID(iIdentifier, "TASK_SEEK_COVER_TO_COVER_POINT");
  6176.            
  6177.             if (scriptVerifyf(pScriptedCoverPoint, "Cover point with id %i didn't exist", iIdentifier))
  6178.             {
  6179.                 s32 iCoverIndex = pScriptedCoverPoint->GetScriptIndex();
  6180.  
  6181.         // Find the cover point specified by the identifier
  6182. #if __ASSERT
  6183.    
  6184.                 CCoverPoint* pCoverPoint = CCover::FindCoverPointWithIndex( iCoverIndex );
  6185.                 scriptAssertf(pCoverPoint, "%s:TASK_SEEK_COVER_TO_COVER_POINT - Invalid cover point specified", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  6186.                 Assert( pCoverPoint->GetType() == CCoverPoint::COVTYPE_SCRIPTED );
  6187. #endif
  6188.                 Vector3 vFrom(scrVecCoors);
  6189.  
  6190.                 CTaskCover* pCoverTask = rage_new CTaskCover(CAITarget(vFrom), bAllowPeekingAndFiring ? 0 : CTaskCover::CF_DisableAimingAndPeeking);
  6191.                 pCoverTask->SetSearchFlags(CTaskCover::CF_SeekCover | CTaskCover::CF_CoverSearchScripted | CTaskCover::CF_ScriptedSeekCover);
  6192.                 pCoverTask->SetScriptedCoverIndex(iCoverIndex);
  6193.                 pCoverTask->SetTimeInCover(fTime);
  6194.                
  6195.                 CScriptPeds::GivePedScriptedTask(iPedIndex, pCoverTask, SCRIPT_TASK_SEEK_COVER_TO_COVER_POINT, "TASK_SEEK_COVER_TO_COVER_POINT");
  6196.             }
  6197.         }
  6198.     }
  6199.  
  6200.     // Seek cover to the given coords, away from the position specified
  6201.     void CommandTaskSeekCoverToCoords( int iPedIndex, const scrVector & scrVecCoverCoors, const scrVector & scrVecFromCoors, int iTime, bool bAllowPeekingAndFiring )
  6202.     {
  6203.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_SEEK_COVER_TO_COVER_COORD - Time must be -1 for infinite and > 0" ))
  6204.         {
  6205.             float fTime = ( ( float )iTime ) / 1000.0f;
  6206.  
  6207.             Vector3 vCover(scrVecCoverCoors);
  6208.             Vector3 vFrom(scrVecFromCoors);
  6209.  
  6210.             CTaskCover* pCoverTask = rage_new CTaskCover(CAITarget(vFrom), bAllowPeekingAndFiring ? 0 : CTaskCover::CF_DisableAimingAndPeeking);
  6211.             pCoverTask->SetSearchFlags(CTaskCover::CF_SeekCover | CTaskCover::CF_CoverSearchByPos | CTaskCover::CF_ScriptedSeekCover);
  6212.             pCoverTask->SetSearchPosition(vCover);
  6213.             pCoverTask->SetTimeInCover(fTime);
  6214.  
  6215.             CScriptPeds::GivePedScriptedTask(iPedIndex, pCoverTask, SCRIPT_TASK_SEEK_COVER_TO_COORDS, "TASK_SEEK_COVER_TO_COVER_COORD");
  6216.         }
  6217.     }
  6218.  
  6219.     CTaskCover* CreatePutPedDirectlyIntoCoverTask( const scrVector & vscStart, const CAITarget& aiTarget, int iTime, bool bAllowPeekingAndFiring, float fBlendInDuration, bool bForceInitialFacingDirection, bool bForceFaceLeft, int iIdentifier, bool bDoEntry )
  6220.     {
  6221.         scriptAssertf(fBlendInDuration < 10.0f, "Setting a long blend in duration (%.2f) are you sure you want the anims to blend in this slowly?", fBlendInDuration);
  6222.         float fTime = ( ( float )iTime ) / 1000.0f;
  6223.         Vector3 vStart = vscStart;
  6224.  
  6225.         s32 iCoverFlags = bAllowPeekingAndFiring ? CTaskCover::CF_PutPedDirectlyIntoCover : CTaskCover::CF_PutPedDirectlyIntoCover | CTaskCover::CF_DisableAimingAndPeeking;
  6226.  
  6227.         if (bForceInitialFacingDirection)
  6228.         {
  6229.             aiDisplayf("TASK_PUT_PED_DIRECTLY_INTO_COVER called forcing ped to face %s at <<%.2f,%.2f,%.2f>>", bForceFaceLeft ? "Left" : "Right", vscStart.x, vscStart.y, vscStart.z);
  6230.             iCoverFlags |= CTaskCover::CF_SpecifyInitialHeading;
  6231.             if (bForceFaceLeft)
  6232.             {
  6233.                 iCoverFlags |= CTaskCover::CF_FacingLeft;
  6234.             }
  6235.         }
  6236.  
  6237.         // Set whether we want to skip the cover entry anims
  6238.         if (!bDoEntry)
  6239.         {
  6240.             iCoverFlags |= CTaskCover::CF_SkipIdleCoverTransition;
  6241.         }
  6242.  
  6243.         CTaskCover* pCoverTask = rage_new CTaskCover(aiTarget, iCoverFlags);
  6244.  
  6245.         CScriptedCoverPoint* pScriptedCoverPoint = NULL;
  6246.  
  6247.         if (iIdentifier != NULL_IN_SCRIPTING_LANGUAGE)
  6248.         {
  6249.             pScriptedCoverPoint = CTheScripts::GetScriptedCoverPointToModifyFromGUID(iIdentifier, "TASK_PUT_PED_DIRECTLY_INTO_COVER");
  6250.         }
  6251.  
  6252.         if (pScriptedCoverPoint)
  6253.         {
  6254.             s32 iCoverIndex = pScriptedCoverPoint->GetScriptIndex();
  6255. #if __ASSERT
  6256.             // Find the cover point specified by the identifier
  6257.             CCoverPoint* pCoverPoint = CCover::FindCoverPointWithIndex( iCoverIndex );
  6258.             scriptAssertf(pCoverPoint, "%s:TASK_SEEK_COVER_TO_COVER_POINT - Invalid cover point specified", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  6259.             Assert( pCoverPoint->GetType() == CCoverPoint::COVTYPE_SCRIPTED );
  6260. #endif
  6261.             pCoverTask->SetSearchFlags(CTaskCover::CF_CoverSearchScripted | CTaskCover::CF_ScriptedSeekCover);
  6262.             pCoverTask->SetScriptedCoverIndex(iCoverIndex);
  6263.         }
  6264.         else
  6265.         {
  6266.             pCoverTask->SetSearchFlags(CTaskCover::CF_FindClosestPointAtStart | CTaskCover::CF_ScriptedSeekCover);
  6267.         }
  6268.  
  6269.         pCoverTask->SetBlendInDuration(fBlendInDuration);
  6270.         pCoverTask->SetSearchPosition(vStart);
  6271.         pCoverTask->SetTimeInCover(fTime);
  6272.         return pCoverTask;
  6273.     }
  6274.  
  6275.     // Seek cover from the given position
  6276.     void CommandTaskPutPedDirectlyIntoCover( int iPedIndex, const scrVector & vscStart, int iTime, bool bAllowPeekingAndFiring, float fBlendInDuration, bool bForceInitialFacingDirection, bool bForceFaceLeft, int iIdentifier, bool bDoEntry  )
  6277.     {
  6278.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_PUT_PED_DIRECTLY_INTO_COVER - Time must be -1 for infinite and > 0" ))
  6279.         {
  6280.             CTaskCover* pCoverTask = CreatePutPedDirectlyIntoCoverTask(vscStart, CAITarget(), iTime, bAllowPeekingAndFiring, fBlendInDuration, bForceInitialFacingDirection, bForceFaceLeft, iIdentifier, bDoEntry);
  6281.             CScriptPeds::GivePedScriptedTask(iPedIndex, pCoverTask, SCRIPT_TASK_PUT_PED_DIRECTLY_INTO_COVER, "TASK_PUT_PED_DIRECTLY_INTO_COVER" );
  6282.         }
  6283.     }
  6284.  
  6285.     bool GetAiTarget(CAITarget& target, int iOtherPedIndex, int iTargetVehicleIndex, const scrVector & vscTargetCoords)
  6286.     {
  6287.         Vector3 TempVec, CentreVec, VecDiff;
  6288.         const CPed *pSecondPed;
  6289.         const CVehicle *pSecondVehicle;
  6290.  
  6291.         TempVec = Vector3(vscTargetCoords);
  6292.  
  6293.         const CEntity *pTargetEntity = NULL;
  6294.         if (iOtherPedIndex  != NULL_IN_SCRIPTING_LANGUAGE)  //  >= 0)
  6295.         {
  6296.             if(SCRIPT_VERIFY(iTargetVehicleIndex == NULL_IN_SCRIPTING_LANGUAGE, "TASK_PUT_PED_DIRECTLY_INTO_COVER_FROM_TARGET - Can't have a target ped and a target car"))
  6297.             {
  6298.                 pSecondPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iOtherPedIndex);
  6299.                 if(!pSecondPed)
  6300.                     return false;
  6301.  
  6302.                 pTargetEntity = pSecondPed;
  6303.             }
  6304.             else
  6305.             {
  6306.                 return false;
  6307.             }
  6308.         }
  6309.         else
  6310.         {
  6311.             pSecondPed = NULL;
  6312.         }
  6313.         if (iTargetVehicleIndex != NULL_IN_SCRIPTING_LANGUAGE)  //  >= 0)
  6314.         {
  6315.             if(SCRIPT_VERIFY(iOtherPedIndex == NULL_IN_SCRIPTING_LANGUAGE, "TASK_PUT_PED_DIRECTLY_INTO_COVER_FROM_TARGET - Can't have a target ped and a target car"))
  6316.             {
  6317.                 pSecondVehicle = CTheScripts::GetEntityToQueryFromGUID<CVehicle>(iTargetVehicleIndex);
  6318.                 if(!SCRIPT_VERIFY(pSecondVehicle, "TASK_PUT_PED_DIRECTLY_INTO_COVER_FROM_TARGET - Target vehicle doesn't exist"))
  6319.                     return false;
  6320.  
  6321.                 pTargetEntity = pSecondVehicle;
  6322.             }
  6323.             else
  6324.             {
  6325.                 return false;
  6326.             }
  6327.         }
  6328.         else
  6329.         {
  6330.             pSecondVehicle = NULL;
  6331.         }
  6332.  
  6333.         // Set up the arguments
  6334.         if (pTargetEntity)
  6335.         {
  6336.             target.SetEntityAndOffset(pTargetEntity,TempVec);
  6337.         }
  6338.         else
  6339.         {
  6340.             target.SetPosition(TempVec);
  6341.         }
  6342.         return true;
  6343.     }
  6344.  
  6345.     // Seek cover from the given position
  6346.     void CommandTaskPutPedDirectlyIntoCoverFromTarget( int iPedIndex, int iOtherPedIndex, int iTargetVehicleIndex, const scrVector & vscTargetCoords, const scrVector & vscStart, int iTime, bool bAllowPeekingAndFiring, float fBlendInDuration, bool bForceInitialFacingDirection, bool bForceFaceLeft, int iIdentifier, bool bDoEntry  )
  6347.     {
  6348.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0) ,"TASK_PUT_PED_DIRECTLY_INTO_COVER_FROM_TARGET - Time must be -1 for infinite and > 0" ))
  6349.         {
  6350.             CAITarget target;
  6351.             if (GetAiTarget(target, iOtherPedIndex, iTargetVehicleIndex, vscTargetCoords))
  6352.             {
  6353.                 CTaskCover* pCoverTask = CreatePutPedDirectlyIntoCoverTask(vscStart, target, iTime, bAllowPeekingAndFiring, fBlendInDuration, bForceInitialFacingDirection, bForceFaceLeft, iIdentifier, bDoEntry);
  6354.                 CScriptPeds::GivePedScriptedTask(iPedIndex, pCoverTask, SCRIPT_TASK_PUT_PED_DIRECTLY_INTO_COVER_FROM_TARGET, "TASK_PUT_PED_DIRECTLY_INTO_COVER" );
  6355.             }
  6356.         }
  6357.     }
  6358.  
  6359.     void CommandTaskWarpPedDirectlyIntoCover(const int iPedIndex, const int iTime, const bool bAllowPeekingAndFiring, const bool bForceInitialFacingDirection, const bool bForceFaceLeft, const int iIdentifier)
  6360.     {
  6361.         if (SCRIPT_VERIFY((iTime == -1) || (iTime > 0), "TASK_WARP_PED_DIRECTLY_INTO_COVER - Time must be -1 for infinite and > 0") &&
  6362.             SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iPedIndex, "TASK_WARP_PED_DIRECTLY_INTO_COVER - Can't warp a NULL ped"))
  6363.         {
  6364.             if (CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES))
  6365.             {
  6366.                 Vector3 vPedPosition = VEC3V_TO_VECTOR3(pPed->GetTransform().GetPosition());
  6367.  
  6368.                 CTaskCover* pCoverTask = CreatePutPedDirectlyIntoCoverTask(vPedPosition, CAITarget(), iTime, bAllowPeekingAndFiring, 0.0f, bForceInitialFacingDirection, bForceFaceLeft, iIdentifier, false);
  6369.                 pCoverTask->SetCoverFlag(CTaskCover::CF_WarpPedToCoverPosition);
  6370.                 CScriptPeds::GivePedScriptedTask(iPedIndex, pCoverTask, SCRIPT_TASK_WARP_PED_DIRECTLY_INTO_COVER, "TASK_WARP_PED_DIRECTLY_INTO_COVER");
  6371.             }
  6372.         }
  6373.     }
  6374.  
  6375.     void CommandSetCoverTarget(int iPedIndex, int iOtherPedIndex, int iTargetVehicleIndex, const scrVector & vscTargetCoords)
  6376.     {
  6377.         if( SCRIPT_VERIFY( NULL_IN_SCRIPTING_LANGUAGE != iPedIndex, "SET_COVER_TARGET - Can't have a NULL ped" ) )
  6378.         {
  6379.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>( iPedIndex );
  6380.             if( pPed && SCRIPT_VERIFY(!pPed->IsNetworkClone(), "SET_COVER_TARGET - Can't call this command on a network clone!"))
  6381.             {
  6382.                 CAITarget aiTarget;
  6383.                 if (GetAiTarget(aiTarget, iOtherPedIndex, iTargetVehicleIndex, vscTargetCoords))
  6384.                 {
  6385.                     CTaskCover* pCoverTask = static_cast<CTaskCover*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_COVER));
  6386.                     if( pCoverTask )
  6387.                     {
  6388.                         CWeaponTarget& weaponTarget = pCoverTask->GetWeaponTarget();
  6389.                         const CEntity* pEntity = aiTarget.GetEntity();
  6390.                         if( pEntity )
  6391.                         {
  6392.                             Vector3 vOffset(Vector3::ZeroType);
  6393.                             if (aiTarget.GetPositionOffset(vOffset))
  6394.                             {
  6395.                                 weaponTarget.SetEntityAndOffset(pEntity, vOffset);
  6396.                             }
  6397.                             else
  6398.                             {
  6399.                                 weaponTarget.SetEntity(pEntity);
  6400.                             }
  6401.                         }
  6402.                         else
  6403.                         {
  6404.                             Vector3 vPosition(Vector3::ZeroType);
  6405.                             if (aiTarget.GetPosition(vPosition))
  6406.                             {
  6407.                                 weaponTarget.SetPosition(vPosition);
  6408.                             }
  6409.                         }
  6410.                     }
  6411.                 }
  6412.             }
  6413.         }
  6414.     }
  6415.  
  6416.     // Exit cover
  6417.     void CommandTaskExitCover( int iPedIndex, int iExitType, const scrVector & vscTargetCoords )
  6418.     {
  6419.         s32 iFlags = 0;
  6420.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>( iPedIndex, 0 );
  6421.         if (pPed)
  6422.         {
  6423.             // Early out if called on network clone or ped doesn't have a cover point
  6424.             if (!SCRIPT_VERIFY(!pPed->IsNetworkClone(), "SCRIPT_TASK_EXIT_COVER - Cannot call on network clone"))
  6425.             {
  6426.                 return;
  6427.             }
  6428.                
  6429.             if (!SCRIPT_VERIFY(pPed->GetCoverPoint(), "SCRIPT_TASK_EXIT_COVER - Called on a ped without a cover point"))
  6430.             {
  6431.                 return;
  6432.             }
  6433.  
  6434.             if (pPed->GetPedResetFlag(CPED_RESET_FLAG_InCoverFacingLeft))
  6435.             {
  6436.                 iFlags |= CTaskCover::CF_FacingLeft;
  6437.             }
  6438.         }
  6439.  
  6440.         CAITarget target;
  6441.  
  6442.         if (iExitType == CTaskCover::FE_Aim)
  6443.         {
  6444.             target.SetPosition(vscTargetCoords);
  6445.         }
  6446.  
  6447.         // Maybe given as part of a sequence, can't detect if ped will be in cover now if this is the case
  6448.         CScriptPeds::GivePedScriptedTask(iPedIndex, rage_new CTaskCover(target, iFlags, (CTaskCover::eForcedExit) iExitType), SCRIPT_TASK_EXIT_COVER, "SCRIPT_TASK_EXIT_COVER");
  6449.     }
  6450.  
  6451.     // Seek cover from the given position
  6452.     void CommandTaskPutPedDirectlyIntoMelee( int iPedIndex, int iTargetIndex, float fBlendInDuration, float fTimeInMelee, float fStrafePhaseSync, const int iAiCombatFlags )
  6453.     {
  6454.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex);
  6455.         if( pPed )
  6456.         {
  6457.             // Force the default unarmed weapon
  6458.             CPedWeaponManager* pWeaponManager = pPed->GetWeaponManager();
  6459.             if( pWeaponManager )
  6460.             {
  6461.                 const CWeaponInfo* pWeaponInfo = pWeaponManager->GetEquippedWeaponInfo();
  6462.                 if( pWeaponInfo && !pWeaponInfo->GetIsMelee() )
  6463.                     pWeaponManager->EquipWeapon( pPed->GetDefaultUnarmedWeaponHash(), -1, true );
  6464.             }
  6465.  
  6466.             CTaskMotionPed* pCurrentMotionTask = static_cast<CTaskMotionPed*>(pPed->GetPedIntelligence()->GetTaskManager()->FindTaskByTypeActive(PED_TASK_TREE_MOTION, CTaskTypes::TASK_MOTION_PED));
  6467.             if( pCurrentMotionTask )
  6468.             {
  6469.                 pCurrentMotionTask->SetTaskFlag( CTaskMotionPed::PMF_SkipStrafeIntroAnim );
  6470.                 pCurrentMotionTask->SetInstantStrafePhaseSync( fStrafePhaseSync );
  6471.                 pCurrentMotionTask->SetStrafeDurationOverride( fBlendInDuration );
  6472.             }
  6473.  
  6474.             CPed* pTargetPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iTargetIndex);
  6475.  
  6476.             aiTask* pCombatTask = NULL;
  6477.             if( pPed->IsAPlayerPed() )
  6478.             {
  6479.                 u32 uMeleeFlags = CTaskMelee::MF_ShouldBeInMeleeMode | CTaskMelee::MF_AllowStrafeMode;
  6480.  
  6481.                 // Would the invoker like to keep the player in strafe?
  6482.                 // NOTE: they also need to set CPED_RESET_FLAG_ForcePedToStrafe
  6483.                 if( fTimeInMelee < 0.0f )
  6484.                     uMeleeFlags |= CTaskMelee::MF_ForceStrafe;
  6485.  
  6486.                 pCombatTask = rage_new CTaskMelee( NULL, pTargetPed, uMeleeFlags, CSimpleImpulseTest::ImpulseNone, (s32)( fTimeInMelee * 1000.0f ) );
  6487.             }
  6488.             else
  6489.             {
  6490.                 CTaskThreatResponse* pTask = rage_new CTaskThreatResponse( pTargetPed );
  6491.                 pTask->SetThreatResponseOverride( CTaskThreatResponse::TR_Fight );
  6492.                 pTask->SetConfigFlagsForCombat( CTaskCombat::ComF_DisableAimIntro | CTaskCombat::ComF_MeleeAnimPhaseSync | iAiCombatFlags );
  6493.                 pTask->SetConfigFlags( CTaskThreatResponse::CF_CanFightArmedPedsWhenNotArmed );
  6494.                 pCombatTask = pTask;
  6495.             }
  6496.            
  6497.             CScriptPeds::GivePedScriptedTask( iPedIndex, pCombatTask, SCRIPT_TASK_PUT_PED_DIRECTLY_INTO_MELEE, "SCRIPT_TASK_PUT_PED_DIRECTLY_INTO_MELEE" );
  6498.         }  
  6499.     }
  6500.  
  6501.  
  6502.     void CommandSetDriveTaskCruiseSpeed(int iPedIndex, float CruiseSpeed )
  6503.     {
  6504.        CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex, CTheScripts::GUID_ASSERT_FLAGS_NO_DEAD_CHECK & CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  6505.    
  6506.         if(pPed)
  6507.         {
  6508.             if(SCRIPT_VERIFY(pPed->GetMyVehicle() && pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle ), "SET_DRIVE_TASK_CRUISE_SPEED - Ped is not in car"))
  6509.             {
  6510.                 if(SCRIPT_VERIFY(pPed->GetMyVehicle()->GetDriver() == pPed, "SET_DRIVE_TASK_CRUISE_SPEED - Ped is not driver of car"))
  6511.                 {
  6512.                     if(NetworkUtils::IsNetworkCloneOrMigrating(pPed))
  6513.                     {
  6514.                         CScriptEntityStateChangeEvent::CSettingOfDriveTaskCruiseSpeed parameters(CruiseSpeed);
  6515.                         CScriptEntityStateChangeEvent::Trigger(pPed->GetNetworkObject(), parameters);                  
  6516.                     }
  6517.                     else
  6518.                     {
  6519.                         CTaskVehicleMissionBase *pCarTask = pPed->GetMyVehicle()->GetIntelligence()->GetActiveTask();
  6520.                         if(pCarTask)
  6521.                         {
  6522.                             pCarTask->SetCruiseSpeed(CruiseSpeed);
  6523.                         }                  
  6524.                     }
  6525.                 }
  6526.             }
  6527.         }
  6528.     }
  6529.  
  6530.     void CommandSetDriveTaskMaxCruiseSpeed(int iPedIndex, float MaxCruiseSpeed )
  6531.     {
  6532.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex);
  6533.  
  6534.         if(pPed)
  6535.         {
  6536.             if(SCRIPT_VERIFY(pPed->GetMyVehicle() && pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle ), "SET_DRIVE_TASK_MAX_CRUISE_SPEED - Ped is not in car"))
  6537.             {
  6538.                 if(SCRIPT_VERIFY(pPed->GetMyVehicle()->GetDriver() == pPed, "SET_DRIVE_TASK_MAX_CRUISE_SPEED - Ped is not driver of car"))
  6539.                 {
  6540.                     CTaskVehicleMissionBase *pCarTask = pPed->GetMyVehicle()->GetIntelligence()->GetActiveTask();
  6541.                     if(pCarTask)
  6542.                         pCarTask->SetMaxCruiseSpeed((u8) MaxCruiseSpeed);
  6543.                 }
  6544.             }
  6545.         }
  6546.     }
  6547.  
  6548.     void CommandSetDriveTaskDrivingStyle(int iPedIndex, int iDrivingFlags)
  6549.     {
  6550.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex);
  6551.  
  6552.         if(pPed)
  6553.         {
  6554.             if(SCRIPT_VERIFY(pPed->GetMyVehicle() && pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle ), "SET_DRIVE_TASK_DRIVING_STYLE - Ped is not in car"))
  6555.             {
  6556.                 if(SCRIPT_VERIFY(pPed->GetMyVehicle()->GetDriver() == pPed, "SET_DRIVE_TASK_DRIVING_STYLE - Ped is not driver of car"))
  6557.                 {
  6558.                     CTaskVehicleMissionBase *pCarTask = pPed->GetMyVehicle()->GetIntelligence()->GetActiveTask();
  6559.                     if(pCarTask)
  6560.                         pCarTask->SetDrivingFlags(iDrivingFlags);
  6561.                 }
  6562.             }
  6563.         }
  6564.     }
  6565.  
  6566.     void CommandSetPursueTaskIdealDistance(int iPedIndex, float fIdealDistance)
  6567.     {
  6568.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex);
  6569.  
  6570.         if(pPed)
  6571.         {
  6572.             if(SCRIPT_VERIFY(pPed->GetMyVehicle() && pPed->GetPedConfigFlag( CPED_CONFIG_FLAG_InVehicle ), "SET_PURSUE_TASK_IDEAL_DISTANCE - Ped is not in car"))
  6573.             {
  6574.                 if(SCRIPT_VERIFY(pPed->GetMyVehicle()->GetDriver() == pPed, "SET_PURSUE_TASK_IDEAL_DISTANCE - Ped is not driver of car"))
  6575.                 {
  6576.                     CTaskVehiclePursue* pPursueTask = static_cast<CTaskVehiclePursue*>(pPed->GetMyVehicle()->GetIntelligence()->GetTaskManager()->FindTaskByTypeActive(VEHICLE_TASK_TREE_PRIMARY, CTaskTypes::TASK_VEHICLE_PURSUE));
  6577.                     if(SCRIPT_VERIFY(pPursueTask, "SET_PURSUE_TASK_IDEAL_DISTANCE - Vehicle is not running TASK_VEHICLE_PURSUE"))
  6578.                     {
  6579.                         pPursueTask->SetIdealDistance(fIdealDistance);
  6580.                     }
  6581.                 }
  6582.             }
  6583.         }
  6584.     }
  6585.  
  6586.     // Add a cover blocking area
  6587.     void CommandAddCoverBlockingArea( const scrVector & vStart, const scrVector & vEnd, bool bBlockObjects, bool bBlockVehicles, bool bBlockMap, bool bBlockPlayer )
  6588.     {
  6589.         Vector3 vStartV3 = vStart;
  6590.         Vector3 vEndV3 = vEnd;
  6591.         CCover::AddCoverBlockingArea( vStartV3, vEndV3, bBlockObjects, bBlockVehicles, bBlockMap, bBlockPlayer );
  6592.     }
  6593.  
  6594.     // Add a scripted cover point
  6595.     void CommandFlushCoverBlockingAreas()
  6596.     {
  6597.         CCover::FlushCoverBlockingAreas();
  6598.     }
  6599.  
  6600.     // Remove any scripted cover points that contain the specified position.
  6601.     void CommandRemoveCoverBlockingAreasAtPosition(const scrVector &vPosition)
  6602.     {
  6603.         Vector3 vPositionV3 = vPosition;
  6604.         CCover::RemoveCoverBlockingAreasAtPosition(vPositionV3);
  6605.     }
  6606.  
  6607.     // Remove any scripter cover points that have the specified params.
  6608.     void CommandRemoveSpecificCoverBlockingAreas(const scrVector & vStart, const scrVector & vEnd, bool bBlockObjects, bool bBlockVehicles, bool bBlockMap, bool bBlockPlayer)
  6609.     {
  6610.         Vector3 vStartV3 = vStart;
  6611.         Vector3 vEndV3 = vEnd;
  6612.         CCover::RemoveSpecificCoverBlockingArea( vStartV3, vEndV3, bBlockObjects, bBlockVehicles, bBlockMap, bBlockPlayer );
  6613.     }
  6614.  
  6615.     void CommandTaskStartScenarioInPlace( int PedIndex, const char* szScenario, int iTimeToLeave, bool playIntro)
  6616.     {
  6617.     s32 type = CScenarioManager::GetScenarioTypeFromName(szScenario);
  6618.        
  6619.         if (scriptVerifyf(type!=Scenario_Invalid, "TASK_START_SCENARIO_IN_PLACE: Unknown scenario type (%s)", szScenario ))
  6620.         {
  6621.             int flags = CTaskUseScenario::SF_StartInCurrentPosition;
  6622.             if (!playIntro)
  6623.             {
  6624.                 flags |= CTaskUseScenario::SF_SkipEnterClip;
  6625.             }
  6626.             if (iTimeToLeave < 0)
  6627.             {
  6628.                 flags |= CTaskUseScenario::SF_IdleForever;
  6629.             }
  6630.             CTaskUseScenario* pTask = rage_new CTaskUseScenario(type, flags );
  6631.  
  6632. #if __ASSERT
  6633.             //If assigning a task with a prop, make sure the ped has an inventory
  6634.             if (PedIndex != NULL_IN_SCRIPTING_LANGUAGE)
  6635.             {
  6636.                 CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  6637.                 scriptAssertf(!pTask->GetScenarioInfo().HasProp() || pPed->GetInventory(), "%s: Attempting to assign a ped a scenario (%s) that has a prop, but the ped(%s) has no inventory", CTheScripts::GetCurrentScriptNameAndProgramCounter(), pTask->GetScenarioInfo().GetName(), pPed->GetModelName());
  6638.             }
  6639. #endif
  6640.  
  6641.             if( iTimeToLeave > 0 )
  6642.             {
  6643.                 float fTimeToLeave = (float) iTimeToLeave;
  6644.                 pTask->SetTimeToLeave(fTimeToLeave/1000.0f);
  6645.             }
  6646.             pTask->CreateProp();
  6647.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_START_SCENARIO_IN_PLACE, "TASK_START_SCENARIO_IN_PLACE");
  6648.         }
  6649.     }
  6650.  
  6651.     void CommandTaskStartScenarioAtPosition( int iPedIndex, const char* szScenario, const scrVector & svScenarioPlace, float fHeading, int iTimeToLeave, bool playIntro, bool bWarp)
  6652.     {
  6653.         Vector3 vScenarioPoint = svScenarioPlace;
  6654.         s32 type = CScenarioManager::GetScenarioTypeFromName(szScenario);
  6655.         if (scriptVerifyf(type!=Scenario_Invalid, "TASK_START_SCENARIO_AT_POSITION: Unknown scenario type (%s)", szScenario ))
  6656.         {
  6657.             int flags = 0;
  6658.             if (bWarp)
  6659.             {
  6660.                 flags |= CTaskUseScenario::SF_Warp;
  6661.             }
  6662.             if (!playIntro)
  6663.             {
  6664.                 flags |= CTaskUseScenario::SF_SkipEnterClip;
  6665.             }
  6666.             if (iTimeToLeave < 0)
  6667.             {
  6668.                 flags |= CTaskUseScenario::SF_IdleForever;
  6669.             }
  6670.             CTaskUseScenario* pTask = rage_new CTaskUseScenario(type, vScenarioPoint, fwAngle::LimitRadianAngle( (DtoR * fHeading) ), flags );
  6671.             if( iTimeToLeave > 0 )
  6672.             {
  6673.                 float fTimeToLeave = (float) iTimeToLeave;
  6674.                 pTask->SetTimeToLeave(fTimeToLeave/1000.0f);
  6675.             }
  6676.             pTask->CreateProp();
  6677.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_START_SCENARIO_AT_POSITION, "TASK_START_SCENARIO_AT_POSITION");
  6678.         }
  6679.     }
  6680.  
  6681.     void CommandTaskStartVehicleScenario( int iPedIndex, int iVehicleIndex, const char* szScenario, bool bWarp )
  6682.     {
  6683.         if( iPedIndex != NULL_IN_SCRIPTING_LANGUAGE  && iVehicleIndex != NULL_IN_SCRIPTING_LANGUAGE)
  6684.         {
  6685.             CVehicle* pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleIndex);
  6686.             if(!pVehicle)
  6687.                 return;
  6688.  
  6689.             s32 type = CScenarioManager::GetScenarioTypeFromName(szScenario);
  6690.             if (scriptVerifyf(type!=Scenario_Invalid, "TASK_START_VEHICLE_SCENARIO: Unknown scenario type (%s)", szScenario ))
  6691.             {
  6692.                 scriptAssertf(SCENARIOINFOMGR.GetScenarioInfoByIndex(type) && SCENARIOINFOMGR.GetScenarioInfoByIndex(type)->GetIsClass<CScenarioParkedVehicleInfo>(), "Invalid Vehicle Scenario");
  6693.                 CTaskParkedVehicleScenario* pTask = rage_new CTaskParkedVehicleScenario(type, pVehicle, bWarp);
  6694.                 CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_START_VEHICLE_SCENARIO, "TASK_START_VEHICLE_SCENARIO");
  6695.             }
  6696.         }
  6697.     }
  6698.  
  6699.     bool CommandDoesScenarioExistInArea( const scrVector & svScenarioPlace, float fMaxRange, bool bMustBeFree )
  6700.     {
  6701.         Vector3 vScenarioPoint = svScenarioPlace;
  6702.         CPedPopulation::GetScenarioPointInAreaArgs args(RCC_VEC3V(vScenarioPoint), fMaxRange);
  6703.         args.m_MustBeFree = bMustBeFree;
  6704.         args.m_CheckPopulation = bMustBeFree;
  6705.     CScenarioPoint* pScenarioPoint = NULL;
  6706.  
  6707.         if(!CPedPopulation::GetScenarioPointInArea(args, &pScenarioPoint))
  6708.         {
  6709.             return false;
  6710.         }
  6711.         return true;
  6712.     }
  6713.  
  6714.     bool CommandDoesScenarioOfTypeExistInArea ( const scrVector & svScenarioPlace, const char* szScenario, float fMaxRange, bool bMustBeFree )
  6715.     {
  6716.         Vector3 vScenarioPoint = svScenarioPlace;
  6717.         CPedPopulation::GetScenarioPointInAreaArgs args(RCC_VEC3V(vScenarioPoint), fMaxRange);
  6718.         args.m_MustBeFree = bMustBeFree;
  6719.         args.m_CheckPopulation = bMustBeFree;
  6720.         args.m_NumTypes = 1;
  6721.         s32 type = CScenarioManager::GetScenarioTypeFromName(szScenario);
  6722.         args.m_Types = &type;
  6723.  
  6724.         scriptAssertf(type!=Scenario_Invalid, "DOES_SCENARIO_OF_TYPE_EXIST_IN_AREA: Unknown scenario type (%s)", szScenario );
  6725.  
  6726.         CScenarioPoint* pScenarioPoint = NULL;
  6727.         if(!CPedPopulation::GetScenarioPointInArea(args, &pScenarioPoint))
  6728.         {
  6729.             return false;
  6730.         }
  6731.         return true;
  6732.     }
  6733.  
  6734.     bool CommandIsScenarioOccupied(const scrVector & svScenarioPlace, float fMaxRange, bool onlyUsersActuallyAtScenario)
  6735.     {
  6736.         Vector3 vScenarioPoint = svScenarioPlace;
  6737.         CScenarioPoint* pScenarioPoint = NULL;
  6738.  
  6739.         CPedPopulation::GetScenarioPointInAreaArgs args(RCC_VEC3V(vScenarioPoint), fMaxRange);
  6740.         args.m_MustBeFree = false;
  6741.         args.m_CheckPopulation = false;
  6742.  
  6743.         if(!CPedPopulation::GetScenarioPointInArea(args, &pScenarioPoint))
  6744.         {
  6745.             return false;
  6746.         }
  6747.  
  6748.         // If onlyUsersActuallyAtScenario is set, we need to loop over the peds later.
  6749.         bool needToCheckPeds = onlyUsersActuallyAtScenario;
  6750.  
  6751.         // Note: CPedPopulation::IsEffectInUse() is a bit unfortunate in how it always
  6752.         // returns true if the scenario is attached to anything but a CObject. This is
  6753.         // different than how the check is done in GetScenarioPointInArea()
  6754.         // and GeneratePedsFromScenarioPointList(), where a scenario attached to something
  6755.         // else is considered not in use. Thus, we check the type here.
  6756.         if(!pScenarioPoint->GetEntity() || pScenarioPoint->GetEntity()->GetIsTypeObject())
  6757.         {
  6758.             if(!CPedPopulation::IsEffectInUse(*pScenarioPoint))
  6759.             {
  6760.                 return false;
  6761.             }
  6762.         }
  6763.         else if(pScenarioPoint->GetEntity() && !pScenarioPoint->GetEntity()->GetIsTypeObject())
  6764.         {
  6765.             // Since we don't keep track of use for non-CObject entities,
  6766.             // we need to check the ped tasks.
  6767.             needToCheckPeds = true;
  6768.         }
  6769.  
  6770.         if(needToCheckPeds)
  6771.         {
  6772.             int scenarioTypeFoundInLocation = pScenarioPoint->GetScenarioTypeVirtualOrReal();
  6773.  
  6774.             bool isVirtual = SCENARIOINFOMGR.IsVirtualIndex(scenarioTypeFoundInLocation);
  6775.  
  6776.             bool foundNearby = false;
  6777.  
  6778.             CPed::Pool* pool = CPed::GetPool();
  6779.             const int maxPeds = pool->GetSize();
  6780.             for(int i = 0; i < maxPeds; i++)
  6781.             {
  6782.                 CPed* pPed = pool->GetSlot(i);
  6783.                 if(!pPed)
  6784.                 {
  6785.                     continue;
  6786.                 }
  6787.  
  6788.                 // Note: for virtual scenario types, we won't ever match GetScenarioType(). We could loop over
  6789.                 // all the real types, but the code below looks like it may work well enough without that.
  6790.                 if(!isVirtual && scenarioTypeFoundInLocation != CPed::GetScenarioType(*pPed))
  6791.                 {
  6792.                     continue;
  6793.                 }
  6794.  
  6795.                 const CTaskUseScenario* pTaskUseScenario = static_cast<const CTaskUseScenario*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_USE_SCENARIO));
  6796.                 if(pTaskUseScenario)
  6797.                 {
  6798.                     if (pTaskUseScenario->GetScenarioPoint() != pScenarioPoint)
  6799.                     {
  6800.                         continue;
  6801.                     }
  6802.                    
  6803.                     const int taskState = pTaskUseScenario->GetState();
  6804.                     if(onlyUsersActuallyAtScenario && (taskState == CTaskUseScenario::State_Start || taskState == CTaskUseScenario::State_GoToStartPosition))
  6805.                     {
  6806.                         // In this case, we certainly appear to have found the ped that's considered the user
  6807.                         // of the scenario point, but it hasn't actually arrived yet. In that case, we don't consider
  6808.                         // the scenario occupied, so we return false.
  6809.                         return false;
  6810.                     }
  6811.                     else
  6812.                     {
  6813.                         // Found the true user of this scenario.
  6814.                         return true;
  6815.                     }
  6816.                 }          
  6817.                 else if(!foundNearby && !isVirtual)
  6818.                 {
  6819.                     // Somehow, according to CPed::GetScenarioType(), we are using a scenario of the type we are looking for,
  6820.                     // but we can't find the CTaskUseScenario. It might be possible for this to happen for some scenario that's
  6821.                     // using a different task, or perhaps in some networking situation, so we try to fall back on a distance
  6822.                     // check.
  6823.  
  6824.                     static float s_DistThresholdSq = square(1.0f);  // MAGIC!
  6825.  
  6826.                     const Vec3V scenarioWorldPosV = pScenarioPoint->GetPosition();
  6827.                     const Vec3V pedPosV = pPed->GetTransform().GetPosition();
  6828.                     const ScalarV distThresholdSqV = LoadScalar32IntoScalarV(s_DistThresholdSq);
  6829.                     const ScalarV distSqV = DistSquared(scenarioWorldPosV, pedPosV);
  6830.                     if(IsLessThanAll(distSqV, distThresholdSqV))
  6831.                     {
  6832.                         // This ped is close, set this variable. Note that we don't return true right away here,
  6833.                         // because we might still find a ped that's actually using this scenario through a CTaskUseScenario,
  6834.                         // in which case returning false is still an option.
  6835.                         foundNearby = true;
  6836.                     }
  6837.                 }
  6838.             }
  6839.  
  6840.             if(foundNearby)
  6841.             {
  6842.                 // We didn't find anybody running a CTaskUseScenario on this scenario, but we found
  6843.                 // somebody using a scenario of the right type, close enough to the point.
  6844.                 return true;
  6845.             }
  6846.             else
  6847.             {
  6848.                 // Nobody nearby is using a scenario of this type.
  6849.                 return false;
  6850.             }
  6851.         }
  6852.         else
  6853.         {
  6854.             return true;
  6855.         }
  6856.     }
  6857.  
  6858.     bool CommandPedHasUseScenarioTask(int iPedIndex)
  6859.     {
  6860.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex);
  6861.         if (SCRIPT_VERIFY(pPed, "PedIndex was invalid for PED_HAS_USE_SCENARIO_TASK!"))
  6862.         {
  6863.             CTaskUseScenario* pTaskScenario = static_cast<CTaskUseScenario*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_USE_SCENARIO));
  6864.             if (pTaskScenario)
  6865.             {
  6866.                 return true;
  6867.             }
  6868.         }
  6869.  
  6870.         return false;
  6871.     }
  6872.  
  6873.     void CommandOverrideTaskedScenarioBaseAnim(int iPedIndex, const char* clipSet, const char* clip)
  6874.     {
  6875.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex);
  6876.         if (SCRIPT_VERIFY(pPed, "PedIndex was invalid for OVERRIDE_TASKED_SCENARIO_BASE_ANIM!"))
  6877.         {
  6878.             CTaskUseScenario* pTaskScenario = static_cast<CTaskUseScenario*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_USE_SCENARIO));
  6879.             if (pTaskScenario)
  6880.             {
  6881.                 fwMvClipSetId setId(clipSet);
  6882.                 fwMvClipId clipId(clip);
  6883.                 pTaskScenario->OverrideBaseClip(setId, clipId);
  6884.             }
  6885.  
  6886.             // if we are already running the ambient clips task then we should set the override on there as well.
  6887.             CTaskAmbientClips* pTaskAmbientClips = static_cast<CTaskAmbientClips*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_AMBIENT_CLIPS));
  6888.             if (pTaskAmbientClips)
  6889.             {
  6890.                 fwMvClipSetId setId(clipSet);
  6891.                 fwMvClipId clipId(clip);
  6892.                 pTaskAmbientClips->OverrideBaseClip(setId, clipId);
  6893.             }
  6894.         }
  6895.     }
  6896.  
  6897.     void CommandPlayAnimOnRunnningScenario(int iPedIndex, const char* clipSet, const char* clip)
  6898.     {
  6899.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex);
  6900.         if (SCRIPT_VERIFY(pPed, "PedIndex was invalid for TASK_SCENARIO_PLAY_AS_IDLE!"))
  6901.         {
  6902.             CTaskAmbientClips* pTaskAmbientClips = static_cast<CTaskAmbientClips*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_AMBIENT_CLIPS));
  6903.             if (SCRIPT_VERIFY(pTaskAmbientClips, "Ped is currently not running the right task to run TASK_SCENARIO_PLAY_AS_IDLE"))
  6904.             {
  6905.                 fwMvClipSetId setId(clipSet);
  6906.                 fwMvClipId clipId(clip);
  6907.                 if (SCRIPT_VERIFYF(fwClipSetManager::GetClipSet(setId) != NULL, "ClipSet %s did not exist.  Are you sure it is in clip_sets.xml?", clipSet))
  6908.                 {
  6909.                     pTaskAmbientClips->PlayAnimAsIdle(setId, clipId);
  6910.                 }
  6911.             }
  6912.         }
  6913.     }
  6914.  
  6915.     int GetScenarioGroupHelper(const char* groupName, const char* ASSERT_ONLY(cmdName), bool ASSERT_ONLY(mayNotExist))
  6916.     {
  6917.         int groupId = CScenarioPointManager::kNoGroup;
  6918.         if(groupName && groupName[0])
  6919.         {
  6920.             groupId = SCENARIOPOINTMGR.FindGroupByNameHash(atHashString(groupName), true);
  6921.         }
  6922.         scriptAssertf(groupId != CScenarioPointManager::kNoGroup || mayNotExist, "%s used with group name %s, which doesn't exist.", cmdName, groupName ? groupName : "<NULL>");
  6923.         return groupId;
  6924.     }
  6925.  
  6926.     bool CommandDoesScenarioGroupExist(const char* groupName)
  6927.     {
  6928.         return GetScenarioGroupHelper(groupName, "DOES_SCENARIO_GROUP_EXIST", true) != CScenarioPointManager::kNoGroup;
  6929.     }
  6930.  
  6931.     bool CommandIsScenarioGroupEnabled(const char* groupName)
  6932.     {
  6933.         int groupId = GetScenarioGroupHelper(groupName, "IS_SCENARIO_GROUP_ENABLED", false);
  6934.         if(groupId != CScenarioPointManager::kNoGroup)
  6935.         {
  6936.             const int groupIndex = groupId - 1;
  6937.             return SCENARIOPOINTMGR.IsGroupEnabled(groupIndex);
  6938.         }
  6939.         return false;
  6940.     }
  6941.  
  6942.     void CommandSetScenarioGroupEnabled(const char* groupName, bool enabled)
  6943.     {
  6944.         int groupId = GetScenarioGroupHelper(groupName, "IS_SCENARIO_GROUP_ENABLED", false);
  6945.         if(groupId != CScenarioPointManager::kNoGroup)
  6946.         {
  6947.             const int groupIndex = groupId - 1;
  6948.             SCENARIOPOINTMGR.SetGroupEnabled(groupIndex, enabled);
  6949.         }
  6950.     }
  6951.  
  6952.     void CommandResetScenarioGroupsEnabled()
  6953.     {
  6954.         SCENARIOPOINTMGR.ResetGroupsEnabledToDefaults();
  6955.     }
  6956.  
  6957.     void CommandSetExclusiveScenarioGroup(const char* groupName)
  6958.     {
  6959.         int groupId = GetScenarioGroupHelper(groupName, "SET_EXCLUSIVE_SCENARIO_GROUP", false);
  6960.         if(groupId != CScenarioPointManager::kNoGroup)
  6961.         {
  6962.             const int groupIndex = groupId - 1;
  6963.             SCENARIOPOINTMGR.SetExclusivelyEnabledScenarioGroupIndex(groupIndex);
  6964.         }
  6965.     }
  6966.  
  6967.     void CommandResetExclusiveScenarioGroup()
  6968.     {
  6969.         SCENARIOPOINTMGR.SetExclusivelyEnabledScenarioGroupIndex(-1);
  6970.     }
  6971.  
  6972.     int GetScenarioTypeHelper(const char* typeName, const char* ASSERT_ONLY(cmdName))
  6973.     {
  6974.         int ret = -1;
  6975.         if(typeName && typeName[0])
  6976.         {
  6977.             const u32 hash = atStringHash(typeName);
  6978.  
  6979.             // Note: this is currently an O(n) operation.
  6980.             ret = SCENARIOINFOMGR.GetScenarioIndex(hash, false);
  6981.         }
  6982.  
  6983.         scriptAssertf(ret >= 0, "%s used with type name %s, which doesn't exist.", cmdName, typeName ? typeName : "<NULL>");
  6984.  
  6985.         return ret;
  6986.     }
  6987.  
  6988.     void CommandForceScenarioGroupPriority(const char* groupName, bool bIsHighPriority)
  6989.     {
  6990.         int groupId = GetScenarioGroupHelper(groupName, "FORCE_SCENARIO_GROUP_PRIORITY", true);
  6991.         if(groupId != CScenarioPointManager::kNoGroup)
  6992.         {
  6993.             CScenarioPointPriorityManager::GetInstance().ForceScenarioPointGroupPriority((u8)groupId, bIsHighPriority);
  6994.         }
  6995.     }
  6996.  
  6997.     void CommandResetScenarioGroupsPriority()
  6998.     {
  6999.         CScenarioPointPriorityManager::GetInstance().RestoreGroupsToOriginalPriorities();
  7000.     }
  7001.  
  7002.     bool CommandIsScenarioTypeEnabled(const char* typeName)
  7003.     {
  7004.         int typeIndex = GetScenarioTypeHelper(typeName, "IS_SCENARIO_TYPE_ENABLED");
  7005.         if(typeIndex >= 0)
  7006.         {
  7007.             return SCENARIOINFOMGR.IsScenarioTypeEnabled(typeIndex);
  7008.         }
  7009.         return true;
  7010.     }
  7011.  
  7012.     void CommandSetScenarioTypeEnabled(const char* typeName, bool enabled)
  7013.     {
  7014.         int typeIndex = GetScenarioTypeHelper(typeName, "SET_SCENARIO_TYPE_ENABLED");
  7015.         if(typeIndex >= 0)
  7016.         {
  7017.             SCENARIOINFOMGR.SetScenarioTypeEnabled(typeIndex, enabled);
  7018.         }
  7019.     }
  7020.  
  7021.     void CommandResetScenarioTypesEnabled()
  7022.     {
  7023.         SCENARIOINFOMGR.ResetScenarioTypesEnabledToDefaults();
  7024.     }
  7025.  
  7026.     void CommandSuppressNormalScenarioExitsNextFrame()
  7027.     {
  7028.         CScenarioManager::SetScenarioExitsSuppressed(true);
  7029.     }
  7030.  
  7031.     void CommandSuppressScenarioAttractionNextFrame()
  7032.     {
  7033.         CScenarioManager::SetScenarioAttractionSuppressed(true);
  7034.     }
  7035.  
  7036.     void CommandSuppressBreakoutScenarioExitsNextFrame()
  7037.     {
  7038.         CScenarioManager::SetScenarioBreakoutExitsSuppressed(true);
  7039.     }
  7040.  
  7041.  
  7042.  
  7043.     CTask* CommonUseNearestScenarioToPos( CPed* pPed, const scrVector & svScenarioPlace, float fMaxRange, bool bWarp, bool ASSERT_ONLY(bCalledFromTask), int iTimeToLeave, bool bMustBeTrainScenario )
  7044.     {
  7045.         Vector3 vScenarioPoint = svScenarioPlace;
  7046.         CScenarioPoint* pScenarioPoint = NULL;
  7047.         CPedPopulation::GetScenarioPointInAreaArgs args(RCC_VEC3V(vScenarioPoint), fMaxRange);
  7048.         args.m_MustBeFree = true;
  7049.         args.m_PedOrDummyToUsePoint = pPed;
  7050.         args.m_Random = false;
  7051.         args.m_MustBeAttachedToTrain = bMustBeTrainScenario;
  7052.         bool bCheckPeds = false;
  7053.         if( !CPedPopulation::GetScenarioPointInArea(    args, &pScenarioPoint ) )
  7054.         {
  7055.             // do it again and process it further...the actual use count on the scenario point isn't
  7056.             // always what we want if they are going to the point on a long chain and the player is much closer
  7057.             args.m_MustBeFree = false;
  7058.             args.m_CheckPopulation = false;
  7059.            
  7060.             if( !CPedPopulation::GetScenarioPointInArea(    args, &pScenarioPoint ) )
  7061.             {
  7062. #if __ASSERT
  7063.                 if( !bCalledFromTask )
  7064.                     scriptAssertf(0, "%s:TASK_USE_NEAREST_SCENARIO_TO_POS(_WARP) - No scenario found within range", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  7065. #endif // __ASSERT
  7066.                 return NULL;
  7067.             }
  7068.             else
  7069.             {
  7070.                 bCheckPeds = true;
  7071.             }  
  7072.         }
  7073.  
  7074.  
  7075.         if(bCheckPeds)
  7076.         {
  7077.             // Really check if the ped is actually using the scenario...
  7078.             // The CScenarioPoint.m_iUses won't get reset until the cleanup function is called in CTaskUseScenario
  7079.             // Other states here may be valid for us to start the scenario
  7080.             CPed::Pool* pool = CPed::GetPool();
  7081.             const int maxPeds = pool->GetSize();
  7082.             for(int i = 0; i < maxPeds; i++)
  7083.             {
  7084.                 CPed* pCurPed = pool->GetSlot(i);
  7085.                 if(!pCurPed || pCurPed == args.m_PedOrDummyToUsePoint || pCurPed->PopTypeIsMission())
  7086.                 {
  7087.                     continue;
  7088.                 }
  7089.  
  7090.                 CTaskUseScenario* pTaskUseScenario = static_cast<CTaskUseScenario*>(pCurPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_USE_SCENARIO));
  7091.                 if(pTaskUseScenario)
  7092.                 {
  7093.                     if (pTaskUseScenario->GetScenarioPoint() != pScenarioPoint)
  7094.                     {
  7095.                         continue;
  7096.                     }
  7097.  
  7098.                     const int taskState = pTaskUseScenario->GetState();
  7099.                     if(taskState != CTaskUseScenario::State_Start && taskState != CTaskUseScenario::State_GoToStartPosition)
  7100.                     {
  7101. #if __ASSERT
  7102.                         if( !bCalledFromTask )
  7103.                             scriptAssertf(0, "%s:TASK_USE_NEAREST_SCENARIO_TO_POS(_WARP) - No scenario found within range -- Scenario State For Another Ped Is Actively Using The Scenario", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  7104. #endif // __ASSERT             
  7105.                         return NULL;
  7106.                     }
  7107.                     else if (pCurPed->PopTypeIsRandom())
  7108.                     {
  7109.                         // Scripted peds take priority over ambient/scenario peds
  7110.                         // This will prevent undesirable conflicts at atms, vending machines, etc
  7111.                         pTaskUseScenario->MakeAbortable(aiTask::ABORT_PRIORITY_URGENT, NULL);
  7112.                     }
  7113.                 }
  7114.             }
  7115.         }
  7116.  
  7117.         s32 scenarioType = CScenarioManager::ChooseRealScenario(pScenarioPoint->GetScenarioTypeVirtualOrReal(), pPed);
  7118.  
  7119.         bool bStartInCurrentPos = !bWarp;
  7120.         float fHeading = 0.0f;
  7121.         Vector3 vPedPos;
  7122.         CTask* pScenarioTask = CScenarioManager::SetupScenarioAndTask(scenarioType, vPedPos, fHeading, *pScenarioPoint, 0, bStartInCurrentPos);
  7123.  
  7124. #if AI_DEBUG_OUTPUT_ENABLED
  7125.         CNetObjGame* pNetObjPed = (NetworkInterface::IsGameInProgress() && pPed) ? pPed->GetNetworkObject() : NULL;
  7126.         CAILogManager::GetLog().Log("CommonUseNearestScenarioToPos: [0x%p][%s], (%.2f,%.2f,%.2f), Range (%.2f), Warp (%d), ScenarioType %d, ScenarioPoint 0x%p (%.2f,%.2f,%.2f)\r\n",
  7127.             pPed, pNetObjPed ? pNetObjPed->GetLogName() : "unknown",
  7128.             svScenarioPlace.x, svScenarioPlace.y, svScenarioPlace.z, fMaxRange, bWarp,
  7129.             scenarioType, pScenarioPoint, pScenarioPoint->GetWorldPosition().GetXf(), pScenarioPoint->GetWorldPosition().GetYf(), pScenarioPoint->GetWorldPosition().GetZf());
  7130. #endif
  7131.  
  7132.         if(pScenarioTask)
  7133.         {
  7134.             if (pScenarioTask->GetTaskType() == CTaskTypes::TASK_USE_SCENARIO)
  7135.             {
  7136.                 if (iTimeToLeave < 0)
  7137.                 {
  7138.                     ((CTaskUseScenario*)pScenarioTask)->SetDontLeaveEver();
  7139.                 }
  7140.  
  7141.                 if( iTimeToLeave > 0)
  7142.                 {
  7143.                     float fTimeToLeave = (float) iTimeToLeave;
  7144.                     ((CTaskUseScenario*)pScenarioTask)->SetTimeToLeave(fTimeToLeave/1000.0f);
  7145.                 }
  7146.             }
  7147.  
  7148.             // This is probably not strictly necessary, as CTaskUseScenario should warp us into
  7149.             // place anyway. But, may still be safest, in case the script gets the position of the ped
  7150.             // before the task has run, or if we're using a ragdoll.
  7151.             if(bWarp && pPed)
  7152.             {
  7153.                 // If we are using ragdoll, the calls to SetPosition() and other functions wouldn't work
  7154.                 // well. FlushImmediately() should take care of this by ending tasks and doing other things
  7155.                 // to restore the ped to a normal state. See B* 333114: "Ignorable Assert - Error: false:
  7156.                 // CPed::UpdatePhysicsFromEntity called while ragdoll active - fired after starting private dance".
  7157.                 // Note: we could potentially do this in the non-ragdoll case too, but to start out with, that
  7158.                 // seemed a bit risky.
  7159.                 if(pPed->GetUsingRagdoll())
  7160.                 {
  7161.                     pPed->GetPedIntelligence()->FlushImmediately(true);
  7162.                 }
  7163.  
  7164.                 pPed->SetPosition(vPedPos);
  7165.                 pPed->SetHeading(fHeading);
  7166.                 pPed->SetDesiredHeading(fHeading);
  7167.             }
  7168.         }
  7169.         else
  7170.         {
  7171. #if __ASSERT
  7172.             if( !bCalledFromTask )
  7173.                 scriptAssertf(0, "%s:TASK_USE_NEAREST_SCENARIO_TO_POS(_WARP) - scenario type found of invalid type", CTheScripts::GetCurrentScriptNameAndProgramCounter());
  7174. #endif // __ASSERT             
  7175.         }
  7176.  
  7177.         // We could probably do this if we wanted to wrap the scenario task in a CTaskUnalerted. The main
  7178.         // reason for that would probably be if we needed to support chaining when done using the current scenario.
  7179.         //  aiTask* pControlTask = CScenarioManager::SetupScenarioControlTask(*pScenarioInfo, pScenarioTask, *pPropScenarioPoint);
  7180.  
  7181.         return pScenarioTask;
  7182.     }
  7183.  
  7184.     CTask* CommonUseNearestScenarioChainToPos(CPed* pPed, const scrVector & svScenarioPlace, float fMaxRange, bool bWarp, bool bCalledFromTask, int iTimeToLeave )
  7185.     {
  7186.         CTask* pControlTask = NULL;
  7187.         if (SCRIPT_VERIFY(pPed, "Invalid ped in CommonUseNearestScenarioChainToPos!"))
  7188.         {
  7189.             // Construct CTaskUseScenario for the nearest scenario point.
  7190.             CTask* pScenarioTask = CommonUseNearestScenarioToPos(pPed, svScenarioPlace, fMaxRange, bWarp, bCalledFromTask, iTimeToLeave);
  7191.  
  7192.             if (SCRIPT_VERIFY(pScenarioTask, "Invalid scenario task!"))
  7193.             {
  7194.                 CScenarioPoint* pScenarioPoint = pScenarioTask->GetScenarioPoint();
  7195.                 if (SCRIPT_VERIFY(pScenarioPoint, "Generated scenario task did not have a valid scenario point!"))
  7196.                 {
  7197.                     s32 iScenarioType = CScenarioManager::ChooseRealScenario(pScenarioPoint->GetScenarioTypeVirtualOrReal(), pPed);
  7198.                     const CScenarioInfo* pScenarioInfo = CScenarioManager::GetScenarioInfo(iScenarioType);
  7199.                     if (SCRIPT_VERIFY(pScenarioInfo, "Invalid scenario info for type!"))
  7200.                     {
  7201.                         // Wrap the scenario point task in CTaskUnalerted so the ped can follow the chain.
  7202.                         pControlTask = CScenarioManager::SetupScenarioControlTask(*pPed, *pScenarioInfo, pScenarioTask, pScenarioPoint, iScenarioType);
  7203.                     }
  7204.                 }
  7205.             }
  7206.         }
  7207.         return pControlTask;
  7208.     }
  7209.  
  7210.     void CommandTaskUseNearestScenarioToPos( int iPedIndex, const scrVector & svScenarioPlace, float fMaxRange, int iTimeToLeave )
  7211.     {
  7212.         // NULL peds are valid since this task can run in a sequence
  7213.         CPed *pPed = NULL;
  7214.         if(iPedIndex != NULL_IN_SCRIPTING_LANGUAGE)
  7215.         {
  7216.             pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  7217.         }
  7218.  
  7219.         CTask* pTask = CommonUseNearestScenarioToPos(pPed, svScenarioPlace, fMaxRange, false, false, iTimeToLeave);
  7220.         if( pTask )
  7221.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_USE_NEAREST_SCENARIO_TO_POS, "TASK_USE_NEAREST_SCENARIO_TO_COORD");
  7222.     }
  7223.  
  7224.     void CommandTaskUseNearestScenarioToPosWarp( int iPedIndex, const scrVector & svScenarioPlace, float fMaxRange, int iTimeToLeave )
  7225.     {
  7226.         // NULL peds are valid since this task can run in a sequence
  7227.         CPed *pPed = NULL;
  7228.         if(iPedIndex != NULL_IN_SCRIPTING_LANGUAGE)
  7229.         {
  7230.             pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  7231.         }
  7232.  
  7233.         CTask* pTask = CommonUseNearestScenarioToPos(pPed, svScenarioPlace, fMaxRange, true, false, iTimeToLeave);
  7234.         if( pTask )
  7235.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_USE_NEAREST_SCENARIO_TO_POS, "TASK_USE_NEAREST_SCENARIO_TO_COORD_WARP");
  7236.     }
  7237.  
  7238.     void CommandTaskUseNearestTrainScenarioToPosWarp( int iPedIndex, const scrVector & svScenarioPlace, float fMaxRange )
  7239.     {
  7240.         // NULL peds are valid since this task can run in a sequence
  7241.         CPed *pPed = NULL;
  7242.         if(iPedIndex != NULL_IN_SCRIPTING_LANGUAGE)
  7243.         {
  7244.             pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  7245.         }
  7246.  
  7247.         CTask* pUseScenarioTask = CommonUseNearestScenarioToPos(pPed, svScenarioPlace, fMaxRange, true, false, 0, true);
  7248.         CTaskRideTrain* pTaskRideTrain = NULL;
  7249.  
  7250.         if (pUseScenarioTask)
  7251.         {
  7252.             const CScenarioPoint* pScenarioPoint = pUseScenarioTask->GetScenarioPoint();
  7253.  
  7254.             if (pScenarioPoint)
  7255.             {
  7256.                 //Check if the scenario is on a train.
  7257.                 CEntity* pEntity = pScenarioPoint->GetEntity();
  7258.                 if(pEntity && pEntity->GetIsTypeVehicle())
  7259.                 {
  7260.                     CVehicle* pVehicle = static_cast<CVehicle *>(pEntity);
  7261.                     if(pVehicle->InheritsFromTrain())
  7262.                     {
  7263.                         //Grab the train.
  7264.                         CTrain* pTrain = static_cast<CTrain *>(pVehicle);
  7265.  
  7266.                         //Ride the train with the scenario point.
  7267.                         pTaskRideTrain = rage_new CTaskRideTrain(pTrain, pUseScenarioTask);
  7268.                     }
  7269.                 }
  7270.             }
  7271.         }
  7272.  
  7273.         if (pTaskRideTrain)
  7274.         {
  7275.             CScriptPeds::GivePedScriptedTask(iPedIndex, pTaskRideTrain, SCRIPT_TASK_USE_NEAREST_TRAIN_SCENARIO_TO_POS, "TASK_USE_NEAREST_TRAIN_SCENARIO_TO_COORD_WARP");
  7276.         }
  7277.     }
  7278.  
  7279.     void CommandTaskUseNearestScenarioChainToPos( int iPedIndex, const scrVector & svScenarioInPlace, float fMaxRange, int iTimeToLeave )
  7280.     {
  7281.         if(SCRIPT_VERIFY(iPedIndex != NULL_IN_SCRIPTING_LANGUAGE, "Ped index was NULL!"))
  7282.         {
  7283.             // Find the ped.
  7284.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  7285.             if (pPed)
  7286.             {
  7287.                 CTask* pTask = CommonUseNearestScenarioChainToPos(pPed, svScenarioInPlace, fMaxRange, false, false, iTimeToLeave);
  7288.                 if(pTask)
  7289.                 {
  7290.                     // Give the ped the scenario following task.
  7291.                     CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_USE_NEAREST_SCENARIO_CHAIN_TO_POS, "TASK_USE_NEAREST_SCENARIO_CHAIN_TO_COORD");
  7292.                 }
  7293.             }
  7294.         }
  7295.     }
  7296.  
  7297.     void CommandTaskUseNearestScenarioChainToPosWarp( int iPedIndex, const scrVector & svScenarioPlace, float fMaxRange, int iTimeToLeave )
  7298.     {
  7299.         if(SCRIPT_VERIFY(iPedIndex != NULL_IN_SCRIPTING_LANGUAGE, "Ped index was NULL!"))
  7300.         {
  7301.             // Find the ped.
  7302.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  7303.             if (pPed)
  7304.             {
  7305.                 CTask* pTask = CommonUseNearestScenarioChainToPos(pPed, svScenarioPlace, fMaxRange, true, false, iTimeToLeave);
  7306.                 if(pTask)
  7307.                 {
  7308.                     // Give the ped the scenario following task.
  7309.                     CScriptPeds::GivePedScriptedTask(iPedIndex, pTask, SCRIPT_TASK_USE_NEAREST_SCENARIO_CHAIN_TO_POS, "TASK_USE_NEAREST_SCENARIO_CHAIN_TO_COORD_WARP");
  7310.                 }
  7311.             }
  7312.         }
  7313.     }
  7314.  
  7315.     bool CommandIsPedActiveInScenario(int iPedIndex)
  7316.     {
  7317.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex);
  7318.         if (SCRIPT_VERIFY(pPed, "PedIndex was invalid for IS_PED_ACTIVE_IN_SCENARIO or IS_PED_PLAYING_BASE_CLIP_IN_SCENARIO!"))
  7319.         {
  7320.             CTaskUseScenario* pTaskScenario = static_cast<CTaskUseScenario*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_USE_SCENARIO));
  7321.             if (pTaskScenario)
  7322.             {
  7323.                 // The ped is really only "in" the scenario when they are playing the ambient animations associated with it.
  7324.                 return pTaskScenario->GetState() == CTaskUseScenario::State_PlayAmbients;
  7325.             }
  7326.         }
  7327.  
  7328.         return false;
  7329.     }
  7330.  
  7331.     bool CommandIsPedPlayingBaseClipInScenario(int iPedIndex)
  7332.     {
  7333.         if (CommandIsPedActiveInScenario(iPedIndex))
  7334.         {
  7335.             const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex);
  7336.             if (pPed)
  7337.             {
  7338.                 CTaskAmbientClips* pTaskAmbientClips = static_cast<CTaskAmbientClips*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_AMBIENT_CLIPS));
  7339.                 if (pTaskAmbientClips)
  7340.                 {
  7341.                     return pTaskAmbientClips->IsBaseClipFullyBlended();
  7342.                 }
  7343.             }
  7344.         }
  7345.  
  7346.         return false;
  7347.     }
  7348.  
  7349.     void CommandSetCanPlayAmbientIdles(int PedIndex, bool bBlockIdleClips, bool bRemoveIdleClipIfPlaying)
  7350.     {
  7351.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  7352.         if (pPed)
  7353.         {
  7354.             CTaskAmbientClips* pTaskAmbientClips = static_cast<CTaskAmbientClips*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_AMBIENT_CLIPS));
  7355.             if (pTaskAmbientClips)
  7356.             {
  7357.                 pTaskAmbientClips->SetBlockAmbientIdles(bBlockIdleClips);
  7358.                 pTaskAmbientClips->SetRemoveAmbientIdles(bRemoveIdleClipIfPlaying);
  7359.             }
  7360.         }
  7361.     }
  7362.  
  7363.     void CommandTaskSwapWeapon(int PedIndex, bool bDrawWeapon)
  7364.     {
  7365.         u32 nFlags = SWAP_HOLSTER;
  7366.         if(bDrawWeapon)
  7367.             nFlags |= SWAP_DRAW;
  7368.  
  7369.         CTask* pTask = rage_new CTaskSwapWeapon(nFlags);
  7370.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_SWAP_WEAPON, "TASK_SWAP_WEAPON");
  7371.     }
  7372.  
  7373.  
  7374.     void CommandTaskReloadWeapon(int PedIndex, bool UNUSED_PARAM(bDrawWeapon))
  7375.     {
  7376.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  7377.  
  7378.         if( SCRIPT_VERIFY(pPed , "PedIndex was invalid for TASK_RELOAD_WEAPON!") &&
  7379.             SCRIPT_VERIFY(pPed->GetWeaponManager() , "WeaponManager was invalid for TASK_RELOAD_WEAPON!") &&
  7380.             SCRIPT_VERIFY(pPed->GetWeaponManager()->GetEquippedWeapon() , "Equipped weapon was invalid for TASK_RELOAD_WEAPON!") )
  7381.         {
  7382.             CTaskReloadGun* pTaskToGiveToPed = rage_new CTaskReloadGun(CWeaponController::WCT_Reload);
  7383.             if (SCRIPT_VERIFY(pTaskToGiveToPed, "TASK_RELOAD_WEAPON - Unable to create reload gun task"))
  7384.             {
  7385.                 CScriptPeds::GivePedScriptedTask(PedIndex, pTaskToGiveToPed, SCRIPT_TASK_RELOAD_WEAPON, "TASK_RELOAD_WEAPON");
  7386.             }  
  7387.         }
  7388.     }
  7389.  
  7390.     void CommandTaskCombatRoll(int UNUSED_PARAM(PedIndex), s32 UNUSED_PARAM(iDirection))
  7391.     {
  7392.         scriptAssertf(0, "TASK_COMBAT_ROLL removed");
  7393.     }
  7394.  
  7395.     void CommandTaskSkyDive(int iPedIndex, bool bInstant)
  7396.     {
  7397.         fwFlags32 fallFlags = FF_ForceSkyDive;
  7398.         if(bInstant)
  7399.         {
  7400.             fallFlags.SetFlag(FF_InstantBlend);
  7401.             fallFlags.SetFlag(FF_DisableSkydiveTransition);
  7402.         }
  7403.  
  7404.         CTaskComplexControlMovement * pCtrlTask;
  7405.         pCtrlTask = rage_new CTaskComplexControlMovement( rage_new CTaskMoveInAir(), rage_new CTaskFall(fallFlags), CTaskComplexControlMovement::TerminateOnSubtask );
  7406.  
  7407.         CScriptPeds::GivePedScriptedTask(iPedIndex, pCtrlTask, SCRIPT_TASK_SKY_DIVE, "TASK_SKY_DIVE");
  7408.     }
  7409.  
  7410.     void CommandTaskParachute(int iPedID, bool UNUSED_PARAM(bGiveParachuteItem), bool bInstant)
  7411.     {
  7412.         //Note: The 'give parachute' param is being ignored -- it is
  7413.         //      too error prone, and causes asserts and failed tasks.
  7414.  
  7415.         fwFlags32 paraFlags = CTaskParachute::PF_GiveParachute;
  7416.         if(bInstant)
  7417.         {
  7418.             paraFlags.SetFlag(CTaskParachute::PF_InstantBlend);
  7419.         }
  7420.  
  7421.         CTaskParachute *pTask = rage_new CTaskParachute(paraFlags);
  7422.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_PARACHUTE, "TASK_PARACHUTE");
  7423.     }
  7424.  
  7425.     void CommandTaskParachuteToTarget(int iPedID, const scrVector & svTargetLocation)
  7426.     {
  7427.         CTaskParachute *pTask = rage_new CTaskParachute(CTaskParachute::PF_GiveParachute | CTaskParachute::PF_SkipSkydiving);
  7428.         pTask->SetTargetPosition(VECTOR3_TO_VEC3V((Vector3)svTargetLocation));
  7429.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_PARACHUTE_TO_TARGET, "TASK_PARACHUTE_TO_TARGET");
  7430.     }
  7431.  
  7432.     void CommandSetParachuteTaskTarget(int iPedID, const scrVector & svTargetLocation)
  7433.     {
  7434.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7435.         if (pPed)
  7436.         {
  7437.             CTaskParachute *pTaskParachute = (CTaskParachute *)pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_PARACHUTE);
  7438.             if (SCRIPT_VERIFY(pTaskParachute, "Ped isn't running parachute task, please use GET_PED_PARACHUTE_STATE != PPS_INVALID to check") )
  7439.             {
  7440.                 pTaskParachute->GetParachuteFlags().SetFlag(CTaskParachute::PF_SkipSkydiving);
  7441.                 pTaskParachute->SetTargetPosition(VECTOR3_TO_VEC3V((Vector3)svTargetLocation));
  7442.             }
  7443.         }
  7444.     }
  7445.    
  7446.     void CommandSetParachuteTaskThrust(int iPedID, float fThrust)
  7447.     {
  7448.         CPed *pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7449.         if (pPed)
  7450.         {
  7451.             CTaskParachute *pTaskParachute = (CTaskParachute *)pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_PARACHUTE);
  7452.             if (SCRIPT_VERIFY(pTaskParachute, "Ped isn't running parachute task, please use GET_PED_PARACHUTE_STATE != PPS_INVALID to check") )
  7453.             {
  7454.                 pTaskParachute->SetParachuteThrust(fThrust);
  7455.             }
  7456.         }
  7457.     }
  7458.    
  7459.     void CommandSetParachuteTaskTargetEntity(int iPedID, int iTargetID, const scrVector & vOffset)
  7460.     {
  7461.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7462.         if(pPed)
  7463.         {
  7464.             const CPhysical* pTarget = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(iTargetID);
  7465.             if(pTarget)
  7466.             {
  7467.                 CTaskParachute* pTaskParachute = static_cast<CTaskParachute *>(pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_PARACHUTE));
  7468.                 if(SCRIPT_VERIFY(pTaskParachute, "Ped isn't running parachute task, please use GET_PED_PARACHUTE_STATE != PPS_INVALID to check") )
  7469.                 {
  7470.                     pTaskParachute->SetTarget(pTarget, VECTOR3_TO_VEC3V((Vector3)vOffset));
  7471.                 }
  7472.             }
  7473.         }
  7474.     }
  7475.  
  7476.     void CommandTaskJetpack(int iPedID)
  7477.     {
  7478.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7479.         if(pPed)
  7480.         {
  7481.             //Ensure the inventory is valid.
  7482.             CPedInventory* pPedInventory = pPed->GetInventory();
  7483.             if(pPedInventory)
  7484.             {
  7485.                 //! Give ped a jetpack.
  7486.                 pPedInventory->AddWeapon(GADGETTYPE_JETPACK);
  7487.  
  7488.                 //! Equip it.
  7489.                 pPed->SetPedConfigFlag(CPED_CONFIG_FLAG_EquipJetpack, true);
  7490.             }
  7491.         }
  7492.     }
  7493.  
  7494.     void CommandTaskJetpackGoToCoord(int JETPACK_ONLY(iPedID), const scrVector & JETPACK_ONLY(scrVecCoors), float JETPACK_ONLY(fMinHeightFromGround), bool JETPACK_ONLY(bDisableThrustAtDestination))
  7495.     {
  7496. #if ENABLE_JETPACK
  7497.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7498.         if(pPed)
  7499.         {
  7500.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_JETPACK);
  7501.             if (SCRIPT_VERIFY(pTask, "TASK_JETPACK_GO_TO_COORD - Not running jetpack task!"))
  7502.             {
  7503.                 CTaskJetpack *pTaskJetpack = static_cast<CTaskJetpack*>(pTask);
  7504.                 if (SCRIPT_VERIFY(pTaskJetpack, "TASK_JETPACK_GO_TO_COORD - Not running jetpack task!"))
  7505.                 {
  7506.                     Vector3 vCoord = Vector3(scrVecCoors);
  7507.                     pTaskJetpack->SetGoToParametersForAI(NULL, vCoord, fMinHeightFromGround, bDisableThrustAtDestination);
  7508.                 }
  7509.             }
  7510.         }
  7511. #endif
  7512.     }
  7513.  
  7514.     void CommandTaskJetpackGoToEntity(int JETPACK_ONLY(iPedID), int JETPACK_ONLY(iTargetEntityID), const scrVector & JETPACK_ONLY(scrVecCoorsOffset), float JETPACK_ONLY(fMinHeightFromGround), bool JETPACK_ONLY(bDisableThrustAtDestination), bool JETPACK_ONLY(bUseRandomTimerWhenClose))
  7515.     {
  7516. #if ENABLE_JETPACK
  7517.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7518.         if(pPed)
  7519.         {
  7520.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_JETPACK);
  7521.             if (SCRIPT_VERIFY(pTask, "TASK_JETPACK_GO_TO_ENTITY - Not running jetpack task!"))
  7522.             {
  7523.                 CTaskJetpack *pTaskJetpack = static_cast<CTaskJetpack*>(pTask);
  7524.                 if (SCRIPT_VERIFY(pTaskJetpack, "TASK_JETPACK_GO_TO_ENTITY - Not running jetpack task!"))
  7525.                 {
  7526.                     CPhysical* pTargetPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(iTargetEntityID);
  7527.                     if (SCRIPT_VERIFY(pTargetPhysical, "TASK_JETPACK_GO_TO_ENTITY - Target entity is not valid!"))
  7528.                     {
  7529.                         Vector3 vCoord = Vector3(scrVecCoorsOffset);
  7530.                         pTaskJetpack->SetGoToParametersForAI(pTargetPhysical, vCoord, fMinHeightFromGround, bDisableThrustAtDestination, bUseRandomTimerWhenClose);
  7531.                     }
  7532.                 }
  7533.             }
  7534.         }
  7535. #endif
  7536.     }
  7537.  
  7538.     void CommandTaskJetpackShootAtCoord(int JETPACK_ONLY(iPedID), const scrVector & JETPACK_ONLY(scrVecCoors), float JETPACK_ONLY(fAbortRange), int JETPACK_ONLY(iFrequencyPercentage), int JETPACK_ONLY(iFiringPatternHash))
  7539.     {
  7540. #if ENABLE_JETPACK
  7541.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7542.         if(pPed)
  7543.         {
  7544.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_JETPACK);
  7545.             if (SCRIPT_VERIFY(pTask, "TASK_JETPACK_SHOOT_AT_COORD - Not running jetpack task!"))
  7546.             {
  7547.                 CTaskJetpack *pTaskJetpack = static_cast<CTaskJetpack*>(pTask);
  7548.                 if (SCRIPT_VERIFY(pTaskJetpack, "TASK_JETPACK_SHOOT_AT_COORD - Not running jetpack task!"))
  7549.                 {
  7550.                     Vector3 vCoord = Vector3(scrVecCoors);
  7551.                     pTaskJetpack->SetShootAtParametersForAI(NULL, vCoord, fAbortRange, iFrequencyPercentage, iFiringPatternHash);
  7552.                 }
  7553.             }
  7554.         }
  7555. #endif
  7556.     }
  7557.  
  7558.     void CommandTaskJetpackShootAtEntity(int JETPACK_ONLY(iPedID), int JETPACK_ONLY(iTargetEntityID), const scrVector & JETPACK_ONLY(scrVecCoorsOffset), float JETPACK_ONLY(fAbortRange), int JETPACK_ONLY(iFrequencyPercentage), int JETPACK_ONLY(iFiringPatternHash))
  7559.     {
  7560. #if ENABLE_JETPACK
  7561.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7562.         if(pPed)
  7563.         {
  7564.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_JETPACK);
  7565.             if (SCRIPT_VERIFY(pTask, "TASK_JETPACK_SHOOT_AT_ENTITY - Not running jetpack task!"))
  7566.             {
  7567.                 CTaskJetpack *pTaskJetpack = static_cast<CTaskJetpack*>(pTask);
  7568.                 if (SCRIPT_VERIFY(pTaskJetpack, "TASK_JETPACK_SHOOT_AT_ENTITY - Not running jetpack task!"))
  7569.                 {
  7570.                     Vector3 vCoord = Vector3(scrVecCoorsOffset);
  7571.  
  7572.                     CPhysical* pTargetPhysical = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(iTargetEntityID);
  7573.                     if (SCRIPT_VERIFY(pTargetPhysical, "TASK_JETPACK_SHOOT_AT_ENTITY - Target entity is not valid!"))
  7574.                     {
  7575.                         pTaskJetpack->SetShootAtParametersForAI(pTargetPhysical, vCoord, fAbortRange, iFrequencyPercentage, iFiringPatternHash);
  7576.                     }
  7577.  
  7578.                 }
  7579.             }
  7580.         }
  7581. #endif
  7582.     }
  7583.  
  7584.     void CommandTaskJetpackStopShooting(int JETPACK_ONLY(iPedID))
  7585.     {
  7586. #if ENABLE_JETPACK
  7587.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7588.         if(pPed)
  7589.         {
  7590.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_JETPACK);
  7591.             if (SCRIPT_VERIFY(pTask, "TASK_JETPACK_SHOOT_AT_COORD - Not running jetpack task!"))
  7592.             {
  7593.                 CTaskJetpack *pTaskJetpack = static_cast<CTaskJetpack*>(pTask);
  7594.                 if (SCRIPT_VERIFY(pTaskJetpack, "TASK_JETPACK_SHOOT_AT_COORD - Not running jetpack task!"))
  7595.                 {
  7596.                     pTaskJetpack->RequestDrivebyTermination(true);
  7597.                 }
  7598.             }
  7599.         }
  7600. #endif
  7601.     }
  7602.  
  7603.     void CommandTaskRappelFromHeli(int iPedIndex, float fMinRappelHeight)
  7604.     {      
  7605.         CTaskHeliPassengerRappel* pRappelTask = rage_new CTaskHeliPassengerRappel(fMinRappelHeight);
  7606.         CScriptPeds::GivePedScriptedTask(iPedIndex, pRappelTask, SCRIPT_TASK_RAPPEL_FROM_HELI, "TASK_RAPPEL_FROM_HELI");
  7607.     }
  7608.    
  7609.     void CommandTaskDragPedToCoord(int iDraggerIndex, int iDraggedIndex, const scrVector & vCoords, float fMoveBlendRatioForApproach)
  7610.     {
  7611.         CPed* pDragged = CTheScripts::GetEntityToModifyFromGUID<CPed>(iDraggedIndex, CTheScripts::GUID_ASSERT_FLAGS_NO_DEAD_CHECK);
  7612.         if(pDragged)
  7613.         {
  7614.             CTaskDraggingToSafety* pTask = rage_new CTaskDraggingToSafety(pDragged, NULL, CTaskDraggingToSafety::CF_CoverNotRequired);
  7615.             pTask->DragToPosition(vCoords);
  7616.             pTask->SetMoveBlendRatioForApproach(fMoveBlendRatioForApproach);
  7617.            
  7618.             CScriptPeds::GivePedScriptedTask(iDraggerIndex, pTask, SCRIPT_TASK_DRAG_PED_TO_COORD, "TASK_DRAG_PED_TO_COORD");
  7619.         }
  7620.     }
  7621.  
  7622.     bool CommandIsPedGettingUp(int PedIndex)
  7623.     {
  7624.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  7625.         if(pPed)
  7626.         {
  7627.             return pPed->GetPedIntelligence()->IsPedGettingUp();
  7628.         }
  7629.         return false;
  7630.     }
  7631.  
  7632.     void CommandTaskWrithe(int iPedID, int iPedTargetID, int nMinFireLoops, int UNUSED_PARAM(StartState), bool bForceShootOnGround, int nShootFromGroundTimer)
  7633.     {
  7634.         const CPed* pTargetPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedTargetID);
  7635.         if (SCRIPT_VERIFY(pTargetPed, "SCRIPT_TASK_WRITHE - Invalid target"))
  7636.         {
  7637.             bool bFromGetUp = true;
  7638.             bool bEnableRagdollOnCollision = true;
  7639.  
  7640.             if (bForceShootOnGround)
  7641.             {
  7642.                 bEnableRagdollOnCollision = false;
  7643.             }
  7644.  
  7645.             CTaskWrithe* pTask = rage_new CTaskWrithe(CWeaponTarget(pTargetPed), bFromGetUp, bEnableRagdollOnCollision , bForceShootOnGround);
  7646.             pTask->SetMinFireLoops(nMinFireLoops);
  7647.             pTask->SetShootFromGroundTimer(nShootFromGroundTimer);
  7648.  
  7649.             CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_WRITHE, "TASK_WRITHE");
  7650.         }
  7651.     }
  7652.  
  7653.     bool CommandIsPedInWrithe(int iPedID)
  7654.     {
  7655.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedID);
  7656.         if (SCRIPT_VERIFY(pPed, "SCRIPT_TASK_WRITHE - Invalid target"))
  7657.         {
  7658.             return pPed->GetPedResetFlag(CPED_RESET_FLAG_IsInWrithe);
  7659.         }
  7660.  
  7661.         return false;
  7662.     }
  7663.  
  7664.     void CommandOpenPatrolRoute(const char* RouteName)
  7665.     {
  7666.         CTheScripts::GetScriptPatrol().OpenPatrolRoute(RouteName);
  7667.     }
  7668.  
  7669.     void CommandClosePatrolRoute()
  7670.     {
  7671.         CTheScripts::GetScriptPatrol().ClosePatrolRoute();
  7672.     }
  7673.    
  7674.     void CommandAddPatrolNode(int NodeId, const char* NodeType, const scrVector & scrNodePos, const scrVector & scrNodeHeading, int Duration)
  7675.     {
  7676.         Vector3 vNodePos(scrNodePos);
  7677.         Vector3 vNodeHeading(scrNodeHeading);
  7678.        
  7679.         CTheScripts::GetScriptPatrol().AddPatrolNode(NodeId, NodeType, vNodePos, vNodeHeading, Duration);
  7680.     }
  7681.  
  7682.     void CommandAddPatrolNodeLink(int NodeID1, int NodeID2)
  7683.     {
  7684.         CTheScripts::GetScriptPatrol().AddPatrolLink(NodeID1, NodeID2);
  7685.     }
  7686.  
  7687.     void CommandCreatePatrolRoute()
  7688.     {
  7689.         CTheScripts::GetScriptPatrol().CreatePatrolRoute();
  7690.     }
  7691.  
  7692.     void CommandDeletePatrolRoute(const char * RouteName)
  7693.     {
  7694.         u32 HashedRouteName = atStringHash(RouteName);
  7695.  
  7696.         CTheScripts::GetCurrentGtaScriptHandler()->RemoveScriptResource(CGameScriptResource::SCRIPT_RESOURCE_PATROL_ROUTE, static_cast<ScriptResourceRef>(HashedRouteName));
  7697.     }
  7698.  
  7699.     void CommandTaskPatrol (int PedIndex, const char* cPatrolRouteName, int iAlertState, bool bCanChatToPeds, bool bUseHeadLookAt)
  7700.     {
  7701.         SCRIPT_ASSERT(cPatrolRouteName,"Error, NULL patrol route name, did you forget to initialise the route name?");
  7702.  
  7703.         int iRouteNameHash  =atStringHash(cPatrolRouteName);
  7704.         CTaskPatrol::AlertStatus asAlertState = CTaskPatrol::AlertStatus (iAlertState);
  7705.         u32 iPatrolFlags = 0;
  7706.         if (bCanChatToPeds)
  7707.         {
  7708.             iPatrolFlags |= GF_CanChatToPeds;
  7709.         }
  7710.         if (bUseHeadLookAt)
  7711.         {
  7712.             iPatrolFlags |= GF_UseHeadLookAt;
  7713.         }
  7714.  
  7715.         CTask* pTask = rage_new CTaskPatrol(iRouteNameHash, asAlertState, iPatrolFlags);
  7716.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_PATROL, "TASK_PATROL");
  7717. }
  7718.  
  7719.     void CommandTaskStayInCover (int PedIndex)
  7720.     {
  7721.         CTask* pTask = rage_new CTaskStayInCover();
  7722.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_STAY_IN_COVER, "TASK_STAY_IN_COVER");
  7723.     }
  7724.  
  7725.     bool CommandGetPatrolNodeInfo (int PedIndex, int &iTimeLeftAtNode, int &iNodeId)
  7726.     {
  7727.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  7728.         bool bHaveVaildTask = false;
  7729.  
  7730.         if (pPed)
  7731.         {
  7732.            
  7733.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_PATROL);
  7734.             //CTask* pTask = pPedAI->GetTaskManager()->GetActiveTask();
  7735.            
  7736.             if (pTask && pTask->GetTaskType()==CTaskTypes::TASK_PATROL)
  7737.             {
  7738.                 CTaskPatrol* pPatrolTask = (CTaskPatrol*)pTask;
  7739.                 iNodeId = pPatrolTask->CTaskPatrol::GetCurrentNode();
  7740.                 iTimeLeftAtNode = pPatrolTask->CTaskPatrol::GetTimeLeftAtNode();
  7741.                 bHaveVaildTask = true;
  7742.             }
  7743.  
  7744.         }
  7745.         return bHaveVaildTask;
  7746.  
  7747.     }
  7748.  
  7749.     void CommandTaskHangGlider(int UNUSED_PARAM(PedIndex), int UNUSED_PARAM(HangGliderObjectIndex))
  7750.     {
  7751.         Assertf(0, "HangGlider is deprecated functionality");
  7752.     }
  7753.  
  7754.     void CommandSetHangGliderAirSpeed(int UNUSED_PARAM(PedIndex), const scrVector & UNUSED_PARAM(scrVAirSpeed))
  7755.     {
  7756.         Assertf(0, "HangGlider is deprecated functionality");
  7757.     }
  7758.  
  7759.     void CommandVehicleShootAtPed(int PedIndex, int OtherPedIndex, float fFireTolerance)
  7760.     {
  7761.         const CPed* pOtherPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(OtherPedIndex);
  7762.  
  7763.         if (pOtherPed)
  7764.         {
  7765.             CAITarget target(pOtherPed);
  7766.             CTask* pTask=rage_new CTaskVehicleCombat(&target, 0, fFireTolerance);
  7767.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_VEHICLE_SHOOT_AT_ENTITY, "TASK_VEHICLE_SHOOT_AT_PED");
  7768.         }
  7769.     }
  7770.  
  7771.     void CommandVehicleAimAtPed(int PedIndex, int OtherPedIndex)
  7772.     {
  7773.         const CPed* pOtherPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(OtherPedIndex);
  7774.  
  7775.         if (pOtherPed)
  7776.         {
  7777.             CAITarget target(pOtherPed);
  7778.             CTask* pTask=rage_new CTaskVehicleCombat(&target, CTaskVehicleCombat::Flag_justAim);
  7779.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_VEHICLE_AIM_AT_ENTITY, "TASK_VEHICLE_AIM_AT_PED");
  7780.         }
  7781.     }
  7782.  
  7783.     void CommandVehicleShootAtCoord(int PedIndex, const scrVector & svTarget, float fFireTolerance)
  7784.     {
  7785.         Vector3 vTarget(svTarget);
  7786.         CAITarget target(vTarget);
  7787.  
  7788.         CTask* pTask=rage_new CTaskVehicleCombat(&target, 0, fFireTolerance);
  7789.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_VEHICLE_SHOOT_AT_COORD, "TASK_VEHICLE_SHOOT_AT_COORD");
  7790.     }
  7791.  
  7792.     void CommandVehicleAimAtCoord(int PedIndex, const scrVector & svTarget)
  7793.     {
  7794.         Vector3 vTarget(svTarget);
  7795.         CAITarget target(vTarget);
  7796.  
  7797.         CTask* pTask=rage_new CTaskVehicleCombat(&target, CTaskVehicleCombat::Flag_justAim);
  7798.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_VEHICLE_AIM_AT_COORD, "TASK_VEHICLE_AIM_AT_COORD");
  7799.     }
  7800.  
  7801.     void CommandVehicleAimUsingCamera(int PedIndex)
  7802.     {
  7803.         CTask* pTask=rage_new CTaskVehicleCombat(NULL, CTaskVehicleCombat::Flag_useCamera);
  7804.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_VEHICLE_AIM_USING_CAMERA, "TASK_VEHICLE_AIM_USING_CAMERA");
  7805.     }
  7806.  
  7807.     // Give a ped the bind-pose task to examine the transition from NM to animation.
  7808.     // DEV ONLY!
  7809.     void CommandTaskBindPose(int DEV_ONLY(iPedID), bool DEV_ONLY(bDoBlendFromNM))
  7810.     {
  7811. #if __DEV
  7812.         CTask* pTask = rage_new CTaskBindPose(bDoBlendFromNM);
  7813.         CScriptPeds::GivePedScriptedTask(iPedID, pTask, SCRIPT_TASK_BIND_POSE, "TASK_BIND_POSE");
  7814. #endif // __DEV
  7815.     }
  7816.  
  7817.     // Give ped an NM electrocution task.
  7818.     void CommandElectrocute(int iPedID, int nMinTime, int nMaxTime)
  7819.     {
  7820.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7821.         if (pPed && CTaskNMBehaviour::CanUseRagdoll(pPed, RAGDOLL_TRIGGER_SCRIPT) )
  7822.         {
  7823.             UpdatePedRagdollBoundsForScriptActivation(pPed);
  7824.             CTask* pNmTask = rage_new CTaskNMElectrocute(nMinTime, nMaxTime);
  7825.             CEventSwitch2NM event(nMaxTime, pNmTask, true, nMinTime);
  7826.             pPed->SwitchToRagdoll(event);
  7827.         }
  7828.  
  7829.     }
  7830.  
  7831.     // Give ped a high fall task.
  7832.     void CommandHighFall(int iPedID, int nMinTime, int nMaxTime, int eEntryType)
  7833.     {
  7834.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7835.         if (pPed && CTaskNMBehaviour::CanUseRagdoll(pPed, RAGDOLL_TRIGGER_SCRIPT) )
  7836.         {
  7837.             UpdatePedRagdollBoundsForScriptActivation(pPed);
  7838.             CTask* pNmTask = rage_new CTaskNMHighFall(nMinTime, NULL, (CTaskNMHighFall::eHighFallEntryType)eEntryType);
  7839.             CEventSwitch2NM event(nMaxTime, pNmTask, true, nMinTime);
  7840.             pPed->SwitchToRagdoll(event);
  7841.         }
  7842.     }
  7843.  
  7844.     // Give ped an NM dangle-from-meathook task.
  7845.     void CommandDangleFromMeathook(bool bStart, int iPedID, int iHookID, const scrVector & scrPos, bool bDoGrab, float fFrequency, int UNUSED_PARAM(nMinTime), int nMaxTime,
  7846.         bool bFixRotation, float fRotMinX, float fRotMinY, float fRotMinZ, float fRotMaxX, float fRotMaxY, float fRotMaxZ)
  7847.     {
  7848.         Vector3 pos = Vector3(scrPos.x, scrPos.y, scrPos.z);
  7849.         Vector3 vecRotMinLimits = Vector3(fRotMinX, fRotMinY, fRotMinZ);
  7850.         Vector3 vecRotMaxLimits = Vector3(fRotMaxX, fRotMaxY, fRotMaxZ);
  7851.  
  7852.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7853.         if (pPed)
  7854.         {
  7855.             // First time activating?
  7856.             if (bStart && CTaskNMBehaviour::CanUseRagdoll(pPed, RAGDOLL_TRIGGER_SCRIPT))
  7857.             {
  7858.                 UpdatePedRagdollBoundsForScriptActivation(pPed);
  7859.  
  7860.                 // Give it the dangle task
  7861.                 CTask* pNmTask = rage_new CTaskNMDangle(pos);
  7862.                 CEventSwitch2NM event(nMaxTime, pNmTask, true);
  7863.                 pPed->SwitchToRagdoll(event);
  7864.  
  7865.                 // Set grab state
  7866.                 ((CTaskNMDangle*)pNmTask)->SetGrabParams(pPed, bDoGrab, fFrequency);
  7867.  
  7868.                 // Create the hook to world constraint
  7869.                 if (pPed->GetRagdollConstraintData())
  7870.                 {
  7871.                     CPhysical* pHook = CTheScripts::GetEntityToModifyFromGUID<CPhysical>(iHookID);
  7872.                     AssertMsg(pHook && pHook->GetCurrentPhysicsInst(), "CommandDangleFromMeathook - valid hookID not provided");
  7873.                     if (pHook && pHook->GetCurrentPhysicsInst())
  7874.                         pPed->GetRagdollConstraintData()->CreateHookToWorldConstraint(pHook, pos, bFixRotation, vecRotMinLimits, vecRotMaxLimits);
  7875.                 }
  7876.             }
  7877.  
  7878.             // Set grab state
  7879.             if (CTaskNMDangle* pTaskDangle = static_cast<CTaskNMDangle*>(
  7880.                 pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_NM_DANGLE)))
  7881.             {
  7882.                 pTaskDangle->SetGrabParams(pPed, bDoGrab, fFrequency);
  7883.                 pTaskDangle->UpdateHookConstraint(pos, vecRotMinLimits, vecRotMaxLimits);
  7884.             }
  7885.             else if (pPed->GetRagdollConstraintData())
  7886.             {
  7887.                 // Update the hook to world constraint manually if the dangle task has ended
  7888.                 pPed->GetRagdollConstraintData()->UpdateHookToWorldConstraint(pos, vecRotMinLimits, vecRotMaxLimits);
  7889.             }
  7890.         }
  7891.     }
  7892.  
  7893.     // Give ped an NM slung-over-shoulder task.
  7894.     void CommandSlungOverShoulder(int iPedIDSlungPed, int iPedIDCarrier, int nMinTime, int nMaxTime)
  7895.     {
  7896.         CPed* pPedSlung = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIDSlungPed);
  7897.         CPed* pPedCarrier = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIDCarrier);
  7898.         if (pPedSlung && pPedCarrier && CTaskNMBehaviour::CanUseRagdoll(pPedSlung, RAGDOLL_TRIGGER_SLUNG_OVER_SHOULDER))
  7899.         {
  7900.             // Perform normal collision to avoid popping upon activation
  7901.             pPedSlung->GetRagdollInst()->SetDontZeroMatricesOnActivation();
  7902.  
  7903.             UpdatePedRagdollBoundsForScriptActivation(pPedSlung);
  7904.  
  7905.             // Give it the slung over shoulder task
  7906.             CTask* pNmTask = rage_new CTaskNMSlungOverShoulder(pPedSlung, pPedCarrier);
  7907.             CEventSwitch2NM event(nMaxTime, pNmTask, true, nMinTime);
  7908.             pPedSlung->SwitchToRagdoll(event);
  7909.         }
  7910.     }
  7911.  
  7912.     // Give ped an NM stumble task.
  7913.     void CommandStumble(int iPedID, int nMinTime, int nMaxTime)
  7914.     {
  7915.         Assertf(0, "CommandStumble is no longer supported");
  7916.  
  7917.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  7918.         if (pPed && CTaskNMBehaviour::CanUseRagdoll(pPed, RAGDOLL_TRIGGER_SCRIPT) )
  7919.         {
  7920.             UpdatePedRagdollBoundsForScriptActivation(pPed);
  7921.  
  7922.             CTask* pNmTask = rage_new CTaskNMRelax(nMinTime, nMaxTime);
  7923.             CEventSwitch2NM event(nMaxTime, pNmTask, true, nMinTime);
  7924.             pPed->SwitchToRagdoll(event);
  7925.         }
  7926.     }
  7927.  
  7928.     void CommandTaskSetBlockingOfNonTemporaryEvents (int PedIndex, bool bSet)
  7929.     {
  7930.         CTask* pTask=rage_new CTaskSetBlockingOfNonTemporaryEvents(bSet);
  7931.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_SET_BLOCKING_OF_NON_TEMPORARY_EVENTS, "TASK_SET_BLOCKING_OF_NON_TEMPORARY_EVENTS");
  7932.     }
  7933.  
  7934.     void CommandTaskForceMotionState (int PedIndex, int motionState, bool bForceRestart)
  7935.     {
  7936.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex, 0);
  7937.         if (scriptVerifyf(CPed::IsAllowedToForceMotionState((CPedMotionStates::eMotionState)motionState, pPed), "%s: TASK_FORCE_MOTION_STATE - Failed to force state %d - See TTY for details", CTheScripts::GetCurrentScriptNameAndProgramCounter(), motionState))
  7938.         {
  7939.             CTask* pTask=rage_new CTaskForceMotionState((CPedMotionStates::eMotionState)motionState, bForceRestart);
  7940.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_FORCE_MOTION_STATE, "TASK_FORCE_MOTION_STATE");
  7941.         }
  7942.     }
  7943.  
  7944.     void CommandTaskMoveNetworkByName(int PedIndex, const char *network, float blendDuration, bool bAllowOverrideCloneUpdate, const char* szDictionary, s32 flags)
  7945.     {
  7946.         if (scriptVerifyf(g_NetworkDefStore.FindSlot(network)!=-1, "TASK_MOVE_NETWORK_BY_NAME - Network def '%s' does not exist!", network ))
  7947.         {
  7948.             u32 iFlags = (u32)flags;
  7949.  
  7950.             if(bAllowOverrideCloneUpdate)
  7951.             {
  7952.                 iFlags |= CTaskMoVEScripted::Flag_AllowOverrideCloneUpdate;
  7953.             }
  7954.  
  7955.             CTaskMoVEScripted* pTask=rage_new CTaskMoVEScripted(fwMvNetworkDefId(network), iFlags, blendDuration, VEC3_ZERO, Quaternion::sm_I);
  7956.  
  7957.             if(szDictionary && szDictionary[0] != '\0')
  7958.             {
  7959.                 pTask->SetCloneSyncDictHash(atStringHash(szDictionary));
  7960.             }
  7961.  
  7962.             bool bPartOfASequence = (PedIndex == NULL_IN_SCRIPTING_LANGUAGE);
  7963.  
  7964.             if (iFlags&CTaskMoVEScripted::Flag_Secondary)
  7965.             {
  7966.                 if(SCRIPT_VERIFY( !bPartOfASequence, "TASK_MOVE_NETWORK_BY_NAME_SECONDARY* Cant be used in a sequence!" ))
  7967.                 {
  7968.                     CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  7969.                     if(pPed)
  7970.                     {
  7971.                         pPed->GetPedIntelligence()->AddTaskSecondary( pTask, PED_TASK_SECONDARY_PARTIAL_ANIM );
  7972.                     }
  7973.                 }
  7974.                 return;
  7975.             }
  7976.  
  7977.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_MOVE_NETWORK, "TASK_MOVE_NETWORK");
  7978.         }
  7979.     }
  7980.  
  7981.     void CommandTaskMoveNetworkByNameWithInitParams(int PedIndex, const char *network, int& initialParameters, float blendDuration, bool bAllowOverrideCloneUpdate, const char* szDictionary, s32 flags)
  7982.     {
  7983.         if (scriptVerifyf(g_NetworkDefStore.FindSlot(network)!=-1, "TASK_MOVE_NETWORK_BY_NAME - Network def '%s' does not exist!", network ))
  7984.         {
  7985.             u32 iFlags = (u32)flags;
  7986.  
  7987.             if(bAllowOverrideCloneUpdate)
  7988.             {
  7989.                 iFlags |= CTaskMoVEScripted::Flag_AllowOverrideCloneUpdate;
  7990.             }
  7991.  
  7992.             CTaskMoVEScripted::ScriptInitialParameters* pInitParams = reinterpret_cast<CTaskMoVEScripted::ScriptInitialParameters*>(&initialParameters);
  7993.  
  7994.             CTaskMoVEScripted* pTask=rage_new CTaskMoVEScripted(fwMvNetworkDefId(network), iFlags, blendDuration, VEC3_ZERO, Quaternion::sm_I, pInitParams);
  7995.  
  7996.             if(szDictionary && szDictionary[0] != '\0')
  7997.             {
  7998.                 pTask->SetCloneSyncDictHash(atStringHash(szDictionary));
  7999.             }
  8000.  
  8001.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_MOVE_NETWORK, "TASK_MOVE_NETWORK");
  8002.         }
  8003.     }
  8004.  
  8005.     void CommandTaskMoveNetworkAdvancedByName(int PedIndex, const char *network, const scrVector & pos, const scrVector & rot, s32 RotOrder, float blendDuration, bool bAllowOverrideCloneUpdate, const char* szDictionary, s32 flags)
  8006.     {
  8007.         if (scriptVerifyf(g_NetworkDefStore.FindSlot(network)!=-1, "TASK_MOVE_NETWORK_ADVANCED_BY_NAME - Network def '%s' does not exist!", network ))
  8008.         {
  8009.             u32 iFlags = ((u32)flags);
  8010.  
  8011.             iFlags |= CTaskMoVEScripted::Flag_SetInitialPosition;
  8012.            
  8013.             if(bAllowOverrideCloneUpdate)
  8014.             {
  8015.                 iFlags |= CTaskMoVEScripted::Flag_AllowOverrideCloneUpdate;
  8016.             }
  8017.  
  8018.             Vector3 vPos(pos);
  8019.             Vector3 vRot(rot);
  8020.  
  8021.             vRot*= DtoR;
  8022.  
  8023.             Quaternion qRot;
  8024.             CScriptEulers::QuaternionFromEulers(qRot, vRot, static_cast<EulerAngleOrder>(RotOrder));
  8025.             CTaskMoVEScripted* pTask=rage_new CTaskMoVEScripted(fwMvNetworkDefId(network), iFlags, blendDuration, vPos, qRot);
  8026.  
  8027.             if(szDictionary && szDictionary[0] != '\0')
  8028.             {
  8029.                 pTask->SetCloneSyncDictHash(atStringHash(szDictionary));
  8030.             }
  8031.  
  8032.             bool bPartOfASequence = (PedIndex == NULL_IN_SCRIPTING_LANGUAGE);
  8033.  
  8034.             if (iFlags&CTaskMoVEScripted::Flag_Secondary)
  8035.             {
  8036.                 if(SCRIPT_VERIFY( !bPartOfASequence, "TASK_MOVE_NETWORK_ADVANCED_BY_NAME_SECONDARY* Cant be used in a sequence!" ))
  8037.                 {
  8038.                     CPed * pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  8039.                     if(pPed)
  8040.                     {
  8041.                         pPed->GetPedIntelligence()->AddTaskSecondary( pTask, PED_TASK_SECONDARY_PARTIAL_ANIM );
  8042.                     }
  8043.                 }
  8044.                 return;
  8045.             }
  8046.  
  8047.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_MOVE_NETWORK, "TASK_MOVE_NETWORK_ADVANCED");
  8048.         }
  8049.     }
  8050.  
  8051.     CTaskMoVEScripted* FindScriptedMoveTask(const CPed* pPed)
  8052.     {
  8053.         CTask* pTask = pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_MOVE_SCRIPTED);
  8054.  
  8055.         if (!pTask)
  8056.         {
  8057.             pTask = pPed->GetPedIntelligence()->FindTaskSecondaryByType(CTaskTypes::TASK_MOVE_SCRIPTED);
  8058.         }
  8059.  
  8060.         return static_cast<CTaskMoVEScripted*>(pTask);
  8061.     }
  8062.  
  8063.     void CommandTaskMoveNetworkAdvancedByNameWithInitParams(int PedIndex, const char *network,  int& initialParameters, const scrVector & pos, const scrVector & rot, s32 RotOrder, float blendDuration, bool bAllowOverrideCloneUpdate, const char* szDictionary, s32 flags)
  8064.     {
  8065.         if (scriptVerifyf(g_NetworkDefStore.FindSlot(network)!=-1, "TASK_MOVE_NETWORK_ADVANCED_BY_NAME - Network def '%s' does not exist!", network ))
  8066.         {
  8067.             u32 iFlags = ((u32)flags);
  8068.  
  8069.             iFlags |= CTaskMoVEScripted::Flag_SetInitialPosition;
  8070.  
  8071.             if(bAllowOverrideCloneUpdate)
  8072.             {
  8073.                 iFlags |= CTaskMoVEScripted::Flag_AllowOverrideCloneUpdate;
  8074.             }
  8075.  
  8076.             CTaskMoVEScripted::ScriptInitialParameters* pInitParams = reinterpret_cast<CTaskMoVEScripted::ScriptInitialParameters*>(&initialParameters);
  8077.  
  8078.             Vector3 vPos(pos);
  8079.             Vector3 vRot(rot);
  8080.  
  8081.             vRot*= DtoR;
  8082.  
  8083.             Quaternion qRot;
  8084.             CScriptEulers::QuaternionFromEulers(qRot, vRot, static_cast<EulerAngleOrder>(RotOrder));
  8085.             CTaskMoVEScripted* pTask=rage_new CTaskMoVEScripted(fwMvNetworkDefId(network), iFlags, blendDuration, vPos, qRot, pInitParams);
  8086.  
  8087.             if(szDictionary && szDictionary[0] != '\0')
  8088.             {
  8089.                 pTask->SetCloneSyncDictHash(atStringHash(szDictionary));
  8090.             }
  8091.  
  8092.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_MOVE_NETWORK, "TASK_MOVE_NETWORK_ADVANCED");
  8093.         }
  8094.     }
  8095.  
  8096.     bool CommandIsTaskMoveNetworkActive(int PedIndex)
  8097.     {
  8098.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8099.         if (pPed && pPed->GetPedIntelligence())
  8100.         {
  8101.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8102.             if( pTaskMoVE && pTaskMoVE->GetIsNetworkActive() )
  8103.             {
  8104.                 return true;
  8105.             }
  8106.         }
  8107.         return false;
  8108.     }
  8109.  
  8110.     void CommandSetTaskMoveNetworkClipSet(s32 pedIndex, s32 clipSetHash, s32 variableClipSetHash = 0)
  8111.     {
  8112.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(pedIndex);
  8113.         if (pPed && pPed->GetPedIntelligence())
  8114.         {
  8115.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8116.             if( SCRIPT_VERIFY (pTaskMoVE, "SET_TASK_MOVE_NETWORK_CLIP_SET - task not running! Have you called TASK_MOVE_NETWORK_BY_NAME yet?" ) )
  8117.             {
  8118.                 fwMvClipSetVarId varId;
  8119.                 fwMvClipSetId setId;
  8120.                 if (variableClipSetHash==0)
  8121.                 {
  8122.                     variableClipSetHash = CLIP_SET_VAR_ID_INVALID;
  8123.                 }
  8124.  
  8125.                 varId.SetHash((u32)variableClipSetHash);
  8126.                 setId.SetHash((u32)clipSetHash);
  8127.  
  8128.                 pTaskMoVE->SetClipSet(varId, setId);
  8129.             }
  8130.         }
  8131.     }
  8132.  
  8133.     bool CommandIsTaskMoveNetworkReadyForTransition(int PedIndex)
  8134.     {
  8135.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8136.         if (pPed && pPed->GetPedIntelligence())
  8137.         {
  8138.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8139.             if (SCRIPT_VERIFY (pTaskMoVE, "IS_TASK_MOVE_NETWORK_READY_FOR_TRANSITION - task is not running!"))
  8140.             {
  8141.                 if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "IS_TASK_MOVE_NETWORK_READY_FOR_TRANSITION - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8142.             {
  8143.                 return pTaskMoVE->GetState() == CTaskMoVEScripted::State_InState;
  8144.             }
  8145.         }
  8146.         }
  8147.         return false;
  8148.     }
  8149.  
  8150.     void CommandRequestTaskMoveNetworkStateTransition(int PedIndex, const char* szState)
  8151.     {
  8152.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  8153.         if (pPed && pPed->GetPedIntelligence())
  8154.         {
  8155.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8156.             if (SCRIPT_VERIFY (pTaskMoVE, "REQUEST_TASK_MOVE_NETWORK_STATE_TRANSITION - task is not running!"))
  8157.             {
  8158.                 if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "REQUEST_TASK_MOVE_NETWORK_STATE_TRANSITION - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8159.             {
  8160.                 if( SCRIPT_VERIFY (pTaskMoVE->GetState() == CTaskMoVEScripted::State_InState, "REQUEST_TASK_MOVE_NETWORK_STATE_TRANSITION - task not ready for a transition! Check IS_TASK_MOVE_NETWORK_READY_FOR_TRANSITION!" ) )
  8161.                 {              
  8162.                     pTaskMoVE->RequestStateTransition(szState);
  8163.                 }
  8164.             }
  8165.         }
  8166.     }
  8167.     }
  8168.  
  8169.     void CommandSetExpectedCloneNextTaskMoveNetworkState(int PedIndex, const char* szState)
  8170.     {
  8171.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  8172.         if (pPed && pPed->GetPedIntelligence())
  8173.         {
  8174.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8175.             if (SCRIPT_VERIFY (pTaskMoVE, "SET_EXPECTED_CLONE_NEXT_TASK_MOVE_NETWORK_STATE - task is not running!"))
  8176.             {
  8177.                 if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "SET_EXPECTED_CLONE_NEXT_TASK_MOVE_NETWORK_STATE - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8178.                 {
  8179.                     if( SCRIPT_VERIFY (pTaskMoVE->GetState() == CTaskMoVEScripted::State_InState, "SET_EXPECTED_CLONE_NEXT_TASK_MOVE_NETWORK_STATE - task not ready for a transition! Check IS_TASK_MOVE_NETWORK_READY_FOR_TRANSITION!" ) )
  8180.                     {              
  8181.                         pTaskMoVE->SetExpectedCloneNextStateTransition(szState);
  8182.                     }
  8183.                 }
  8184.             }
  8185.         }
  8186.     }
  8187.     const char* CommandGetTaskMoveNetworkState(int PedIndex)
  8188.     {
  8189.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8190.         if (pPed && pPed->GetPedIntelligence())
  8191.         {
  8192.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8193.             if (SCRIPT_VERIFY (pTaskMoVE, "GET_TASK_MOVE_NETWORK_STATE - task is not running!"))
  8194.             {
  8195.                 if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "GET_TASK_MOVE_NETWORK_STATE - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8196.             {
  8197.                 return pTaskMoVE->GetScriptStateName();
  8198.             }
  8199.         }
  8200.         }
  8201.         return "Unknown";
  8202.     }
  8203.  
  8204.     void CommandSetTaskMoveNetworkSignalFloat(int PedIndex, const char* szSignal, float fSignal)
  8205.     {
  8206.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  8207.         if (pPed && pPed->GetPedIntelligence())
  8208.         {
  8209.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8210.             if (SCRIPT_VERIFY (pTaskMoVE, "SET_TASK_MOVE_NETWORK_SIGNAL_FLOAT - task is not running!"))
  8211.             {
  8212.                 if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "SET_TASK_MOVE_NETWORK_SIGNAL_FLOAT - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8213.                 {
  8214.                     if( SCRIPT_VERIFY ((!pPed->IsNetworkClone() || pTaskMoVE->GetAllowOverrideCloneUpdate()),
  8215.                         "SET_TASK_MOVE_NETWORK_SIGNAL_FLOAT - Can't set float on cloned ped if its task is not being overridden!" ) )
  8216.                     {
  8217.                         pTaskMoVE->SetSignalFloat(szSignal, fSignal);
  8218.                     }
  8219.                 }
  8220.             }
  8221.         }
  8222.     }
  8223.  
  8224.     void CommandSetTaskMoveNetworkSignalFloatLerpRate(int PedIndex, const char* szSignal, float fLerpRate)
  8225.     {
  8226.         scriptAssertf(fLerpRate!=0.0f, "CommandSetTaskMoveNetworkSignalFloatLerpRate don't expect fLerpRate to be 0.0f");
  8227.  
  8228.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  8229.         if (pPed && pPed->GetPedIntelligence())
  8230.         {
  8231.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8232.             if (SCRIPT_VERIFY (pTaskMoVE, "SET_TASK_MOVE_NETWORK_SIGNAL_FLOAT_LERP_RATE - task is not running!"))
  8233.             {
  8234.                 if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "SET_TASK_MOVE_NETWORK_SIGNAL_FLOAT_LERP_RATE - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8235.                 {
  8236.                     return pTaskMoVE->SetSignalFloatLerpRate(szSignal, fLerpRate);
  8237.                 }
  8238.             }
  8239.         }
  8240.     }
  8241.  
  8242.     float CommandGetTaskMoveNetworkSignalFloat(int PedIndex, const char* szSignal)
  8243.     {
  8244.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8245.         if (pPed && pPed->GetPedIntelligence())
  8246.         {
  8247.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8248.             if (SCRIPT_VERIFY (pTaskMoVE, "GET_TASK_MOVE_NETWORK_SIGNAL_FLOAT - task is not running!"))
  8249.             {
  8250.             if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "GET_TASK_MOVE_NETWORK_SIGNAL_FLOAT - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8251.             {
  8252.                 return pTaskMoVE->GetSignalFloat(szSignal);
  8253.             }
  8254.         }
  8255.         }
  8256.         return 0.0f;
  8257.     }
  8258.  
  8259.     void CommandSetTaskMoveNetworkSignalBool(int PedIndex, const char* szSignal, bool bSignal)
  8260.     {
  8261.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  8262.         if (pPed && pPed->GetPedIntelligence())
  8263.         {
  8264.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8265.             if (SCRIPT_VERIFY (pTaskMoVE, "SET_TASK_MOVE_NETWORK_SIGNAL_BOOL - task is not running!"))
  8266.             {
  8267.                 if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "SET_TASK_MOVE_NETWORK_SIGNAL_BOOL - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8268.                 {
  8269.                     if( SCRIPT_VERIFY ((!pPed->IsNetworkClone() || pTaskMoVE->GetAllowOverrideCloneUpdate()),
  8270.                         "SET_TASK_MOVE_NETWORK_SIGNAL_BOOL - Can't set bool on cloned ped if its task is not being overridden!" ) )
  8271.                     {
  8272.                         pTaskMoVE->SetSignalBool(szSignal, bSignal);
  8273.                     }
  8274.                 }
  8275.             }
  8276.         }
  8277.     }
  8278.  
  8279.     void CommandSetTaskMoveNetworkSignalLocalBool(int PedIndex, const char* szSignal, bool bSignal)
  8280.     {
  8281.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  8282.         if (pPed && pPed->GetPedIntelligence())
  8283.         {
  8284.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8285.             if (SCRIPT_VERIFY (pTaskMoVE, "SET_TASK_MOVE_NETWORK_SIGNAL_LOCAL_BOOL - task is not running!"))
  8286.             {
  8287.                 if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "SET_TASK_MOVE_NETWORK_SIGNAL_LOCAL_BOOL - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8288.                 {
  8289.                     pTaskMoVE->SetSignalBool(szSignal, bSignal, false);
  8290.                 }
  8291.             }
  8292.         }
  8293.     }
  8294.  
  8295.     void CommandSetTaskMoveNetworkSignalLocalFloat(int PedIndex, const char* szSignal, float signal)
  8296.     {
  8297.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  8298.         if (pPed && pPed->GetPedIntelligence())
  8299.         {
  8300.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8301.             if (SCRIPT_VERIFY (pTaskMoVE, "SET_TASK_MOVE_NETWORK_SIGNAL_LOCAL_FLOAT - task is not running!"))
  8302.             {
  8303.                 if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "SET_TASK_MOVE_NETWORK_SIGNAL_LOCAL_FLOAT - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8304.                 {
  8305.                     pTaskMoVE->SetSignalFloat(szSignal, signal, false);
  8306.                 }
  8307.             }
  8308.         }
  8309.     }
  8310.  
  8311.  
  8312.     bool CommandGetTaskMoveNetworkSignalBool(int PedIndex, const char* szSignal)
  8313.     {
  8314.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8315.         if (pPed && pPed->GetPedIntelligence())
  8316.         {
  8317.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8318.             if (SCRIPT_VERIFY (pTaskMoVE, "GET_TASK_MOVE_NETWORK_SIGNAL_BOOL - task is not running!"))
  8319.             {
  8320.             if( SCRIPT_VERIFY (pTaskMoVE->GetIsNetworkActive(), "GET_TASK_MOVE_NETWORK_SIGNAL_BOOL - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8321.             {
  8322.                 return pTaskMoVE->GetSignalBool(szSignal);
  8323.             }
  8324.         }
  8325.         }
  8326.         return false;
  8327.     }
  8328.  
  8329.  
  8330.     bool CommandGetTaskMoveNetworkEvent(int PedIndex, const char * eventName)
  8331.     {
  8332.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8333.         if (pPed && pPed->GetPedIntelligence())
  8334.         {
  8335.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8336.             if (SCRIPT_VERIFY (pTaskMoVE, "GET_TASK_MOVE_NETWORK_EVENT - task is not running!"))
  8337.             {
  8338.                 if( SCRIPT_VERIFY (pTaskMoVE && pTaskMoVE->GetIsNetworkActive(), "GET_TASK_MOVE_NETWORK_EVENT - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!" ) )
  8339.                 {
  8340.                     return pTaskMoVE->GetMoveEvent(eventName);
  8341.                 }
  8342.             }
  8343.         }
  8344.         return false;
  8345.     }
  8346.  
  8347.     void CommandSetTaskMoveNetworkEnableCollisionOnNetworkCloneWhenFixed(int PedIndex, bool bEnableCollisionOnNetworkCloneWhenFixed)
  8348.     {
  8349.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  8350.         if (pPed && pPed->GetPedIntelligence())
  8351.         {
  8352.             CTaskMoVEScripted* pTaskMoVE = FindScriptedMoveTask(pPed);
  8353.             if (SCRIPT_VERIFY(pTaskMoVE, "SET_TASK_MOVE_NETWORK_ENABLE_COLLISION_ON_NETWORK_CLONE_WHEN_FIXED - task is not running!"))
  8354.             {
  8355.                 if (SCRIPT_VERIFY(pTaskMoVE && pTaskMoVE->GetIsNetworkActive(), "SET_TASK_MOVE_NETWORK_ENABLE_COLLISION_ON_NETWORK_CLONE_WHEN_FIXED - task not active! Check IS_TASK_MOVE_NETWORK_ACTIVE!"))
  8356.                 {
  8357.                     return pTaskMoVE->SetEnableCollisionOnNetworkCloneWhenFixed(bEnableCollisionOnNetworkCloneWhenFixed);
  8358.                 }
  8359.             }
  8360.         }
  8361.     }
  8362.  
  8363.     void PlayVehicleAnimScriptCommand(int VehicleIndex, const char *pAnimName, const char *pAnimDictNameStr)
  8364.     {
  8365.         const strStreamingObjectName    pAnimDictName( pAnimDictNameStr );
  8366.  
  8367.         if(!SCRIPT_VERIFY(pAnimName, "VEHICLE_TASK_PLAY_ANIM - Animation name is null"))
  8368.         {          
  8369.             return;
  8370.         }
  8371.  
  8372.         if(!SCRIPT_VERIFY(pAnimDictName.IsNotNull(), "VEHICLE_TASK_PLAY_ANIM - Animation dictionary name is null"))
  8373.         {          
  8374.             return;
  8375.         }
  8376.  
  8377.         CVehicle *pVehicle = NULL;
  8378.         if(NULL_IN_SCRIPTING_LANGUAGE!=VehicleIndex)
  8379.         {
  8380.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(VehicleIndex);
  8381.             if(!pVehicle)
  8382.             {          
  8383.                 return;
  8384.             }
  8385.         }
  8386.  
  8387.         //scriptAssertf(strlen(pAnimName)<ANIM_NAMELEN, "%s:TASK_PLAY_ANIM - Animation name is null : %s", CTheScripts::GetCurrentScriptNameAndProgramCounter(), pAnimName);
  8388.  
  8389.  
  8390.         aiTask* pTask = rage_new CTaskVehicleAnimation(pAnimDictName, pAnimName);
  8391.  
  8392.         if(pVehicle)
  8393.         {
  8394.             pVehicle->GetIntelligence()->AddTask(VEHICLE_TASK_TREE_SECONDARY, pTask, VEHICLE_TASK_SECONDARY_ANIM);
  8395.         }
  8396.     }
  8397.  
  8398.     void CommandVehicleTaskPlayAnim(int VehicleIndex, const char *pAnimDictName, const char *pAnimName)
  8399.     {
  8400.         PlayVehicleAnimScriptCommand(VehicleIndex, pAnimName, pAnimDictName);
  8401.     }
  8402.  
  8403.     bool CommandIsMoveBlendRatioStill(float fMoveBlendRatio)
  8404.     {
  8405.         return CPedMotionData::GetIsStill(fMoveBlendRatio);
  8406.     }
  8407.  
  8408.     bool CommandIsMoveBlendRatioWalking(float fMoveBlendRatio)
  8409.     {
  8410.         return CPedMotionData::GetIsWalking(fMoveBlendRatio);
  8411.     }
  8412.  
  8413.     bool CommandIsMoveBlendRatioRunning(float fMoveBlendRatio)
  8414.     {
  8415.         return CPedMotionData::GetIsRunning(fMoveBlendRatio);
  8416.     }
  8417.  
  8418.     bool CommandIsMoveBlendRatioSprinting(float fMoveBlendRatio)
  8419.     {
  8420.         return CPedMotionData::GetIsSprinting(fMoveBlendRatio);
  8421.     }
  8422.  
  8423.     bool CommandIsPedStill(int PedIndex)
  8424.     {
  8425.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8426.         if (pPed)
  8427.         {
  8428.             return pPed->GetMotionData()->GetIsStill();
  8429.         }
  8430.         return false;
  8431.     }
  8432.  
  8433.     bool CommandIsPedWalking(int PedIndex)
  8434.     {
  8435.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8436.         if (pPed)
  8437.         {
  8438.             return pPed->GetMotionData()->GetIsWalking();
  8439.         }
  8440.         return false;
  8441.     }
  8442.  
  8443.     bool CommandPedIsRunning(int PedIndex)
  8444.     {
  8445.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8446.         if (pPed)
  8447.         {
  8448.             return pPed->GetMotionData()->GetIsRunning();
  8449.         }
  8450.         return false;
  8451.     }
  8452.  
  8453.     bool CommandPedIsSprinting(int PedIndex)
  8454.     {
  8455.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8456.         if (pPed)
  8457.         {
  8458.             return pPed->GetMotionData()->GetIsSprinting();
  8459.         }
  8460.         return false;
  8461.     }
  8462.  
  8463.     bool CommandPedIsStrafing(int PedIndex)
  8464.     {
  8465.         const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8466.         if (pPed)
  8467.         {
  8468.             return pPed->GetMotionData()->GetIsStrafing();
  8469.         }
  8470.         return false;
  8471.     }
  8472.  
  8473.     /////////////////////////////////////////////////
  8474.     // Start the sweep task and point at an entity
  8475.     /////////////////////////////////////////////////
  8476.     void CommandTaskSweepAimEntity(int PedIndex, const char* pAnimDictName, const char* pLowAnimName, const char* pMedAnimName, const char* pHiAnimName, int runTime, int TargetEntityIndex, float turnRate, float fBlendInDuration)
  8477.     {
  8478.         const CEntity *pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(TargetEntityIndex);
  8479.         if( pEntity )
  8480.         {
  8481.             int             clipDictId = fwAnimManager::FindSlot(strStreamingObjectName(pAnimDictName)).Get();
  8482.             fwMvClipId      lowClipId(pLowAnimName);
  8483.             fwMvClipId      medClipId(pMedAnimName);
  8484.             fwMvClipId      highClipId(pHiAnimName);
  8485.  
  8486.             aiTask *pTask = rage_new CTaskGeneralSweep(clipDictId, lowClipId, medClipId, highClipId, runTime, pEntity, turnRate, fBlendInDuration);
  8487.             CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_GENERAL_SWEEP, "TASK_GENERAL_SWEEP");
  8488.         }
  8489.     }
  8490.  
  8491.     // Update the sweep task and point at an entity
  8492.     void CommandUpdateTaskSweepAimEntity(int PedIndex, int TargetEntityIndex)
  8493.     {
  8494.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  8495.         if(pPed)
  8496.         {
  8497.             // Check if the task is running
  8498.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType( CTaskTypes::TASK_GENERAL_SWEEP );
  8499.             if( Verifyf( pTask, "TaskGeneralSweep Isn't running, so cannot be updated!" ) )
  8500.             {
  8501.                 const CEntity *pEntity = CTheScripts::GetEntityToQueryFromGUID<CEntity>(TargetEntityIndex);
  8502.  
  8503.                 if( Verifyf( pEntity, "Tracking Entity doesn't exist!" ) )
  8504.                 {
  8505.                     static_cast<CTaskGeneralSweep*>(pTask)->SetTrackEntity(pEntity);
  8506.                 }
  8507.             }
  8508.         }
  8509.     }
  8510.  
  8511.     // Start the sweep task and point at a position
  8512.     void CommandTaskSweepAimPosition(int PedIndex, const char* pAnimDictName, const char* pLowAnimName, const char* pMedAnimName, const char* pHiAnimName, int runTime, const scrVector & scrVecCoors, float turnRate, float fBlendInDuration)
  8513.     {
  8514.         int             clipDictId = fwAnimManager::FindSlot(strStreamingObjectName(pAnimDictName)).Get();
  8515.         fwMvClipId      lowClipId(pLowAnimName);
  8516.         fwMvClipId      medClipId(pMedAnimName);
  8517.         fwMvClipId      highClipId(pHiAnimName);
  8518.         const Vector3   AimCoords = Vector3(scrVecCoors);
  8519.  
  8520.         aiTask *pTask = rage_new CTaskGeneralSweep(clipDictId, lowClipId, medClipId, highClipId, runTime, &AimCoords, turnRate, fBlendInDuration);
  8521.         CScriptPeds::GivePedScriptedTask(PedIndex, pTask, SCRIPT_TASK_GENERAL_SWEEP, "TASK_GENERAL_SWEEP");
  8522.     }
  8523.  
  8524.     // Update the sweep task and point at a position
  8525.     void CommandUpdateTaskSweepAimPosition(int PedIndex, const scrVector & scrVecCoors)
  8526.     {
  8527.         CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(PedIndex);
  8528.         if(pPed)
  8529.         {
  8530.             // Check if the task is running
  8531.             CTask* pTask = pPed->GetPedIntelligence()->FindTaskActiveByType( CTaskTypes::TASK_GENERAL_SWEEP );
  8532.             if( Verifyf( pTask, "TaskGeneralSweep Isn't running, so cannot be updated!" ) )
  8533.             {
  8534.                 const Vector3 AimCoords = Vector3(scrVecCoors);
  8535.                 static_cast<CTaskGeneralSweep*>(pTask)->SetTrackPosition(&AimCoords);
  8536.             }
  8537.         }
  8538.     }
  8539.  
  8540.     void CommandTaskArrestPed(int CopPedIndex, int CrookPedIndex)
  8541.     {
  8542.         scriptDisplayf("CommandTaskArrestPed\n");
  8543.  
  8544.         CPed *pCopPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(CopPedIndex, 0);
  8545.         CPed *pCrookPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(CrookPedIndex, CTheScripts::GUID_ASSERT_FLAGS_INCLUDE_CLONES);
  8546.         SCRIPT_ASSERT(pCrookPed, "TASK_ARREST_PED - You must specify the crook ped!");
  8547.         if(pCrookPed)
  8548.         {
  8549.             if(!pCopPed || !pCopPed->IsAPlayerPed())
  8550.             {
  8551.                 CTask* pTask = rage_new CTaskArrestPed(pCrookPed);
  8552.                 CScriptPeds::GivePedScriptedTask(CopPedIndex, pTask, SCRIPT_TASK_ARREST_PED, "TASK_ARREST_PED");
  8553.             }
  8554.         }
  8555.     }
  8556.  
  8557.     bool CommandIsPedRunningArrestTask(int PedIndex)
  8558.     {
  8559.         const CPed *pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(PedIndex);
  8560.         SCRIPT_ASSERT(pPed, "IS_PED_RUNNING_ARREST_TASK - You must specify the ped!");
  8561.         if(pPed)
  8562.         {
  8563.             CTaskPlayerOnFoot *pTaskPlayerOnFoot = static_cast< CTaskPlayerOnFoot * >(pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_PLAYER_ON_FOOT));
  8564.             if(pTaskPlayerOnFoot)
  8565.             {
  8566.                 aiTask *pTask = pTaskPlayerOnFoot->GetScriptedTask();
  8567.                 if(pTask && pTask->GetTaskType() == CTaskTypes::TASK_ARREST_PED2)
  8568.                 {
  8569.                     return true;
  8570.                 }
  8571.             }
  8572.  
  8573.             CTaskArrestPed2 *pTaskArrestPed2 = static_cast< CTaskArrestPed2 * >(pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_ARREST_PED2));
  8574.             if(pTaskArrestPed2)
  8575.             {
  8576.                 return true;
  8577.             }
  8578.         }
  8579.  
  8580.         return false;
  8581.     }
  8582.  
  8583.     bool CommandIsArrestTypeValid(int CopPedIndex, int CrookPedIndex, int ArrestType)
  8584.     {
  8585.         const CPed *pCopPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(CopPedIndex);
  8586.         SCRIPT_ASSERT(pCopPed, "IS_ARREST_TYPE_VALID - You must specify the cop ped!");
  8587.         const CPed *pCrookPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(CrookPedIndex);
  8588.         SCRIPT_ASSERT(pCrookPed, "IS_ARREST_TYPE_VALID - You must specify the crook ped!");
  8589.         SCRIPT_ASSERT(ArrestType >= 0 && ArrestType < CArrestHelpers::ARREST_COUNT, "IS_ARREST_TYPE_VALID - You must specify a valid ArrestType!");
  8590.         if(pCopPed && pCrookPed && ArrestType >= 0 && ArrestType < CArrestHelpers::ARREST_COUNT)
  8591.         {
  8592.             return CArrestHelpers::IsArrestTypeValid(pCopPed, pCrookPed, ArrestType);
  8593.         }
  8594.  
  8595.         return false;
  8596.     }
  8597.  
  8598.     bool CommandIsPedBeingArrested(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8599.     {
  8600. #if ENABLE_TASKS_ARREST_CUFFED
  8601.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8602.         {
  8603.             CTaskCuffed* pTaskCuffed = static_cast<CTaskCuffed*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CUFFED));
  8604.             return pTaskCuffed && pTaskCuffed->IsBeingCuffed();
  8605.         }
  8606. #endif // ENABLE_TASKS_ARREST_CUFFED
  8607.         return false;
  8608.     }
  8609.  
  8610.     int CommandGetPedArrester(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8611.     {
  8612. #if ENABLE_TASKS_ARREST_CUFFED
  8613.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8614.         {
  8615.             CTaskCuffed* pTaskCuffed = static_cast<CTaskCuffed*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CUFFED));
  8616.             if (pTaskCuffed && pTaskCuffed->IsBeingCuffed())
  8617.             {
  8618.                 if (CPed* pCustodianPed = pTaskCuffed->GetArrestPed())
  8619.                 {
  8620.                     return CTheScripts::GetGUIDFromEntity(*pCustodianPed);
  8621.                 }
  8622.             }
  8623.         }
  8624. #endif // ENABLE_TASKS_ARREST_CUFFED
  8625.         return 0;
  8626.     }
  8627.  
  8628.     bool CommandIsPedCuffed(int iPedIndex)
  8629.     {
  8630.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8631.         {
  8632.             // Just check the handcuffed flag rather than checking for the cuffed state,
  8633.             // as other higher priority states may have bumped it off temporarily.
  8634.             return pPed->GetPedConfigFlag(CPED_CONFIG_FLAG_IsHandCuffed);
  8635.         }
  8636.  
  8637.         return false;
  8638.     }
  8639.  
  8640.     int CommandGetPedCustodian(int iPedIndex)
  8641.     {
  8642.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8643.         {
  8644.             if (CPed* pCustodianPed = pPed->GetCustodian())
  8645.             {
  8646.                 return CTheScripts::GetGUIDFromEntity(*pCustodianPed);
  8647.             }
  8648.         }
  8649.  
  8650.         return 0;
  8651.     }
  8652.  
  8653.     bool CommandIsPedBeingUncuffed(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8654.     {
  8655. #if ENABLE_TASKS_ARREST_CUFFED
  8656.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8657.         {
  8658.             CTaskCuffed* pTaskCuffed = static_cast<CTaskCuffed*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CUFFED));
  8659.             return pTaskCuffed && pTaskCuffed->IsBeingUncuffed();
  8660.         }
  8661. #endif // ENABLE_TASKS_ARREST_CUFFED
  8662.         return false;
  8663.     }
  8664.  
  8665.     int CommandGetPedUncuffer(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8666.     {
  8667. #if ENABLE_TASKS_ARREST_CUFFED
  8668.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8669.         {
  8670.             CTaskCuffed* pTaskCuffed = static_cast<CTaskCuffed*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CUFFED));
  8671.             if (pTaskCuffed && pTaskCuffed->IsBeingUncuffed())
  8672.             {
  8673.                 if (CPed* pCustodianPed = pTaskCuffed->GetArrestPed())
  8674.                 {
  8675.                     return CTheScripts::GetGUIDFromEntity(*pCustodianPed);
  8676.                 }
  8677.             }
  8678.         }
  8679. #endif // ENABLE_TASKS_ARREST_CUFFED
  8680.         return 0;
  8681.     }
  8682.  
  8683.     bool CommandIsPedArresting(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8684.     {
  8685. #if ENABLE_TASKS_ARREST_CUFFED
  8686.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8687.         {
  8688.             if (CTaskArrest* pTaskArrest = static_cast<CTaskArrest*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_ARREST)))
  8689.             {
  8690.                 return pTaskArrest->IsArresting();
  8691.             }
  8692.         }
  8693. #endif // ENABLE_TASKS_ARREST_CUFFED
  8694.         return false;
  8695.     }
  8696.  
  8697.     int CommandGetPedArrestingTarget(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8698.     {
  8699. #if ENABLE_TASKS_ARREST_CUFFED
  8700.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8701.         {
  8702.             if (CTaskArrest* pTaskArrest = static_cast<CTaskArrest*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_ARREST)))
  8703.             {
  8704.                 if (pTaskArrest->IsArresting())
  8705.                 {
  8706.                     if (CPed* pTargetPed = pTaskArrest->GetTargetPed())
  8707.                     {
  8708.                         return CTheScripts::GetGUIDFromEntity(*pTargetPed);
  8709.                     }
  8710.                 }
  8711.             }
  8712.         }
  8713. #endif // ENABLE_TASKS_ARREST_CUFFED
  8714.         return 0;
  8715.     }
  8716.  
  8717.     bool CommandIsPedTakingCustody(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8718.     {
  8719. #if ENABLE_TASKS_ARREST_CUFFED
  8720.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8721.         {
  8722.             if (CTaskArrest* pTaskArrest = static_cast<CTaskArrest*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_ARREST)))
  8723.             {
  8724.                 return pTaskArrest->IsTakingCustody();
  8725.             }
  8726.  
  8727.         }
  8728. #endif // ENABLE_TASKS_ARREST_CUFFED
  8729.         return false;
  8730.     }
  8731.  
  8732.     int CommandGetPedTakingCustodyTarget(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8733.     {
  8734. #if ENABLE_TASKS_ARREST_CUFFED
  8735.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8736.         {      
  8737.             if (CTaskArrest* pTaskArrest = static_cast<CTaskArrest*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_ARREST)))
  8738.             {
  8739.                 if (pTaskArrest->IsTakingCustody())
  8740.                 {
  8741.                     if (CPed* pTargetPed = pTaskArrest->GetTargetPed())
  8742.                     {
  8743.                         return CTheScripts::GetGUIDFromEntity(*pTargetPed);
  8744.                     }
  8745.                 }
  8746.             }
  8747.         }
  8748. #endif // ENABLE_TASKS_ARREST_CUFFED
  8749.         return 0;
  8750.     }
  8751.  
  8752.     bool CommandIsPedBeingTakenIntoCustody(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8753.     {
  8754. #if ENABLE_TASKS_ARREST_CUFFED
  8755.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8756.         {
  8757.             if(!pPed->GetPedConfigFlag(CPED_CONFIG_FLAG_IsInCustody))
  8758.             {
  8759.                 CTaskInCustody* pTaskInCustody = static_cast<CTaskInCustody*>(pPed->GetPedIntelligence()->FindTaskByType(CTaskTypes::TASK_IN_CUSTODY));
  8760.                 if (pTaskInCustody)
  8761.                 {
  8762.                     //! Ask in custody task.
  8763.                     return pTaskInCustody->IsBeingTakenIntoCustody();
  8764.                 }
  8765.                 else if(pPed->GetCustodian())
  8766.                 {
  8767.                     //! Having a custodian indicates that someone is trying to put you into custody.
  8768.                     return true;
  8769.                 }
  8770.             }
  8771.         }
  8772. #endif // ENABLE_TASKS_ARREST_CUFFED
  8773.         return false;
  8774.     }
  8775.  
  8776.     bool CommandIsPedUncuffing(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8777.     {
  8778. #if ENABLE_TASKS_ARREST_CUFFED
  8779.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8780.         {
  8781.             if (CTaskArrest* pTaskArrest = static_cast<CTaskArrest*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_ARREST)))
  8782.             {
  8783.                 return pTaskArrest->IsUnCuffing();
  8784.             }
  8785.         }
  8786. #endif // ENABLE_TASKS_ARREST_CUFFED
  8787.         return false;
  8788.     }
  8789.  
  8790.     int CommandGetPedUncuffingTarget(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8791.     {
  8792. #if ENABLE_TASKS_ARREST_CUFFED
  8793.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8794.         {
  8795.             if (CTaskArrest* pTaskArrest = static_cast<CTaskArrest*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_ARREST)))
  8796.             {
  8797.                 if(pTaskArrest->IsUnCuffing())
  8798.                 {
  8799.                     if (CPed* pTargetPed = pTaskArrest->GetTargetPed())
  8800.                     {
  8801.                         return CTheScripts::GetGUIDFromEntity(*pTargetPed);
  8802.                     }
  8803.                 }
  8804.             }
  8805.         }
  8806. #endif // ENABLE_TASKS_ARREST_CUFFED
  8807.         return 0;
  8808.     }
  8809.  
  8810.     void CommandCuffPed(int iPedIndex)
  8811.     {
  8812.         if (CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex))
  8813.         {
  8814.             if(SCRIPT_VERIFY(!pPed->IsNetworkClone(), "CUFF_PED - Can't cuff cloned ped!"))
  8815.             {
  8816.                 // Force the ped to be handcuffed immediately
  8817.                 pPed->SetPedConfigFlag(CPED_CONFIG_FLAG_IsHandCuffed, true);
  8818.             }
  8819.         }
  8820.     }
  8821.  
  8822.     void CommandUncuffPed(int iPedIndex)
  8823.     {
  8824.         if (CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex))
  8825.         {
  8826.             if(SCRIPT_VERIFY(!pPed->IsNetworkClone(), "UNCUFF_PED - Can't remove clone ped from cuffs!"))
  8827.             {
  8828.                 // Just unset the handcuffed flag, this will kick the ped out of the cuffed task
  8829.                 pPed->SetPedConfigFlag(CPED_CONFIG_FLAG_IsHandCuffed, false);
  8830.             }
  8831.         }
  8832.     }
  8833.  
  8834.     void CommandTaskTakeCustody(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iCustodianIndex), int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8835.     {
  8836. #if ENABLE_TASKS_ARREST_CUFFED
  8837.         if (CPed* pCustodianPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iCustodianIndex))
  8838.         {
  8839.             CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex, 0);
  8840.             if(pPed)
  8841.             {
  8842.                 if(SCRIPT_VERIFY(!pPed->IsNetworkClone(), "TASK_TAKE_CUSTODY - Must set on ped owner's, not clone!"))
  8843.                 {
  8844.                     pPed->SetInCustody(true, pCustodianPed);
  8845.                     CTaskInCustody* pTaskInCustody = rage_new CTaskInCustody(pCustodianPed, true);
  8846.                     CScriptPeds::GivePedScriptedTask(iPedIndex, pTaskInCustody, SCRIPT_TASK_IN_CUSTODY, "TASK_IN_CUSTODY");
  8847.                 }
  8848.             }
  8849.         }
  8850. #endif //ENABLE_TASKS_ARREST_CUFFED
  8851.     }
  8852.  
  8853.     void CommandRemovePedFromCustody(int iPedIndex)
  8854.     {
  8855.         if (CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex))
  8856.         {
  8857.             if(SCRIPT_VERIFY(!pPed->IsNetworkClone(), "REMOVE_PED_FROM_CUSTODY - Can't remove clone ped from custody!"))
  8858.             {
  8859.                 pPed->SetInCustody(false, NULL);
  8860.             }
  8861.         }
  8862.     }
  8863.  
  8864.     float CommandGetPedArrestPhase(int ENABLE_TASKS_ARREST_CUFFED_ONLY(iPedIndex))
  8865.     {
  8866. #if ENABLE_TASKS_ARREST_CUFFED
  8867.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8868.         {
  8869.             //! Arrest Task.
  8870.             CTaskArrest* pTaskArrest = static_cast<CTaskArrest*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_ARREST));
  8871.             if (pTaskArrest)
  8872.             {
  8873.                 return pTaskArrest->GetPhase();
  8874.             }
  8875.             //! Cuffed Task
  8876.             CTaskCuffed* pTaskCuffed = static_cast<CTaskCuffed*>(pPed->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_CUFFED));
  8877.             if (pTaskCuffed)
  8878.             {
  8879.                 return pTaskCuffed->GetPhase();
  8880.             }
  8881.             //! In Custody Task.
  8882.             if(pPed->GetCustodian())
  8883.             {
  8884.                 CTaskArrest* pTaskArrest = static_cast<CTaskArrest*>(pPed->GetCustodian()->GetPedIntelligence()->FindTaskActiveByType(CTaskTypes::TASK_ARREST));
  8885.                 if(pTaskArrest && pTaskArrest->IsTakingCustody())
  8886.                 {
  8887.                     return pTaskArrest->GetPhase();
  8888.                 }
  8889.             }
  8890.         }
  8891. #endif // ENABLE_TASKS_ARREST_CUFFED
  8892.         return 0.0f;
  8893.     }
  8894.  
  8895.     int CommandGetPedPotentialArrestTarget(int iPedIndex)
  8896.     {
  8897.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8898.         {
  8899.             if (CPed* pTargetPed = pPed->GetArrestTarget())
  8900.             {
  8901.                 return CTheScripts::GetGUIDFromEntity(*pTargetPed);
  8902.             }
  8903.         }
  8904.  
  8905.         return 0;
  8906.     }
  8907.  
  8908.     int CommandGetPedPotentialUncuffTarget(int iPedIndex)
  8909.     {
  8910.         if (const CPed* pPed = CTheScripts::GetEntityToQueryFromGUID<CPed>(iPedIndex))
  8911.         {
  8912.             if (CPed* pTargetPed = pPed->GetUncuffTarget())
  8913.             {
  8914.                 return CTheScripts::GetGUIDFromEntity(*pTargetPed);
  8915.             }
  8916.         }
  8917.  
  8918.         return 0;
  8919.     }
  8920.  
  8921.     void CommandSetPedCustodyOverrideFollowDistance(int iPedIndex, float fFollowDistance)
  8922.     {
  8923.         if (CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex))
  8924.         {
  8925.             pPed->SetCustodyFollowDistanceOverride(fFollowDistance);
  8926.         }
  8927.     }
  8928.  
  8929.     void CommandWarpIntoLeadersVehicle(int iPedIndex)
  8930.     {
  8931.         if (CPed* pPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedIndex))
  8932.         {
  8933.             pPed->SetPedConfigFlag(CPED_CONFIG_FLAG_WarpIntoLeadersVehicle, true);
  8934.         }
  8935.     }
  8936.  
  8937.     void CommandTaskVehicleGotoNavmesh(int iPedID, int iVehicleID, const scrVector & scrVecCoors,
  8938.         float fCruiseSpeed, int iDrivingFlags, float fTargetReached)
  8939.     {
  8940.         CVehicle* pVehicle = NULL;
  8941.  
  8942.         if(SCRIPT_VERIFY(NULL_IN_SCRIPTING_LANGUAGE != iVehicleID, "TASK_VEHICLE_GOTO_NAVMESH - You must specify a vehicle!"))
  8943.         {
  8944.             pVehicle = CTheScripts::GetEntityToModifyFromGUID<CVehicle>(iVehicleID);
  8945.         }
  8946.  
  8947.         if(!pVehicle)
  8948.         {
  8949.             return;
  8950.         }
  8951.  
  8952.         sVehicleMissionParams params;
  8953.         params.m_iDrivingFlags = iDrivingFlags;
  8954.         if (fCruiseSpeed > 0.0f)
  8955.         {
  8956.             params.m_fCruiseSpeed = fCruiseSpeed;
  8957.         }
  8958.         else
  8959.         {
  8960.             params.m_fCruiseSpeed = 64.0f;
  8961.         }
  8962.         Vector3 vTargetPos(scrVecCoors);
  8963.         params.SetTargetPosition(vTargetPos);
  8964.         params.m_fTargetArriveDist = fTargetReached;
  8965.  
  8966.         ASSERT_ONLY(params.IsTargetValid());
  8967.  
  8968.         CTaskVehicleGoToNavmesh* pNavmeshTask = rage_new CTaskVehicleGoToNavmesh(params);
  8969.  
  8970.         CTask* pTask = rage_new CTaskControlVehicle(pVehicle, pNavmeshTask);
  8971.         CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_VEHICLE_GOTO_NAVMESH, "TASK_VEHICLE_GOTO_NAVMESH");
  8972.     }
  8973.  
  8974.     void CommandGivePedAgitatedTaskConfront(int iPedID, int iAgitatorPedID)
  8975.     {
  8976.         if( SCRIPT_VERIFYF((iPedID != NULL_IN_SCRIPTING_LANGUAGE && iAgitatorPedID != NULL_IN_SCRIPTING_LANGUAGE), "TASK_AGITATED_ACTION_CONFRONT_RESPONSE - iPedID (%i) or iAgitatorPedID(%i) is NULL",iPedID,iAgitatorPedID) )
  8977.         {
  8978.             CPed* pTargetPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iPedID);
  8979.             if (SCRIPT_VERIFYF((pTargetPed && !pTargetPed->IsAPlayerPed()),"TASK_AGITATED_ACTION_CONFRONT_RESPONSE is trying to give agitated task to a player ped or could not find ped with this ID - %i!", iPedID))
  8980.             {
  8981.                 CPed* pAgitatorPed = CTheScripts::GetEntityToModifyFromGUID<CPed>(iAgitatorPedID);
  8982.                 if (SCRIPT_VERIFYF(pAgitatorPed,"TASK_AGITATED_ACTION_CONFRONT_RESPONSE could not find agitator ped with this ID - %i", iAgitatorPedID))
  8983.                 {
  8984.                     CTaskConfront* pConfrontTask = rage_new CTaskConfront(pAgitatorPed);
  8985.                     CTask* pTask = rage_new CTaskAgitatedAction(pConfrontTask);
  8986.  
  8987.                     pTargetPed->SetPedConfigFlag(CPED_CONFIG_FLAG_CanBeAgitated, true);
  8988.                     pTargetPed->SetPedConfigFlag(CPED_CONFIG_FLAG_IsAgitated, true);
  8989.  
  8990.                     CTaskAgitated* pAgitatedTask = rage_new CTaskAgitated(pAgitatorPed);
  8991.                     pAgitatedTask->SetStartedFromScript(true);
  8992.  
  8993.                     pTargetPed->GetPedIntelligence()->AddTaskSecondary( pAgitatedTask, PED_TASK_SECONDARY_PARTIAL_ANIM );
  8994.  
  8995.                     CScriptPeds::GivePedScriptedTask( iPedID, pTask, SCRIPT_TASK_AGITATED_ACTION, "TASK_AGITATED_ACTION");
  8996.                 }
  8997.             }
  8998.         }
  8999.     }
  9000.  
  9001.     /////////////////////////////////////////////////
  9002.  
  9003.  
  9004.     void SetupScriptCommands()
  9005.     {
  9006.         SCR_REGISTER_SECURE(TASK_PAUSE,0x19c58ba8a663b64b,                                  CommandTaskPause                        );
  9007.         SCR_REGISTER_SECURE(TASK_STAND_STILL,0x83f5bcfffba26699,                            CommandTaskStandStill                   );
  9008.         SCR_REGISTER_SECURE(TASK_JUMP,0x012983f49702416c,                                   CommandTaskJump                         );
  9009.         SCR_REGISTER_SECURE(TASK_COWER,0x402a537158a551bd,                                  CommandTaskCower                        );
  9010.         SCR_REGISTER_SECURE(TASK_HANDS_UP,0x3598f95a00026dd8,                               CommandTaskHandsUp                      );
  9011.         SCR_REGISTER_SECURE(UPDATE_TASK_HANDS_UP_DURATION,0x46a203feec0ecef4,               CommandUpdateTaskHandsUpDuration        );
  9012.         SCR_REGISTER_UNUSED(TASK_DUCK,0x54b5addaf8a132f7,                                   CommandTaskDuck                         );
  9013.         SCR_REGISTER_SECURE(TASK_OPEN_VEHICLE_DOOR,0xf9d446af83e7a624,                      CommandTaskOpenVehicleDoor              );
  9014.         SCR_REGISTER_SECURE(TASK_ENTER_VEHICLE,0xb486640392ec50bb,                          CommandTaskEnterVehicle                 );
  9015.         SCR_REGISTER_SECURE(TASK_LEAVE_VEHICLE,0x02f1caac7cb77e47,                          CommandTaskLeaveVehicle                 );
  9016.         SCR_REGISTER_UNUSED(TASK_MOUNT_ANIMAL,0x3f0ad0f6b2f34df6,                           CommandTaskMountAnimal                  );
  9017.         SCR_REGISTER_UNUSED(TASK_DISMOUNT_ANIMAL,0xfe2e56c600a68fce,                        CommandTaskDismountAnimal               );
  9018.         SCR_REGISTER_SECURE(TASK_GET_OFF_BOAT,0x9aef335a2f73e00a,                           CommandTaskGetOffBoat                   );
  9019.         SCR_REGISTER_SECURE(TASK_SKY_DIVE,0x622c61505349f582,                               CommandTaskSkyDive                      );
  9020.         SCR_REGISTER_SECURE(TASK_PARACHUTE,0xb7121915a3797c65,                              CommandTaskParachute                    );
  9021.         SCR_REGISTER_SECURE(TASK_PARACHUTE_TO_TARGET,0xf323d744a727a4a2,                    CommandTaskParachuteToTarget            );
  9022.         SCR_REGISTER_SECURE(SET_PARACHUTE_TASK_TARGET,0x878fd7e3c8110527,                   CommandSetParachuteTaskTarget           );
  9023.         SCR_REGISTER_SECURE(SET_PARACHUTE_TASK_THRUST,0x3ca038370f6e3223,                   CommandSetParachuteTaskThrust           );
  9024.         SCR_REGISTER_UNUSED(SET_PARACHUTE_TASK_TARGET_ENTITY,0x63b1ba4dbcd822ac,            CommandSetParachuteTaskTargetEntity     );
  9025.         SCR_REGISTER_UNUSED(TASK_JETPACK,0x23c36cbde291e36c,                                CommandTaskJetpack                      );
  9026.         SCR_REGISTER_UNUSED(TASK_JETPACK_GO_TO_COORD,0x586dae563b9e50c6,                    CommandTaskJetpackGoToCoord             );
  9027.         SCR_REGISTER_UNUSED(TASK_JETPACK_GO_TO_ENTITY,0x67794f749799bd7d,                   CommandTaskJetpackGoToEntity            );
  9028.         SCR_REGISTER_UNUSED(TASK_JETPACK_SHOOT_AT_COORD,0x6ebd50cacaab197e,                 CommandTaskJetpackShootAtCoord          );
  9029.         SCR_REGISTER_UNUSED(TASK_JETPACK_SHOOT_AT_ENTITY,0xa767f2d717d074f9,                CommandTaskJetpackShootAtEntity         );
  9030.         SCR_REGISTER_UNUSED(TASK_JETPACK_STOP_SHOOTING,0xafd3096512ccc6cd,                  CommandTaskJetpackStopShooting          );
  9031.         SCR_REGISTER_SECURE(TASK_RAPPEL_FROM_HELI,0x01ddcf3e0afad31b,                       CommandTaskRappelFromHeli               );
  9032.         SCR_REGISTER_UNUSED(TASK_DRAG_PED_TO_COORD,0xb269aa2c4e7f407c,                      CommandTaskDragPedToCoord               );
  9033.  
  9034.         SCR_REGISTER_SECURE(TASK_VEHICLE_DRIVE_TO_COORD,0x3b8f94419979a0b1,             CommandTaskVehicleDriveToCoord          );
  9035.         SCR_REGISTER_SECURE(TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE,0x70d024128ce0c114,       CommandTaskVehicleDriveToCoordLongRange);
  9036.         SCR_REGISTER_SECURE(TASK_VEHICLE_DRIVE_WANDER,0xad6cdbcda713560a,                   CommandTaskVehicleDriveWander           );
  9037.         SCR_REGISTER_SECURE(TASK_FOLLOW_TO_OFFSET_OF_ENTITY,0x6fce069e4940878c,         CommandTaskFollowToOffsetOfEntity           );
  9038.         SCR_REGISTER_UNUSED(TASK_FOLLOW_TO_OFFSET_OF_PICKUP,0x6f91735acae34873,         CommandTaskFollowToOffsetOfPickup);
  9039.         SCR_REGISTER_SECURE(TASK_GO_STRAIGHT_TO_COORD,0x13c3030981ea7c3b,                   CommandTaskGoStraightToCoord            );
  9040.         SCR_REGISTER_SECURE(TASK_GO_STRAIGHT_TO_COORD_RELATIVE_TO_ENTITY,0xc98e8d7f0d9d4795, CommandTaskGoStraightToCoordRelativeToEntity   );
  9041.         SCR_REGISTER_SECURE(TASK_ACHIEVE_HEADING,0x30e00b59448ab97e,                        CommandTaskAchieveHeading               );
  9042.         SCR_REGISTER_SECURE(TASK_FLUSH_ROUTE,0x83a64e1fe4669225,                            CommandFlushRoute                       );
  9043.         SCR_REGISTER_SECURE(TASK_EXTEND_ROUTE,0x9d38259cb54342be,                           CommandExtendRoute                      );
  9044.         SCR_REGISTER_SECURE(TASK_FOLLOW_POINT_ROUTE,0x790dea4e63d61baa,                 CommandTaskFollowPointRoute             );
  9045.         SCR_REGISTER_SECURE(TASK_GO_TO_ENTITY,0xc149e50fbb27dd70,                           CommandTaskGoToEntity                   );
  9046.         SCR_REGISTER_SECURE(TASK_SMART_FLEE_COORD,0x84918839a90c954c,                       CommandTaskSmartFleeCoord               );
  9047.         SCR_REGISTER_SECURE(TASK_SMART_FLEE_PED,0x7734082b0edb0be0,                     CommandTaskSmartFleePed                 );
  9048.         SCR_REGISTER_UNUSED(TASK_REACT_AND_FLEE_COORD,0x596713d55325f5c9,                   CommandTaskReactAndFleeCoord            );
  9049.         SCR_REGISTER_SECURE(TASK_REACT_AND_FLEE_PED,0x7a9da0518e81ec15,                 CommandTaskReactAndFleePed              );
  9050.         SCR_REGISTER_UNUSED(TASK_SHOCKING_EVENT_BACK_AWAY,0xa19ac1e1c0d01b42,               CommandTaskShockingEventBackAway        );
  9051.         SCR_REGISTER_UNUSED(TASK_SHOCKING_EVENT_HURRY_AWAY,0x4e742aa861140b96,              CommandTaskShockingEventHurryAway       );
  9052.         SCR_REGISTER_SECURE(TASK_SHOCKING_EVENT_REACT,0xb5bc9e2b43334cef,                   CommandTaskShockingEventReact           );
  9053.         SCR_REGISTER_SECURE(TASK_WANDER_IN_AREA,0x5315f7ac22dc95f1,                     CommandTaskWanderInArea                 );
  9054.         SCR_REGISTER_SECURE(TASK_WANDER_STANDARD,0xd86a0bc9cc0a625a,                        CommandTaskWanderStandard               );
  9055.         SCR_REGISTER_SECURE(TASK_WANDER_SPECIFIC,0x26f1da9738c260f2,                        CommandTaskWanderSpecific);
  9056.         SCR_REGISTER_SECURE(TASK_VEHICLE_PARK,0x5b7af57d366861f2,                           CommandTaskVehiclePark                  );
  9057.  
  9058.         SCR_REGISTER_SECURE(TASK_STEALTH_KILL,0xe2c1d6fa4e5ea991,                           CommandTaskStealthKill                  );
  9059.         SCR_REGISTER_SECURE(TASK_PLANT_BOMB,0xd9ab2b08ce49a043,                         CommandTaskPlantBomb                    );
  9060.  
  9061.         SCR_REGISTER_UNUSED(TASK_SHARK_CIRCLE_COORD,0xfff1232e7a485388,                 CommandTaskSharkCircleCoord             );
  9062.         SCR_REGISTER_UNUSED(TASK_SHARK_CIRCLE_PED,0xfd4e7488138e4f25,                       CommandTaskSharkCirclePed               );
  9063.  
  9064.         SCR_REGISTER_SECURE(TASK_FOLLOW_NAV_MESH_TO_COORD,0x7d1424753688ee7a,               CommandTaskFollowNavMeshToCoord         );
  9065.         scrThread::RegisterCommand(SCRHASH("TASK_FOLLOW_NAV_MESH_TO_COORD_ADVANCED",0x72f317bc03266125), CommandTaskFollowNavMeshToCoordAdvanced_ScrStruct SCRIPT_DEBUGGING_ONLY(, "TASK_FOLLOW_NAV_MESH_TO_COORD_ADVANCED", __FILE__, scrSignature()));
  9066.  
  9067.         SCR_REGISTER_SECURE(SET_PED_PATH_CAN_USE_CLIMBOVERS,0xcacf57ad414acc75,         CommandSetPedPathCanUseClimbOvers       );
  9068.         SCR_REGISTER_SECURE(SET_PED_PATH_CAN_USE_LADDERS,0x32bb80e6e576379a,                CommandSetPedPathCanUseLadders          );
  9069.         SCR_REGISTER_SECURE(SET_PED_PATH_CAN_DROP_FROM_HEIGHT,0x91d9c55e11392690,           CommandSetPedPathCanDropFromHeight      );
  9070.         SCR_REGISTER_SECURE(SET_PED_PATH_CLIMB_COST_MODIFIER,0xd0b0e285f00a8b61,            CommandSetPedPathClimbCostModifier      );
  9071.         SCR_REGISTER_SECURE(SET_PED_PATH_MAY_ENTER_WATER,0xbe74e997fb714956,                CommandSetPedToMayEnterWater            );
  9072.         SCR_REGISTER_SECURE(SET_PED_PATH_PREFER_TO_AVOID_WATER,0x8bb90eda0a7b150e,          CommandSetPedPreferToAvoidWater         );
  9073.         SCR_REGISTER_SECURE(SET_PED_PATH_AVOID_FIRE,0x9ef69bf12b6fbcb3,                 CommandSetPedPathAvoidFire          );
  9074.  
  9075.         SCR_REGISTER_SECURE(SET_GLOBAL_MIN_BIRD_FLIGHT_HEIGHT,0xb133bc406357c5a5,           CommandSetGlobalMinBirdFlightHeight     );
  9076.        
  9077.        
  9078.         SCR_REGISTER_SECURE(GET_NAVMESH_ROUTE_DISTANCE_REMAINING,0x9fa616df1ef7172a,        CommandGetNavMeshRouteDistanceRemaining );
  9079.         SCR_REGISTER_SECURE(GET_NAVMESH_ROUTE_RESULT,0xb02b2cd950b6ba04,                    CommandGetNavMeshRouteResult            );
  9080.         SCR_REGISTER_SECURE(IS_CONTROLLED_VEHICLE_UNABLE_TO_GET_TO_ROAD,0xa8a55d2ba7497f6f, CommandIsControlledVehicleUnableToGetToRoad );
  9081.  
  9082.         SCR_REGISTER_SECURE(TASK_GO_TO_COORD_ANY_MEANS,0x9603c0ec536c6425,                  CommandTaskGoToCoordAnyMeans            );
  9083.         SCR_REGISTER_SECURE(TASK_GO_TO_COORD_ANY_MEANS_EXTRA_PARAMS,0x110dedd855267ad4, CommandTaskGoToCoordAnyMeansExtraParams );
  9084.         SCR_REGISTER_SECURE(TASK_GO_TO_COORD_ANY_MEANS_EXTRA_PARAMS_WITH_CRUISE_SPEED,0xfaaa6a6a67097054, CommandTaskGoToCoordAnyMeansExtraParamsWithCruiseSpeed    );
  9085.  
  9086.         //////////////////////////////////////////////////////////////////////////
  9087.         //Animation task commands
  9088.         //////////////////////////////////////////////////////////////////////////
  9089.  
  9090.         SCR_REGISTER_SECURE(TASK_PLAY_ANIM,0x49d97b076e3590ac,                              CommandTaskPlayAnim                     );
  9091.         SCR_REGISTER_SECURE(TASK_PLAY_ANIM_ADVANCED,0x246c656f8e525dc7,                 CommandTaskPlayAnimAdvanced             );
  9092.         SCR_REGISTER_SECURE(STOP_ANIM_TASK,0x227b2dd85a708e68,                              CommandStopAnimTask                     );
  9093.  
  9094.         SCR_REGISTER_SECURE(TASK_SCRIPTED_ANIMATION,0x86577f7f045f84c7,                 CommandTaskScriptedAnimation            );
  9095.         SCR_REGISTER_SECURE(PLAY_ENTITY_SCRIPTED_ANIM,0xc51d165944c64ca6,                   CommandPlayEntityScriptedAnimation      ); 
  9096.         SCR_REGISTER_UNUSED(START_ANIM_PLAYBACK,0x8fc2aa42fd9fa172,                     CommandStartAnimPlayback                );
  9097.         SCR_REGISTER_SECURE(STOP_ANIM_PLAYBACK,0xe3258b995b832e6a,                          CommandStopAnimPlayback                 );
  9098.         SCR_REGISTER_UNUSED(SET_ANIM_CLIP,0xf962040546b0d2d7,                               CommandTaskClipSetClip                  );
  9099.         SCR_REGISTER_SECURE(SET_ANIM_WEIGHT,0xecd4da16b454528f,                         CommandTaskClipSetBlendWeight           );
  9100.         SCR_REGISTER_UNUSED(SET_ANIM_FILTER,0x979aba5e5d177c74,                         CommandTaskClipSetFilter                );
  9101.         SCR_REGISTER_SECURE(SET_ANIM_PHASE,0x60f9850ce23ed209,                              CommandTaskClipSetPhase                 );
  9102.         SCR_REGISTER_SECURE(SET_ANIM_RATE,0x1cbf84e41b1bfe92,                               CommandTaskClipSetRate                  );
  9103.         SCR_REGISTER_SECURE(SET_ANIM_LOOPED,0x8bf7b8753e6fadd0,                         CommandTaskClipSetLooped                );
  9104.  
  9105.         SCR_REGISTER_SECURE(TASK_PLAY_PHONE_GESTURE_ANIMATION,0xb8ea44dc2c77645c,           CommandTaskPlayPhoneGestureAnimation    );
  9106.         SCR_REGISTER_SECURE(TASK_STOP_PHONE_GESTURE_ANIMATION,0xfcd42d914e921580,           CommandTaskStopPhoneGestureAnimation    );
  9107.         SCR_REGISTER_SECURE(IS_PLAYING_PHONE_GESTURE_ANIM,0x7ce0cfe0533867b0,               CommandIsPlayingPhoneGestureAnim        );
  9108.         SCR_REGISTER_SECURE(GET_PHONE_GESTURE_ANIM_CURRENT_TIME,0x198866ca14785166,     CommandGetPhoneGestureAnimCurrentTime   );
  9109.         SCR_REGISTER_SECURE(GET_PHONE_GESTURE_ANIM_TOTAL_TIME,0xc20701b83e0998c5,           CommandGetPhoneGestureAnimTotalTime     );
  9110.  
  9111.         SCR_REGISTER_SECURE(TASK_VEHICLE_PLAY_ANIM,0x8da8932b29e225ed,                      CommandVehicleTaskPlayAnim              );
  9112.         SCR_REGISTER_SECURE(TASK_LOOK_AT_COORD,0xe1e1af00ca06a2b7,                          CommandTaskLookAtCoord                  );
  9113.         SCR_REGISTER_SECURE(TASK_LOOK_AT_ENTITY,0xf30f15f203736de4,                     CommandTaskLookAtEntity                 );
  9114.         SCR_REGISTER_SECURE(TASK_CLEAR_LOOK_AT,0xc89ea639a6f338a6,                          CommandClearLookAt                      );
  9115.        
  9116.         SCR_REGISTER_SECURE(OPEN_SEQUENCE_TASK,0xa888f8cc04f25cc8,                          CommandOpenSequenceTask                 );
  9117.         SCR_REGISTER_SECURE(CLOSE_SEQUENCE_TASK,0xc963a45b50851768,                     CommandCloseSequenceTask                );
  9118.         SCR_REGISTER_SECURE(TASK_PERFORM_SEQUENCE,0x8acada903fcaa42f,                       CommandTaskPerformSequence              );
  9119.         SCR_REGISTER_SECURE(TASK_PERFORM_SEQUENCE_LOCALLY,0x7bcccccdabd49a93,               CommandTaskPerformSequenceLocally       );
  9120.  
  9121.         SCR_REGISTER_SECURE(CLEAR_SEQUENCE_TASK,0x7461d7c5ba953bc7,                     CommandClearSequenceTask                );
  9122.         SCR_REGISTER_SECURE(SET_SEQUENCE_TO_REPEAT,0x3f2b528df27c8a9f,                      CommandSetSequenceToRepeat              );
  9123.         SCR_REGISTER_UNUSED(SET_SEQUENCE_PREVENT_MIGRATION,0x6a177d7d156481ae,              CommandSetSequencePreventMigration      );
  9124.         SCR_REGISTER_SECURE(GET_SEQUENCE_PROGRESS,0x0829092f169950ab,                       CommandGetSequenceProgress              );
  9125.  
  9126.         SCR_REGISTER_SECURE(GET_IS_TASK_ACTIVE,0x7f528e84564c4d10,                          CommandGetIsTaskActive                  );
  9127.  
  9128.         SCR_REGISTER_SECURE(GET_SCRIPT_TASK_STATUS,0x174ced88b97c78d9,                      CommandGetScriptTaskStatus              );
  9129.         SCR_REGISTER_SECURE(GET_ACTIVE_VEHICLE_MISSION_TYPE,0xf9eec73ae0b9c439,         CommandGetActiveVehicleMissionType);
  9130.         SCR_REGISTER_SECURE(TASK_LEAVE_ANY_VEHICLE,0xab7639d658bbccee,                      CommandTaskLeaveAnyVehicle              );
  9131.         SCR_REGISTER_SECURE(TASK_AIM_GUN_SCRIPTED,0xccf862b807fe3901,                       CommandTaskAimGunScripted               );
  9132.         SCR_REGISTER_SECURE(TASK_AIM_GUN_SCRIPTED_WITH_TARGET,0x30cd3d58df974a16,           CommandTaskAimGunScriptedWithTarget     );
  9133.         SCR_REGISTER_SECURE(UPDATE_TASK_AIM_GUN_SCRIPTED_TARGET,0x20a2aeaf04674323,     CommmandUpdateTaskAimGunScriptedTarget  );
  9134.         SCR_REGISTER_SECURE(GET_CLIP_SET_FOR_SCRIPTED_GUN_TASK,0x3943988de42ef74a,          CommandGetClipSetForScriptedGunTask     );
  9135.         SCR_REGISTER_UNUSED(SET_ROPE_TRACK_ENTITY_FOR_SCRIPTED_GUN_TASK,0x87ac327b490ecccc, CommandSetRopeTrackEntityForGunTask );
  9136.  
  9137.         SCR_REGISTER_SECURE(TASK_AIM_GUN_AT_ENTITY,0x636b3584208a6d73,                      CommandTaskAimGunAtEntity               );
  9138.         SCR_REGISTER_SECURE(TASK_TURN_PED_TO_FACE_ENTITY,0x529d306014d3c29a,                CommandTaskTurnPedToFaceEntity          );
  9139.         SCR_REGISTER_SECURE(TASK_AIM_GUN_AT_COORD,0x2ea72cdbfacd9e92,                       CommandTaskAimGunAtCoord                );
  9140.         SCR_REGISTER_SECURE(TASK_SHOOT_AT_COORD,0xa99ad9dee4794c48,                     CommandTaskShootAtCoord                 );
  9141.         SCR_REGISTER_SECURE(TASK_SHUFFLE_TO_NEXT_VEHICLE_SEAT,0x8625186d3a8ddd7a,           CommandTaskShuffleToNextVehicleSeat     );
  9142.         SCR_REGISTER_SECURE(CLEAR_PED_TASKS,0x03a927199a2dfe46,                         CommandClearPedTasks                    );
  9143.         SCR_REGISTER_UNUSED(CLEAR_PED_SCRIPT_TASK_IF_RUNNING_THREAT_RESPONSE_NON_TEMP_TASK,0xf3642376bf6ac7a8,  CommandClearPedScriptTaskIfRunningThreatResponseNonTempTask );
  9144.        
  9145.         SCR_REGISTER_SECURE(CLEAR_PED_SECONDARY_TASK,0xca2872f050840231,                    CommandClearPedSecondaryTask            );
  9146.         SCR_REGISTER_SECURE(TASK_EVERYONE_LEAVE_VEHICLE,0x417047b1f659225c,             CommandTaskEveryoneLeaveVehicle         );
  9147.         SCR_REGISTER_SECURE(TASK_GOTO_ENTITY_OFFSET,0x6624b56c8f9a7bbf,                 CommandTaskGotoEntityOffset             );
  9148.         SCR_REGISTER_SECURE(TASK_GOTO_ENTITY_OFFSET_XY,0xb17a6034b9f1bcc2,                  CommandTaskGotoEntityOffsetXY           );
  9149.         SCR_REGISTER_UNUSED(TASK_INVESTIGATE_COORDS,0xb834945c258dac7b, CommandTaskInvestigateCoords);
  9150.        
  9151.         SCR_REGISTER_SECURE(TASK_TURN_PED_TO_FACE_COORD,0x1a96b8b416bc07d0,             CommandTaskTurnPedToFaceCoord           );
  9152.         SCR_REGISTER_UNUSED(TASK_DRIVE_POINT_ROUTE,0x8c4f2dd2f4b46da9,                      CommandTaskDrivePointRoute              );
  9153.         SCR_REGISTER_SECURE(TASK_VEHICLE_TEMP_ACTION,0xcd41d6f721cb9c3a,                    CommandTaskVehicleTempAction            );
  9154.         SCR_REGISTER_SECURE(TASK_VEHICLE_MISSION,0xfe5a02cf2178b6a8,                        CommandTaskVehicleMission               );
  9155.         SCR_REGISTER_SECURE(TASK_VEHICLE_MISSION_PED_TARGET,0xb69d13e19147910f,         CommandTaskVehicleMissionPedTarget      );
  9156.         SCR_REGISTER_SECURE(TASK_VEHICLE_MISSION_COORS_TARGET,0xfdb121077308e944,           CommandTaskVehicleMissionCoorsTarget    );
  9157.         SCR_REGISTER_UNUSED(IS_PED_INVESTIGATING_WHISTLING_EVENT,0x7fd44d022e2a2e07,        CommandIsPedInvestigatingWhistlingEvent );
  9158.         SCR_REGISTER_UNUSED(SET_INVESTIGATION_POSITION,0x00f6e31f2f0528cc,                  CommandSetInvestigationPosition         );
  9159.         SCR_REGISTER_SECURE(TASK_VEHICLE_ESCORT,0xdbee353c7ca6e88e,                     CommandTaskVehicleEscort                );
  9160.         SCR_REGISTER_SECURE(TASK_VEHICLE_FOLLOW,0xbb97101b3b2dbef5,                     CommandTaskVehicleFollow                );
  9161.         SCR_REGISTER_SECURE(TASK_VEHICLE_CHASE,0x9286a110a3fd81f1,                          CommandTaskVehicleChase                 );
  9162.         SCR_REGISTER_SECURE(TASK_VEHICLE_HELI_PROTECT,0x69ac7dd318a3e1ba,                   CommandTaskHeliProtect                  );
  9163.        
  9164.        
  9165.  
  9166.         SCR_REGISTER_SECURE(SET_TASK_VEHICLE_CHASE_BEHAVIOR_FLAG,0xc8d0b0d2cfd76bb5,        CommandSetTaskVehicleChaseBehaviorFlag  );
  9167.         SCR_REGISTER_SECURE(SET_TASK_VEHICLE_CHASE_IDEAL_PURSUIT_DISTANCE,0xdfad0df477fd9eb3,   CommandSetTaskVehicleChaseIdealPursuitDistance);
  9168.         SCR_REGISTER_SECURE(TASK_HELI_CHASE,0x42935fa7528ffce8,                         CommandTaskHeliChase                    );
  9169.         SCR_REGISTER_UNUSED(SET_TASK_HELI_CHASE_TARGET_OFFSET,0x4caff843df59d524,           CommandSetTaskHeliChaseTargetOffset     );
  9170.         SCR_REGISTER_UNUSED(SET_TASK_HELI_CHASE_TARGET_OFFSET_WORLD_SPACE,0x8d6ba126f7ac98e4,   CommandSetTaskHeliChaseTargetOffsetWorldSpace );
  9171.         SCR_REGISTER_UNUSED(SET_TASK_HELI_CHASE_ORIENTATION,0xe97d050a690da21c,         CommandSetTaskHeliChaseOrientation );
  9172.  
  9173.         SCR_REGISTER_SECURE(TASK_PLANE_CHASE,0xe8f8c382b0eb7478,                            CommandTaskPlaneChase                   );
  9174.         SCR_REGISTER_SECURE(TASK_PLANE_LAND,0x214f418bf9481244,                         CommandTaskPlaneLand                    );
  9175.  
  9176.         SCR_REGISTER_SECURE(CLEAR_DEFAULT_PRIMARY_TASK,0xeb6fbc20375e72c2,                  CommandClearDefaultPrimaryTask          );
  9177.         SCR_REGISTER_SECURE(CLEAR_PRIMARY_VEHICLE_TASK,0xe4a094de05c0210c,                  CommandClearPrimaryVehicleTask          );
  9178.         SCR_REGISTER_SECURE(CLEAR_VEHICLE_CRASH_TASK,0x273bc6472375634c,                    CommandClearVehicleCrashTask            );
  9179.         SCR_REGISTER_SECURE(TASK_PLANE_GOTO_PRECISE_VTOL,0xce661a3c8cf58b44,                CommandTaskPlaneGotoPreciseVtol         );
  9180.         SCR_REGISTER_SECURE(TASK_SUBMARINE_GOTO_AND_STOP,0x835cbdb247b09c67,                CommandTaskSubmarineGotoAndStop         );
  9181.         SCR_REGISTER_SECURE(TASK_HELI_MISSION,0x545c59578966d5b8,                           CommandTaskHeliMission                  );
  9182.         SCR_REGISTER_SECURE(TASK_HELI_ESCORT_HELI,0x53a1d75e294fdb30,                       CommandTaskHeliEscort                   );
  9183.         SCR_REGISTER_SECURE(TASK_PLANE_MISSION,0xcdaacb23d43f080d,                          CommandTaskPlaneMission                 );
  9184.         SCR_REGISTER_SECURE(TASK_PLANE_TAXI,0x908b77e6d8aa83d8,                             CommandTaskPlaneTaxi                    );
  9185.  
  9186.         SCR_REGISTER_SECURE(TASK_BOAT_MISSION,0xc5a824d6ee9c9cd3,                           CommandTaskBoatMission                  );
  9187.  
  9188.         SCR_REGISTER_UNUSED(TASK_WEAPON_ROLL, 0x123b2716,                           CommandTaskWeaponRoll                   );
  9189.        
  9190.         SCR_REGISTER_SECURE(TASK_DRIVE_BY,0x0e6c3a4efa9d9d35,                               CommandTaskDriveBy                      );
  9191.         SCR_REGISTER_SECURE(SET_DRIVEBY_TASK_TARGET,0x8217f7dfe30383b0,                 CommandSetDriveByTarget                 );
  9192.         SCR_REGISTER_SECURE(CLEAR_DRIVEBY_TASK_UNDERNEATH_DRIVING_TASK,0xd639b91d6baf25c6,  CommandClearDrivebyTaskUnderneathDrivingTask);
  9193.         SCR_REGISTER_SECURE(IS_DRIVEBY_TASK_UNDERNEATH_DRIVING_TASK,0x99d3be8c39ba34ff, CommandIsDrivebyTaskUnderneathDrivingTask);
  9194.        
  9195.         SCR_REGISTER_SECURE(CONTROL_MOUNTED_WEAPON,0xb604014eee3ca5f8,                      CommandControlMountedWeapon             );
  9196.         SCR_REGISTER_SECURE(SET_MOUNTED_WEAPON_TARGET,0x748e7aee8deb2a3a,                   CommandSetMountedWeaponTarget           );
  9197.         SCR_REGISTER_UNUSED(CLEAR_MOUNTED_WEAPON_TASK_UNDERNEATH_DRIVING_TASK,0xf4dedafc0c550318,   CommandClearMountedWeaponTaskUnderneathDrivingTask);
  9198.         SCR_REGISTER_SECURE(IS_MOUNTED_WEAPON_TASK_UNDERNEATH_DRIVING_TASK,0xcb8e14dc7871f52c,  CommandIsMountedWeaponTaskUnderneathDrivingTask);
  9199.            
  9200.         SCR_REGISTER_SECURE(TASK_USE_MOBILE_PHONE,0x57caa5fbf134d4ae,                       CommandTaskUseMobilePhone               );
  9201.         SCR_REGISTER_SECURE(TASK_USE_MOBILE_PHONE_TIMED,0x9bd5d84c8c3f0b2c,             CommandTaskUseMobilePhoneTimed          );
  9202.         SCR_REGISTER_UNUSED(TASK_USE_WALKIE_TALKIE,0x46f7b490eb75e92c,                      CommandTaskUseWalkieTalkie              );
  9203.         SCR_REGISTER_SECURE(TASK_CHAT_TO_PED,0x2966111306fa6611,                            CommandTaskChatToPed                    );
  9204.         SCR_REGISTER_UNUSED(IS_CHATTING_PED_IN_POSITION,0xd701a91d13919148,             CommandIsChattingPedInPosition          );
  9205.         SCR_REGISTER_UNUSED(IS_CHATTING_PED_PLAYING_ANIM,0xae8fabcda3959d22,                CommandIsChattingPedPlayingAnim         );
  9206.         SCR_REGISTER_UNUSED(MAKE_CHATTING_PED_PLAY_ANIM,0x3f4bfc1622d674be,             CommandMakeChattingPedPlayAnim          );
  9207.         SCR_REGISTER_UNUSED(MAKE_CHATTING_PED_LEAVE,0x9dfbb232fdaa2244,                 CommandMakeChattingPedLeave             );
  9208.            
  9209.         SCR_REGISTER_UNUSED(ADD_FOLLOW_NAVMESH_TO_PHONE_TASK,0xe12df85ba18a27f8,                CommandAddFollowNavmeshToPhoneTask      );
  9210.  
  9211.         SCR_REGISTER_UNUSED(GET_MOBILE_PHONE_TASK_SUB_TASK,0xeb6576b40ae232f5,              CommandGetMobilePhoneTaskSubTask        );
  9212.         SCR_REGISTER_SECURE(TASK_WARP_PED_INTO_VEHICLE,0x73a521eac1ef5c1b,                  CommandTaskWarpPedIntoVehicle           );
  9213.        
  9214.         SCR_REGISTER_SECURE(TASK_SHOOT_AT_ENTITY,0x913e191f1f726271,                        CommandTaskShootAtEntity                );
  9215.         SCR_REGISTER_SECURE(TASK_CLIMB,0x893ddd76cc7c67b1,                                  CommandTaskClimb                        );
  9216.         SCR_REGISTER_SECURE(TASK_CLIMB_LADDER,0x12425bd281be5f3c,                           CommandTaskClimbLadder                  );
  9217.         SCR_REGISTER_UNUSED(TASK_RAPPEL_DOWN_WALL,0x42ee24d502e263b3,                       CommandTaskRappelDownWall               );
  9218.         SCR_REGISTER_SECURE(TASK_RAPPEL_DOWN_WALL_USING_CLIPSET_OVERRIDE,0x80f9b0598b0c9c85, CommandTaskRappelDownWallUsingClipsetOverride);
  9219.         SCR_REGISTER_SECURE(GET_TASK_RAPPEL_DOWN_WALL_STATE,0xa0584425edd6ec9d,         CommandsGetTaskRappelDownWallState      );     
  9220.         SCR_REGISTER_SECURE(CLEAR_PED_TASKS_IMMEDIATELY,0x51bb443b279e4104,             CommandClearPedTasksImmediately         );
  9221.         SCR_REGISTER_SECURE(TASK_PERFORM_SEQUENCE_FROM_PROGRESS,0x23378ce912d5b544,     CommandTaskPerformSequenceFromProgress  );
  9222.         SCR_REGISTER_SECURE(SET_NEXT_DESIRED_MOVE_STATE,0x8ff5f2b541a0e471,             CommandSetNextDesiredMoveState          );
  9223.         SCR_REGISTER_SECURE(SET_PED_DESIRED_MOVE_BLEND_RATIO,0x98f7e0916b6b5a0b,            CommandSetPedDesiredMoveBlendRatio      );
  9224.         SCR_REGISTER_SECURE(GET_PED_DESIRED_MOVE_BLEND_RATIO,0x5e9b3bbf63a5e2f6,            CommandGetPedDesiredMoveBlendRatio      ); 
  9225.  
  9226.         SCR_REGISTER_SECURE(TASK_GOTO_ENTITY_AIMING,0x27c6152f3e5f2933,                 CommandTaskGotoEntityAiming             );
  9227.         SCR_REGISTER_SECURE(TASK_SET_DECISION_MAKER,0xd029ba670c8df65b,                 CommandTaskSetDecisionMaker             );
  9228.         SCR_REGISTER_SECURE(TASK_SET_SPHERE_DEFENSIVE_AREA,0x223133feb94059cd,              CommandTaskSetSphereDefensiveArea       );
  9229.         SCR_REGISTER_SECURE(TASK_CLEAR_DEFENSIVE_AREA,0x4b16afbb0c12b630,                   CommandTaskClearDefensiveArea           );
  9230.         SCR_REGISTER_SECURE(TASK_PED_SLIDE_TO_COORD,0xed2842d9cc50eb6e,                 CommandTaskPedSlideToCoord              );
  9231.         SCR_REGISTER_UNUSED(TASK_PED_SLIDE_TO_COORD_AND_PLAY_ANIM,0x93a741ed3ed7f56f,       CommandTaskPedSlideToCoordAndPlayAnim   );
  9232.         SCR_REGISTER_UNUSED(TASK_PED_SLIDE_TO_COORD_AND_PLAY_ANIM_HDG_RATE, 0x95abc676, CommandTaskPedSlideToCoordAndPlayAnimWithHeadingChangeRate  );
  9233.         SCR_REGISTER_SECURE(TASK_PED_SLIDE_TO_COORD_HDG_RATE,0xd6711eee6b632dae,            CommandTaskPedSlideToCoordWithHeadingChangeRate         );
  9234.         SCR_REGISTER_UNUSED(TASK_DRIVE_POINT_ROUTE_ADVANCED,0x730dad3cf7f02fa7,         CommandTaskDrivePointRouteAdvanced      );
  9235.  
  9236.         // Combat and cover
  9237.         SCR_REGISTER_SECURE(ADD_COVER_POINT,0x41ba9dba367c9c12,                         CommandAddCoverPoint                    );
  9238.         SCR_REGISTER_SECURE(REMOVE_COVER_POINT,0x5990dad3727a1b45,                          CommandRemoveCoverPoint                 );
  9239.         SCR_REGISTER_SECURE(DOES_SCRIPTED_COVER_POINT_EXIST_AT_COORDS,0x7fd113b09d96c678,   CommandDoesScriptedCoverPointExistAtCoords          );
  9240.         SCR_REGISTER_SECURE(GET_SCRIPTED_COVER_POINT_COORDS,0x137fb6fc6e40a0a8,         CommandGetScriptedCoverPointCoords      );
  9241.         SCR_REGISTER_SECURE(ADD_SCRIPTED_COVER_AREA, 0x28b7b9bfdaf274aa,                CommandAddScriptedCoverArea);
  9242.         //SCR_REGISTER_UNUSED(GET_SCRIPTED_COVER_POINT_STATUS, 0x56c9de8d,          CommandGetScriptedCoverPointStatus      );
  9243.         SCR_REGISTER_SECURE(TASK_COMBAT_PED,0xc1a74225341aa9fb,                         CommandTaskCombat                       );
  9244.         SCR_REGISTER_SECURE(TASK_COMBAT_PED_TIMED,0x5fc4a511155d6f9a,                       CommandTaskCombatTimed                  );
  9245.         SCR_REGISTER_SECURE(TASK_SEEK_COVER_FROM_POS,0x3f58924930345d8d,                    CommandTaskSeekCoverFromPos             );
  9246.         SCR_REGISTER_SECURE(TASK_SEEK_COVER_FROM_PED,0xb67d1d267c666dc4,                    CommandTaskSeekCoverFromPed             );
  9247.         SCR_REGISTER_SECURE(TASK_SEEK_COVER_TO_COVER_POINT,0x419e449559bf60b4,              CommandTaskSeekCoverToCoverPoint        );
  9248.         SCR_REGISTER_SECURE(TASK_SEEK_COVER_TO_COORDS,0x264cd1b504831626,                   CommandTaskSeekCoverToCoords            );
  9249.         SCR_REGISTER_SECURE(TASK_PUT_PED_DIRECTLY_INTO_COVER,0x809dfa39515d5981,            CommandTaskPutPedDirectlyIntoCover      );
  9250.         SCR_REGISTER_UNUSED(TASK_PUT_PED_DIRECTLY_INTO_COVER_FROM_TARGET,0x9f8e54193d416a78,    CommandTaskPutPedDirectlyIntoCoverFromTarget    );
  9251.         SCR_REGISTER_SECURE(TASK_WARP_PED_DIRECTLY_INTO_COVER,0x6e01e9e8d89f8276,           CommandTaskWarpPedDirectlyIntoCover);
  9252.         SCR_REGISTER_UNUSED(SET_COVER_TASK_TARGET,0x778c4e702f2a65e5,                       CommandSetCoverTarget                   );
  9253.         SCR_REGISTER_SECURE(TASK_EXIT_COVER,0x412ed6ee0b28c20d,                         CommandTaskExitCover                    );
  9254.         SCR_REGISTER_SECURE(TASK_PUT_PED_DIRECTLY_INTO_MELEE,0x957211dc68d2869f,            CommandTaskPutPedDirectlyIntoMelee      );
  9255.         SCR_REGISTER_UNUSED(TASK_ADVANCE_TO_TARGET_IN_LINE,0xd9c691ad25d0d5eb,              CommandTaskAdvanceToTargetInLine        );
  9256.  
  9257.         SCR_REGISTER_UNUSED(SET_CHARGE_TARGET_ENABLED,0x9dea9d830bfc9937, CommandSetChargeTargetEnabled );
  9258.         SCR_REGISTER_UNUSED(SET_MAX_NUM_ACTIVE_CHARGERS,0xa2d85c968ea44e3d,             CommandSetMaxNumActiveChargers          );
  9259.         SCR_REGISTER_UNUSED(SET_MIN_TIME_BETWEEN_CHARGES_AT_SAME_TARGET,0xfbb868ae331debcd, CommandSetMinTimeBetweenChargesAtSameTarget     );
  9260.  
  9261.         SCR_REGISTER_SECURE(TASK_TOGGLE_DUCK,0xa5af895dd224fdc0,                            CommandTaskToggleDuck                   );
  9262.  
  9263.         SCR_REGISTER_SECURE(TASK_GUARD_CURRENT_POSITION,0x274a180d57a0d9a6,             CommandTaskGuardCurrentPosition         );
  9264.         SCR_REGISTER_SECURE(TASK_GUARD_ASSIGNED_DEFENSIVE_AREA,0x4182d960e26d40bb,          CommandTaskGuardAssignedDefensiveArea   );
  9265.         SCR_REGISTER_UNUSED(TASK_GUARD_ANGLED_DEFENSIVE_AREA,0xf035a69189e11b7a,            CommandTaskGuardAngledDefensiveArea     );
  9266.         SCR_REGISTER_SECURE(TASK_GUARD_SPHERE_DEFENSIVE_AREA,0x061a42ebc9ceb366,            CommandTaskGuardSphereDefensiveArea     );
  9267.         SCR_REGISTER_SECURE(TASK_STAND_GUARD,0x4b551665e9b2e8f6,                            CommandTaskStandGuard                   );
  9268.  
  9269.         SCR_REGISTER_SECURE(SET_DRIVE_TASK_CRUISE_SPEED,0xbb3480bb855cdb33,             CommandSetDriveTaskCruiseSpeed          );
  9270.         SCR_REGISTER_SECURE(SET_DRIVE_TASK_MAX_CRUISE_SPEED,0x3d2ebac0a745e60c,         CommandSetDriveTaskMaxCruiseSpeed       );
  9271.         SCR_REGISTER_SECURE(SET_DRIVE_TASK_DRIVING_STYLE,0x27be5555cdf6f983,                CommandSetDriveTaskDrivingStyle         );
  9272.         SCR_REGISTER_UNUSED(SET_PURSUE_TASK_IDEAL_DISTANCE,0x971919670679e003,              CommandSetPursueTaskIdealDistance       );
  9273.  
  9274.         SCR_REGISTER_SECURE(ADD_COVER_BLOCKING_AREA,0x5af3192f3c3d45ec,                 CommandAddCoverBlockingArea             );
  9275.         SCR_REGISTER_SECURE(REMOVE_ALL_COVER_BLOCKING_AREAS,0x71fcd88fc7f98621,         CommandFlushCoverBlockingAreas          );
  9276.         SCR_REGISTER_SECURE(REMOVE_COVER_BLOCKING_AREAS_AT_POSITION,0xac7ab29fe3c36266, CommandRemoveCoverBlockingAreasAtPosition           );
  9277.         SCR_REGISTER_SECURE(REMOVE_SPECIFIC_COVER_BLOCKING_AREAS,0xaa443863046f380a,    CommandRemoveSpecificCoverBlockingAreas);
  9278.  
  9279.         SCR_REGISTER_SECURE(TASK_START_SCENARIO_IN_PLACE,0xc9fefb406c44f60b,                CommandTaskStartScenarioInPlace         );
  9280.         SCR_REGISTER_SECURE(TASK_START_SCENARIO_AT_POSITION,0xdb4f67aafbf32aa5,         CommandTaskStartScenarioAtPosition      );
  9281.         SCR_REGISTER_UNUSED(TASK_START_VEHICLE_SCENARIO,0xbfb160b082e439fa,             CommandTaskStartVehicleScenario         );
  9282.         SCR_REGISTER_SECURE(TASK_USE_NEAREST_SCENARIO_TO_COORD,0x1d698ecdff42ac58,          CommandTaskUseNearestScenarioToPos      );
  9283.         SCR_REGISTER_SECURE(TASK_USE_NEAREST_SCENARIO_TO_COORD_WARP,0x8ceb5d8b56025aa2, CommandTaskUseNearestScenarioToPosWarp  );
  9284.         SCR_REGISTER_UNUSED(TASK_USE_NEAREST_TRAIN_SCENARIO_TO_COORD_WARP,0x97deba5039a7f6c7, CommandTaskUseNearestTrainScenarioToPosWarp);
  9285.         SCR_REGISTER_SECURE(TASK_USE_NEAREST_SCENARIO_CHAIN_TO_COORD,0xaf0492886bc6c105,    CommandTaskUseNearestScenarioChainToPos );
  9286.         SCR_REGISTER_SECURE(TASK_USE_NEAREST_SCENARIO_CHAIN_TO_COORD_WARP,0x6d44636281842060, CommandTaskUseNearestScenarioChainToPosWarp   );
  9287.         SCR_REGISTER_SECURE(DOES_SCENARIO_EXIST_IN_AREA,0x5b138084858689ac,             CommandDoesScenarioExistInArea          );
  9288.         SCR_REGISTER_SECURE(DOES_SCENARIO_OF_TYPE_EXIST_IN_AREA,0x48d8c2729764de01,                 CommandDoesScenarioOfTypeExistInArea);
  9289.         SCR_REGISTER_SECURE(IS_SCENARIO_OCCUPIED,0xc85b76c87214bd87,                        CommandIsScenarioOccupied               );
  9290.         SCR_REGISTER_SECURE(PED_HAS_USE_SCENARIO_TASK,0x23bf8abbc9594609,                   CommandPedHasUseScenarioTask            );
  9291.         SCR_REGISTER_UNUSED(OVERRIDE_TASKED_SCENARIO_BASE_ANIM,0xdd7e39f6a9fa3ce0,          CommandOverrideTaskedScenarioBaseAnim   );
  9292.         SCR_REGISTER_SECURE(PLAY_ANIM_ON_RUNNING_SCENARIO,0x8b90895f7d0bee59,               CommandPlayAnimOnRunnningScenario       );
  9293.  
  9294.         SCR_REGISTER_SECURE(DOES_SCENARIO_GROUP_EXIST,0x1e63be2394148da0,                   CommandDoesScenarioGroupExist           );
  9295.         SCR_REGISTER_SECURE(IS_SCENARIO_GROUP_ENABLED,0x96a05000ccd43584,                   CommandIsScenarioGroupEnabled           );
  9296.         SCR_REGISTER_SECURE(SET_SCENARIO_GROUP_ENABLED,0xa3d2c191df3cb742,                  CommandSetScenarioGroupEnabled          );
  9297.         SCR_REGISTER_SECURE(RESET_SCENARIO_GROUPS_ENABLED,0xb750df5029a6790a,               CommandResetScenarioGroupsEnabled       );
  9298.         SCR_REGISTER_SECURE(SET_EXCLUSIVE_SCENARIO_GROUP,0xedf1af96b1a92325,                CommandSetExclusiveScenarioGroup        );
  9299.         SCR_REGISTER_SECURE(RESET_EXCLUSIVE_SCENARIO_GROUP,0xa7fee431b0d22e80,              CommandResetExclusiveScenarioGroup      );
  9300.         SCR_REGISTER_UNUSED(FORCE_SCENARIO_GROUP_PRIORITY,0xb2a385f314986d7d,               CommandForceScenarioGroupPriority       );
  9301.         SCR_REGISTER_UNUSED(RESET_SCENARIO_GROUPS_PRIORITY,0xf842c44cfffb8884,              CommandResetScenarioGroupsPriority      );
  9302.  
  9303.         SCR_REGISTER_SECURE(IS_SCENARIO_TYPE_ENABLED,0xaec3fb024079cf27,                    CommandIsScenarioTypeEnabled            );
  9304.         SCR_REGISTER_SECURE(SET_SCENARIO_TYPE_ENABLED,0x247f21b1803f0ec4,                   CommandSetScenarioTypeEnabled           );
  9305.         SCR_REGISTER_SECURE(RESET_SCENARIO_TYPES_ENABLED,0xa9fc42dea687033d,                CommandResetScenarioTypesEnabled        );
  9306.  
  9307.         SCR_REGISTER_UNUSED(SUPPRESS_NORMAL_SCENARIO_EXITS_NEXT_FRAME,0x462559c9bfdb51d1,   CommandSuppressNormalScenarioExitsNextFrame);
  9308.         SCR_REGISTER_UNUSED(SUPPRESS_SCENARIO_ATTRACTION_NEXT_FRAME,0xf50d4dd468864fca, CommandSuppressScenarioAttractionNextFrame);
  9309.         SCR_REGISTER_UNUSED(SUPPRESS_BREAKOUT_SCENARIO_EXITS_NEXT_FRAME,0x743ef6f4b8c462a8,CommandSuppressBreakoutScenarioExitsNextFrame);
  9310.  
  9311.  
  9312.         SCR_REGISTER_SECURE(IS_PED_ACTIVE_IN_SCENARIO,0x67360b9474054c5e,                   CommandIsPedActiveInScenario            );
  9313.         SCR_REGISTER_SECURE(IS_PED_PLAYING_BASE_CLIP_IN_SCENARIO,0x2dc1bc483b6a3316,        CommandIsPedPlayingBaseClipInScenario   );
  9314.         SCR_REGISTER_SECURE(SET_PED_CAN_PLAY_AMBIENT_IDLES,0xe72d9eb9db4b874d,              CommandSetCanPlayAmbientIdles           );
  9315.  
  9316.         SCR_REGISTER_SECURE(TASK_COMBAT_HATED_TARGETS_IN_AREA,0xe45039a194d735de,           CommandTaskCombatHatedTargetsInArea     );
  9317.         SCR_REGISTER_SECURE(TASK_COMBAT_HATED_TARGETS_AROUND_PED,0x766d377a16f499e3,        CommandTaskCombatHatedTargetsAroundPed  );
  9318.         SCR_REGISTER_SECURE(TASK_COMBAT_HATED_TARGETS_AROUND_PED_TIMED,0x34ad04c1e7cb67d8,  CommandTaskCombatHatedTargetsAroundPedTimed );
  9319.  
  9320.         SCR_REGISTER_SECURE(TASK_THROW_PROJECTILE,0xa43ab969c8956eb8,                       CommandTaskThrowProjectile              );
  9321.    
  9322.         SCR_REGISTER_SECURE(TASK_SWAP_WEAPON,0xd4834169f570e6d2,                            CommandTaskSwapWeapon                   );
  9323.         SCR_REGISTER_SECURE(TASK_RELOAD_WEAPON,0x62f1ebed7a072b40,                          CommandTaskReloadWeapon                 );
  9324.         SCR_REGISTER_UNUSED(TASK_COMBAT_ROLL,0x8eddf98bab0a7bc9,                            CommandTaskCombatRoll                   );
  9325.         SCR_REGISTER_SECURE(IS_PED_GETTING_UP,0x03454821a9ecf4aa,                           CommandIsPedGettingUp                   );
  9326.         SCR_REGISTER_SECURE(TASK_WRITHE,0x99e9c3c2d6af9a52,                             CommandTaskWrithe                       );
  9327.         SCR_REGISTER_SECURE(IS_PED_IN_WRITHE,0x645f244ecddef6cf,                            CommandIsPedInWrithe                    );
  9328.  
  9329.         SCR_REGISTER_SECURE(OPEN_PATROL_ROUTE,0x9d3e7062e40f2049,                           CommandOpenPatrolRoute                  );
  9330.         SCR_REGISTER_SECURE(CLOSE_PATROL_ROUTE,0xc65dee4d8f9f02eb,                          CommandClosePatrolRoute                 );
  9331.         SCR_REGISTER_SECURE(ADD_PATROL_ROUTE_NODE,0xad84831de60c1442,                       CommandAddPatrolNode                    );
  9332.         SCR_REGISTER_SECURE(ADD_PATROL_ROUTE_LINK,0x23c767cf5993cf13,                       CommandAddPatrolNodeLink                );
  9333.         SCR_REGISTER_SECURE(CREATE_PATROL_ROUTE,0x274f700901c096dd,                         CommandCreatePatrolRoute                );
  9334.         SCR_REGISTER_SECURE(DELETE_PATROL_ROUTE,0x6bd70dca1fdc1c56,                     CommandDeletePatrolRoute                );
  9335.         SCR_REGISTER_SECURE(GET_PATROL_TASK_INFO,0x52f734cebe20dfba,                        CommandGetPatrolNodeInfo                );
  9336.  
  9337.         SCR_REGISTER_SECURE(TASK_PATROL,0xac81ed4a4f2fec9c,                             CommandTaskPatrol                       );
  9338.  
  9339.         SCR_REGISTER_SECURE(TASK_STAY_IN_COVER,0xf21f1b3825b46822,                          CommandTaskStayInCover                  );
  9340.        
  9341.         SCR_REGISTER_SECURE(ADD_VEHICLE_SUBTASK_ATTACK_COORD,0xf2e8f4bd20869ab2,            CommandAddVehicleSubtaskAttackCoord     );
  9342.         SCR_REGISTER_SECURE(ADD_VEHICLE_SUBTASK_ATTACK_PED,0x80e8bfe6e62212c1,              CommandAddVehicleSubtaskAttackPed       );
  9343.  
  9344.         SCR_REGISTER_SECURE(TASK_VEHICLE_SHOOT_AT_PED,0xbba695ad5315cdd8,                   CommandVehicleShootAtPed                );
  9345.         SCR_REGISTER_SECURE(TASK_VEHICLE_AIM_AT_PED,0xc514d16960a4fa43,                 CommandVehicleAimAtPed                  );
  9346.         SCR_REGISTER_SECURE(TASK_VEHICLE_SHOOT_AT_COORD,0xe5d96c43ab0b0dc6,             CommandVehicleShootAtCoord              );
  9347.         SCR_REGISTER_SECURE(TASK_VEHICLE_AIM_AT_COORD,0x7d49955a299139e9,                   CommandVehicleAimAtCoord                );
  9348.         SCR_REGISTER_UNUSED(TASK_VEHICLE_AIM_USING_CAMERA,0x6614a146419eb189,               CommandVehicleAimUsingCamera            );
  9349.         SCR_REGISTER_UNUSED(TASK_HANG_GLIDER,0xbdbadc2ff688e5b2,                            CommandTaskHangGlider                   );
  9350.         SCR_REGISTER_UNUSED(SET_HANG_GLIDER_AIR_SPEED,0x23b2c655efd82c53,                   CommandSetHangGliderAirSpeed            );
  9351.         SCR_REGISTER_SECURE(TASK_VEHICLE_GOTO_NAVMESH,0xdf44785f7bc09dd2,                   CommandTaskVehicleGotoNavmesh           );
  9352.  
  9353.         SCR_REGISTER_SECURE(TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD,0x642c58f4ca259448,      CommandTaskGoToCoordWhileAimingAtCoord  );
  9354.         SCR_REGISTER_SECURE(TASK_GO_TO_COORD_WHILE_AIMING_AT_ENTITY,0x98db2abd53b8d70b, CommandTaskGoToCoordWhileAimingAtEntity );
  9355.         SCR_REGISTER_SECURE(TASK_GO_TO_COORD_AND_AIM_AT_HATED_ENTITIES_NEAR_COORD,0x2a83cd9941ec44d0, CommandTaskGoToCoordAndAimAtHatedEntitiesNearCoord);
  9356.         SCR_REGISTER_SECURE(TASK_GO_TO_ENTITY_WHILE_AIMING_AT_COORD,0x60fad147bb45a92a, CommandTaskGoToEntityWhileAimingAtCoord );
  9357.         SCR_REGISTER_SECURE(TASK_GO_TO_ENTITY_WHILE_AIMING_AT_ENTITY,0x0b47872e9d74882c,    CommandTaskGoToEntityWhileAimingAtEntity);
  9358.  
  9359.         SCR_REGISTER_UNUSED(TASK_BIND_POSE,0xac5fea0754bcc7cf,                             CommandTaskBindPose                     );
  9360.         SCR_REGISTER_UNUSED(ELECTROCUTE_PED,0x9eebf0c360e75bef,                         CommandElectrocute                      );
  9361.         SCR_REGISTER_SECURE(SET_HIGH_FALL_TASK,0xdb1174c6546afc65,                                  CommandHighFall                         );
  9362.         SCR_REGISTER_UNUSED(DANGLE_FROM_MEATHOOK,0xd9c1a873ff69a447,                        CommandDangleFromMeathook               );
  9363.         SCR_REGISTER_UNUSED(SLUNG_OVER_SHOULDER,0xcbdd75b6dfb92714,                     CommandSlungOverShoulder                );
  9364.         SCR_REGISTER_UNUSED(MAKE_PED_STUMBLE,0x6b0ebf2507baba30,                            CommandStumble                          );
  9365.    
  9366.  
  9367.         SCR_REGISTER_SECURE(REQUEST_WAYPOINT_RECORDING,0x70f260358d1a42c4,                  waypoint_commands::CommandRequestWaypointRecording          );
  9368.         SCR_REGISTER_SECURE(GET_IS_WAYPOINT_RECORDING_LOADED,0xbd3cea9cd36e271e,            waypoint_commands::CommandGetIsWaypointRecordingLoaded      );
  9369.         SCR_REGISTER_SECURE(REMOVE_WAYPOINT_RECORDING,0x10f7bfe3a88cb99b,                   waypoint_commands::CommandRemoveWaypointRecording           );
  9370.  
  9371.         SCR_REGISTER_SECURE(WAYPOINT_RECORDING_GET_NUM_POINTS,0x042959494b85e155,           waypoint_commands::CommandWaypointRecordingGetNumPoints );
  9372.         SCR_REGISTER_SECURE(WAYPOINT_RECORDING_GET_COORD,0x76263b6f2b150aff,                waypoint_commands::CommandWaypointRecordingGetCoord     );
  9373.         SCR_REGISTER_SECURE(WAYPOINT_RECORDING_GET_SPEED_AT_POINT,0xaa4b93a8c0d05be3,       waypoint_commands::CommandWaypointRecordingGetSpeedAtPoint);
  9374.         SCR_REGISTER_SECURE(WAYPOINT_RECORDING_GET_CLOSEST_WAYPOINT,0xe49fae8c75dfe3b0, waypoint_commands::CommandWaypointRecordingGetClosestWaypoint       );
  9375.  
  9376.         SCR_REGISTER_SECURE(TASK_FOLLOW_WAYPOINT_RECORDING,0x4218764824f31173,              waypoint_commands::CommandTaskFollowWaypointRecording       );
  9377.         SCR_REGISTER_SECURE(IS_WAYPOINT_PLAYBACK_GOING_ON_FOR_PED,0xb4ae2a423a4176ce,       waypoint_commands::CommandIsWaypointPlaybackGoingOnForPed   ); 
  9378.         SCR_REGISTER_SECURE(GET_PED_WAYPOINT_PROGRESS,0x0b331f8dc5c61933,                   waypoint_commands::CommandGetPedWaypointProgress            );
  9379.         SCR_REGISTER_UNUSED(SET_PED_WAYPOINT_PROGRESS,0xadc4c24903027450,                   waypoint_commands::CommandSetPedWaypointProgress            );
  9380.         SCR_REGISTER_SECURE(GET_PED_WAYPOINT_DISTANCE,0xb80b2f3bfb68df1a,                   waypoint_commands::CommandGetPedWaypointDistance            );
  9381.         SCR_REGISTER_SECURE(SET_PED_WAYPOINT_ROUTE_OFFSET,0x455e0249f399ef4c,               waypoint_commands::CommandSetPedWaypointRouteOffset         );
  9382.         SCR_REGISTER_SECURE(GET_WAYPOINT_DISTANCE_ALONG_ROUTE,0xd2fe51a38e9a1946,           waypoint_commands::CommandGetWaypointDistanceAlongRoute     );
  9383.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_GET_IS_PAUSED,0x656f70678f75d966,         waypoint_commands::CommandWaypointPlaybackGetIsPaused       );
  9384.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_PAUSE,0x499c4b0d70f4097c,                 waypoint_commands::CommandWaypointPlaybackPause         );
  9385.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_RESUME,0x4ffeb98e621afb27,                    waypoint_commands::CommandWaypointPlaybackResume            );
  9386.  
  9387.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_OVERRIDE_SPEED,0x369b082b04a4f619,            waypoint_commands::CommandWaypointPlaybackOverrideSpeed         );
  9388.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_USE_DEFAULT_SPEED,0x5039c5050b42f1e0,     waypoint_commands::CommandWaypointPlaybackUseDefaultSpeed           );
  9389.  
  9390.         SCR_REGISTER_SECURE(USE_WAYPOINT_RECORDING_AS_ASSISTED_MOVEMENT_ROUTE,0xbb6589e0d27bd54e, waypoint_commands::CommandUseWaypointRecordingAsAssistedMovementRoute);
  9391.        
  9392.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_START_AIMING_AT_PED,0x9b4dd143cd0c78fe,       waypoint_commands::CommandWaypointPlaybackStartAimingAtPed );
  9393.         SCR_REGISTER_UNUSED(WAYPOINT_PLAYBACK_START_AIMING_AT_ENTITY,0x47e2d6d68a34062a,    waypoint_commands::CommandWaypointPlaybackStartAimingAtEntity );
  9394.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_START_AIMING_AT_COORD,0xa142fd669ff80016, waypoint_commands::CommandWaypointPlaybackStartAimingAtCoord );
  9395.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_START_SHOOTING_AT_PED,0xa9b13da1d075a160, waypoint_commands::CommandWaypointPlaybackStartShootingAtPed );
  9396.         SCR_REGISTER_UNUSED(WAYPOINT_PLAYBACK_START_SHOOTING_AT_ENTITY,0x4f6e75c1ca97a1ef,  waypoint_commands::CommandWaypointPlaybackStartShootingAtEntity );
  9397.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_START_SHOOTING_AT_COORD,0x4f826adf9bdb6bd8,   waypoint_commands::CommandWaypointPlaybackStartShootingAtCoord );
  9398.         SCR_REGISTER_SECURE(WAYPOINT_PLAYBACK_STOP_AIMING_OR_SHOOTING,0x282cae6fb0e3b2fc,   waypoint_commands::CommandWaypointPlaybackStopAimingOrShooting );
  9399.        
  9400.         SCR_REGISTER_SECURE(ASSISTED_MOVEMENT_REQUEST_ROUTE,0xb5549ea4fcf75870,         waypoint_commands::CommandAssistedMovementRequestRoute);
  9401.         SCR_REGISTER_SECURE(ASSISTED_MOVEMENT_REMOVE_ROUTE,0xed4af6b9266b55c9,              waypoint_commands::CommandAssistedMovementRemoveRoute);
  9402.  
  9403.         SCR_REGISTER_SECURE(ASSISTED_MOVEMENT_IS_ROUTE_LOADED,0x632b7d3b9b85016a,           waypoint_commands::CommandAssistedMovementIsRouteLoaded);
  9404.         SCR_REGISTER_UNUSED(ASSISTED_MOVEMENT_GET_ROUTE_PROPERTIES,0xec6dfa1a86cf270a,      waypoint_commands::CommandAssistedMovementGetRouteProperties);
  9405.         SCR_REGISTER_SECURE(ASSISTED_MOVEMENT_SET_ROUTE_PROPERTIES,0x50569e4320bc8e92,      waypoint_commands::CommandAssistedMovementSetRouteProperties);
  9406.         SCR_REGISTER_SECURE(ASSISTED_MOVEMENT_OVERRIDE_LOAD_DISTANCE_THIS_FRAME,0xd7e4e11cc0659bb6,     waypoint_commands::CommandAssistedMovementOverrideLoadDistanceThisFrame);
  9407.  
  9408.         SCR_REGISTER_SECURE(TASK_VEHICLE_FOLLOW_WAYPOINT_RECORDING,0xa24707688ba83cea,      waypoint_commands::CommandTaskVehicleFollowWaypointRecording);
  9409.         SCR_REGISTER_SECURE(IS_WAYPOINT_PLAYBACK_GOING_ON_FOR_VEHICLE,0x22ff01f89d3006c0,   waypoint_commands::CommandIsWaypointPlaybackGoingOnForVehicle);
  9410.         SCR_REGISTER_SECURE(GET_VEHICLE_WAYPOINT_PROGRESS,0x46ea6598acefacc1,       waypoint_commands::CommandGetVehicleWaypointProgress);
  9411.         SCR_REGISTER_SECURE(GET_VEHICLE_WAYPOINT_TARGET_POINT,0x0e9d3608e0ae9ee3,           waypoint_commands::CommandGetVehicleWaypointTargetPoint);
  9412.         SCR_REGISTER_SECURE(VEHICLE_WAYPOINT_PLAYBACK_PAUSE,0xe3948de25c763434,     waypoint_commands::CommandVehicleWaypointPlaybackPause);
  9413.         SCR_REGISTER_UNUSED(VEHICLE_WAYPOINT_PLAYBACK_GET_IS_PAUSED,0xa84a1cf14183e169, waypoint_commands::CommandVehicleWaypointPlaybackGetIsPaused);
  9414.         SCR_REGISTER_SECURE(VEHICLE_WAYPOINT_PLAYBACK_RESUME,0x211bb80656beac0f,        waypoint_commands::CommandVehicleWaypointPlaybackResume);
  9415.         SCR_REGISTER_SECURE(VEHICLE_WAYPOINT_PLAYBACK_USE_DEFAULT_SPEED,0x502f9fce448f5724, waypoint_commands::CommandVehicleWaypointPlaybackUseDefaultSpeed);
  9416.         SCR_REGISTER_SECURE(VEHICLE_WAYPOINT_PLAYBACK_OVERRIDE_SPEED,0xf248aeaab65d17cd,    waypoint_commands::CommandVehicleWaypointPlaybackOverrideSpeed);
  9417.  
  9418.         SCR_REGISTER_UNUSED(TASK_NM_ATTACH_PED_TO_ENTITY,0x7ed90e7321ac4a87,                CommandTaskNMAttachPedToEntity);
  9419.         SCR_REGISTER_SECURE(TASK_SET_BLOCKING_OF_NON_TEMPORARY_EVENTS,0xf7b73727a8f72f54,   CommandTaskSetBlockingOfNonTemporaryEvents);
  9420.         SCR_REGISTER_SECURE(TASK_FORCE_MOTION_STATE,0x57374b880e0a67bd, CommandTaskForceMotionState);
  9421.  
  9422.         // MoVE interface
  9423.         SCR_REGISTER_SECURE(TASK_MOVE_NETWORK_BY_NAME,0x84a70ae1a2393914,                                           CommandTaskMoveNetworkByName);
  9424.         SCR_REGISTER_SECURE(TASK_MOVE_NETWORK_ADVANCED_BY_NAME,0xad3d17c7e426d09d,                                  CommandTaskMoveNetworkAdvancedByName);
  9425.         SCR_REGISTER_SECURE(TASK_MOVE_NETWORK_BY_NAME_WITH_INIT_PARAMS,0x4601817fd87b48e3,                          CommandTaskMoveNetworkByNameWithInitParams);
  9426.         SCR_REGISTER_SECURE(TASK_MOVE_NETWORK_ADVANCED_BY_NAME_WITH_INIT_PARAMS,0xca9cbdbc10f9d281,                 CommandTaskMoveNetworkAdvancedByNameWithInitParams);
  9427.         SCR_REGISTER_SECURE(IS_TASK_MOVE_NETWORK_ACTIVE,0xfcd53f51d587f4c6,                                         CommandIsTaskMoveNetworkActive);
  9428.         SCR_REGISTER_SECURE(IS_TASK_MOVE_NETWORK_READY_FOR_TRANSITION,0x0422aefd9002867b,                           CommandIsTaskMoveNetworkReadyForTransition);
  9429.         SCR_REGISTER_SECURE(REQUEST_TASK_MOVE_NETWORK_STATE_TRANSITION,0xdcd29be535921736,                          CommandRequestTaskMoveNetworkStateTransition);
  9430.         SCR_REGISTER_SECURE(SET_EXPECTED_CLONE_NEXT_TASK_MOVE_NETWORK_STATE,0x2029bef342249fb1,                     CommandSetExpectedCloneNextTaskMoveNetworkState);
  9431.         SCR_REGISTER_SECURE(GET_TASK_MOVE_NETWORK_STATE,0x111890991356db66,                                         CommandGetTaskMoveNetworkState);
  9432.         SCR_REGISTER_SECURE(SET_TASK_MOVE_NETWORK_ANIM_SET,0x2d9f06756211492a,                                      CommandSetTaskMoveNetworkClipSet);
  9433.         SCR_REGISTER_SECURE(SET_TASK_MOVE_NETWORK_SIGNAL_FLOAT,0x8e11f085404a3100,                                  CommandSetTaskMoveNetworkSignalFloat);
  9434.         SCR_REGISTER_SECURE(SET_TASK_MOVE_NETWORK_SIGNAL_LOCAL_FLOAT,0x357c016ef8883bad,                            CommandSetTaskMoveNetworkSignalLocalFloat);
  9435.         SCR_REGISTER_SECURE(SET_TASK_MOVE_NETWORK_SIGNAL_FLOAT_LERP_RATE,0x6e3f82dd454ea5b1,                        CommandSetTaskMoveNetworkSignalFloatLerpRate);
  9436.         SCR_REGISTER_SECURE(SET_TASK_MOVE_NETWORK_SIGNAL_BOOL,0xdde2a56a49baf5b0,                                   CommandSetTaskMoveNetworkSignalBool);
  9437.         SCR_REGISTER_UNUSED(SET_TASK_MOVE_NETWORK_SIGNAL_LOCAL_BOOL,0xbe46dff5c216a2b0,                             CommandSetTaskMoveNetworkSignalLocalBool);
  9438.         SCR_REGISTER_SECURE(GET_TASK_MOVE_NETWORK_SIGNAL_FLOAT,0x103bce39f925945e,                                  CommandGetTaskMoveNetworkSignalFloat);
  9439.         SCR_REGISTER_SECURE(GET_TASK_MOVE_NETWORK_SIGNAL_BOOL,0x501632a36a6512aa,                                   CommandGetTaskMoveNetworkSignalBool);
  9440.         SCR_REGISTER_SECURE(GET_TASK_MOVE_NETWORK_EVENT,0xce3f029a4833b5e1,                                         CommandGetTaskMoveNetworkEvent);
  9441.         SCR_REGISTER_SECURE(SET_TASK_MOVE_NETWORK_ENABLE_COLLISION_ON_NETWORK_CLONE_WHEN_FIXED,0x4a5f1661be58e97e,  CommandSetTaskMoveNetworkEnableCollisionOnNetworkCloneWhenFixed);
  9442.         // End MoVE interface
  9443.  
  9444.         SCR_REGISTER_SECURE(IS_MOVE_BLEND_RATIO_STILL,0x98daeb6e7093895e,                           CommandIsMoveBlendRatioStill);
  9445.         SCR_REGISTER_SECURE(IS_MOVE_BLEND_RATIO_WALKING,0x6b46f0285c770b5b,                     CommandIsMoveBlendRatioWalking);
  9446.         SCR_REGISTER_SECURE(IS_MOVE_BLEND_RATIO_RUNNING,0x833a52f892a42353,                     CommandIsMoveBlendRatioRunning);
  9447.         SCR_REGISTER_SECURE(IS_MOVE_BLEND_RATIO_SPRINTING,0x3861da7f20602340,                       CommandIsMoveBlendRatioSprinting);
  9448.         SCR_REGISTER_SECURE(IS_PED_STILL,0x443c6afb940b3c83,                                        CommandIsPedStill);
  9449.         SCR_REGISTER_SECURE(IS_PED_WALKING,0x834c649d79d5128d,                                      CommandIsPedWalking);
  9450.         SCR_REGISTER_SECURE(IS_PED_RUNNING,0x81bbcaf9fe3b469d,                                      CommandPedIsRunning);
  9451.         SCR_REGISTER_SECURE(IS_PED_SPRINTING,0xe02d8bdf4b18d48d,                                    CommandPedIsSprinting);
  9452.         SCR_REGISTER_SECURE(IS_PED_STRAFING,0xfe3baaf47e48d31f,                                 CommandPedIsStrafing);
  9453.  
  9454.         // synchronized scenes
  9455.         SCR_REGISTER_SECURE(TASK_SYNCHRONIZED_SCENE,0x950b26f4c891073f,                         CommandTaskSynchronizedScene);
  9456.  
  9457.         SCR_REGISTER_SECURE(TASK_AGITATED_ACTION_CONFRONT_RESPONSE,0x3e7d91f4eece76b8,          CommandGivePedAgitatedTaskConfront);
  9458.  
  9459.         //////////////////////////////////////////////////////////////////////////
  9460.         //  Ped SweepTask commands
  9461.         //////////////////////////////////////////////////////////////////////////
  9462.         SCR_REGISTER_SECURE(TASK_SWEEP_AIM_ENTITY,0x26d2934cf2d5b32c,           CommandTaskSweepAimEntity);
  9463.         SCR_REGISTER_SECURE(UPDATE_TASK_SWEEP_AIM_ENTITY,0x878b7bb84cc31442,            CommandUpdateTaskSweepAimEntity);
  9464.         SCR_REGISTER_SECURE(TASK_SWEEP_AIM_POSITION,0x07c9c36e1a3234e9,         CommandTaskSweepAimPosition);
  9465.         SCR_REGISTER_SECURE(UPDATE_TASK_SWEEP_AIM_POSITION,0xc82e4267a5f18820,          CommandUpdateTaskSweepAimPosition);
  9466.  
  9467.         // @DEPRECATED: Old arrest commands
  9468.         SCR_REGISTER_SECURE(TASK_ARREST_PED,0x463d4f9c4826a59b, CommandTaskArrestPed);
  9469.         SCR_REGISTER_SECURE(IS_PED_RUNNING_ARREST_TASK,0x64152dd440e37f50, CommandIsPedRunningArrestTask);
  9470.         SCR_REGISTER_UNUSED(IS_ARREST_TYPE_VALID,0x1c805a9f43140ae6, CommandIsArrestTypeValid);
  9471.  
  9472.         // Arrest/uncuff commands
  9473.         SCR_REGISTER_SECURE(IS_PED_BEING_ARRESTED,0x1c7f03843c4541ad,                   CommandIsPedBeingArrested);
  9474.         SCR_REGISTER_UNUSED(IS_PED_BEING_UNCUFFED,0x522ef0aaa44cd03a,                   CommandIsPedBeingUncuffed);
  9475.         SCR_REGISTER_UNUSED(IS_PED_ARRESTING,0x2a706f5c5d386b6e,                        CommandIsPedArresting);
  9476.         SCR_REGISTER_UNUSED(IS_PED_UNCUFFING,0x1590a589bdbbf96c,                        CommandIsPedUncuffing);
  9477.         SCR_REGISTER_UNUSED(GET_PED_ARRESTER,0x1d081ef24f8c6203,                        CommandGetPedArrester);
  9478.         SCR_REGISTER_UNUSED(GET_PED_UNCUFFER,0x79a3054bf21c9039,                        CommandGetPedUncuffer);
  9479.         SCR_REGISTER_UNUSED(GET_PED_ARRESTING_TARGET,0x9def9d10068f6f46,                CommandGetPedArrestingTarget);
  9480.         SCR_REGISTER_UNUSED(GET_PED_UNCUFFING_TARGET,0x08c5c742c9b17f90,                CommandGetPedUncuffingTarget);
  9481.  
  9482.         SCR_REGISTER_UNUSED(CUFF_PED,0x7b9873a2f170f8b0,                                CommandCuffPed);
  9483.         SCR_REGISTER_SECURE(UNCUFF_PED,0x9a89b72b9931965c,                              CommandUncuffPed);
  9484.         SCR_REGISTER_SECURE(IS_PED_CUFFED,0xea266e5f12328e62,                           CommandIsPedCuffed);
  9485.  
  9486.         SCR_REGISTER_UNUSED(IS_PED_TAKING_CUSTODY,0xb178acc0bca5b82c,                   CommandIsPedTakingCustody);
  9487.         SCR_REGISTER_UNUSED(GET_PED_TAKING_CUSTODY_TARGET,0x2f6461d574428769,           CommandGetPedTakingCustodyTarget);
  9488.         SCR_REGISTER_UNUSED(IS_PED_BEING_TAKEN_INTO_CUSTODY,0xcaff880c04b723c0,     CommandIsPedBeingTakenIntoCustody);
  9489.  
  9490.         SCR_REGISTER_UNUSED(TASK_TAKE_CUSTODY,0x53baad9817f5de01,                       CommandTaskTakeCustody);
  9491.         SCR_REGISTER_UNUSED(GET_PED_CUSTODIAN,0x670b52c53b47a811,                       CommandGetPedCustodian);
  9492.         SCR_REGISTER_UNUSED(REMOVE_PED_FROM_CUSTODY,0x512b985df2d0e125,             CommandRemovePedFromCustody);
  9493.        
  9494.         SCR_REGISTER_UNUSED(GET_PED_ARREST_PHASE,0x44559d9a1dd62526,                    CommandGetPedArrestPhase);
  9495.  
  9496.         SCR_REGISTER_UNUSED(GET_PED_POTENTIAL_ARREST_TARGET,0x1214edf270c95469,     CommandGetPedPotentialArrestTarget);
  9497.         SCR_REGISTER_UNUSED(GET_PED_POTENTIAL_UNCUFF_TARGET,0x346aeaa1e63abaeb,     CommandGetPedPotentialUncuffTarget);
  9498.  
  9499.         SCR_REGISTER_UNUSED(SET_PED_CUSTODY_FOLLOW_DISTANCE,0x006f134efa946bd1,     CommandSetPedCustodyOverrideFollowDistance);
  9500.         SCR_REGISTER_UNUSED(WARP_INTO_LEADERS_VEHICLE,0x196931342f1803a2,               CommandWarpIntoLeadersVehicle);
  9501.     }
  9502. }   //  end of namespace task_commands
  9503.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement