From 1b8caaf7c4d78d9d6774a01af8f9da1d8be1c5c4 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Fri, 14 Jul 2023 21:08:19 -0300 Subject: [PATCH] improving copilot and instruction mode --- lib_planes/entities.lua | 6 +++++- lib_planes/forms.lua | 7 ++++++- lib_planes/utilities.lua | 21 ++++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index 8943c15..8ec23bc 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -784,10 +784,14 @@ function airutils.on_rightclick(self, clicker) if clicker:get_player_control().sneak == true then -- flight instructor mode self._instruction_mode = true - airutils.attach(self, clicker, true) + self.co_pilot_seat_base = self._passengers_base[1] + self.pilot_seat_base = self._passengers_base[2] + airutils.attach(self, clicker) else -- no driver => clicker is new driver self._instruction_mode = false + self.co_pilot_seat_base = self._passengers_base[2] + self.pilot_seat_base = self._passengers_base[1] airutils.attach(self, clicker) end self._command_is_given = false diff --git a/lib_planes/forms.lua b/lib_planes/forms.lua index 968d042..23a36fd 100644 --- a/lib_planes/forms.lua +++ b/lib_planes/forms.lua @@ -126,7 +126,12 @@ function airutils.manage_copilot_formspec(name) }, "") basic_form = basic_form.."label[1,1.0;Bring a copilot:]" - basic_form = basic_form.."dropdown[1,1.5;4,0.6;copilot;"..pass_list..";0;false]" + + local max_seats = table.getn(ent._seats) + if ent._have_copilot and max_seats > 2 then --no need to select if there are only 2 occupants + basic_form = basic_form.."dropdown[1,1.5;4,0.6;copilot;"..pass_list..";0;false]" + end + basic_form = basic_form.."button[1,2.5;4,1;pass_control;Pass the Control]" minetest.show_formspec(name, "lib_planes:manage_copilot", basic_form) diff --git a/lib_planes/utilities.lua b/lib_planes/utilities.lua index 75fab40..6048f24 100644 --- a/lib_planes/utilities.lua +++ b/lib_planes/utilities.lua @@ -140,7 +140,26 @@ function airutils.attach_pax(self, player, is_copilot) --randomize the seat local max_seats = table.getn(self._seats) local crew = 1 - if self._have_copilot and max_seats > 2 then crew = crew + 1 end + if self._have_copilot and max_seats > 2 then + crew = crew + 1 + else + self.co_pilot = name + player:set_attach(self.co_pilot_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) + player:set_eye_offset({x = 0, y = eye_y, z = 0}, {x = 0, y = 3, z = -30}) + player_api.player_attached[name] = true + player_api.set_animation(player, "sit") + -- make the driver sit + minetest.after(1, function() + player = minetest.get_player_by_name(name) + if player then + airutils.sit(player) + --apply_physics_override(player, {speed=0,gravity=0,jump=0}) + end + end) + + return + end + t = {} -- new array for i=1, max_seats - crew do --(the first are for the crew t[i] = i