Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This function allows any ped on an attack heli to use its weapons against the enemies the ped is fighting.
- Pasted here as used in https://www.gta5-mods.com/scripts/bodyguard-squads.
- Call on tick, providing the ped that is on an heli that has weapons.
- Lacks multiweapon handling for now, they only use the default weapon (Minigun for buzzard/annihilator, explosive rounds for Valk/Savage).
- */
- void HandleAirCombat(Ped RecieveOrder)
- {
- if (CanWeUse(RecieveOrder) && RecieveOrder.IsSittingInVehicle())
- {
- if (RecieveOrder.CurrentVehicle.Model == (Model)VehicleHash.Savage)
- {
- if (RecieveOrder.IsInCombat && GetRandomInt(1, 30) == 1)
- {
- foreach (Ped target in World.GetAllPeds())
- {
- if (target.IsAlive && GTA.Native.Function.Call<bool>(GTA.Native.Hash.IS_PED_IN_COMBAT, RecieveOrder, target) && GTA.Native.Function.Call<Vector3>(GTA.Native.Hash.GET_OFFSET_FROM_ENTITY_GIVEN_WORLD_COORDS, RecieveOrder, target.Position.X, target.Position.Y, target.Position.Z).Y > -10)
- {
- Vector3 Velocity = new Vector3(GetRandomInt(-2, 2), GetRandomInt(-2, 2), 0);
- if (target.Velocity.Length() > 10f)
- {
- Velocity = Velocity + RecieveOrder.Velocity - target.Velocity;
- }
- GTA.Native.Function.Call(GTA.Native.Hash.SET_VEHICLE_SHOOT_AT_TARGET, RecieveOrder, 0, target.Position.X + Velocity.X, target.Position.Y + Velocity.Y, target.Position.Z);
- }
- }
- }
- }
- if (RecieveOrder.CurrentVehicle.Model == (Model)VehicleHash.Annihilator)
- {
- if (RecieveOrder.IsInCombat)
- {
- foreach (Ped target in World.GetAllPeds())
- {
- if (target.IsAlive && GTA.Native.Function.Call<bool>(GTA.Native.Hash.IS_PED_IN_COMBAT, RecieveOrder, target) && GTA.Native.Function.Call<Vector3>(GTA.Native.Hash.GET_OFFSET_FROM_ENTITY_GIVEN_WORLD_COORDS, RecieveOrder, target.Position.X, target.Position.Y, target.Position.Z).Y > 30)
- {
- Vector3 Velocity = new Vector3(GetRandomInt(-2, 2), GetRandomInt(-2, 2), 0);
- if (target.Velocity.Length() > 10f)
- {
- Velocity = Velocity + RecieveOrder.Velocity - target.Velocity;
- }
- GTA.Native.Function.Call(GTA.Native.Hash.SET_VEHICLE_SHOOT_AT_TARGET, RecieveOrder, 0, target.Position.X + Velocity.X, target.Position.Y + Velocity.Y, target.Position.Z);
- }
- }
- }
- }
- if (RecieveOrder.CurrentVehicle.Model == (Model)VehicleHash.Buzzard)
- {
- if (RecieveOrder.IsInCombat)
- {
- foreach (Ped target in World.GetAllPeds())
- {
- if (target.IsAlive && GTA.Native.Function.Call<bool>(GTA.Native.Hash.IS_PED_IN_COMBAT, RecieveOrder, target) && GTA.Native.Function.Call<Vector3>(GTA.Native.Hash.GET_OFFSET_FROM_ENTITY_GIVEN_WORLD_COORDS, RecieveOrder, target.Position.X, target.Position.Y, target.Position.Z).Y > 30)
- {
- Vector3 Velocity = new Vector3(GetRandomInt(-2, 2), GetRandomInt(-2, 2), 0);
- if (target.Velocity.Length() > 10f)
- {
- Velocity = Velocity + RecieveOrder.Velocity - target.Velocity;
- }
- GTA.Native.Function.Call(GTA.Native.Hash.SET_VEHICLE_SHOOT_AT_TARGET, RecieveOrder, 0, target.Position.X + Velocity.X, target.Position.Y + Velocity.Y, target.Position.Z);
- }
- }
- }
- }
- if (RecieveOrder.CurrentVehicle.Model == (Model)VehicleHash.Valkyrie)
- {
- if (RecieveOrder.IsInCombat && GetRandomInt(1, 30) == 1)
- {
- if (CanWeUse(RecieveOrder.CurrentVehicle.GetPedOnSeat(VehicleSeat.RightFront)))
- {
- foreach (Ped target in World.GetAllPeds())
- {
- if (target.IsAlive && GTA.Native.Function.Call<bool>(GTA.Native.Hash.IS_PED_IN_COMBAT, RecieveOrder, target))
- {
- Vector3 Velocity = new Vector3(GetRandomInt(-5, 5), GetRandomInt(-5, 5), 0);
- if (target.Velocity.Length() > 10f)
- {
- Velocity = Velocity + Squad1Leader.Velocity - target.Velocity;
- }
- GTA.Native.Function.Call(GTA.Native.Hash.SET_VEHICLE_SHOOT_AT_TARGET, RecieveOrder.CurrentVehicle.GetPedOnSeat(VehicleSeat.RightFront), 0, target.Position.X + Velocity.X, target.Position.Y + Velocity.Y, target.Position.Z);
- }
- }
- }
- }
- }
- }
- }
- //Used by HandleAirCombat.
- bool CanWeUse(Entity entity)
- {
- return entity != null && entity.Exists();
- }
- Random rnd = new Random();
- protected int GetRandomInt(int min, int max)
- {
- return rnd.Next(min, max);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement