-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIncomingVehicle.cs
159 lines (129 loc) · 6.51 KB
/
IncomingVehicle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GTA;
using GTA.Math;
using GTA.Native;
using MMI_SP.Common;
namespace MMI_SP
{
class IncomingVehicle
{
public Vehicle vehicle;
public Ped driver;
public Vector3 destination;
public int calledTime;
public int price;
public bool recovered;
public object[] additional;
public bool hasReachedDestination = false;
public EntityPosition originalPosition = new EntityPosition(Vector3.Zero, 0f);
private static readonly List<PedHash> _drivers = new List<PedHash> { PedHash.Car3Guy2, PedHash.Xmech01SMY, PedHash.Autoshop01SMM, PedHash.Autoshop02SMM };
public static List<PedHash> Drivers => _drivers;
public IncomingVehicle(Vehicle veh, Ped ped, Vector3 dest, int cost, bool isRecovered, object[] add = null)
{
vehicle = veh;
driver = ped;
destination = dest;
calledTime = Game.GameTime;
price = cost;
recovered = isRecovered;
additional = add;
}
public IncomingVehicle(Vehicle veh, Ped ped, Vector3 dest, int cost, bool isRecovered, Vector3 originPos, float originHeading, object[] add = null)
{
vehicle = veh;
driver = ped;
destination = dest;
calledTime = Game.GameTime;
price = cost;
recovered = isRecovered;
originalPosition.Position = originPos;
originalPosition.Heading = originHeading;
additional = add;
}
public static IncomingVehicle BringHelicopter(Vehicle veh, int cost, bool recoveredVehicle)
{
float zOffset = 80f;
Vector3 startPosition = Game.Player.Character.Position;
do {
startPosition = startPosition.Around(Config.BringVehicleRadius);
} while (Game.Player.Character.Position.DistanceTo(startPosition) < (int)(Config.BringVehicleRadius * 0.95));
startPosition.Z += World.GetGroundHeight(startPosition) + zOffset;
veh.Position = startPosition;
veh.Heading = (startPosition - Game.Player.Character.Position).ToHeading();
veh.PreviouslyOwnedByPlayer = true;
veh.EngineRunning = true;
Function.Call(Hash.SET_HELI_BLADES_FULL_SPEED, veh);
Vector3 destination = Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0f, 1.5f, -1f));
Ped driver = CreateDriver(veh);
Function.Call(Hash.TASK_HELI_MISSION, driver, veh, 0, Game.Player.Character, destination.X, destination.Y, destination.Z, 20, 30f, 15f, (destination - veh.Position).ToHeading(), -1, -1, -1, 32);
return new IncomingVehicle(veh, driver, destination, cost, recoveredVehicle);
}
public static IncomingVehicle BringPlane(Vehicle veh, int cost, bool recoveredVehicle)
{
float zOffset = 80f;
Vector3 startPosition = Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0f, -5 * Config.BringVehicleRadius, 0f));
if ((World.GetGroundHeight(startPosition) + zOffset) < Game.Player.Character.Position.Z)
startPosition.Z = Game.Player.Character.Position.Z + zOffset;
else
startPosition.Z = World.GetGroundHeight(startPosition) + 200f;
veh.Position = startPosition;
veh.Heading = Game.Player.Character.Heading;
veh.PreviouslyOwnedByPlayer = true;
veh.EngineRunning = true;
veh.ApplyForceRelative(new Vector3(0f, 20f, 0f));
Vector3 runwayStartPoint = Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0f, -110f, 0f));
Vector3 runwayEndPoint = Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0f, -40.0f, 0f));
Ped driver = CreateDriver(veh);
Function.Call(Hash.TASK_PLANE_LAND, driver, veh, runwayStartPoint.X, runwayStartPoint.Y, runwayStartPoint.Z, runwayEndPoint.X, runwayEndPoint.Y, runwayEndPoint.Z);
return new IncomingVehicle(veh, driver, runwayEndPoint, cost, recoveredVehicle);
}
public static void BringBoat(Vehicle veh, int cost, bool recoveredVehicle)
{
Vector3 coords = Game.Player.Character.Position;
Vector3 nodePos;
float nodeHeading;
OutputArgument pos = new OutputArgument();
OutputArgument heading = new OutputArgument();
Function.Call(Hash.GET_CLOSEST_VEHICLE_NODE_WITH_HEADING, coords.X, coords.Y, coords.Z, pos, heading, 3, 3.0f, 0);
nodePos = pos.GetResult<Vector3>();
nodeHeading = heading.GetResult<float>();
veh.Position = nodePos;
veh.Heading = nodeHeading;
veh.PreviouslyOwnedByPlayer = true;
}
public static IncomingVehicle BringVehicle(Vehicle veh, int cost, bool recoveredVehicle)
{
Vector3 startPosition = Game.Player.Character.Position;
do {
startPosition = startPosition.Around(Config.BringVehicleRadius);
} while (Game.Player.Character.Position.DistanceTo(startPosition) < (int)(Config.BringVehicleRadius * 0.8));
EntityPosition vehPos = Utils.GetVehicleSpawnLocation(startPosition);
veh.Position = vehPos.Position;
veh.Heading = vehPos.Heading;
veh.PreviouslyOwnedByPlayer = true;
veh.EngineRunning = true;
Vector3 destination = Utils.GetVehicleSpawnLocation(Game.Player.Character.Position).Position;
Ped driver = CreateDriver(veh);
driver.Task.DriveTo(veh, destination, 0f, 10.0f, (int)DrivingStyle.IgnoreLights);
return new IncomingVehicle(veh, driver, destination, cost, recoveredVehicle);
}
private static Ped CreateDriver(Vehicle vehicle)
{
Vector3 npcPos = vehicle.Position;
npcPos.X += 5f;
PedHash driverModel = Drivers[new Random().Next(0, Drivers.Count - 1)];
Ped driver = World.CreatePed(driverModel, npcPos);
// Stop the NPC from fleeing
driver.BlockPermanentEvents = true;
Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, driver, 0, 0);
Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, driver, 17, 1);
driver.IsPersistent = true;
driver.SetIntoVehicle(vehicle, VehicleSeat.Driver);
return driver;
}
}
}