added mouse control to all vehicles

This commit is contained in:
Alexsandro Percy 2022-09-12 21:40:42 -03:00
parent 422d861454
commit 478b0a17ea
5 changed files with 41 additions and 5 deletions

View File

@ -740,7 +740,7 @@ minetest.register_entity("automobiles_buggy:buggy", {
automobiles_lib.attach_driver(self, clicker)
-- sound
self.sound_handle = minetest.sound_play({name = "buggy_engine"},
{object = self.object, gain = 4, pitch = 1, max_hear_distance = 10, loop = true,})
{object = self.object, gain = 4, pitch = 1, max_hear_distance = 30, loop = true,})
end
else
--minetest.chat_send_all("clicou")

View File

@ -767,7 +767,7 @@ minetest.register_entity("automobiles_coupe:coupe", {
automobiles_lib.attach_driver(self, clicker)
-- sound
self.sound_handle = minetest.sound_play({name = "automobiles_engine"},
{object = self.object, gain = 4, pitch = 1, max_hear_distance = 10, loop = true,})
{object = self.object, gain = 4, pitch = 1, max_hear_distance = 30, loop = true,})
end
else
--minetest.chat_send_all("clicou")

View File

@ -13,13 +13,24 @@ function coupe.getCarFromPlayer(player)
end
function coupe.driver_formspec(name)
local player = minetest.get_player_by_name(name)
local vehicle_obj = coupe.getCarFromPlayer(player)
if vehicle_obj == nil then
return
end
local ent = vehicle_obj:get_luaentity()
local yaw = "false"
if ent._yaw_by_mouse then yaw = "true" end
local basic_form = table.concat({
"formspec_version[3]",
"size[6,4.5]",
"size[6,7]",
}, "")
basic_form = basic_form.."button[1,1.0;4,1;go_out;Go Offboard]"
basic_form = basic_form.."button[1,2.5;4,1;lights;Lights]"
basic_form = basic_form.."checkbox[1,5.5;yaw;Direction by mouse;"..yaw.."]"
minetest.show_formspec(name, "coupe:driver_main", basic_form)
end
@ -47,6 +58,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
ent._show_lights = true
end
end
if fields.yaw then
if ent._yaw_by_mouse == true then
ent._yaw_by_mouse = false
else
ent._yaw_by_mouse = true
end
end
end
end
minetest.close_formspec(name, "coupe:driver_main")

View File

@ -712,7 +712,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
automobiles_lib.attach_driver(self, clicker)
-- sound
self.sound_handle = minetest.sound_play({name = "roadster_engine"},
{object = self.object, gain = 0.5, pitch = 0.6, max_hear_distance = 10, loop = true,})
{object = self.object, gain = 0.5, pitch = 0.6, max_hear_distance = 30, loop = true,})
end
else
--minetest.chat_send_all("clicou")

View File

@ -13,14 +13,25 @@ function roadster.getCarFromPlayer(player)
end
function roadster.driver_formspec(name)
local player = minetest.get_player_by_name(name)
local vehicle_obj = roadster.getCarFromPlayer(player)
if vehicle_obj == nil then
return
end
local ent = vehicle_obj:get_luaentity()
local yaw = "false"
if ent._yaw_by_mouse then yaw = "true" end
local basic_form = table.concat({
"formspec_version[3]",
"size[6,6]",
"size[6,7]",
}, "")
basic_form = basic_form.."button[1,1.0;4,1;go_out;Go Offboard]"
basic_form = basic_form.."button[1,2.5;4,1;top;Close/Open Ragtop]"
basic_form = basic_form.."button[1,4.0;4,1;lights;Lights]"
basic_form = basic_form.."checkbox[1,5.5;yaw;Direction by mouse;"..yaw.."]"
minetest.show_formspec(name, "roadster:driver_main", basic_form)
end
@ -55,6 +66,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
ent._show_lights = true
end
end
if fields.yaw then
if ent._yaw_by_mouse == true then
ent._yaw_by_mouse = false
else
ent._yaw_by_mouse = true
end
end
end
end
minetest.close_formspec(name, "roadster:driver_main")