private void QuestUpdates() { var questsInProgress = PlayerData.Quests.Where(q => q.InProgress).ToList(); var qNum = 1; foreach (var q in questsInProgress.Where(qu => qu.SpawnTargets && qu.HasSpawnedTargets)) { foreach (var b in q.BlipObjects) { if (qNum < 10) { b.Blip.ShowNumber(qNum); } } var conditionsToFix = q.Conditions.Where(c => !c.Done && (c.Type == ConditionType.Kill || c.Type == ConditionType.Loot) && c.Parameters.ContainsKey("ModelHash")); foreach (var c in conditionsToFix) { var quest = q; var npcs = WorldData.Npcs.Where(n => n.Name == "Quest_" + quest.Name).ToList(); for (int i = 0; i < npcs.Count; i++) { var n = npcs[i]; if (n.Ped.Exists() && !n.Ped.IsAlive) { n.Destroy(); } } //If no npcs found, or npcs are too high if (WorldData.Npcs.All(n => n.Name != "Quest_" + quest.Name) || WorldData.Npcs.Where(n => n.Name == "Quest_" + quest.Name).All(n => !n.Ped.IsAlive) || WorldData.Npcs.Where(n => n.Name == "Quest_" + quest.Name).All(w => w.Ped.Exists() && w.Ped.Position.Z > Game.Player.Character.Position.Z + 45) || WorldData.Npcs.Where(n => n.Name == "Quest_" + quest.Name).All(w => w.Ped.Exists() && w.Ped.Position.Z < Game.Player.Character.Position.Z - 45)) { q.HasSpawnedTargets = false; c.Position = RPGMethods.GetSpawnPoint(200); q.ClearObjectsAndBlips(); q.SetupCondition(c, false); RPGLog.Log("Spawning more peds for quest : " + quest.Name); } } qNum++; } }
public void SetupCondition(QuestCondition c, bool firstSetup) { if (c.Type == ConditionType.Kill && c.Parameters.ContainsKey("ModelHash") || c.Type == ConditionType.Loot && c.Parameters.ContainsKey("ModelHash")) { int[] hashes; var models = c.Parameters["ModelHash"] as uint[]; var modelsA = c.Parameters["ModelHash"] as JArray; if (models != null) { hashes = models.Select(m => (int)m).ToArray(); } else { hashes = modelsA.Select(jv => (uint)jv).Select(t => (int)t).ToArray(); } if (SpawnTargets) { c.Position = c.Position == Vector3.Zero ? RPGMethods.GetSpawnPoint(350) : c.Position; BlipObjects.Add(RPGBlips.QuestArea(Name, c.Position)); EventHandler.Do(q => { var pos = c.Position; var amountToSpawn = AmountToSpawn; var playerGroup = Game.Player.Character.RelationshipGroup; var enemies = World.AddRelationshipGroup("RPG_Enemies"); World.SetRelationshipBetweenGroups(Relationship.Neutral, playerGroup, enemies); for (int i = 0; i < amountToSpawn; i++) { var hash = hashes[Random.Range(0, hashes.Length)]; var m = new Model(hash); m.Request(1000); var ped = World.CreatePed(m, pos + Vector3.RandomXY() * 2, Game.Player.Character.Heading + 180); ped.RelationshipGroup = enemies; var b = ped.AddBlip(); EventHandler.Wait(100); b.IsFriendly = false; b.Scale = 0.6f; ped.Task.WanderAround(); //todo: apply some weapon damage scaling here lol ped.Weapons.Give(WeaponHash.Pistol, 1000, false, true); ped.CanSwitchWeapons = true; RPG.WorldData.AddPed(new NpcObject("Quest_" + Name, ped)); RPG.WorldData.AddBlip(new BlipObject("Quest_" + Name, b)); HasSpawnedTargets = true; } }); } } if (!c.Parameters.ContainsKey("Current")) { c.Parameters.Add("Current", 0); } if (firstSetup) { switch (c.Type) { case ConditionType.Kill: case ConditionType.Loot: case ConditionType.DestroyVehicle: case ConditionType.Acquire: c.Parameters["Current"] = 0; break; case ConditionType.Interact: case ConditionType.Escort: case ConditionType.Race: case ConditionType.EvadeCops: c.Parameters["Current"] = false; break; case ConditionType.Custom: break; default: throw new ArgumentOutOfRangeException(); } } }