-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain.cs
More file actions
259 lines (231 loc) · 9.77 KB
/
Main.cs
File metadata and controls
259 lines (231 loc) · 9.77 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
namespace API_Example
{
using System;
using System.Windows.Forms;
using API_Example.Callouts;
using API_Example.World_Events;
using GTA;
using LCPDFR.Networking.User;
using LCPD_First_Response.Engine;
using LCPD_First_Response.Engine.Input;
using LCPD_First_Response.Engine.Networking;
using LCPD_First_Response.Engine.Scripting.Plugins;
using LCPD_First_Response.Engine.Timers;
using LCPD_First_Response.LCPDFR.API;
using LCPDFR.Networking;
using SlimDX.XInput;
/// <summary>
/// The network messages.
/// </summary>
public enum ENetworkMessages
{
/// <summary>
/// The message sent when user requests backup.
/// </summary>
RequestBackup,
}
/// <summary>
/// Sample plugin making use of the LCPDFR API. In the attribute below you can specify the name of the plugin.
/// </summary>
[PluginInfo("TestPlugin", false, true)]
public class TestPlugin : Plugin
{
/// <summary>
/// A LCPDFR ped.
/// </summary>
private LPed lcpdfrPed;
/// <summary>
/// Called when the plugin has been created successfully.
/// </summary>
public override void Initialize()
{
// Bind console commands
this.RegisterConsoleCommands();
// Listen for on duty event
Functions.OnOnDutyStateChanged += this.Functions_OnOnDutyStateChanged;
Networking.JoinedNetworkGame += this.Networking_JoinedNetworkGame;
Log.Info("Started", this);
}
/// <summary>
/// Called when player changed the on duty state.
/// </summary>
/// <param name="onDuty">The new on duty state.</param>
public void Functions_OnOnDutyStateChanged(bool onDuty)
{
if (onDuty)
{
// Register callouts to LCPDFR
Functions.RegisterCallout(typeof(Shooting));
Functions.RegisterCallout(typeof(Pursuit));
Functions.AddWorldEvent(typeof(Brawl), "Brawl");
}
}
/// <summary>
/// Called every tick to process all plugin logic.
/// </summary>
public override void Process()
{
// If on duty and Z is down
if (LPlayer.LocalPlayer.IsOnDuty && (Functions.IsKeyDown(Keys.Z) || (Functions.IsControllerInUse() && Functions.IsControllerKeyDown(GamepadButtonFlags.DPadRight))))
{
DelayedCaller.Call(
delegate
{
LPlayer.LocalPlayer.Ped.DrawTextAboveHead("Test", 500);
},
this,
500);
if (this.lcpdfrPed == null || this.lcpdfrPed.Exists() || this.lcpdfrPed.IsAliveAndWell)
{
// Create a ped
this.lcpdfrPed = new LPed(LPlayer.LocalPlayer.Ped.Position, "F_Y_HOOKER_01");
this.lcpdfrPed.NoLongerNeeded();
this.lcpdfrPed.AttachBlip();
this.lcpdfrPed.ItemsCarried = LPed.EPedItem.Drugs;
LPed.EPedItem item = this.lcpdfrPed.ItemsCarried;
this.lcpdfrPed.PersonaData = new PersonaData(DateTime.Now, 0, "Sam", "T", false, 1337, true);
}
}
// If our ped exists and has been arrested, kill it
if (this.lcpdfrPed != null && this.lcpdfrPed.Exists())
{
if (this.lcpdfrPed.HasBeenArrested && this.lcpdfrPed.IsAliveAndWell)
{
this.lcpdfrPed.Die();
}
}
if (Functions.IsKeyDown(Keys.B))
{
if (Functions.IsPlayerPerformingPullover())
{
LHandle pullover = Functions.GetCurrentPullover();
if (pullover != null)
{
LVehicle vehicle = Functions.GetPulloverVehicle(pullover);
if (vehicle != null && vehicle.Exists())
{
vehicle.AttachBlip().Color = BlipColor.Cyan;
if (vehicle.HasDriver)
{
// Change name of driver to Sam T.
LPed driver = vehicle.GetPedOnSeat(VehicleSeat.Driver);
if (driver != null && driver.Exists())
{
// Modify name.
driver.PersonaData = new PersonaData(DateTime.Now, 0, "Sam", "T", true, 0, false);
string name = driver.PersonaData.FullName;
Functions.PrintText("--- Pulling over: " + name + " ---", 10000);
// Looking up the driver will make the vehicle explode.
Functions.PedLookedUpInPoliceComputer += delegate(PersonaData data)
{
if (data.FullName == name)
{
DelayedCaller.Call(delegate { if (vehicle.Exists()) { vehicle.Explode(); } }, this, Common.GetRandomValue(5000, 10000));
}
};
}
}
}
}
}
else
{
// Disable pullovers for vehicle in front.
GTA.Vehicle vehicle = World.GetClosestVehicle(LPlayer.LocalPlayer.Ped.GetOffsetPosition(new Vector3(0, 10, 0)), 5f);
if (vehicle != null && vehicle.Exists())
{
LVehicle veh = LVehicle.FromGTAVehicle(vehicle);
if (veh != null)
{
veh.DisablePullover = true;
veh.AttachBlip();
}
}
}
}
// Kill all partners.
if (Functions.IsKeyDown(Keys.N))
{
LHandle partnerManger = Functions.GetCurrentPartner();
LPed[] peds = Functions.GetPartnerPeds(partnerManger);
if (peds != null)
{
foreach (LPed partner in peds)
{
if (partner.Exists())
{
partner.Die();
}
}
}
}
// Send RequestBackup message in network game.
if (Functions.IsKeyDown(Keys.X))
{
if (Networking.IsInSession && Networking.IsConnected)
{
if (Networking.IsHost)
{
Vector3 position = LPlayer.LocalPlayer.Ped.Position;
// Tell client we need backup.
DynamicData dynamicData = new DynamicData(Networking.GetServerInstance());
dynamicData.Write(position);
Networking.GetServerInstance().Send("API_Example", ENetworkMessages.RequestBackup, dynamicData);
}
}
}
}
/// <summary>
/// Called when the plugin is being disposed, e.g. because an unhandled exception occured in Process. Free all resources here!
/// </summary>
public override void Finally()
{
}
/// <summary>
/// Called when player has joined a network game.
/// </summary>
private void Networking_JoinedNetworkGame()
{
// Just to be sure.
if (Networking.IsInSession && Networking.IsConnected)
{
// When client, listen for messages. Of course, this could be changed to work for host as well.
// It's recommended to use the same string identifier all the time.
if (!Networking.IsHost)
{
Client client = Networking.GetClientInstance();
client.AddUserDataHandler("API_Example", ENetworkMessages.RequestBackup, this.NeedBackupHandlerFunction);
}
}
}
/// <summary>
/// Called when <see cref="ENetworkMessages.RequestBackup"/> has been received.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="message">The message.</param>
private void NeedBackupHandlerFunction(NetworkServer sender, ReceivedUserMessage message)
{
// Read position and get associated area.
Vector3 position = message.ReadVector3();
string area = Functions.GetAreaStringFromPosition(position);
// Display message and blip.
Functions.PrintText(string.Format("Officer {0} requests backup at {1}", sender.SafeName, area), 5000);
Blip areaBlip = Functions.CreateBlipForArea(position, 25f);
// Cleanup.
DelayedCaller.Call(parameter => areaBlip.Delete(), this, 10000);
}
[ConsoleCommand("StartCallout", false)]
private void StartCallout(ParameterCollection parameterCollection)
{
if (parameterCollection.Count > 0)
{
string name = parameterCollection[0];
Functions.StartCallout(name);
}
else
{
Game.Console.Print("StartCallout: No argument given.");
}
}
}
}