omp_gdk/scripting/objects/
events.rs1#![allow(clippy::all)]
2use std::mem::transmute;
3
4use crate::{events::EventArgs, players::Player, runtime::each_module, types::vector::Vector3};
5
6use super::{Object, ObjectAttachmentSlotData, PlayerObject};
7
8#[repr(C)]
9pub struct OnObjectMoveArgs {
10 object: *const *const std::ffi::c_void,
11}
12
13#[no_mangle]
14pub unsafe extern "C" fn OMPRS_OnObjectMove(args: *const EventArgs<OnObjectMoveArgs>) {
15 each_module(move |mut script| {
16 script.on_object_moved(Object::new(*(*(*args).list).object));
17 None
18 });
19}
20
21#[repr(C)]
22pub struct OnPlayerObjectMoveArgs {
23 player: *const *const std::ffi::c_void,
24 object: *const *const std::ffi::c_void,
25}
26
27#[no_mangle]
28pub unsafe extern "C" fn OMPRS_OnPlayerObjectMove(args: *const EventArgs<OnPlayerObjectMoveArgs>) {
29 each_module(move |mut script| {
30 script.on_player_object_moved(
31 Player::new(*(*(*args).list).player),
32 PlayerObject::new(
33 *(*(*args).list).object,
34 Player::new(*(*(*args).list).player),
35 ),
36 );
37 None
38 });
39}
40
41#[repr(C)]
42pub struct OnPlayerEditObjectArgs {
43 player: *const *const std::ffi::c_void,
44 object: *const *const std::ffi::c_void,
45 response: *const i32,
46 offsetX: *const f32,
47 offsetY: *const f32,
48 offsetZ: *const f32,
49 rotationX: *const f32,
50 rotationY: *const f32,
51 rotationZ: *const f32,
52}
53
54#[no_mangle]
55pub unsafe extern "C" fn OMPRS_OnPlayerEditObject(args: *const EventArgs<OnPlayerEditObjectArgs>) {
56 each_module(move |mut script| {
57 script.on_player_edit_object(
58 Player::new(*(*(*args).list).player),
59 Object::new(*(*(*args).list).object),
60 transmute(*(*(*args).list).response),
61 Vector3::new(
62 *(*(*args).list).offsetX,
63 *(*(*args).list).offsetY,
64 *(*(*args).list).offsetZ,
65 ),
66 Vector3::new(
67 *(*(*args).list).rotationX,
68 *(*(*args).list).rotationY,
69 *(*(*args).list).rotationZ,
70 ),
71 );
72 None
73 });
74}
75
76#[repr(C)]
77pub struct OnPlayerEditPlayerObjectArgs {
78 player: *const *const std::ffi::c_void,
79 object: *const *const std::ffi::c_void,
80 response: *const i32,
81 offsetX: *const f32,
82 offsetY: *const f32,
83 offsetZ: *const f32,
84 rotationX: *const f32,
85 rotationY: *const f32,
86 rotationZ: *const f32,
87}
88
89#[repr(C)]
90pub struct OnPlayerEditAttachedObjectArgs {
91 player: *const *const std::ffi::c_void,
92 saved: *const bool,
93 index: *const i32,
94 model: *const i32,
95 bone: *const i32,
96 offsetX: *const f32,
97 offsetY: *const f32,
98 offsetZ: *const f32,
99 rotationX: *const f32,
100 rotationY: *const f32,
101 rotationZ: *const f32,
102 scaleX: *const f32,
103 scaleY: *const f32,
104 scaleZ: *const f32,
105}
106
107#[no_mangle]
108pub unsafe extern "C" fn OMPRS_OnPlayerEditAttachedObject(
109 args: *const EventArgs<OnPlayerEditAttachedObjectArgs>,
110) {
111 each_module(move |mut script| {
112 script.on_player_edit_attached_object(
113 Player::new(*(*(*args).list).player),
114 *(*(*args).list).index,
115 *(*(*args).list).saved,
116 ObjectAttachmentSlotData {
117 model: *(*(*args).list).model,
118 bone: *(*(*args).list).bone,
119 offset: Vector3::new(
120 *(*(*args).list).offsetX,
121 *(*(*args).list).offsetY,
122 *(*(*args).list).offsetZ,
123 ),
124 rotation: Vector3::new(
125 *(*(*args).list).rotationX,
126 *(*(*args).list).rotationY,
127 *(*(*args).list).rotationZ,
128 ),
129 scale: Vector3::new(
130 *(*(*args).list).scaleX,
131 *(*(*args).list).scaleY,
132 *(*(*args).list).scaleZ,
133 ),
134 ..Default::default()
135 },
136 );
137 None
138 });
139}
140
141#[repr(C)]
142pub struct OnPlayerSelectObjectArgs {
143 player: *const *const std::ffi::c_void,
144 object: *const *const std::ffi::c_void,
145 model: *const i32,
146 x: *const f32,
147 y: *const f32,
148 z: *const f32,
149}
150
151#[no_mangle]
152pub unsafe extern "C" fn OMPRS_OnPlayerSelectObject(
153 args: *const EventArgs<OnPlayerSelectObjectArgs>,
154) {
155 each_module(move |mut script| {
156 script.on_player_select_object(
157 Player::new(*(*(*args).list).player),
158 Object::new(*(*(*args).list).object),
159 *(*(*args).list).model,
160 Vector3::new(*(*(*args).list).x, *(*(*args).list).y, *(*(*args).list).z),
161 );
162 None
163 });
164}
165
166#[repr(C)]
167pub struct OnPlayerSelectPlayerObjectArgs {
168 player: *const *const std::ffi::c_void,
169 object: *const *const std::ffi::c_void,
170 model: *const i32,
171 x: *const f32,
172 y: *const f32,
173 z: *const f32,
174}