Advertisement
Eddlm

MissionExample (Hitman)

Oct 22nd, 2017
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.55 KB | None | 0 0
  1.     bool MissionIsRunning = false;
  2.     Vector3 MissionTrigger = Vector3.Zero;
  3.  
  4.     int EnemyRLGroup = World.AddRelationshipGroup("enemies");
  5.     List<Ped> Guards = new List<Ped>(); //The list of peds that will guard the Target ped.
  6.     Ped Target = null; //The target ped itself.
  7.     Ped Companion = null; //Your companion.
  8.     int Reward = 5000;
  9.     Vector3 Location = Vector3.Zero;
  10.  
  11.     void OnTick(object sender, EventArgs e)
  12.     {
  13.         if (MissionIsRunning)
  14.         {
  15.             HandleMission();
  16.         }
  17.         else
  18.         {
  19.             if (Game.Player.Character.IsInRangeOf(MissionTrigger, 2f))
  20.             {
  21.                 SetupMission();
  22.             }
  23.         }
  24.     }
  25.  
  26.     void SetupMission()
  27.     {
  28.         //Set relationships
  29.         World.SetRelationshipBetweenGroups(Relationship.Hate, Game.GenerateHash("PLAYER"), EnemyRLGroup);
  30.         World.SetRelationshipBetweenGroups(Relationship.Hate, EnemyRLGroup, Game.GenerateHash("PLAYER"));
  31.  
  32.         //Create the Target
  33.         Target = World.CreateRandomPed(Location);
  34.  
  35.         Target.AlwaysKeepTask = true;
  36.         Target.RelationshipGroup = EnemyRLGroup;
  37.         Target.Weapons.Give(WeaponHash.Bat, -1, true, true);
  38.         Target.Task.WanderAround(Location, 4f);
  39.  
  40.  
  41.         //Create the Guards
  42.         int NumberOfGuards = 4;
  43.         for (int i = 0; i < NumberOfGuards; i++)
  44.         {
  45.             Ped p = World.CreateRandomPed(Location.Around(3));
  46.  
  47.             p.AlwaysKeepTask = true;
  48.             p.RelationshipGroup = EnemyRLGroup;
  49.             p.Weapons.Give(WeaponHash.Pistol, 90, true, true);
  50.             p.Task.WanderAround(Location, 5f);
  51.    
  52.             Guards.Add(p);
  53.         }
  54.  
  55.         //Create the companion
  56.         Companion = World.CreateRandomPed(Game.Player.Character.Position.Around(3f));
  57.         Companion.AlwaysKeepTask = true;
  58.         Companion.RelationshipGroup = Game.GenerateHash("PLAYER");
  59.         Companion.Task.FollowToOffsetFromEntity(Game.Player.Character, Game.Player.Character.ForwardVector * -1, 2f, -1, 2f, true); //Make the companion follow the player
  60.  
  61.         UI.ShowSubtitle("~b~[Contact]~w~: Kill the guy located in "+World.GetStreetName(Location)+".", 6000);
  62.         MissionIsRunning = true;
  63.     }
  64.     void HandleMission()
  65.     {
  66.         //Win conditions
  67.         if (Target.IsDead)
  68.         {          
  69.             Game.Player.Money += Reward;
  70.             UI.Notify("~g~Mission completed.");
  71.             CleanMissionEntities();
  72.             MissionIsRunning = false;
  73.             return;
  74.         }
  75.  
  76.         //Fail conditions
  77.         if (Game.Player.IsDead)
  78.         {
  79.             UI.Notify("~r~Mission failed.");
  80.             CleanMissionEntities();
  81.             MissionIsRunning = false;
  82.             return;
  83.         }
  84.  
  85.         //^ We always RETURN whenever the mission has ended, to make sure the mission doesn't get processed anymore.
  86.         //If you won/failed, there's no point if checking anything mission-specific anymore.
  87.  
  88.  
  89.    //Handle the entities
  90.         //Teleport the companion near the player if its too far away (lost)
  91.         if (Companion.Exists() && Companion.IsAlive && Companion.IsInRangeOf(Game.Player.Character.Position, 50f))
  92.         {
  93.             Companion.Position = Game.Player.Character.Position.Around(2f);
  94.         }
  95.  
  96.         //For the sake of examples, we'll make an excuse to handle the target, make them flee if you're nearby and armed with an RPG.        
  97.         if(!Target.IsFleeing && Game.Player.Character.IsInRangeOf(Target.Position, 40f) && Game.Player.Character.Weapons.Current.Hash == WeaponHash.RPG)
  98.         {
  99.             //This bit only will be applied if the target is NOT fleeing yet, and because we task them to flee, "IsFleeing" will remain true forever, preventing this from triggering again.
  100.             //So we can put here stuff that will only happen ONCE, when the Target starts fleeing.
  101.             //Like a subtitle emulating the Target's vocal reaction.
  102.  
  103.             UI.ShowSubtitle("~r~[Target]:~w~ WHAT THE FUCK, DUDE", 3000);
  104.             Target.Task.FleeFrom(Game.Player.Character, -1);
  105.         }
  106.     }
  107.  
  108. //This function will make sure all entities are removed from your control, and left to be despawned by the game.
  109. //You can force an immediate deletion by replacing 'MarkAsNoLongerNeeded()' with 'Delete()'.
  110.     void CleanMissionEntities()
  111.     {
  112.         if (Target.Exists()) Target.MarkAsNoLongerNeeded();
  113.  
  114.         foreach (Ped p in Guards)
  115.         {
  116.             if (p.Exists()) p.MarkAsNoLongerNeeded();
  117.         }
  118.  
  119.         if (Companion.Exists()) Companion.MarkAsNoLongerNeeded();
  120.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement