-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathMapObject.cs
262 lines (212 loc) · 6.1 KB
/
MapObject.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
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
260
261
262
using System;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
using GTA;
using GTA.Math;
using GTA.Native;
namespace MapEditor
{
public class MapObject
{
public ObjectTypes Type;
public Vector3 Position;
public Vector3 Rotation;
public int Hash;
public bool Dynamic;
public Quaternion Quaternion;
// Prop stuff
public bool Door;
// Ped stuff
public string Action;
public string Relationship;
public WeaponHash? Weapon;
// Vehicle stuff
public bool SirensActive;
public int PrimaryColor;
public int SecondaryColor;
// Pickup stuff
public int Amount;
public int RespawnTimer;
public int Flag;
[XmlAttribute("Id")]
public string Id;
// XML Stuff
public bool ShouldSerializeDoor()
{
return Type == ObjectTypes.Prop;
}
public bool ShouldSerializeAction()
{
return Type == ObjectTypes.Ped;
}
public bool ShouldSerializeRelationship()
{
return Type == ObjectTypes.Ped;
}
public bool ShouldSerializeWeapon()
{
return Type == ObjectTypes.Ped;
}
public bool ShouldSerializeSirensActive()
{
return Type == ObjectTypes.Vehicle;
}
public bool ShouldSerializePrimaryColor()
{
return Type == ObjectTypes.Vehicle;
}
public bool ShouldSerializeSecondaryColor()
{
return Type == ObjectTypes.Vehicle;
}
public bool ShouldSerializeAmount()
{
return Type == ObjectTypes.Pickup;
}
public bool ShouldSerializeRespawnTimer()
{
return Type == ObjectTypes.Pickup;
}
public bool ShouldSerializeFlag()
{
return Type == ObjectTypes.Pickup;
}
}
public class PedDrawables
{
public int[] Drawables;
public int[] Textures;
}
public class DynamicPickup
{
public DynamicPickup(int handle)
{
PickupHandle = handle;
IsInRange = handle != -1;
}
private int _timeout = -1;
private bool _dynamic = true;
public bool IsInRange { get; set; }
public bool Dynamic
{
get { return _dynamic; }
set
{
_dynamic = value;
new Prop(ObjectHandle).FreezePosition = !value;
}
}
public string PickupName
{
get
{
if (Enum.IsDefined(typeof (ObjectDatabase.PickupHash), PickupHash))
return ((ObjectDatabase.PickupHash) PickupHash).ToString();
return "";
}
}
public int UID { get; set; }
public int PickupHash { get; set; }
public int PickupHandle { get; set; }
public int Amount { get; set; }
public int Flag { get; set; }
public bool PickedUp { get; set; }
public DateTime LastPickup { get; set; }
public int ObjectHandle => Function.Call<int>((Hash) 0x5099BC55630B25AE, PickupHandle);
//public Vector3 Position => Function.Call<Vector3>(Hash.GET_PICKUP_COORDS, PickupHandle);
public void UpdatePos()
{
RealPosition = Position;
}
public Vector3 RealPosition { get; set; }
public Vector3 Position
{
get { return new Prop(ObjectHandle).Position; }
set
{
new Prop(ObjectHandle).Position = value;
RealPosition = value;
}
}
public void SetPickupHash(int newHash)
{
PickupHash = newHash;
ReloadPickup();
}
public void SetPickupFlag(int newFlag)
{
Flag = newFlag;
ReloadPickup();
}
public void SetAmount(int newAmount)
{
Amount = newAmount;
ReloadPickup();
}
private void ReloadPickup()
{
var newPickup = Function.Call<int>(Hash.CREATE_PICKUP_ROTATE, PickupHash, RealPosition.X, RealPosition.Y, RealPosition.Z, 0, 0, 0, Flag, Amount, 0, false, 0);
var tmpDyn = new DynamicPickup(newPickup);
var start = 0;
while (tmpDyn.ObjectHandle == -1 && start < 20)
{
start++;
Script.Yield();
tmpDyn.Position = RealPosition;
}
tmpDyn.Dynamic = Dynamic;
tmpDyn.Timeout = Timeout;
new Prop(tmpDyn.ObjectHandle).IsPersistent = true;
if (PickupHandle != -1)
Remove();
PickupHandle = newPickup;
}
public int Timeout
{
get { return _timeout; }
set
{
_timeout = value;
//Function.Call(Hash.SET_PICKUP_REGENERATION_TIME, PickupHandle, value);
}
}
public bool PickupObjectExists => Function.Call<bool>(Hash.DOES_PICKUP_OBJECT_EXIST, PickupHandle);
public bool PickupExists => Function.Call<bool>(Hash.DOES_PICKUP_EXIST, PickupHandle);
public void Remove()
{
Function.Call(Hash.REMOVE_PICKUP, PickupHandle);
}
public void Update()
{
var inRange = Game.Player.Character.IsInRangeOf(RealPosition, 20f);
if (inRange && PickupHandle == -1)
{
ReloadPickup();
}
if (PickupHandle != -1)
{
Position = RealPosition;
if (!inRange) return;
if (!PickupObjectExists && !PickedUp)
{
PickedUp = true;
LastPickup = DateTime.Now;
Remove();
}
if (PickedUp && DateTime.Now.Subtract(LastPickup).TotalSeconds > Timeout && Timeout != 0)
{
PickedUp = false;
ReloadPickup();
}
}
}
}
public enum ObjectTypes
{
Prop,
Vehicle,
Ped,
Marker,
Pickup,
}
}