mostly finished get position raw stuff

This commit is contained in:
Luuk van Oijen 2023-11-30 16:27:23 +01:00
parent 8e1d235dee
commit b8211166ad
4 changed files with 46 additions and 19 deletions

View File

@ -43,6 +43,14 @@ function onChatMessage(pid, name, message)
MP.SendChatMessage(-1, "i hate this " .. name .. " guy!")
MP.SendChatMessage(pid, "hiii babe i didnt mean it :3")
print("" .. name .. " (" .. pid .. "): " .. message)
print("identifiers:")
for key, value in pairs(MP.GetPlayerIdentifiers(pid)) do
print(key .. ": " .. value)
end
print("unknown identifiers (nil): " .. tostring(MP.GetPlayerIdentifiers(100)))
return message .. " (edited by lua!!!)"
end

View File

@ -24,6 +24,14 @@ impl Car {
}
}
pub fn raw_position(&self) -> DVec3 {
self.pos
}
pub fn raw_rotation(&self) -> DQuat {
self.rot
}
pub fn position(&self) -> DVec3 {
self.pos + self.vel * self.last_pos_update.map(|t| t.elapsed().as_secs_f64()).unwrap_or(0.0)
}

View File

@ -684,8 +684,8 @@ impl Server {
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.position().as_vec3().to_array(),
rot: vehicle.rotation().as_f32().to_array(),
pos: vehicle.raw_position().as_vec3().to_array(),
rot: vehicle.raw_rotation().as_f32().to_array(),
};
let _ = responder.send(PluginBoundPluginEvent::PositionRaw(pos_rot));
} else {

View File

@ -104,13 +104,15 @@ impl UserData for Context {
}
let message = rx.blocking_recv();
if let Ok(message) = message {
if let PluginBoundPluginEvent::PlayerIdentifiers(identifiers) = message {
let table = lua.create_table()?;
table.set("id", identifiers.ip)?;
table.set("beammp_id", identifiers.beammp_id)?;
Ok(table)
} else {
unreachable!() // This should really never be reachable
match message {
PluginBoundPluginEvent::PlayerIdentifiers(identifiers) => {
let table = lua.create_table()?;
table.set("id", identifiers.ip)?;
table.set("beammp_id", identifiers.beammp_id)?;
Ok(Value::Table(table))
},
PluginBoundPluginEvent::None => Ok(Value::Nil),
_ => unreachable!() // This should really never be reachable
}
} else {
todo!("Receiving a response from the server failed! How?")
@ -173,17 +175,26 @@ impl UserData for Context {
}
let message = rx.blocking_recv();
if let Ok(message) = message {
if let PluginBoundPluginEvent::PositionRaw(pos_raw) = message {
let pos_table = lua.create_table()?;
pos_table.set("x", pos_raw.pos[0])?;
pos_table.set("y", pos_raw.pos[1])?;
pos_table.set("z", pos_raw.pos[2])?;
match message {
PluginBoundPluginEvent::PositionRaw(pos_raw) => {
let pos_table = lua.create_table()?;
pos_table.set("x", pos_raw.pos[0])?;
pos_table.set("y", pos_raw.pos[1])?;
pos_table.set("z", pos_raw.pos[2])?;
let table = lua.create_table()?;
table.set("pos", pos_table)?;
Ok(table)
} else {
unreachable!() // This really should never be reachable
let rot_table = lua.create_table()?;
pos_table.set("x", pos_raw.rot[0])?;
pos_table.set("y", pos_raw.rot[1])?;
pos_table.set("z", pos_raw.rot[2])?;
pos_table.set("w", pos_raw.rot[3])?;
let table = lua.create_table()?;
table.set("pos", pos_table)?;
table.set("rot", rot_table)?;
Ok(Value::Table(table))
},
PluginBoundPluginEvent::None => Ok(Value::Nil),
_ => unreachable!() // This really should never be reachable
}
} else {
todo!("Receiving a response from the server failed! How?")