mirror of
https://github.com/APercy/airutils.git
synced 2025-03-15 08:01:22 +00:00
creating adf functions
This commit is contained in:
parent
8f325e1418
commit
df04f66d25
2 changed files with 75 additions and 0 deletions
|
@ -18,6 +18,7 @@ function airutils.get_staticdata(self) -- unloaded/unloads ... is now saved
|
|||
stored_inv_id = self._inv_id,
|
||||
stored_flap = self._flap,
|
||||
stored_passengers = self._passengers,
|
||||
stored_adf_destiny = self._adf_destiny,
|
||||
stored_vehicle_custom_data = self._vehicle_custom_data
|
||||
})
|
||||
end
|
||||
|
@ -43,6 +44,7 @@ function airutils.on_activate(self, staticdata, dtime_s)
|
|||
self._inv_id = data.stored_inv_id
|
||||
self._flap = data.stored_flap
|
||||
self._passengers = data.stored_passengers or {}
|
||||
self._adf_destiny = data.stored_adf_destiny or vector.new()
|
||||
local custom_data = data.stored_vehicle_custom_data
|
||||
if custom_data then
|
||||
self._vehicle_custom_data = custom_data
|
||||
|
|
|
@ -107,6 +107,46 @@ function airutils.manage_copilot_formspec(name)
|
|||
minetest.show_formspec(name, "lib_planes:manage_copilot", basic_form)
|
||||
end
|
||||
|
||||
function airutils.adf_formspec(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj == nil then
|
||||
return
|
||||
end
|
||||
local ent = plane_obj:get_luaentity()
|
||||
|
||||
local adf = "false"
|
||||
if ent._adf then adf = "true" end
|
||||
local x = 0
|
||||
local z = 0
|
||||
if ent._adf_destiny then
|
||||
if ent._adf_destiny.x then
|
||||
if type(ent._adf_destiny.x) ~= nil then
|
||||
x = math.floor(ent._adf_destiny.x)
|
||||
end
|
||||
end
|
||||
if ent._adf_destiny.z then
|
||||
if type(ent._adf_destiny.z) ~= nil then
|
||||
z = math.floor(ent._adf_destiny.z)
|
||||
end
|
||||
end
|
||||
else
|
||||
--return
|
||||
end
|
||||
|
||||
local basic_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[6,3.5]",
|
||||
}, "")
|
||||
|
||||
basic_form = basic_form.."checkbox[1.0,1.0;adf;Auto Direction Find;"..adf.."]"
|
||||
basic_form = basic_form.."field[1.0,1.7;1.5,0.6;adf_x;pos x;"..x.."]"
|
||||
basic_form = basic_form.."field[2.8,1.7;1.5,0.6;adf_z;pos z;"..z.."]"
|
||||
basic_form = basic_form.."button[4.5,1.7;0.6,0.6;save_adf;OK]"
|
||||
|
||||
minetest.show_formspec(name, "lib_planes:adf_main", basic_form)
|
||||
end
|
||||
|
||||
function airutils.pax_formspec(name)
|
||||
local basic_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
|
@ -148,6 +188,39 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
end
|
||||
minetest.close_formspec(name, "lib_planes:go_out_confirmation_form")
|
||||
end
|
||||
if formname == "lib_planes:adf_main" then
|
||||
local name = player:get_player_name()
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj == nil then
|
||||
minetest.close_formspec(name, "lib_planes:adf_main")
|
||||
return
|
||||
end
|
||||
local ent = plane_obj:get_luaentity()
|
||||
if ent then
|
||||
if fields.adf then
|
||||
if ent._adf == true then
|
||||
ent._adf = false
|
||||
else
|
||||
ent._adf = true
|
||||
end
|
||||
end
|
||||
if fields.save_adf then
|
||||
if ent._adf_destiny then
|
||||
if fields.adf_x then
|
||||
if tonumber(fields.adf_x, 10) ~= nil then
|
||||
ent._adf_destiny.x = tonumber(fields.adf_x, 10)
|
||||
end
|
||||
end
|
||||
if fields.adf_z then
|
||||
if tonumber(fields.adf_z, 10) ~= nil then
|
||||
ent._adf_destiny.z = tonumber(fields.adf_z, 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.close_formspec(name, "lib_planes:adf_main")
|
||||
end
|
||||
if formname == "lib_planes:passenger_main" then
|
||||
local name = player:get_player_name()
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
|
|
Loading…
Add table
Reference in a new issue