mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 00:05:34 +00:00
wip position raw event
This commit is contained in:
parent
03ac847683
commit
dc61d4649c
@ -683,6 +683,22 @@ impl Server {
|
||||
}
|
||||
},
|
||||
|
||||
ServerBoundPluginEvent::RequestPositionRaw((pid, vid, responder)) => {
|
||||
if let Some(client) = self.clients.iter().find(|client| client.id == pid) {
|
||||
if let Some((_id, vehicle)) = client.cars.iter().find(|(id, _car)| *id == vid) {
|
||||
// let pos_rot = PositionRaw {
|
||||
// pos: vehicle.pos().
|
||||
// };
|
||||
todo!()
|
||||
// let _ = responder.send(PluginBoundPluginEvent::PositionRaw(pos_rot));
|
||||
} else {
|
||||
let _ = responder.send(PluginBoundPluginEvent::None);
|
||||
}
|
||||
} else {
|
||||
let _ = responder.send(PluginBoundPluginEvent::None);
|
||||
}
|
||||
}
|
||||
|
||||
ServerBoundPluginEvent::SendChatMessage((pid, msg)) => {
|
||||
let pid = if pid >= 0 { Some(pid as u8) } else { None };
|
||||
self.send_chat_message(&msg, pid).await;
|
||||
|
@ -165,6 +165,28 @@ impl UserData for Context {
|
||||
}
|
||||
});
|
||||
|
||||
methods.add_function("GetPositionRaw", |lua, (pid, vid): (u8, u8)| {
|
||||
let me: Context = lua.globals().get("MP")?;
|
||||
let (tx, rx) = oneshot::channel();
|
||||
if let Err(e) = me.tx.blocking_send(ServerBoundPluginEvent::RequestPositionRaw((pid, vid, tx))) {
|
||||
error!("Failed to send packet: {:?}", e);
|
||||
}
|
||||
let message = rx.blocking_recv();
|
||||
if let Ok(message) = message {
|
||||
if let PluginBoundPluginEvent::PositionRaw(pos_raw) = message {
|
||||
let table = lua.create_table()?;
|
||||
// for (vid, veh_json) in vehicles {
|
||||
// table.set(vid, veh_json)?;
|
||||
// }
|
||||
Ok(table)
|
||||
} else {
|
||||
unreachable!() // This really should never be reachable
|
||||
}
|
||||
} else {
|
||||
todo!("Receiving a response from the server failed! How?")
|
||||
}
|
||||
});
|
||||
|
||||
methods.add_function("SendChatMessage", |lua, (id, msg): (isize, String)| {
|
||||
let me: Context = lua.globals().get("MP")?;
|
||||
if let Err(e) = me.tx.blocking_send(ServerBoundPluginEvent::SendChatMessage((id, msg))) {
|
||||
|
@ -42,6 +42,32 @@ impl PlayerIdentifiers {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PositionRaw {
|
||||
pub pos: [f32; 3],
|
||||
pub rot: [f32; 4],
|
||||
}
|
||||
|
||||
impl PositionRaw {
|
||||
pub fn to_map(&self) -> HashMap<String, Argument> {
|
||||
let mut pm = HashMap::new();
|
||||
pm.insert(String::from("x"), Argument::Number(self.pos[0]));
|
||||
pm.insert(String::from("y"), Argument::Number(self.pos[1]));
|
||||
pm.insert(String::from("z"), Argument::Number(self.pos[2]));
|
||||
|
||||
let mut rm = HashMap::new();
|
||||
rm.insert(String::from("x"), Argument::Number(self.rot[0]));
|
||||
rm.insert(String::from("y"), Argument::Number(self.rot[1]));
|
||||
rm.insert(String::from("z"), Argument::Number(self.rot[2]));
|
||||
rm.insert(String::from("w"), Argument::Number(self.rot[3]));
|
||||
|
||||
let mut m = HashMap::new();
|
||||
m.insert(String::from("pos"), Argument::Table(pm));
|
||||
m.insert(String::from("rot"), Argument::Table(rm));
|
||||
m
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ScriptEvent {
|
||||
OnPluginLoaded,
|
||||
@ -77,6 +103,7 @@ pub enum PluginBoundPluginEvent {
|
||||
PlayerIdentifiers(PlayerIdentifiers),
|
||||
|
||||
PlayerVehicles(HashMap<u8, String>),
|
||||
PositionRaw(PositionRaw),
|
||||
}
|
||||
|
||||
// TODO: Perhaps it would be nice to ensure each sender can only sned specifically what it needs to.
|
||||
@ -90,6 +117,7 @@ pub enum ServerBoundPluginEvent {
|
||||
RequestPlayerIdentifiers((u8, oneshot::Sender<PluginBoundPluginEvent>)),
|
||||
|
||||
RequestPlayerVehicles((u8, oneshot::Sender<PluginBoundPluginEvent>)),
|
||||
RequestPositionRaw((u8, u8, oneshot::Sender<PluginBoundPluginEvent>)),
|
||||
|
||||
SendChatMessage((isize, String)),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user