From 7a0cc3fa92477fbdb5ff25072d0e056d4475abe0 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Fri, 16 Feb 2024 17:41:31 -0300 Subject: [PATCH] added position to disembark on attached plane --- entities.lua | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ forms.lua | 10 ++---- utilities.lua | 5 +++ 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/entities.lua b/entities.lua index 5aa85e2..446322d 100755 --- a/entities.lua +++ b/entities.lua @@ -170,6 +170,63 @@ local function right_click_cabin(self, clicker) end end +local function right_click_exit(self, clicker) + local message = "" + if not clicker or not clicker:is_player() then + return + end + + local name = clicker:get_player_name() + local ship_self = nil + + local is_attached = false + local seat = clicker:get_attach() + if seat then + ship_attach = seat:get_attach() + if ship_attach then + ship_self = ship_attach:get_luaentity() + is_attached = true + end + end + + if is_attached then + local ent, obj = airutils.get_attached_entity(ship_self) + if ent and obj then + local name = clicker:get_player_name() + if ent._inv_id and ent._seats then --to check if is one of my puppies + local can_enter = false + --check first if it is the owner + if not ent.driver_name then + if ent._needed_licence then + local can_fly = minetest.check_player_privs(clicker, ent._needed_licence) + if not can_fly then + minetest.chat_send_player(name, core.colorize('#ff0000', S(' >>> You need the priv') .. '"'..ent._needed_licence..'" ' .. S('to fly this plane.'))) + return + end + end + if ent.owner == name or minetest.check_player_privs(clicker, {protection_bypass=true}) then can_enter = true end + else + local max_seats = table.getn(ent._seats) + local count = 1 + for i = 2,max_seats do + if ent._passengers[i] then + count = count + 1 + end + end + --minetest.chat_send_all("count: "..count.." - seats: "..max_seats) + if count < max_seats then can_enter = true end + end + if can_enter then + ap_airship.dettach_pax(ship_self, clicker, "c") + airutils.on_rightclick(ent, clicker) + end + end + else + ap_airship.pax_formspec(name) + end + end +end + local function find_chair_index(self, curr_seat) for i = ap_airship.max_seats,1,-1 do @@ -295,6 +352,39 @@ minetest.register_entity('ap_airship:cabin_interactor',{ }) +minetest.register_entity('ap_airship:exit_interactor',{ + initial_properties = { + physical = true, + collide_with_objects=true, + collisionbox = {-0.5, 0, -0.5, 0.5, 3, 0.5}, + visual = "mesh", + mesh = "ap_airship_stand_base.b3d", + textures = {"ap_airship_alpha.png",}, + }, + dist_moved = 0, + max_hp = 65535, + + on_activate = function(self,std) + self.sdata = minetest.deserialize(std) or {} + if self.sdata.remove then self.object:remove() end + end, + + get_staticdata=function(self) + self.sdata.remove=true + return minetest.serialize(self.sdata) + end, + + on_punch = function(self, puncher, ttime, toolcaps, dir, damage) + --minetest.chat_send_all("punch") + if not puncher or not puncher:is_player() then + return + end + end, + + on_rightclick = right_click_exit, + +}) + -- and item just to run the sit function minetest.register_entity('ap_airship:chair_interactor',{ initial_properties = { @@ -540,6 +630,8 @@ minetest.register_entity("ap_airship:airship", { self._control_interactor:set_attach(self.object,'',{x=0,y=-28,z=175},{x=0,y=0,z=0}) self._cabin_interactor=minetest.add_entity(pos,'ap_airship:cabin_interactor') self._cabin_interactor:set_attach(self.object,'',{x=-7,y=-28,z=115},{x=0,y=0,z=0}) + self._cabin_interactor=minetest.add_entity(pos,'ap_airship:exit_interactor') + self._cabin_interactor:set_attach(self.object,'',{x=0,y=0,z=-120},{x=0,y=0,z=0}) --chairs self._chairs_pos = ap_airship.copy_vector({ diff --git a/forms.lua b/forms.lua index f7932a9..2e2eaa5 100755 --- a/forms.lua +++ b/forms.lua @@ -51,8 +51,7 @@ function ap_airship.pax_formspec(name) }, "") basic_form = basic_form.."label[1,1.0;Disembark:]" - basic_form = basic_form.."button[1,1.2;2,1;disembark_l;<< Left]" - basic_form = basic_form.."button[3,1.2;2,1;disembark_r;Right >>]" + basic_form = basic_form.."button[1,1.2;4,1;disembark_c;Click to disembark]" minetest.show_formspec(name, "ap_airship:passenger_main", basic_form) end @@ -150,11 +149,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local ent = plane_obj:get_luaentity() if ent then - if fields.disembark_l then - ap_airship.dettach_pax(ent, player, "l") - end - if fields.disembark_r then - ap_airship.dettach_pax(ent, player, "r") + if fields.disembark_c then + ap_airship.dettach_pax(ent, player, "c") end end minetest.close_formspec(name, "ap_airship:passenger_main") diff --git a/utilities.lua b/utilities.lua index 0bf991c..6a896b8 100755 --- a/utilities.lua +++ b/utilities.lua @@ -182,6 +182,7 @@ end function ap_airship.dettach_pax(self, player, side) side = side or "r" + if not self._passengers then return end if player then local name = player:get_player_name() --self._passenger ap_airship.remove_hud(player) @@ -211,6 +212,10 @@ function ap_airship.dettach_pax(self, player, side) end local move = 5 + if side == "c" then + direction = direction - math.rad(90) + move = 1 + end pos.x = pos.x + move * math.cos(direction) pos.z = pos.z + move * math.sin(direction) if self.isinliquid then