-
Notifications
You must be signed in to change notification settings - Fork 64
/
Util.cs
39 lines (33 loc) · 1.21 KB
/
Util.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
namespace SaltyClient
{
public static class Util
{
public static string ToJson(object obj)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
}
public static bool TryParseJson<T>(string json, out T result)
{
result = default;
try
{
result = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(json);
}
catch { }
return result is object;
}
public static bool HasOpening(this Vehicle vehicle)
{
VehicleDoor[] doors = vehicle.Doors.GetAll();
return doors.Length == 0 || doors.Any(d => d.Index != VehicleDoorIndex.Hood && (d.IsBroken || d.IsOpen)) ||
!vehicle.Windows.AreAllWindowsIntact || vehicle.Windows.GetAllWindows().Any(w => !w.IsIntact) || // AreAllWindowsIntact = damage on all windows (also bullet holes) | IsIntact = also true if window is rolled down
(vehicle.IsConvertible && vehicle.RoofState != VehicleRoofState.Closed);
}
}
}