From 1bd0e8706d0a230542ab674d90ecb8204e2439f1 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Fri, 12 Aug 2022 19:47:27 -0300 Subject: [PATCH] fix sit position --- heli_utilities.lua | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/heli_utilities.lua b/heli_utilities.lua index b0a5528..e3f4e75 100644 --- a/heli_utilities.lua +++ b/heli_utilities.lua @@ -35,6 +35,25 @@ function helicopter.setText(self) end end +--returns 0 for old, 1 for new +function helicopter.detect_player_api(player) + local player_proterties = player:get_properties() + local mesh = "character.b3d" + if player_proterties.mesh == mesh then + local models = player_api.registered_models + local character = models[mesh] + if character then + if character.animations.sit.eye_height then + return 1 + else + return 0 + end + end + end + + return 0 +end + -- attach player function helicopter.attach(self, player) local name = player:get_player_name() @@ -45,15 +64,22 @@ function helicopter.attach(self, player) {object = self.object, gain = 2.0, max_hear_distance = 32, loop = true,}) self.object:set_animation_frame_speed(60) + -- attach the driver player:set_attach(self.pilot_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) - player:set_eye_offset({x = 0, y = -4, z = 1}, {x = 0, y = 8, z = -30}) + if helicopter.detect_player_api(player) == 0 then + player:set_eye_offset({x = 0, y = -4, z = 1}, {x = 0, y = 8, z = -30}) + else + player:set_eye_offset({x = 0, y = 2, z = 1}, {x = 0, y = 8, z = -30}) + end player_api.player_attached[name] = true + player_api.set_animation(player, "sit") -- make the driver sit minetest.after(0.2, function() local player = minetest.get_player_by_name(name) if player then - player_api.set_animation(player, "sit") + --player_api.set_animation(player, "sit") + player:set_animation({x = 81, y = 160},30, 0, true) update_heli_hud(player) end end) @@ -94,13 +120,18 @@ function helicopter.attach_pax(self, player) self._passenger = name -- attach the passenger player:set_attach(self.passenger_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) - player:set_eye_offset({x = 0, y = -4, z = 1}, {x = 0, y = 8, z = -5}) + if helicopter.detect_player_api(player) == 0 then + player:set_eye_offset({x = 0, y = -4, z = 1}, {x = 0, y = 8, z = -5}) + else + player:set_eye_offset({x = 0, y = 2, z = 1}, {x = 0, y = 8, z = -5}) + end player_api.player_attached[name] = true + player_api.set_animation(player, "sit") -- make the driver sit minetest.after(0.2, function() local player = minetest.get_player_by_name(name) if player then - player_api.set_animation(player, "sit") + player:set_animation({x = 81, y = 160},30, 0, true) end end) end