omp-gdk 2.1.0

Rust SDK for developing open.mp gamemodes
Documentation
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
use std::ffi::c_void;

pub mod events;
pub mod functions;

pub use functions::load_functions;

use crate::{
    players::Player,
    types::colour::Colour,
    types::vector::{Vector2, Vector3},
};

pub struct TextDraw {
    handle: *const c_void,
}

#[deny(non_snake_case)]
impl TextDraw {
    pub fn get_handle(&self) -> *const c_void {
        self.handle
    }
    pub fn new(handle: *const c_void) -> Self {
        Self { handle }
    }
    /// Creates a textdraw.
    pub fn create(position: Vector2, text: &str) -> Option<TextDraw> {
        let mut _id = -1;

        functions::TextDraw_Create(position.x, position.y, text, &mut _id)
    }
    /// Destroys a previously-created textdraw.
    pub fn destroy(&self) -> bool {
        functions::TextDraw_Destroy(self)
    }
    pub fn is_shown_for_player(&self, player: &Player) -> bool {
        functions::TextDraw_IsVisibleForPlayer(player, self)
    }
    pub fn set_letter_size(&self, size: Vector2) -> bool {
        functions::TextDraw_SetLetterSize(self, size.x, size.y)
    }
    pub fn set_text_size(&self, size: Vector2) -> bool {
        functions::TextDraw_SetTextSize(self, size.x, size.y)
    }
    pub fn set_alignment(&self, alignment: TextDrawAlignmentTypes) -> bool {
        functions::TextDraw_SetAlignment(self, alignment as i32)
    }
    pub fn set_color(&self, colour: Colour) -> bool {
        functions::TextDraw_SetColor(self, colour.rgba())
    }
    /// Toggle whether a textdraw uses a box or not.
    pub fn use_box(&self, use_box: bool) -> bool {
        functions::TextDraw_SetUseBox(self, use_box)
    }
    pub fn set_box_color(&self, colour: Colour) -> bool {
        functions::TextDraw_SetBoxColor(self, colour.rgba())
    }
    /// Sets the size of a textdraw's text's shadow.
    pub fn set_shadow(&self, size: i32) -> bool {
        functions::TextDraw_SetShadow(self, size)
    }
    /// Sets the thickness of a textdraw's text's outline.
    pub fn set_outline(&self, size: i32) -> bool {
        functions::TextDraw_SetOutline(self, size)
    }
    pub fn set_background_color(&self, colour: Colour) -> bool {
        functions::TextDraw_SetBackgroundColor(self, colour.rgba())
    }
    pub fn set_style(&self, font: TextDrawStyle) -> bool {
        functions::TextDraw_SetFont(self, font as i32)
    }
    /// Appears to scale text spacing to a proportional ratio.
    pub fn set_proportional(&self, set: bool) -> bool {
        functions::TextDraw_SetSetProportional(self, set)
    }
    /// Sets whether a textdraw can be selected (clicked on) or not.
    pub fn set_selectable(&self, set: bool) -> bool {
        functions::TextDraw_SetSelectable(self, set)
    }
    /// Shows a textdraw for a specific player.
    pub fn show_for_player(&self, player: &Player) -> bool {
        functions::TextDraw_ShowForPlayer(player, self)
    }
    /// Hides a textdraw for a specific player.
    pub fn hide_for_player(&self, player: &Player) -> bool {
        functions::TextDraw_HideForPlayer(player, self)
    }
    /// Shows a textdraw for all players.
    pub fn show_for_all(&self) -> bool {
        functions::TextDraw_ShowForAll(self)
    }
    /// Hides a text draw for all players.
    pub fn hide_for_all(&self) -> bool {
        functions::TextDraw_HideForAll(self)
    }
    /// Changes the text on a textdraw.
    pub fn set_string(&self, text: &str) -> bool {
        functions::TextDraw_SetString(self, text)
    }
    /// Set the model for a textdraw model preview.
    pub fn set_preview_model(&self, model: i32) -> bool {
        functions::TextDraw_SetPreviewModel(self, model)
    }
    pub fn set_preview_rotation(&self, rotation: Vector3, zoom: f32) -> bool {
        functions::TextDraw_SetPreviewRot(self, rotation.x, rotation.y, rotation.z, zoom)
    }
    pub fn set_preview_veh_colour(&self, colour1: i32, colour2: i32) -> bool {
        functions::TextDraw_SetPreviewVehCol(self, colour1, colour2)
    }
    /// Sets the position of a textdraw.
    pub fn set_pos(&self, pos: Vector2) -> bool {
        functions::TextDraw_SetPos(self, pos.x, pos.y)
    }
    /// Gets the text of a textdraw.
    pub fn get_string(&self) -> String {
        let mut text = String::new();
        functions::TextDraw_GetString(self, &mut text, 16);
        text
    }
    /// Gets the width and height of the letters.
    pub fn get_letter_size(&self) -> Vector2 {
        let mut size = Vector2::default();
        functions::TextDraw_GetLetterSize(self, &mut size.x, &mut size.y);
        size
    }
    /// Gets the X axis and Y axis of the textdraw.
    pub fn get_text_size(&self) -> Vector2 {
        let mut size = Vector2::default();
        functions::TextDraw_GetTextSize(self, &mut size.x, &mut size.y);
        size
    }
    /// Gets the position of a textdraw.
    pub fn get_pos(&self) -> Vector2 {
        let mut pos = Vector2::default();
        functions::TextDraw_GetPos(self, &mut pos.x, &mut pos.y);
        pos
    }
    /// Gets the text color of a textdraw.
    pub fn get_color(&self) -> Colour {
        Colour::from_rgba(functions::TextDraw_GetColor(self) as u32)
    }
    /// Gets the box color of a textdraw.
    pub fn get_box_color(&self) -> Colour {
        Colour::from_rgba(functions::TextDraw_GetBoxColor(self) as u32)
    }
    /// Gets the background color of a textdraw.
    pub fn get_background_color(&self) -> Colour {
        Colour::from_rgba(functions::TextDraw_GetBackgroundColor(self) as u32)
    }
    /// Gets the size of a textdraw's text's shadow.
    pub fn get_shadow(&self) -> i32 {
        functions::TextDraw_GetShadow(self)
    }
    /// Gets the thickness of a textdraw's text's outline.
    pub fn get_outline(&self) -> i32 {
        functions::TextDraw_GetOutline(self)
    }
    pub fn get_style(&self) -> i32 {
        functions::TextDraw_GetFont(self)
    }
    /// Checks if a textdraw is box.
    pub fn is_box(&self) -> bool {
        functions::TextDraw_IsBox(self)
    }
    /// Checks if a textdraw is proportional.
    pub fn is_proportional(&self) -> bool {
        functions::TextDraw_IsProportional(self)
    }
    /// Checks if a textdraw is selectable.
    pub fn is_selectable(&self) -> bool {
        functions::TextDraw_IsSelectable(self)
    }
    /// Gets the text alignment of a textdraw.
    pub fn get_alignment(&self) -> TextDrawAlignmentTypes {
        unsafe { std::mem::transmute(functions::TextDraw_GetAlignment(self)) }
    }
    /// Gets the preview model of a 3D preview textdraw.
    pub fn get_preview_model(&self) -> i32 {
        functions::TextDraw_GetPreviewModel(self)
    }
    pub fn get_preview_rotation(&self) -> (Vector3, f32) {
        let mut rotation = Vector3::default();
        let mut zoom = 0.0;
        functions::TextDraw_GetPreviewRot(
            self,
            &mut rotation.x,
            &mut rotation.y,
            &mut rotation.z,
            &mut zoom,
        );
        (rotation, zoom)
    }
    pub fn get_preview_veh_colour(&self) -> (i32, i32) {
        let mut colour1 = 0;
        let mut colour2 = 0;
        functions::TextDraw_GetPreviewVehColor(self, &mut colour1, &mut colour2);
        (colour1, colour2)
    }
    /// Changes the text on a textdraw for a specific player.
    pub fn set_string_for_player(&self, player: &Player, text: &str) -> bool {
        functions::TextDraw_SetStringForPlayer(self, player, text)
    }
    pub fn get_id(&self) -> i32 {
        functions::TextDraw_GetID(self)
    }
    pub fn from_id(id: i32) -> Option<TextDraw> {
        functions::TextDraw_FromID(id)
    }
}

pub struct PlayerTextDraw {
    handle: *const c_void,
    pub player: Player,
}

impl PlayerTextDraw {
    pub fn get_handle(&self) -> *const c_void {
        self.handle
    }
    pub fn new(handle: *const c_void, player: Player) -> Self {
        Self { handle, player }
    }
    pub fn is_shown(&self) -> bool {
        functions::PlayerTextDraw_IsVisible(&self.player, self)
    }
    pub fn set_letter_size(&self, size: Vector2) -> bool {
        functions::PlayerTextDraw_SetLetterSize(&self.player, self, size.x, size.y)
    }
    pub fn set_text_size(&self, size: Vector2) -> bool {
        functions::PlayerTextDraw_SetTextSize(&self.player, self, size.x, size.y)
    }
    /// Set the text alignment of a player-textdraw.
    pub fn alignment(&self, alignment: TextDrawAlignmentTypes) -> bool {
        functions::PlayerTextDraw_SetAlignment(&self.player, self, alignment as i32)
    }
    /// Sets the text color of a player-textdraw.
    pub fn color(&self, colour: Colour) -> bool {
        functions::PlayerTextDraw_SetColor(&self.player, self, colour.rgba())
    }
    /// Toggle the box on a player-textdraw.
    pub fn use_box(&self, box_use: bool) -> bool {
        functions::PlayerTextDraw_UseBox(&self.player, self, box_use)
    }
    pub fn set_box_color(&self, colour: Colour) -> bool {
        functions::PlayerTextDraw_SetBoxColor(&self.player, self, colour.rgba())
    }
    /// Adds a shadow to the bottom-right side of the text in a player-textdraw.
    pub fn set_shadow(&self, size: i32) -> bool {
        functions::PlayerTextDraw_SetShadow(&self.player, self, size)
    }
    /// Set the outline of a player-textdraw.
    pub fn set_outline(&self, size: i32) -> bool {
        functions::PlayerTextDraw_SetOutline(&self.player, self, size)
    }
    /// Adjust the background color of a player-textdraw.
    pub fn background_color(&self, colour: Colour) -> bool {
        functions::PlayerTextDraw_SetBackgroundColor(&self.player, self, colour.rgba())
    }
    pub fn set_style(&self, font: TextDrawStyle) -> bool {
        functions::PlayerTextDraw_SetFont(&self.player, self, font as i32)
    }
    /// Appears to scale text spacing to a proportional ratio.
    pub fn set_proportional(&self, set: bool) -> bool {
        functions::PlayerTextDraw_SetProportional(&self.player, self, set)
    }
    /// Toggles whether a player-textdraw can be selected or not.
    pub fn set_selectable(&self, set: bool) -> bool {
        functions::PlayerTextDraw_SetSelectable(&self.player, self, set)
    }
    /// Show a player-textdraw to the player it was created for.
    pub fn show(&self) -> bool {
        functions::PlayerTextDraw_Show(&self.player, self)
    }
    /// Hide a player-textdraw from the player it was created for.
    pub fn hide(&self) -> bool {
        functions::PlayerTextDraw_Hide(&self.player, self)
    }
    /// Change the text of a player-textdraw.
    pub fn set_string(&self, text: &str) -> bool {
        functions::PlayerTextDraw_SetString(&self.player, self, text)
    }
    /// Sets a player textdraw 3D preview sprite of a specified model ID.
    pub fn set_preview_model(&self, model: i32) -> bool {
        functions::PlayerTextDraw_SetPreviewModel(&self.player, self, model)
    }
    pub fn set_preview_rotation(&self, rotation: Vector3, zoom: f32) -> bool {
        functions::PlayerTextDraw_SetPreviewRot(
            &self.player,
            self,
            rotation.x,
            rotation.y,
            rotation.z,
            zoom,
        )
    }
    pub fn set_preview_veh_colour(&self, colour1: i32, colour2: i32) -> bool {
        functions::PlayerTextDraw_SetPreviewVehCol(&self.player, self, colour1, colour2)
    }
    /// Sets the position of a player-textdraw.
    pub fn set_pos(&self, pos: Vector2) -> bool {
        functions::PlayerTextDraw_SetPos(&self.player, self, pos.x, pos.y)
    }
    /// Gets the text of a player-textdraw.
    pub fn get_string(&self) -> String {
        let mut text = String::new();
        functions::PlayerTextDraw_GetString(&self.player, self, &mut text, 16);
        text
    }
    /// Gets the width and height of the letters.
    pub fn get_letter_size(&self) -> Vector2 {
        let mut size = Vector2::default();
        functions::PlayerTextDraw_GetLetterSize(&self.player, self, &mut size.x, &mut size.y);
        size
    }
    /// Gets the X axis and Y axis of the player-textdraw text size.
    pub fn get_text_size(&self) -> Vector2 {
        let mut size = Vector2::default();
        functions::PlayerTextDraw_GetTextSize(&self.player, self, &mut size.x, &mut size.y);
        size
    }
    /// Gets the position of a player-textdraw.
    pub fn get_pos(&self) -> Vector2 {
        let mut pos = Vector2::default();
        functions::PlayerTextDraw_GetPos(&self.player, self, &mut pos.x, &mut pos.y);
        pos
    }
    /// Gets the text color of a player-textdraw
    pub fn get_color(&self) -> Colour {
        Colour::from_rgba(functions::PlayerTextDraw_GetColor(&self.player, self) as u32)
    }
    /// Gets the box color of a player-textdraw
    pub fn get_box_color(&self) -> Colour {
        Colour::from_rgba(functions::PlayerTextDraw_GetBoxColor(&self.player, self) as u32)
    }
    /// Gets the background colour of a player-textdraw
    pub fn get_background_colour(&self) -> Colour {
        Colour::from_rgba(functions::PlayerTextDraw_GetBackgroundColor(&self.player, self) as u32)
    }
    /// Get the shadow size on a player-textdraw.
    pub fn get_shadow(&self) -> i32 {
        functions::PlayerTextDraw_GetShadow(&self.player, self)
    }
    /// Get the outline size on a player-textdraw.
    pub fn get_outline(&self) -> i32 {
        functions::PlayerTextDraw_GetOutline(&self.player, self)
    }
    pub fn get_style(&self) -> i32 {
        functions::PlayerTextDraw_GetFont(&self.player, self)
    }
    /// Checks if a player-textdraw is box.
    pub fn is_box(&self) -> bool {
        functions::PlayerTextDraw_IsBox(&self.player, self)
    }
    /// Checks if a player-textdraw is proportional.
    pub fn is_proportional(&self) -> bool {
        functions::PlayerTextDraw_IsProportional(&self.player, self)
    }
    /// Checks if a player-textdraw is selectable.
    pub fn is_selectable(&self) -> bool {
        functions::PlayerTextDraw_IsSelectable(&self.player, self)
    }
    /// Gets the text alignment of a player-textdraw.
    pub fn get_alignment(&self) -> TextDrawAlignmentTypes {
        unsafe { std::mem::transmute(functions::PlayerTextDraw_GetAlignment(&self.player, self)) }
    }
    /// Gets the preview model of a 3D preview player-textdraw.
    pub fn get_preview_model(&self) -> i32 {
        functions::PlayerTextDraw_GetPreviewModel(&self.player, self)
    }
    pub fn get_preview_rotation(&self) -> (Vector3, f32) {
        let mut rotation = Vector3::default();
        let mut zoom = 0.0;
        functions::PlayerTextDraw_GetPreviewRot(
            &self.player,
            self,
            &mut rotation.x,
            &mut rotation.y,
            &mut rotation.z,
            &mut zoom,
        );
        (rotation, zoom)
    }
    pub fn get_preview_veh_colour(&self) -> (i32, i32) {
        let mut colour1 = 0;
        let mut colour2 = 0;
        functions::PlayerTextDraw_GetPreviewVehColor(
            &self.player,
            self,
            &mut colour1,
            &mut colour2,
        );
        (colour1, colour2)
    }
    pub fn get_id(&self) -> i32 {
        functions::PlayerTextDraw_GetID(&self.player, self)
    }
    pub fn from_id(selfid: i32, player: &Player) -> Option<PlayerTextDraw> {
        functions::PlayerTextDraw_FromID(player, selfid)
    }
}

#[repr(C)]
#[derive(PartialEq, Clone, Copy, Debug, Default)]
pub enum TextDrawAlignmentTypes {
    #[default]
    Default,
    Left,
    Center,
    Right,
}

#[repr(C)]
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum TextDrawStyle {
    FontBeckettRegular = 0,
    FontAharoniBold,
    FontBankGothic,
    FontPricedown,
    Sprite,
    Preview,
}