public static void Recruit(this Ped ped, Ped leader) { if (!(leader == null)) { PedGroup group = leader.CurrentPedGroup; ped.LeaveGroup(); Function.Call(Hash.SET_PED_RAGDOLL_ON_COLLISION, ped.Handle, false); ped.Task.ClearAll(); group.SeparationRange = 2.14748365E+09f; if (!group.Contains(leader)) { group.Add(leader, true); } if (!group.Contains(ped)) { group.Add(ped, false); } ped.IsPersistent = true; ped.RelationshipGroup = leader.RelationshipGroup; ped.NeverLeavesGroup = true; Blip currentBlip = ped.CurrentBlip; if (currentBlip.Type != 0) { currentBlip.Remove(); } Blip blip = ped.AddBlip(); blip.Color = BlipColor.Green; blip.Scale = 0.65f; blip.Name = "Group"; PlayerGroup.SetPedTasks(ped, PedTasks.Follow); } }
private void CreateColonel() { _colonel?.Delete(); // in case the colonel already exists somehow. var m = new Model(PedHash.Marine01SMM); m.Request(); while (!m.IsLoaded) { Script.Yield(); } _colonel = World.CreatePed(m, _colonelSpawn - Vector3.WorldUp, _colonelHeading); if (_colonel == null) { // Let's break here just in case. throw new NullReferenceException("Colonel returned null for IntroMission."); } var b = _colonel.AddBlip(); b.Sprite = BlipSprite.GTAOMission; b.Color = Scene.MarkerBlipColor; b.Name = "Colonel Larson"; _colonel.SetDefaultClothes(); _colonel.RelationshipGroup = PlayerPed.RelationshipGroup; _colonel.CanRagdoll = false; m.MarkAsNoLongerNeeded(); }
/// <summary> /// attempts to change the player's body. /// if the player has already changed body, the original body is restored /// </summary> public void TryBodyChange() { if (!HasChangedBody) { List <Ped> playerGangMembers = SpawnManager.instance.GetSpawnedPedsOfGang (GangManager.instance.PlayerGang); for (int i = 0; i < playerGangMembers.Count; i++) { if (Game.Player.IsTargetting(playerGangMembers[i])) { if (playerGangMembers[i].IsAlive) { theOriginalPed = CurrentPlayerCharacter; //adds a blip to the protagonist so that we know where we left him Blip protagonistBlip = theOriginalPed.AddBlip(); protagonistBlip.Sprite = BlipSprite.Creator; Function.Call(Hash.BEGIN_TEXT_COMMAND_SET_BLIP_NAME, "STRING"); Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, "Last Used Protagonist"); Function.Call(Hash.END_TEXT_COMMAND_SET_BLIP_NAME, protagonistBlip); defaultMaxHealth = theOriginalPed.MaxHealth; moneyFromLastProtagonist = Game.Player.Money; TakePedBody(playerGangMembers[i]); break; } } } } else { RestorePlayerBody(); } }
public static void Recruit(this Ped ped, Ped leader) { if (leader != null) { PedGroup currentPedGroup = leader.CurrentPedGroup; ped.LeaveGroup(); InputArgument[] arguments = new InputArgument[] { ped.Handle, false }; Function.Call(Hash._0xF0A4F1BBF4FA7497, arguments); ped.Task.ClearAll(); currentPedGroup.SeparationRange = 2.147484E+09f; if (!currentPedGroup.Contains(leader)) { currentPedGroup.Add(leader, true); } if (!currentPedGroup.Contains(ped)) { currentPedGroup.Add(ped, false); } ped.IsPersistent = true; ped.RelationshipGroup = leader.RelationshipGroup; ped.NeverLeavesGroup = true; Blip currentBlip = ped.CurrentBlip; if (currentBlip.Type != 0) { currentBlip.Remove(); } Blip blip2 = ped.AddBlip(); blip2.Color = BlipColor.Green; blip2.Scale = 0.65f; blip2.Name = "Group"; PlayerGroup.SetPedTasks(ped, PedTasks.Follow); } }
private void startSellingDrugs() { Ped closestPed = World.GetClosestPed(Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0, 5, 0)), 5.0f); if (closestPed != Game.Player.Character && closestPed.IsDead == false && isPlayerSelling == false && !buyedPeds.Contains(closestPed) && sellers[0] != closestPed) { buyerBlip = closestPed.AddBlip(); closestPed.Task.Wait(1000000); closestPed.AlwaysKeepTask = true; displayMenu(sellMenu); isPlayerSelling = true; } else if (isPlayerSelling == true) { closestPed.CurrentBlip.Remove(); closestPed.Task.Wait(1); closestPed.AlwaysKeepTask = false; isPlayerSelling = false; } else if (buyedPeds.Contains(closestPed)) { UI.Notify("~r~Already Tried Selling Drugs To This Person."); } buyedPeds.Add(closestPed); }
public override void SpawnEntities() { int rand = Database.Random.Next(3, 6); Vector3 spawn = GetSpawnPoint(); if (IsValidSpawn(spawn)) { for (int i = 0; i <= rand; i++) { Ped ped = World.CreateRandomPed(spawn.Around(5f)); if (!(ped == null)) { Blip blip = ped.AddBlip(); blip.Color = GTA.BlipColor.Blue; blip.Name = "Friendly"; ped.RelationshipGroup = Relationships.FriendlyRelationship; ped.Task.FightAgainstHatedTargets(9000f); ped.SetAlertness(Alertness.FullyAlert); ped.SetCombatAttributes(CombatAttributes.AlwaysFight, true); ped.Weapons.Give(Database.WeaponHashes[Database.Random.Next(Database.WeaponHashes.Length)], 25, true, true); _pedGroup.Add(ped, i == 0); _pedGroup.FormationType = 0; _peds.Add(ped); EntityEventWrapper eventWrapper = new EntityEventWrapper(ped); eventWrapper.Died += EventWrapperOnDied; eventWrapper.Disposed += EventWrapperOnDisposed; } } UI.Notify("~b~Friendly~s~ survivors nearby.", true); } }
private static void AddBlip(Ped ped) { if (!ped.CurrentBlip.Exists()) { Blip blip = ped.AddBlip(); blip.Name = "Enemy Ped"; EntityEventWrapper entWrapper = new EntityEventWrapper(ped); entWrapper.Died += delegate(EntityEventWrapper sender, Entity entity) { Blip currentBlip2 = entity.CurrentBlip; if (currentBlip2.Handle != 0) { currentBlip2.Remove(); } sender.Dispose(); }; entWrapper.Aborted += delegate(EntityEventWrapper sender, Entity entity) { Blip currentBlip = entity.CurrentBlip; if (currentBlip.Handle != 0) { currentBlip.Remove(); } }; } }
public static void SpawnRandomPeds(float distance = 100f) { Vector3 SpawnPoint = new Vector3(); Random rnd = new Random(); for (int i = 0; i < rnd.Next(1, 9); i++) { if (Function.Call <bool>(Hash.CAN_CREATE_RANDOM_PED)) { if (i == 0) { SpawnPoint = Game.Player.Character.Position.Around(distance); } else { SpawnPoint = SpawnPoint.Around(3); } SpawnPoint.Z = World.GetGroundHeight(SpawnPoint); SpawnPoint.Z += 0.9f; Ped RandPed = World.CreateRandomPed(SpawnPoint); RandPed.AddBlip().Color = BlipColor.White; // For test RandPed.MarkAsNoLongerNeeded(); RandPed.Task.RunTo(Game.Player.Character.Position); RandPed.Task.FightAgainst(Game.Player.Character); } Wait(0); } }
void ConfigPedForMission(Ped _ped) { _ped.BlockPermanentEvents = true; _ped.AlwaysKeepTask = true; _ped.AddBlip(); _ped.CurrentBlip.IsFriendly = true; _ped.CurrentBlip.Scale = 0.5f; }
// Spawn blip for Ped public static Blip SpawnPedBlip(Ped pedName, BlipSprite sprite, int blipColour, bool isEnemy) { // Add blip to ped pedName.AddBlip(); // Set blip colour Function.Call(Hash.SET_BLIP_COLOUR, pedName.CurrentBlip, blipColour); // Is ped an enemy Function.Call(Hash.SET_BLIP_AS_FRIENDLY, pedName.CurrentBlip, isEnemy); return(pedName.CurrentBlip); }
public static void Docs_help() { truck = World.CreateVehicle("benson", World.GetNextPositionOnStreet(Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0, 150, 0)))); truck.EngineRunning = true; Doc = truck.CreatePedOnSeat(VehicleSeat.Driver, PedHash.Scientist01SMM); Doc.Task.DriveTo(truck, Game.Player.Character.Position, 10, 30); Doc.AddBlip(); docshelp = true; delorean = Game.Player.Character.CurrentVehicle; }
public void MakeFriendly(Ped ped, RelationshipGroup relationshipGroup) { ped.RelationshipGroup = relationshipGroup; ped.Health = 100; Function.Call(Hash.SET_PED_AS_GROUP_MEMBER, ped, Game.Player.Character.PedGroup); ped.Weapons.Give(WeaponHash.CarbineRifle, 100, true, true); ped.Task.FightAgainstHatedTargets(30f); ped.AlwaysKeepTask = true; Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, ped, 46, true); Blip blip = ped.AddBlip(); blip.Sprite = BlipSprite.Friend; blip.Color = BlipColor.Blue; }
public TaxiEvent(Ped ped, Ped driver, Vehicle taxi) { hitch = ped; Driver = driver; Taxi = taxi; hitch.IsPersistent = true; Taxi.IsPersistent = true; Driver.IsPersistent = true; if (LivelyWorld.DebugBlips && !taxi.CurrentBlip.Exists()) { Taxi.AddBlip(); Taxi.CurrentBlip.Sprite = BlipSprite.Cab; Taxi.CurrentBlip.Color = BlipColor.Yellow; Taxi.CurrentBlip.IsShortRange = true; hitch.AddBlip(); hitch.CurrentBlip.Color = BlipColor.White; hitch.CurrentBlip.Scale = 0.7f; hitch.CurrentBlip.IsShortRange = true; } hitch.AlwaysKeepTask = true; driver.AlwaysKeepTask = true; if (hitch.IsInVehicle(Taxi)) { if (LivelyWorld.Debug >= DebugLevel.EventsAndScenarios) { UI.Notify("Taxi event mode: dropoff"); } DropOff = true; //Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD, Driver, Taxi, pos.X, pos.Y, pos.Z, 10f, 1, Taxi.Model, 1 + 2 + 8 + 16 + 32 + 128 + 256, 15.0, 1.0); } else { if (LivelyWorld.Debug >= DebugLevel.EventsAndScenarios) { UI.Notify("Taxi event mode: pick up"); } Vector3 pos = hitch.Position; Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD, Driver, Taxi, pos.X, pos.Y, pos.Z, 10f, 1, Taxi.Model, 1 + 2 + 8 + 16 + 32 + 128 + 256, 15.0, 1.0); hitch.Task.LookAt(Taxi, -1); } //Driver.Task.DriveTo(Taxi, hitch.Position, 10f, 10f, 1+2+ 16+32 + 128 + 256); }
/* * private void LogToFile(string text) * { * using (StreamWriter w = File.AppendText("log.txt")) * { * w.Write(text + "\n"); * } * }*/ private void StartAmbulanceMissions() { Ped player = Game.Player.Character; _onAmbulanceMission = true; _missionState = 1; _critical = false; _cprAppliedThisMission = false; _cprBeingApplied = false; _reanimationFailed = false; _headsup = new UIText("Level: ~b~" + _level, new Point(2, 320), 0.7f, Color.WhiteSmoke, GTA.Font.HouseScript, false); _headsupRectangle = new UIRectangle(new Point(0, 320), new Size(215, 65), Color.FromArgb(100, 0, 0, 0)); /*Function.Call(Hash._0xB87A37EEB7FAA67D, "STRING"); * Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, "Pick up the ~g~patient~w~."); * Function.Call(Hash._0x9D77056A530643F6, 0.5f, 1);*/ UI.ShowSubtitle("Pick up the ~g~patient~w~.", 9999999); Vector3 pedSpawnPoint = GetRandomVictim(); _victimPed = Function.Call <Ped>(Hash.CREATE_RANDOM_PED, pedSpawnPoint.X, pedSpawnPoint.Y, pedSpawnPoint.Z); _victimPed.IsPersistent = true; _victimPed.AlwaysDiesOnLowHealth = false; //this.victimPed.IsPersistent = true; //this.victimPed.AlwaysDiesOnLowHealth = false; _victimPed.Health = _level >= 14 ? 30 : _difficultyScale[_level - 1]; player.IsEnemy = false; _victimPed.IsEnemy = false; Function.Call(Hash.SET_PED_MOVEMENT_CLIPSET, _victimPed.Handle, _victimPed.Gender == Gender.Male ? "move_m@injured" : "move_f@injured"); if (_blip != null) { if (_blip.Exists()) { _blip.Remove(); } } _blip = _victimPed.AddBlip(); Function.Call(Hash.SET_BLIP_AS_FRIENDLY, _blip.Handle, true); _blip.Color = BlipColor.Green; _blip.ShowRoute = true; }
public override void SpawnEntities() { Vector3 spawn = GetSpawnPoint(); if (IsValidSpawn(spawn)) { Vehicle vehicle = World.CreateVehicle(Database.GetRandomVehicleModel(), spawn, (float)Database.Random.Next(1, 360)); if (vehicle == null) { Complete(); } else { _vehicle = vehicle; Blip vehicleBlip = _vehicle.AddBlip(); vehicleBlip.Name = "Enemy Vehicle"; vehicleBlip.Sprite = GTA.BlipSprite.PersonalVehicleCar; vehicleBlip.Color = GTA.BlipColor.Red; EntityEventWrapper vehicleWrapper = new EntityEventWrapper(_vehicle); vehicleWrapper.Died += VehicleWrapperOnDied; vehicleWrapper.Updated += VehicleWrapperOnUpdated; for (int i = 0; i < vehicle.PassengerSeats + 1; i++) { if (_group.MemberCount < 6 && vehicle.IsSeatFree(GTA.VehicleSeat.Any)) { Ped ped = vehicle.CreateRandomPedOnSeat((i == 0) ? GTA.VehicleSeat.Driver : GTA.VehicleSeat.Any); if (!(ped == null)) { ped.Weapons.Give(Database.WeaponHashes[Database.Random.Next(Database.WeaponHashes.Length)], 25, true, true); ped.SetCombatAttributes(CombatAttributes.AlwaysFight, true); ped.SetAlertness(Alertness.FullyAlert); ped.RelationshipGroup = Relationships.HostileRelationship; _group.Add(ped, i == 0); Blip blip = ped.AddBlip(); blip.Name = "Enemy"; _peds.Add(ped); EntityEventWrapper pedWrapper = new EntityEventWrapper(ped); pedWrapper.Died += PedWrapperOnDied; pedWrapper.Updated += PedWrapperOnUpdated; pedWrapper.Disposed += PedWrapperOnDisposed; } } } UI.Notify("~r~Hostiles~s~ nearby!"); } } }
public static void Recruit(this Ped ped, Ped leader, bool canBeTargeted, bool invincible, int accuracy) { if (!(leader == null)) { ped.LeaveGroup(); ped.SetRagdollOnCollision(false); ped.Task.ClearAll(); PedGroup group = leader.CurrentPedGroup; group.SeparationRange = 2.14748365E+09f; if (!group.Contains(leader)) { group.Add(leader, true); } if (!group.Contains(ped)) { group.Add(ped, false); } ped.CanBeTargetted = canBeTargeted; ped.Accuracy = accuracy; ped.IsInvincible = invincible; ped.IsPersistent = true; ped.RelationshipGroup = leader.RelationshipGroup; ped.NeverLeavesGroup = true; Blip currentBlip = ped.CurrentBlip; if (currentBlip.Type != 0) { currentBlip.Remove(); } Blip blip = ped.AddBlip(); blip.Color = GTA.BlipColor.Blue; blip.Scale = 0.7f; blip.Name = "Friend"; EntityEventWrapper wrapper = new EntityEventWrapper(ped); wrapper.Died += delegate(EntityEventWrapper sender, Entity entity) { Blip currentBlip2 = entity.CurrentBlip; if (currentBlip2.Type != 0) { currentBlip2.Remove(); } wrapper.Dispose(); }; ped.PlayAmbientSpeech("GENERIC_HI", SpeechModifier.Standard); } }
private bool CreateRandomTarget() { Random rand = new Random(); int rnd = rand.Next(3, 12); if (inVehicle) { target = CreateRandomDriver(Game.Player.Character.Position, true); if (target == null) { return(false); } if (rnd < weapons.Count) { target.Weapons.Give((WeaponHash)weapons[rnd].WeaponHashValue, 120, false, true); } } else { Vector3 awaitedVec = Vector3.Zero; if ((awaitedVec = getRandomPosNearPlayer()) != Vector3.Zero) { target = GTA.World.CreateRandomPed(awaitedVec); if (rnd < weapons.Count) { target.Weapons.Give((WeaponHash)weapons[rnd].WeaponHashValue, 120, false, true); } } else { return(false); } } if (target != null) { target.AddBlip(); } else { return(false); } Function.Call(Hash.CLEAR_AREA_OF_VEHICLES, target.Position.X, target.Position.Y, target.Position.Z, 100, false, false, false, false, false); return(true); }
public void Configure(bool wander = true) { if (Ped == null) { throw new ArgumentException(); } WeaponHash weapon; if (FighterCfg.Weapon == WeaponHash.Unarmed) { weapon = GlobalInfo.WeaponsList[ GlobalInfo.GeneralRandomInstance.Next(0, GlobalInfo.WeaponsList.Count - 1) ]; } else { weapon = FighterCfg.Weapon; } Ped.Weapons.Give(weapon, -1, true, true); Ped.Accuracy = 15; Ped.MaxHealth = 200; Ped.Health = 200; Ped.Armor = 100; Ped.IsPersistent = true; // TODO if (wander) { Ped.Task.WanderAround(); } Ped.RelationshipGroup = GlobalInfo.RELATIONSHIP_TERRORIST; Function.Call(Hash.SET_PED_COMBAT_MOVEMENT, Ped, 2); // Offensive combat movement Function.Call(Hash.SET_PED_HEARING_RANGE, Ped, 10000f); Function.Call(Hash.SET_PED_SEEING_RANGE, Ped, 10000f); Ped.AddBlip(); if (Ped.AttachedBlip != null) { Ped.AttachedBlip.Color = _BlipColor; } Exists = true; }
/// <summary> /// Apply configurations to ground crew /// </summary> /// <param name="crew"><c>Ped</c> to apply configuration to</param> /// <returns><c>true</c> if the specified <c>Ped</c> is in the leader's PedGroup</returns> protected bool configureGroundCrew(Ped crew) { // add to player's PedGroup if there is space leaderPedGroup.Add(crew, false); crew.NeverLeavesGroup = true; // verify that the crew is part of the player's PedGroup if (!crew.IsInGroup) { return(false); } // draw blip crew.AddBlip(); crew.AttachedBlip.Scale = blipScale; crew.AttachedBlip.Color = BlipColor.Green; return(true); }
public void StartRC() { if (Vehicle == null) { return; } IsRemoteControlled = true; Vehicle.LockStatus = VehicleLockStatus.StickPlayerInside; Clone = PlayerSwitch.CreatePedAndSwitch(out OriginalPed, Main.PlayerPed.Position, Main.PlayerPed.Heading, true); Clone.SetIntoVehicle(Vehicle, VehicleSeat.Driver); Clone.CanFlyThroughWindscreen = false; Clone.CanBeDraggedOutOfVehicle = false; Clone.BlockPermanentEvents = true; Clone.AlwaysKeepTask = true; Clone.IsVisible = false; _blip = OriginalPed.AddBlip(); _blip.Sprite = (BlipSprite)480; _blip.Color = BlipColor.White; foreach (var sound in _rcSounds) { sound.SourceEntity = OriginalPed; } rcOn.Play(); OriginalPed.Task.TurnTo(Vehicle); if (CurrentMode == RcModes.FromPlayerCamera) { _camera = World.CreateCamera(GameplayCamera.Position, GameplayCamera.Rotation, GameplayCamera.FieldOfView); _camera.PointAt(Vehicle); World.RenderingCamera = _camera; } }
public void SpawnCustomers(int max) { if (!_generatingPeds) { _generatingPeds = true; int createdPeds = 0; int customerCount = Main.RNG.Next(1, max + 1); Vector3 playerPos = Game.Player.Character.Position; Vector3 spawnPos = Vector3.Zero; float spawnRange = 300f; while (createdPeds < customerCount) { // credits to alexguirre while ((spawnPos = World.GetSafeCoordForPed(playerPos.Around(spawnRange), true, 16)) == Vector3.Zero) { Script.Yield(); spawnRange -= 5f; } Ped ped = World.CreateRandomPed(spawnPos); ped.IsInvincible = true; ped.BlockPermanentEvents = true; ped.AlwaysKeepTask = true; Function.Call(Hash.TASK_START_SCENARIO_IN_PLACE, ped.Handle, "WORLD_HUMAN_STAND_IMPATIENT", 0, true); Blip pedBlip = ped.AddBlip(); pedBlip.Sprite = BlipSprite.Friend; pedBlip.Color = (BlipColor)2; pedBlip.IsShortRange = false; pedBlip.Scale = 1.0f; pedBlip.Name = Localization.Get("CUSTOMER_NAME"); Customers.Add(ped); createdPeds++; } _generatingPeds = false; } }
public static void SetPedTasks(Ped ped, PedTasks task) { ped.Task.ClearAll(); if (task != PedTasks.Follow) { if (task == PedTasks.Guard) { ped.Task.GuardCurrentPosition(); } else if (task == PedTasks.Wander) { ped.Task.WanderAround(ped.Position, 100f); } else if (task == PedTasks.None) { ped.Task.StandStill(-1); } else if (task == PedTasks.Leave) { ped.LeaveGroup(); Blip currentBlip = ped.CurrentBlip; if (currentBlip.Handle != 0) { currentBlip.Remove(); } ped.RelationshipGroup = Relationships.FriendlyGroup; ped.Task.ClearAll(); Blip blip2 = ped.AddBlip(); blip2.Color = BlipColor.Blue; blip2.Scale = 0.65f; blip2.Name = "Friendly"; task = PedTasks.Wander; ped.Task.WanderAround(ped.Position, 100f); } } Population.survivorList.Find(a => a.pedEntity == ped).tasks = task; }
/// <summary> /// Creates a new Ped /// </summary> /// <param name="team">Team A or B</param> void CreateNewPed(string team) { //If there are both Spawnpoints defined if (IsSpawnLocADefined && IsSpawnLocBDefined) { //depending on team we build a small list of models for a random selection List <string> model_names = new List <string>(); if (team == "A") { //Tip: Google one of the strings for find lists of Modelnames model_names.Add("g_f_y_families_01"); model_names.Add("g_m_y_famca_01"); model_names.Add("g_m_y_famdnf_01"); model_names.Add("g_m_y_famfor_01"); } if (team == "B") { model_names.Add("g_f_y_lost_01"); model_names.Add("g_m_y_lost_01"); model_names.Add("g_m_y_lost_02"); model_names.Add("g_m_y_lost_03"); } //for random selection Random r = new Random(); //This will become the new created ped Ped ped = null; //Yes.. the following code is uggly (to much copy paste for team A & B, nicer would be to isolated this in a new method) //if there are excepitons in the follwing lines check the spelling of your modelnames if (team == "A") { ped = GTA.World.CreatePed(model_names[r.Next(0, model_names.Count)], spawnLocA); //Relationship if (ped != null) { managedPedsTeamA.Add(ped); ped.RelationshipGroup = relgrpA; } } if (team == "B") { ped = GTA.World.CreatePed(model_names[r.Next(0, model_names.Count)], spawnLocB); //Relationship if (ped != null) { managedPedsTeamB.Add(ped); ped.RelationshipGroup = relgrpB; } } //There should be no tasks but... ped.Task.ClearAllImmediately(); //ped.Task.FightAgainst(Game.Player.Character); //Setting Up Health and Ammo ped.Health = 50; ped.Armor = 50; //Weapon ped.Weapons.Give(GTA.Native.WeaponHash.Musket, 1, true, true); //blip on the GTA map Blip blip = ped.AddBlip(); if (blip != null) { if (team == "A") { blip.Color = BlipColor.Yellow; } if (team == "B") { blip.Color = BlipColor.Green; } blip.Scale = 0.5f; } //Output for debugging //UI.Notify(ped.Handle.ToString() + " spawned for team " + team ); } else { //If there are not both Spawnpoints defined UI.Notify("Press H = TeamA or J = Team B to define the teams spawnlocation at your actual position"); } }
public void DisplayLocally() { try { var isPlane = Function.Call <bool>(Hash.IS_THIS_MODEL_A_PLANE, VehicleHash); float hRange = isPlane ? 1200f : 400f; var gPos = IsInVehicle ? VehiclePosition : Position; var inRange = isPlane ? true : Game.Player.Character.IsInRangeOf(gPos, hRange); if (inRange && !_isStreamedIn) { _isStreamedIn = true; if (_mainBlip != null) { _mainBlip.Remove(); _mainBlip = null; } } else if (!inRange && _isStreamedIn) { Clear(); _isStreamedIn = false; } if (!inRange) { if (_mainBlip == null && _blip) { _mainBlip = World.CreateBlip(gPos); _mainBlip.Color = BlipColor.White; _mainBlip.Scale = 0.8f; SetBlipName(_mainBlip, Name == null ? "<nameless>" : Name); } if (_blip && _mainBlip != null) { _mainBlip.Position = gPos; } return; } if (Character == null || !Character.Exists() || (!Character.IsInRangeOf(gPos, hRange) && Game.GameTime - LastUpdateReceived < 5000) || Character.Model.Hash != ModelHash || (Character.IsDead && PedHealth > 0)) { if (Character != null) { Character.Delete(); } Character = World.CreatePed(new Model(ModelHash), gPos, Rotation.Z); if (Character == null) { return; } Character.BlockPermanentEvents = true; Character.IsInvincible = true; Character.CanRagdoll = false; Character.RelationshipGroup = _relGroup; if (_blip) { Character.AddBlip(); if (Character.CurrentBlip == null) { return; } Character.CurrentBlip.Color = BlipColor.White; Character.CurrentBlip.Scale = 0.8f; SetBlipName(Character.CurrentBlip, Name); } if (PedProps != null) { foreach (KeyValuePair <int, int> pedprop in PedProps) { Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, pedprop.Key, pedprop.Value, 0, 0); } } return; } if (!Character.IsOccluded && Character.IsInRangeOf(Game.Player.Character.Position, 20f)) { Vector3 targetPos = Character.GetBoneCoord(Bone.IK_Head) + new Vector3(0, 0, 0.5f); targetPos += Character.Velocity / Game.FPS; Function.Call(Hash.SET_DRAW_ORIGIN, targetPos.X, targetPos.Y, targetPos.Z, 0); float sizeOffset = Math.Max(1f - ((GameplayCamera.Position - Character.Position).Length() / 30f), 0.3f); new UIResText(Name ?? "<Nameless>", new Point(0, 0), 0.4f * sizeOffset, Color.WhiteSmoke, Font.ChaletLondon, UIResText.Alignment.Centered) { Outline = true, }.Draw(); Function.Call(Hash.CLEAR_DRAW_ORIGIN); } if ((!_lastVehicle && IsInVehicle && VehicleHash != 0) || (_lastVehicle && IsInVehicle && (MainVehicle == null || !Character.IsInVehicle(MainVehicle) || MainVehicle.Model.Hash != VehicleHash || VehicleSeat != Util.GetPedSeat(Character)))) { if (MainVehicle != null && Util.IsVehicleEmpty(MainVehicle)) { MainVehicle.Position = MainVehicle.GetOffsetInWorldCoords(new Vector3(0, 0, -100)); MainVehicle.Delete(); } var vehs = World.GetAllVehicles().OrderBy(v => { if (v == null) { return(float.MaxValue); } return((v.Position - Character.Position).Length()); }).ToList(); if (vehs.Any() && vehs[0].Model.Hash == VehicleHash && vehs[0].IsInRangeOf(gPos, 3f)) { MainVehicle = vehs[0]; /*if (Game.Player.Character.IsInVehicle(MainVehicle) && * VehicleSeat == Util.GetPedSeat(Game.Player.Character)) * { * Game.Player.Character.Task.WarpOutOfVehicle(MainVehicle); * UI.Notify("~r~Car jacked!"); * }*/ } else { MainVehicle = World.CreateVehicle(new Model(VehicleHash), gPos, 0); } if (MainVehicle != null) { Function.Call(Hash.SET_VEHICLE_COLOURS, MainVehicle, VehiclePrimaryColor, VehicleSecondaryColor); MainVehicle.Livery = Livery; MainVehicle.Quaternion = VehicleRotation; MainVehicle.IsInvincible = true; Character.SetIntoVehicle(MainVehicle, (VehicleSeat)VehicleSeat); /*if (_playerSeat != -2 && !Game.Player.Character.IsInVehicle(_mainVehicle)) * { // TODO: Fix me. * Game.Player.Character.Task.WarpIntoVehicle(_mainVehicle, (VehicleSeat)_playerSeat); * }*/ } _lastVehicle = true; _justEnteredVeh = true; _enterVehicleStarted = DateTime.Now; return; } if (_lastVehicle && _justEnteredVeh && IsInVehicle && !Character.IsInVehicle(MainVehicle) && DateTime.Now.Subtract(_enterVehicleStarted).TotalSeconds <= 4) { return; } _justEnteredVeh = false; if (_lastVehicle && !IsInVehicle && MainVehicle != null) { if (Character != null) { Character.Task.LeaveVehicle(MainVehicle, true); } } Character.Health = PedHealth; _switch++; if (!inRange) { if (Character != null && Game.GameTime - LastUpdateReceived < 10000) { if (!IsInVehicle) { Character.PositionNoOffset = gPos; } else if (MainVehicle != null && GetResponsiblePed(MainVehicle).Handle == Character.Handle) { MainVehicle.Position = VehiclePosition; MainVehicle.Quaternion = VehicleRotation; } } return; } if (IsInVehicle) { if (GetResponsiblePed(MainVehicle).Handle == Character.Handle) { MainVehicle.Health = VehicleHealth; if (MainVehicle.Health <= 0) { MainVehicle.IsInvincible = false; //_mainVehicle.Explode(); } else { MainVehicle.IsInvincible = true; if (MainVehicle.IsDead) { MainVehicle.Repair(); } } MainVehicle.EngineRunning = IsEngineRunning; if (Plate != null) { MainVehicle.NumberPlate = Plate; } var radioStations = Util.GetRadioStations(); if (radioStations?.ElementAtOrDefault(RadioStation) != null) { Function.Call(Hash.SET_VEH_RADIO_STATION, radioStations[RadioStation]); } if (VehicleMods != null && _modSwitch % 50 == 0 && Game.Player.Character.IsInRangeOf(VehiclePosition, 30f)) { var id = _modSwitch / 50; if (VehicleMods.ContainsKey(id) && VehicleMods[id] != MainVehicle.GetMod((VehicleMod)id)) { Function.Call(Hash.SET_VEHICLE_MOD_KIT, MainVehicle.Handle, 0); MainVehicle.SetMod((VehicleMod)id, VehicleMods[id], false); Function.Call(Hash.RELEASE_PRELOAD_MODS, id); } } _modSwitch++; if (_modSwitch >= 2500) { _modSwitch = 0; } if (IsHornPressed && !_lastHorn) { _lastHorn = true; MainVehicle.SoundHorn(99999); } if (!IsHornPressed && _lastHorn) { _lastHorn = false; MainVehicle.SoundHorn(1); } if (IsInBurnout && !_lastBurnout) { Function.Call(Hash.SET_VEHICLE_BURNOUT, MainVehicle, true); Function.Call(Hash.TASK_VEHICLE_TEMP_ACTION, Character, MainVehicle, 23, 120000); // 30 - burnout } else if (!IsInBurnout && _lastBurnout) { Function.Call(Hash.SET_VEHICLE_BURNOUT, MainVehicle, false); Character.Task.ClearAll(); } _lastBurnout = IsInBurnout; Function.Call(Hash.SET_VEHICLE_BRAKE_LIGHTS, MainVehicle, Speed > 0.2 && _lastSpeed > Speed); if (MainVehicle.SirenActive && !Siren) { MainVehicle.SirenActive = Siren; } else if (!MainVehicle.SirenActive && Siren) { MainVehicle.SirenActive = Siren; } MainVehicle.LightsOn = LightsOn; MainVehicle.HighBeamsOn = HighBeamsOn; MainVehicle.SirenActive = Siren; if (Steering != MainVehicle.SteeringAngle) { Util.CustomSteeringAngle(MainVehicle.Handle, (float)(Math.PI / 180) * Steering); } Function.Call(Hash.SET_VEHICLE_LIVERY, MainVehicle, Livery); Function.Call(Hash.SET_VEHICLE_COLOURS, MainVehicle, VehiclePrimaryColor, VehicleSecondaryColor); if (MainVehicle.Model.IsPlane && LandingGear != MainVehicle.LandingGear) { MainVehicle.LandingGear = LandingGear; } if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles) { var isPedaling = IsPedaling(false); var isFastPedaling = IsPedaling(true); if (Speed < 2f) { if (isPedaling) { StopPedalingAnim(false); } else if (isFastPedaling) { StopPedalingAnim(true); } } else if (Speed < 11f && !isPedaling) { StartPedalingAnim(false); } else if (Speed >= 11f && !isFastPedaling) { StartPedalingAnim(true); } } if ((Speed > 0.2f || IsInBurnout) && MainVehicle.IsInRangeOf(VehiclePosition, 7.0f)) { MainVehicle.Velocity = VehicleVelocity + (VehiclePosition - MainVehicle.Position); MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f); _stopTime = Game.GameTime; } else if ((Game.GameTime - _stopTime) <= 1000) { Vector3 posTarget = Util.LinearVectorLerp(MainVehicle.Position, VehiclePosition + (VehiclePosition - MainVehicle.Position), (Game.GameTime - _stopTime), 1000); MainVehicle.PositionNoOffset = posTarget; MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f); } else { MainVehicle.PositionNoOffset = VehiclePosition; MainVehicle.Quaternion = VehicleRotation; } } } else { if (PedProps != null && _clothSwitch % 50 == 0 && Game.Player.Character.IsInRangeOf(Position, 30f)) { var id = _clothSwitch / 50; if (PedProps.ContainsKey(id) && PedProps[id] != Function.Call <int>(Hash.GET_PED_DRAWABLE_VARIATION, Character.Handle, id)) { Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, id, PedProps[id], 0, 0); } } _clothSwitch++; if (_clothSwitch >= 750) { _clothSwitch = 0; } if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeapon) { var wep = Character.Weapons.Give((WeaponHash)CurrentWeapon, 9999, true, true); Character.Weapons.Select(wep); } if (!_lastJumping && IsJumping) { Character.Task.Jump(); } if (IsParachuteOpen) { if (_parachuteProp == null) { _parachuteProp = World.CreateProp(new Model(1740193300), Character.Position, Character.Rotation, false, false); _parachuteProp.FreezePosition = true; Function.Call(Hash.SET_ENTITY_COLLISION, _parachuteProp.Handle, false, 0); } Character.FreezePosition = true; Character.Position = Position - new Vector3(0, 0, 1); Character.Quaternion = Rotation; _parachuteProp.Position = Character.Position + new Vector3(0, 0, 3.7f); _parachuteProp.Quaternion = Character.Quaternion; Character.Task.PlayAnimation("skydive@parachute@first_person", "chute_idle_right", 8f, 5000, false, 8f); } else { var dest = Position; Character.FreezePosition = false; if (_parachuteProp != null) { _parachuteProp.Delete(); _parachuteProp = null; } const int threshold = 50; if (IsAiming && !IsShooting && !Character.IsInRangeOf(Position, 0.5f) && _switch % threshold == 0) { Function.Call(Hash.TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD, Character.Handle, dest.X, dest.Y, dest.Z, AimCoords.X, AimCoords.Y, AimCoords.Z, 2f, 0, 0x3F000000, 0x40800000, 1, 512, 0, (uint)FiringPattern.FullAuto); } else if (IsAiming && !IsShooting && Character.IsInRangeOf(Position, 0.5f)) { Character.Task.AimAt(AimCoords, 100); } if (!Character.IsInRangeOf(Position, 0.5f) && ((IsShooting && !_lastShooting) || (IsShooting && _lastShooting && _switch % (threshold * 2) == 0))) { Function.Call(Hash.TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD, Character.Handle, dest.X, dest.Y, dest.Z, AimCoords.X, AimCoords.Y, AimCoords.Z, 2f, 1, 0x3F000000, 0x40800000, 1, 0, 0, (uint)FiringPattern.FullAuto); } else if ((IsShooting && !_lastShooting) || (IsShooting && _lastShooting && _switch % (threshold / 2) == 0)) { Function.Call(Hash.TASK_SHOOT_AT_COORD, Character.Handle, AimCoords.X, AimCoords.Y, AimCoords.Z, 1500, (uint)FiringPattern.FullAuto); } if (!IsAiming && !IsShooting && !IsJumping && !IsInParachuteFreeFall) { float distance = Character.Position.DistanceTo(Position); if (distance <= 0.15f || distance > 7.0f) // Still or too far away { if (distance > 7.0f) { Character.Position = dest - new Vector3(0, 0, 1f); Character.Quaternion = Rotation; } } else if (distance <= 1.25f) // Walking { Function.Call(Hash.TASK_GO_STRAIGHT_TO_COORD, Character, Position.X, Position.Y, Position.Z, 1.0f, -1, Character.Heading, 0.0f); Function.Call(Hash.SET_PED_DESIRED_MOVE_BLEND_RATIO, Character, 1.0f); } else if (distance > 1.75f) // Sprinting { Function.Call(Hash.TASK_GO_STRAIGHT_TO_COORD, Character, Position.X, Position.Y, Position.Z, 3.0f, -1, Character.Heading, 2.0f); Function.Call(Hash.SET_RUN_SPRINT_MULTIPLIER_FOR_PLAYER, Character, 1.49f); Function.Call(Hash.SET_PED_DESIRED_MOVE_BLEND_RATIO, Character, 3.0f); } else // Running { Function.Call(Hash.TASK_GO_STRAIGHT_TO_COORD, Character, Position.X, Position.Y, Position.Z, 4.0f, -1, Character.Heading, 1.0f); Function.Call(Hash.SET_PED_DESIRED_MOVE_BLEND_RATIO, Character, 2.0f); } } if (IsInParachuteFreeFall) { if (!Function.Call <bool>(Hash.IS_PED_IN_PARACHUTE_FREE_FALL, Character)) { Function.Call(Hash.TASK_SKY_DIVE, Character); } Character.Position = dest - new Vector3(0, 0, 1f); Character.Quaternion = Rotation; } } _lastJumping = IsJumping; _lastShooting = IsShooting; _lastAiming = IsAiming; } _lastVehicle = IsInVehicle; } catch (Exception ex) { UI.Notify("Sync error: " + ex.Message); Main.Logger.WriteException("Exception in SyncPed code", ex); } }
public void DisplayLocally() { try { const float hRange = 200f; var gPos = IsInVehicle ? VehiclePosition : Position; var inRange = Game.Player.Character.IsInRangeOf(gPos, hRange); if (inRange && !_isStreamedIn) { _isStreamedIn = true; if (_mainBlip != null) { _mainBlip.Remove(); _mainBlip = null; } } else if (!inRange && _isStreamedIn) { Clear(); _isStreamedIn = false; } if (!inRange) { if (_mainBlip == null && _blip) { _mainBlip = World.CreateBlip(gPos); _mainBlip.Color = BlipColor.White; _mainBlip.Scale = 0.8f; SetBlipNameFromTextFile(_mainBlip, Name == null ? "<nameless>" : Name); } if (_blip && _mainBlip != null) { _mainBlip.Position = gPos; } return; } if (Character == null || !Character.Exists() || !Character.IsInRangeOf(gPos, hRange) || Character.Model.Hash != ModelHash || (Character.IsDead && PedHealth > 0)) { if (Character != null) { Character.Delete(); } Character = World.CreatePed(new Model(ModelHash), gPos, Rotation.Z); if (Character == null) { return; } Character.BlockPermanentEvents = true; Character.IsInvincible = true; Character.CanRagdoll = false; Character.RelationshipGroup = _relGroup; if (_blip) { Character.AddBlip(); if (Character.CurrentBlip == null) { return; } Character.CurrentBlip.Color = BlipColor.White; Character.CurrentBlip.Scale = 0.8f; SetBlipNameFromTextFile(Character.CurrentBlip, Name); } return; } if (!Character.IsOccluded && Character.IsInRangeOf(Game.Player.Character.Position, 20f)) { var oldPos = UI.WorldToScreen(Character.Position + new Vector3(0, 0, 1.5f)); if (oldPos.X != 0 && oldPos.Y != 0) { var res = UIMenu.GetScreenResolutionMantainRatio(); var pos = new Point((int)((oldPos.X / (float)UI.WIDTH) * res.Width), (int)((oldPos.Y / (float)UI.HEIGHT) * res.Height)); new UIResText(Name == null ? "<nameless>" : Name, pos, 0.3f, Color.WhiteSmoke, Font.ChaletLondon, UIResText.Alignment.Centered) { Outline = true, }.Draw(); } } if ((!_lastVehicle && IsInVehicle && VehicleHash != 0) || (_lastVehicle && IsInVehicle && (MainVehicle == null || !Character.IsInVehicle(MainVehicle) || MainVehicle.Model.Hash != VehicleHash || VehicleSeat != Util.GetPedSeat(Character)))) { if (MainVehicle != null && Util.IsVehicleEmpty(MainVehicle)) { MainVehicle.Delete(); } var vehs = World.GetAllVehicles().OrderBy(v => { if (v == null) { return(float.MaxValue); } return((v.Position - Character.Position).Length()); }).ToList(); if (vehs.Any() && vehs[0].Model.Hash == VehicleHash && vehs[0].IsInRangeOf(gPos, 3f)) { MainVehicle = vehs[0]; if (Game.Player.Character.IsInVehicle(MainVehicle) && VehicleSeat == Util.GetPedSeat(Game.Player.Character)) { Game.Player.Character.Task.WarpOutOfVehicle(MainVehicle); UI.Notify("~r~Car jacked!"); } } else { MainVehicle = World.CreateVehicle(new Model(VehicleHash), gPos, 0); } if (MainVehicle != null) { MainVehicle.PrimaryColor = (VehicleColor)VehiclePrimaryColor; MainVehicle.SecondaryColor = (VehicleColor)VehicleSecondaryColor; MainVehicle.Quaternion = VehicleRotation; MainVehicle.IsInvincible = true; Character.Task.WarpIntoVehicle(MainVehicle, (VehicleSeat)VehicleSeat); /*if (_playerSeat != -2 && !Game.Player.Character.IsInVehicle(_mainVehicle)) * { // TODO: Fix me. * Game.Player.Character.Task.WarpIntoVehicle(_mainVehicle, (VehicleSeat)_playerSeat); * }*/ } _lastVehicle = true; _justEnteredVeh = true; _enterVehicleStarted = DateTime.Now; return; } if (_lastVehicle && _justEnteredVeh && IsInVehicle && !Character.IsInVehicle(MainVehicle) && DateTime.Now.Subtract(_enterVehicleStarted).TotalSeconds <= 4) { return; } _justEnteredVeh = false; if (_lastVehicle && !IsInVehicle && MainVehicle != null) { if (Character != null) { Character.Task.LeaveVehicle(MainVehicle, true); } } Character.Health = PedHealth; _switch++; if (IsInVehicle) { if (VehicleSeat == (int)GTA.VehicleSeat.Driver || MainVehicle.GetPedOnSeat(GTA.VehicleSeat.Driver) == null) { MainVehicle.Health = VehicleHealth; if (MainVehicle.Health <= 0) { MainVehicle.IsInvincible = false; //_mainVehicle.Explode(); } else { MainVehicle.IsInvincible = true; if (MainVehicle.IsDead) { MainVehicle.Repair(); } } MainVehicle.PrimaryColor = (VehicleColor)VehiclePrimaryColor; MainVehicle.SecondaryColor = (VehicleColor)VehicleSecondaryColor; if (VehicleMods != null && _modSwitch % 50 == 0 && Game.Player.Character.IsInRangeOf(VehiclePosition, 30f)) { var id = _modSwitch / 50; if (VehicleMods.ContainsKey(id) && VehicleMods[id] != MainVehicle.GetMod((VehicleMod)id)) { Function.Call(Hash.SET_VEHICLE_MOD_KIT, MainVehicle.Handle, 0); MainVehicle.SetMod((VehicleMod)id, VehicleMods[id], false); Function.Call(Hash.RELEASE_PRELOAD_MODS, id); } } _modSwitch++; if (_modSwitch >= 2500) { _modSwitch = 0; } if (IsHornPressed && !_lastHorn) { _lastHorn = true; MainVehicle.SoundHorn(99999); } if (!IsHornPressed && _lastHorn) { _lastHorn = false; MainVehicle.SoundHorn(1); } if (MainVehicle.SirenActive && !Siren) { MainVehicle.SirenActive = Siren; } else if (!MainVehicle.SirenActive && Siren) { MainVehicle.SirenActive = Siren; } var dir = VehiclePosition - _lastVehiclePos; dir.Normalize(); var range = Math.Max(20f, Speed * Math.Ceiling(DateTime.Now.Subtract(LastUpdateReceived).TotalSeconds)); if (MainVehicle.IsInRangeOf(VehiclePosition, (float)range)) { var timeElapsed = (float)DateTime.Now.Subtract(LastUpdateReceived).TotalSeconds; var acceleration = Speed - _lastSpeed; MainVehicle.Position = _lastVehiclePos + dir * (Speed * timeElapsed) + dir * (0.5f * acceleration * (float)Math.Pow(timeElapsed, 2)); } else { MainVehicle.Position = VehiclePosition; _lastVehiclePos = VehiclePosition - (dir * 0.5f); } #if DEBUG if (MainVehicle.Heading < 270) { MainVehicle.Quaternion = Util.LerpQuaternion(MainVehicle.Quaternion, VehicleRotation, 0.1f); } else if (MainVehicle.Heading >= 270) { MainVehicle.Quaternion = Util.LerpQuaternion(VehicleRotation, MainVehicle.Quaternion, 0.1f); } #else MainVehicle.Quaternion = VehicleRotation; #endif } } else { if (PedProps != null && _clothSwitch % 50 == 0 && Game.Player.Character.IsInRangeOf(Position, 30f)) { var id = _clothSwitch / 50; if (PedProps.ContainsKey(id) && PedProps[id] != Function.Call <int>(Hash.GET_PED_DRAWABLE_VARIATION, Character.Handle, id)) { Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, id, PedProps[id], 0, 0); } } _clothSwitch++; if (_clothSwitch >= 750) { _clothSwitch = 0; } if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeapon) { var wep = Character.Weapons.Give((WeaponHash)CurrentWeapon, 9999, true, true); Character.Weapons.Select(wep); } if (!_lastJumping && IsJumping) { Character.Task.Jump(); } if (IsParachuteOpen) { if (_parachuteProp == null) { _parachuteProp = World.CreateProp(new Model(1740193300), Character.Position, Character.Rotation, false, false); _parachuteProp.FreezePosition = true; Function.Call(Hash.SET_ENTITY_COLLISION, _parachuteProp.Handle, false, 0); } Character.FreezePosition = true; Character.Position = Position - new Vector3(0, 0, 1); Character.Quaternion = Rotation; _parachuteProp.Position = Character.Position + new Vector3(0, 0, 3.7f); _parachuteProp.Quaternion = Character.Quaternion; Character.Task.PlayAnimation("skydive@parachute@first_person", "chute_idle_right", 8f, 5000, false, 8f); } else { var dest = Position; Character.FreezePosition = false; if (_parachuteProp != null) { _parachuteProp.Delete(); _parachuteProp = null; } const int threshold = 50; if (IsAiming && !IsShooting && !Character.IsInRangeOf(Position, 0.5f) && _switch % threshold == 0) { Function.Call(Hash.TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD, Character.Handle, dest.X, dest.Y, dest.Z, AimCoords.X, AimCoords.Y, AimCoords.Z, 2f, 0, 0x3F000000, 0x40800000, 1, 512, 0, (uint)FiringPattern.FullAuto); } else if (IsAiming && !IsShooting && Character.IsInRangeOf(Position, 0.5f)) { Character.Task.AimAt(AimCoords, 100); } if (!Character.IsInRangeOf(Position, 0.5f) && ((IsShooting && !_lastShooting) || (IsShooting && _lastShooting && _switch % (threshold * 2) == 0))) { Function.Call(Hash.TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD, Character.Handle, dest.X, dest.Y, dest.Z, AimCoords.X, AimCoords.Y, AimCoords.Z, 2f, 1, 0x3F000000, 0x40800000, 1, 0, 0, (uint)FiringPattern.FullAuto); } else if ((IsShooting && !_lastShooting) || (IsShooting && _lastShooting && _switch % (threshold / 2) == 0)) { Function.Call(Hash.TASK_SHOOT_AT_COORD, Character.Handle, AimCoords.X, AimCoords.Y, AimCoords.Z, 1500, (uint)FiringPattern.FullAuto); } if (!IsAiming && !IsShooting && !IsJumping) { switch (SyncMode) { case SynchronizationMode.Tasks: if (!Character.IsInRangeOf(Position, 0.5f)) { Character.Task.RunTo(Position, true, 500); //var targetAngle = Rotation.Z/Math.Sqrt(1 - Rotation.W*Rotation.W); //Function.Call(Hash.TASK_GO_STRAIGHT_TO_COORD, Character.Handle, Position.X, Position.Y, Position.Z, 5f, 3000, targetAngle, 0); } if (!Character.IsInRangeOf(Position, 5f)) { Character.Position = dest - new Vector3(0, 0, 1f); Character.Quaternion = Rotation; } break; case SynchronizationMode.Teleport: Character.Position = dest - new Vector3(0, 0, 1f); Character.Quaternion = Rotation; break; } } } _lastJumping = IsJumping; _lastShooting = IsShooting; _lastAiming = IsAiming; } _lastVehicle = IsInVehicle; } catch (Exception ex) { UI.Notify("Sync error: " + ex.Message); } }
/// <summary> /// Spawns a ped on the given team, ready to fight. /// </summary> /// <param name="alliedTeam">true=ally team / false=enemy team</param> /// <returns>The spawned ped</returns> private Ped SpawnRandomPed(bool alliedTeam) { Vector3 pedPosition = alliedTeam ? spawnpointAllies : spawnpointEnemies; string pedName = RandomChoice(alliedTeam ? pedsAllies : pedsEnemies); string weaponName = RandomChoice(alliedTeam ? weaponsAllies : weaponsEnemies); PedHash pedSpawn; WeaponHash weaponGive; // TODO verify names from arrays on script startup if (!Enum.TryParse(pedName, true, out pedSpawn)) { throw new FormatException("Ped name " + pedName + " does not exist!"); } if (!Enum.TryParse(weaponName, true, out weaponGive)) { throw new FormatException("Weapon name " + weaponName + " does not exist!"); } Ped ped = World.CreatePed(pedSpawn, pedPosition); ped.Weapons.Give(weaponGive, 1, true, true); ped.Health = ped.MaxHealth = alliedTeam ? healthAllies : healthEnemies; ped.Armor = alliedTeam ? armorAllies : armorEnemies; ped.Money = 0; ped.Accuracy = alliedTeam ? accuracyAllies : accuracyEnemies; ped.RelationshipGroup = alliedTeam ? relationshipGroupAllies : relationshipGroupEnemies; ped.DropsWeaponsOnDeath = dropWeaponOnDead; CombatRange combatRange = alliedTeam ? combatRangeAllies : combatRangeEnemies; if (combatRange != CombatRange.Disabled) { if (combatRange == CombatRange.Random) { combatRange = RandomChoice(randomizableCombatRanges); } Function.Call(Hash.SET_PED_COMBAT_RANGE, ped, (int)combatRange); } CombatMovement combatMovement = alliedTeam ? combatMovementAllies : combatMovementEnemies; if (combatMovement != CombatMovement.Disabled) { if (combatMovement == CombatMovement.Random) { combatMovement = RandomChoice(randomizableCombatMovements); } Function.Call(Hash.SET_PED_COMBAT_MOVEMENT, ped, (int)combatMovement); } Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, ped, 46, true); // force peds to fight Function.Call(Hash.SET_PED_SEEING_RANGE, ped, spawnpointsDistance); Function.Call(Hash.SET_PED_COMBAT_RANGE, ped, (int)(alliedTeam ? combatRangeAllies : combatRangeEnemies)); Function.Call(Hash.SET_PED_COMBAT_MOVEMENT, ped, (int)(alliedTeam ? combatMovementAllies : combatMovementEnemies)); if (showBlipsOnPeds) { Blip blip = ped.AddBlip(); blip.Color = alliedTeam ? BlipColor.Blue : BlipColor.Orange; blip.Name = alliedTeam ? "Ally team member" : "Enemy team member"; blip.Scale = 0.5f; } ped.Task.ClearAllImmediately(); ped.AlwaysKeepTask = true; // TODO Investigate if this could be making peds avoid reloads if (alliedTeam) { spawnedAllies.Add(ped); spawnedAlliesCounter++; } else { spawnedEnemies.Add(ped); spawnedEnemiesCounter++; } return(ped); }
//CREATE_PED_INSIDE_VEHICLE(Vehicle vehicle, int pedType, Hash modelHash, int seat, BOOL p4, BOOL p5) // //void SET_PED_INTO_VEHICLE(Ped PedHandle, Vehicle VehicleHandle, int SeatIndex) private void StartMissions() { _onMission = true; _spotted = false; UI.ShowSubtitle("Eliminate the ~r~suspects~w~.", 10000); Ped player = Game.Player.Character; _headsupRectangle.Size = new Size(200, 110); for (int i = 1; i <= Math.Ceiling((decimal)_level / 4); i++) { Model vehModel = _vehicleList[_rndGet.Next(0, _vehicleList.Length)]; if (vehModel.Request(2000)) { Vector3 pedSpawnPoint; if (i == 1) { Vector3 playerpos = player.Position; Vector3 v; v.X = (float)(_rndGet.NextDouble() - 0.5); v.Y = (float)(_rndGet.NextDouble() - 0.5); v.Z = 0.0f; v.Normalize(); playerpos += v * 500.0f; pedSpawnPoint = GetSafeRoadPos(playerpos); } else { Vector3 playerpos = _hostVehicle.Position; Vector3 v; v.X = (float)(_rndGet.NextDouble() - 0.5); v.Y = (float)(_rndGet.NextDouble() - 0.5); v.Z = 0.0f; v.Normalize(); playerpos += v * 200.0f; pedSpawnPoint = GetSafeRoadPos(playerpos); } Vehicle tmpVeh = World.CreateVehicle(vehModel, pedSpawnPoint); tmpVeh.PlaceOnGround(); //FUTURE tmpVeh.IsPersistent = true; int maxPasseng; if (i == Math.Ceiling((decimal)_level / 4)) { maxPasseng = _level % 4; if (maxPasseng == 0) { maxPasseng = 4; } } else { maxPasseng = 4; } for (int d = 0; d < maxPasseng; d++) { Ped tmpPed = Function.Call <Ped>(Hash.CREATE_RANDOM_PED, pedSpawnPoint.X, pedSpawnPoint.Y, pedSpawnPoint.Z); var gunid = _level > _weaponList.Length ? _weaponList[_rndGet.Next(0, _weaponList.Length)] : _weaponList[_rndGet.Next(0, _level)]; tmpPed.Weapons.Give(gunid, 999, true, true); if (d == 0) { Function.Call(Hash.SET_PED_INTO_VEHICLE, tmpPed.Handle, tmpVeh.Handle, -1); //-1 driver, -2 any } else { Function.Call(Hash.SET_PED_INTO_VEHICLE, tmpPed.Handle, tmpVeh.Handle, -2); } if (i == 1 && d == 0) { tmpPed.Task.CruiseWithVehicle(tmpPed.CurrentVehicle, 15.0f, 6); _hostVehicle = tmpVeh; } else if (d == 0) { //TASK_VEHICLE_ESCORT(Ped pedHandle, Vehicle vehicle, Vehicle targetVehicle, int p3, float speed, Any p5, float minDistance, int p7, float p8) Function.Call(Hash.TASK_VEHICLE_ESCORT, tmpPed.Handle, tmpPed.CurrentVehicle.Handle, _hostVehicle.Handle, -1, 10.0f); } tmpPed.IsPersistent = true; Function.Call(Hash.SET_PED_RELATIONSHIP_GROUP_HASH, tmpPed.Handle, _criminalGroup); //tmpPed.RelationshipGroup = this.CriminalGroup; //FUTURE tmpPed.IsEnemy = true; tmpPed.CanSwitchWeapons = true; Blip tmpBlip = tmpPed.AddBlip(); tmpBlip.Color = BlipColor.Red; //FUTURE _criminalBlips.Add(tmpBlip); _criminals.Add(tmpPed); } tmpVeh.MarkAsNoLongerNeeded(); } else { UI.Notify("Error loading vehicle."); } } }
//public Ped target=null; public Hunter(Vector3 place) { Function.Call(Hash.REQUEST_MISSION_AUDIO_BANK, "SCRIPT\\HUNTING_2_ELK_CALLS", 0, -1); if (LivelyWorld.DebugOutput) { File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - Called for Hunter Event"); } /* * if( place == Vector3.Zero) * { * for (int i = 0; i < 50; i++) * { * if (place == Vector3.Zero) * { * place = LivelyWorld.GenerateSpawnPos(fix, LivelyWorld.Nodetype.Offroad, false);// World.GetSafeCoordForPed(Game.Player.Character.Position.Around(100), false); * } * } * }*/ if (LivelyWorld.DebugOutput) { File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - Found suitable place, spawning Hunter"); } HunterPed = World.CreatePed(PedHash.Hunter, place); Vector3 pos = HunterPed.Position; if (LivelyWorld.DebugBlips) { HunterPed.AddBlip(); HunterPed.CurrentBlip.Sprite = BlipSprite.Hunting; HunterPed.CurrentBlip.Color = BlipColor.Yellow; HunterPed.CurrentBlip.IsShortRange = true; HunterPed.CurrentBlip.Name = "Hunter"; } HunterPed.AlwaysKeepTask = true; HunterPed.Accuracy = 100; //if(Game.Player.Character.Position.DistanceTo(place)>50F) DespawnRange = Game.Player.Character.Position.DistanceTo(place)*1.5f; //HunterPed.FiringPattern = FiringPattern.SingleShot; HunterPed.Weapons.Give(WeaponHash.SniperRifle, 999, true, true); HunterPed.Weapons.Current.SetComponent(WeaponComponent.AtArSupp02, true); if (LivelyWorld.DebugOutput) { File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - Set up"); } World.SetRelationshipBetweenGroups(Relationship.Respect, HunterRLGroup, Game.GenerateHash("CIVMALE")); World.SetRelationshipBetweenGroups(Relationship.Respect, Game.GenerateHash("CIVMALE"), HunterRLGroup); World.SetRelationshipBetweenGroups(Relationship.Respect, Game.GenerateHash("CIVFEMALE"), HunterRLGroup); World.SetRelationshipBetweenGroups(Relationship.Respect, HunterRLGroup, Game.GenerateHash("CIVFEMALE")); World.SetRelationshipBetweenGroups(Relationship.Respect, Game.GenerateHash("COP"), HunterRLGroup); World.SetRelationshipBetweenGroups(Relationship.Respect, HunterRLGroup, Game.GenerateHash("COP")); World.SetRelationshipBetweenGroups(Relationship.Hate, HunterRLGroup, Game.GenerateHash("WILD_ANIMAL")); //World.SetRelationshipBetweenGroups(Relationship.Hate, Game.GenerateHash("WILD_ANIMAL"), HunterRLGroup); //World.SetRelationshipBetweenGroups(Relationship.Hate, Game.GenerateHash("DEER"), HunterRLGroup); World.SetRelationshipBetweenGroups(Relationship.Hate, HunterRLGroup, Game.GenerateHash("DEER")); if (LivelyWorld.DebugOutput) { File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - animal relationships set"); } //World.SetRelationshipBetweenGroups(Relationship.Hate, HunterRLGroup, Game.GenerateHash("PLAYER")); //World.SetRelationshipBetweenGroups(Relationship.Hate, Game.GenerateHash("PLAYER"), HunterRLGroup); //Function.Call(Hash.SET_PED_STEALTH_MOVEMENT, HunterPed, 1,0); //Function.Call(Hash.SET_PED_TARGET_LOSS_RESPONSE, HunterPed, 3); if (LivelyWorld.RandomInt(0, 10) <= 5) { HunterCar = World.CreateVehicle(LivelyWorld.HuntingTrucks[LivelyWorld.RandomInt(0, LivelyWorld.HuntingTrucks.Count - 1)], HunterPed.Position + (HunterPed.ForwardVector * -8)); //World.GetNextPositionOnStreet(HunterPed.Position) //LivelyWorld.MoveEntitytoNearestRoad(HunterCar,false,true); HunterCar.Position = HunterCar.Position + (HunterCar.RightVector * 3); if (LivelyWorld.DebugBlips) { HunterCar.AddBlip(); HunterCar.CurrentBlip.Sprite = BlipSprite.PersonalVehicleCar; HunterCar.CurrentBlip.Color = BlipColor.Yellow; HunterCar.CurrentBlip.IsShortRange = true; HunterCar.CurrentBlip.Name = "Hunter's car"; } } else { HunterDog = World.CreatePed(PedHash.Retriever, HunterPed.Position.Around(0)); HunterDog.RelationshipGroup = HunterRLGroup; HunterDog.AlwaysKeepTask = true; HunterDog.BlockPermanentEvents = true; } HunterPed.RelationshipGroup = HunterRLGroup; int patience = 0; while (patience < 500 && (!Function.Call <bool>(Hash.HAS_ANIM_SET_LOADED, "move_ped_crouched") || !Function.Call <bool>(Hash.HAS_ANIM_SET_LOADED, "move_ped_crouched_strafing"))) { patience++; Function.Call(Hash.REQUEST_ANIM_SET, "move_ped_crouched"); Function.Call(Hash.REQUEST_ANIM_SET, "move_ped_crouched_strafing"); } Script.Wait(300); Function.Call(Hash.SET_PED_MOVEMENT_CLIPSET, HunterPed, "move_ped_crouched", 1048576000); Function.Call(Hash.SET_PED_STRAFE_CLIPSET, HunterPed, "move_ped_crouched_strafing"); Function.Call(Hash.SET_PED_SEEING_RANGE, HunterPed, 150f); Function.Call(Hash.SET_PED_VISUAL_FIELD_MIN_ELEVATION_ANGLE, HunterPed, -40f); Function.Call(Hash.SET_PED_VISUAL_FIELD_MAX_ELEVATION_ANGLE, HunterPed, 5f); Function.Call(Hash.SET_PED_SHOOT_RATE, HunterPed, 50); Function.Call(Hash.SET_PED_COMBAT_MOVEMENT, HunterPed, 0); Function.Call(Hash.SET_PED_TARGET_LOSS_RESPONSE, HunterPed, 0); Function.Call(Hash.TASK_WANDER_IN_AREA, HunterPed, pos.X, pos.Y, pos.Z, 100f, 2f, 3f); //Function.Call(Hash.TASK_WANDER_STANDARD, HunterPed, 20f,0); if (LivelyWorld.DebugOutput) { File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - spawn finished"); } }
/// <summary> /// This method will update this PlayerPed blip sprite and color /// </summary> /// <param name="sprite">new BlipSprite</param> /// <param name="color">new BlipColor</param> public void UpdateBlip(BlipSprite sprite, BlipColor color) { Ped.CurrentBlip.Remove(); Ped.AddBlip().Sprite = sprite; Ped.CurrentBlip.Color = color; }
/// <summary> /// Befriend the critter. /// </summary> /// <param name="group"> /// The group the critter should join. /// </param> /// <param name="relationshipGroup"> /// The relationship group the critter should join. /// </param> public void Befriend(int group, int relationshipGroup) { // Only proceed if not already a friend if (state != CritterState.NotFriend) { return; } // Now it's a friend state = CritterState.Following; // Shortcut to player var player = Game.Player.Character; // Turn on friendly blip if (critterPed.CurrentBlip == null) { critterPed.AddBlip(); } critterPed.CurrentBlip.IsFriendly = true; critterPed.CurrentBlip.Scale = 0.7f; // Warn for unknown animal, otherwise notify what's found if (animalClass != AnimalClass.Unknown) { Log.Info(string.Format("Found {0}", animalName)); } #if DEBUG else { Log.Debug(string.Format("Unknown Animal: {0}", critterPed.Model)); critterPed.CurrentBlip.IsFlashing = true; } #endif // Make the critter run (or fly) to the player critterPed.TaskHurryToEntity(player); // If the critter is not allowed in our group, we're done if (!IsAllowedInGroup) { return; } // Give the critter super health critterPed.MaxHealth = SUPER_HEALTH; critterPed.Health = SUPER_HEALTH; // Set the critter into the relationship group critterPed.RelationshipGroup = relationshipGroup; // Set the critter into the group? if (group != 0) { critterPed.SetAsGroupMember(group); } // Make sure the critter will never leave the group (unless told to do so) critterPed.SetNeverLeavesGroup(true); // Allow switch weapons (and fight?) critterPed.CanSwitchWeapons = true; // Block non-temporary events Function.Call(Hash.SET_BLOCKING_OF_NON_TEMPORARY_EVENTS, critterPed, true); // Critter never flees Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, critterPed, 0, 0); // Critter fights to the death Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, critterPed, 46, true); // Start following the player Follow(); }