Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool MissionIsRunning = false;
- Vector3 MissionTrigger = Vector3.Zero;
- int EnemyRLGroup = World.AddRelationshipGroup("enemies");
- List<Ped> Guards = new List<Ped>(); //The list of peds that will guard the Target ped.
- Ped Target = null; //The target ped itself.
- Ped Companion = null; //Your companion.
- int Reward = 5000;
- Vector3 Location = Vector3.Zero;
- void OnTick(object sender, EventArgs e)
- {
- if (MissionIsRunning)
- {
- HandleMission();
- }
- else
- {
- if (Game.Player.Character.IsInRangeOf(MissionTrigger, 2f))
- {
- SetupMission();
- }
- }
- }
- void SetupMission()
- {
- //Set relationships
- World.SetRelationshipBetweenGroups(Relationship.Hate, Game.GenerateHash("PLAYER"), EnemyRLGroup);
- World.SetRelationshipBetweenGroups(Relationship.Hate, EnemyRLGroup, Game.GenerateHash("PLAYER"));
- //Create the Target
- Target = World.CreateRandomPed(Location);
- Target.AlwaysKeepTask = true;
- Target.RelationshipGroup = EnemyRLGroup;
- Target.Weapons.Give(WeaponHash.Bat, -1, true, true);
- Target.Task.WanderAround(Location, 4f);
- //Create the Guards
- int NumberOfGuards = 4;
- for (int i = 0; i < NumberOfGuards; i++)
- {
- Ped p = World.CreateRandomPed(Location.Around(3));
- p.AlwaysKeepTask = true;
- p.RelationshipGroup = EnemyRLGroup;
- p.Weapons.Give(WeaponHash.Pistol, 90, true, true);
- p.Task.WanderAround(Location, 5f);
- Guards.Add(p);
- }
- //Create the companion
- Companion = World.CreateRandomPed(Game.Player.Character.Position.Around(3f));
- Companion.AlwaysKeepTask = true;
- Companion.RelationshipGroup = Game.GenerateHash("PLAYER");
- Companion.Task.FollowToOffsetFromEntity(Game.Player.Character, Game.Player.Character.ForwardVector * -1, 2f, -1, 2f, true); //Make the companion follow the player
- UI.ShowSubtitle("~b~[Contact]~w~: Kill the guy located in "+World.GetStreetName(Location)+".", 6000);
- MissionIsRunning = true;
- }
- void HandleMission()
- {
- //Win conditions
- if (Target.IsDead)
- {
- Game.Player.Money += Reward;
- UI.Notify("~g~Mission completed.");
- CleanMissionEntities();
- MissionIsRunning = false;
- return;
- }
- //Fail conditions
- if (Game.Player.IsDead)
- {
- UI.Notify("~r~Mission failed.");
- CleanMissionEntities();
- MissionIsRunning = false;
- return;
- }
- //^ We always RETURN whenever the mission has ended, to make sure the mission doesn't get processed anymore.
- //If you won/failed, there's no point if checking anything mission-specific anymore.
- //Handle the entities
- //Teleport the companion near the player if its too far away (lost)
- if (Companion.Exists() && Companion.IsAlive && Companion.IsInRangeOf(Game.Player.Character.Position, 50f))
- {
- Companion.Position = Game.Player.Character.Position.Around(2f);
- }
- //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.
- if(!Target.IsFleeing && Game.Player.Character.IsInRangeOf(Target.Position, 40f) && Game.Player.Character.Weapons.Current.Hash == WeaponHash.RPG)
- {
- //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.
- //So we can put here stuff that will only happen ONCE, when the Target starts fleeing.
- //Like a subtitle emulating the Target's vocal reaction.
- UI.ShowSubtitle("~r~[Target]:~w~ WHAT THE FUCK, DUDE", 3000);
- Target.Task.FleeFrom(Game.Player.Character, -1);
- }
- }
- //This function will make sure all entities are removed from your control, and left to be despawned by the game.
- //You can force an immediate deletion by replacing 'MarkAsNoLongerNeeded()' with 'Delete()'.
- void CleanMissionEntities()
- {
- if (Target.Exists()) Target.MarkAsNoLongerNeeded();
- foreach (Ped p in Guards)
- {
- if (p.Exists()) p.MarkAsNoLongerNeeded();
- }
- if (Companion.Exists()) Companion.MarkAsNoLongerNeeded();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement