added position to disembark on attached plane

This commit is contained in:
Alexsandro Percy 2024-02-16 17:41:31 -03:00
parent 4055702e85
commit 7a0cc3fa92
3 changed files with 100 additions and 7 deletions

View file

@ -170,6 +170,63 @@ local function right_click_cabin(self, clicker)
end end
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) local function find_chair_index(self, curr_seat)
for i = ap_airship.max_seats,1,-1 for i = ap_airship.max_seats,1,-1
do 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 -- and item just to run the sit function
minetest.register_entity('ap_airship:chair_interactor',{ minetest.register_entity('ap_airship:chair_interactor',{
initial_properties = { 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._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=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: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 --chairs
self._chairs_pos = ap_airship.copy_vector({ self._chairs_pos = ap_airship.copy_vector({

View file

@ -51,8 +51,7 @@ function ap_airship.pax_formspec(name)
}, "") }, "")
basic_form = basic_form.."label[1,1.0;Disembark:]" 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[1,1.2;4,1;disembark_c;Click to disembark]"
basic_form = basic_form.."button[3,1.2;2,1;disembark_r;Right >>]"
minetest.show_formspec(name, "ap_airship:passenger_main", basic_form) minetest.show_formspec(name, "ap_airship:passenger_main", basic_form)
end end
@ -150,11 +149,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
local ent = plane_obj:get_luaentity() local ent = plane_obj:get_luaentity()
if ent then if ent then
if fields.disembark_l then if fields.disembark_c then
ap_airship.dettach_pax(ent, player, "l") ap_airship.dettach_pax(ent, player, "c")
end
if fields.disembark_r then
ap_airship.dettach_pax(ent, player, "r")
end end
end end
minetest.close_formspec(name, "ap_airship:passenger_main") minetest.close_formspec(name, "ap_airship:passenger_main")

View file

@ -182,6 +182,7 @@ end
function ap_airship.dettach_pax(self, player, side) function ap_airship.dettach_pax(self, player, side)
side = side or "r" side = side or "r"
if not self._passengers then return end
if player then if player then
local name = player:get_player_name() --self._passenger local name = player:get_player_name() --self._passenger
ap_airship.remove_hud(player) ap_airship.remove_hud(player)
@ -211,6 +212,10 @@ function ap_airship.dettach_pax(self, player, side)
end end
local move = 5 local move = 5
if side == "c" then
direction = direction - math.rad(90)
move = 1
end
pos.x = pos.x + move * math.cos(direction) pos.x = pos.x + move * math.cos(direction)
pos.z = pos.z + move * math.sin(direction) pos.z = pos.z + move * math.sin(direction)
if self.isinliquid then if self.isinliquid then