added pilot form

master
Alexsandro Percy 2022-03-23 09:50:48 -03:00
parent 4d52a49afe
commit 5c7df7554a
3 changed files with 81 additions and 31 deletions

View File

@ -447,7 +447,7 @@ minetest.register_entity("hidroplane:hidro", {
passenger_name = self._passenger
end
local touching_ground, liquid_below = airutils.check_node_below(self.object, 2.5)
local touching_ground, liquid_below = airutils.check_node_below(self.object, 1.3)
local is_on_ground = self.isinliquid or touching_ground or liquid_below
local is_under_water = airutils.check_is_under_water(self.object)
@ -456,36 +456,7 @@ minetest.register_entity("hidroplane:hidro", {
-- detach pilot
--=========================
if name == self.driver_name then
if is_on_ground or clicker:get_player_control().sneak then
if passenger_name then --any pax?
if is_on_ground then --okay, goodbye
local pax_obj = minetest.get_player_by_name(passenger_name)
hidroplane.dettach_pax(self, pax_obj)
else -- oh no!!!! you are the pilot now! Good luck
airutils.transfer_control(self, true)
self._command_is_given = true
end
end
self._instruction_mode = false
hidroplane.dettachPlayer(self, clicker)
--[[ sound and animation
if self.sound_handle then
minetest.sound_stop(self.sound_handle)
self.sound_handle = nil
end
self.engine:set_animation_frame_speed(0)]]--
else
-- not on ground
if self._passenger then
--give the control to the pax
self._autopilot = false
airutils.transfer_control(self, true)
self._command_is_given = true
self._instruction_mode = true
end
minetest.chat_send_player(name, "Hold sneak and right-click to disembark while flying")
end
hidroplane.pilot_formspec(name)
--=========================
-- detach passenger
--=========================
@ -531,6 +502,8 @@ minetest.register_entity("hidroplane:hidro", {
self._instruction_mode = false
hidroplane.attach(self, clicker)
end
self._elevator_angle = 0
self._rudder_angle = 0
self._command_is_given = false
end
else

76
hidroplane_forms.lua Normal file
View File

@ -0,0 +1,76 @@
dofile(minetest.get_modpath("hidroplane") .. DIR_DELIM .. "hidroplane_global_definitions.lua")
--------------
-- Manual --
--------------
function hidroplane.getPlaneFromPlayer(player)
local seat = player:get_attach()
if seat then
local plane = seat:get_attach()
return plane
end
return nil
end
function hidroplane.pilot_formspec(name)
local basic_form = table.concat({
"formspec_version[3]",
"size[6,6]",
}, "")
basic_form = basic_form.."button[1,1.0;4,1;go_out;Go Offboard]"
basic_form = basic_form.."button[1,2.5;4,1;hud;Show/Hide Gauges]"
basic_form = basic_form.."button[1,4.0;4,1;manual;Show Manual]"
minetest.show_formspec(name, "hidroplane:pilot_main", basic_form)
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "hidroplane:pilot_main" then
local name = player:get_player_name()
local plane_obj = hidroplane.getPlaneFromPlayer(player)
if plane_obj then
local ent = plane_obj:get_luaentity()
if fields.hud then
if ent._show_hud == true then
ent._show_hud = false
else
ent._show_hud = true
end
end
if fields.go_out then
local touching_ground, liquid_below = airutils.check_node_below(plane_obj, 2.5)
local is_on_ground = ent.isinliquid or touching_ground or liquid_below
if is_on_ground then --or clicker:get_player_control().sneak then
if ent._passenger then --any pax?
local pax_obj = minetest.get_player_by_name(ent._passenger)
hidroplane.dettach_pax(ent, pax_obj)
end
ent._instruction_mode = false
--[[ sound and animation
if ent.sound_handle then
minetest.sound_stop(ent.sound_handle)
ent.sound_handle = nil
end
ent.engine:set_animation_frame_speed(0)]]--
else
-- not on ground
if ent._passenger then
--give the control to the pax
ent._autopilot = false
airutils.transfer_control(ent, true)
ent._command_is_given = true
ent._instruction_mode = true
end
end
hidroplane.dettachPlayer(ent, player)
end
if fields.manual then
hidroplane.manual_formspec(name)
end
end
minetest.close_formspec(name, "hidroplane:pilot_main")
end
end)

View File

@ -33,6 +33,7 @@ dofile(minetest.get_modpath("hidroplane") .. DIR_DELIM .. "hidroplane_custom_phy
dofile(minetest.get_modpath("hidroplane") .. DIR_DELIM .. "hidroplane_utilities.lua")
dofile(minetest.get_modpath("hidroplane") .. DIR_DELIM .. "hidroplane_entities.lua")
dofile(minetest.get_modpath("hidroplane") .. DIR_DELIM .. "hidroplane_manual.lua")
dofile(minetest.get_modpath("hidroplane") .. DIR_DELIM .. "hidroplane_forms.lua")
--
-- helpers and co.