From 478b0a17ea84f8e4ec15aec3d2a4271bd6c2f378 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Mon, 12 Sep 2022 21:40:42 -0300 Subject: [PATCH] added mouse control to all vehicles --- automobiles_buggy/buggy_entities.lua | 2 +- automobiles_coupe/coupe_entities.lua | 2 +- automobiles_coupe/coupe_forms.lua | 20 +++++++++++++++++++- automobiles_roadster/roadster_entities.lua | 2 +- automobiles_roadster/roadster_forms.lua | 20 +++++++++++++++++++- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/automobiles_buggy/buggy_entities.lua b/automobiles_buggy/buggy_entities.lua index 989bd67..ae25671 100755 --- a/automobiles_buggy/buggy_entities.lua +++ b/automobiles_buggy/buggy_entities.lua @@ -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") diff --git a/automobiles_coupe/coupe_entities.lua b/automobiles_coupe/coupe_entities.lua index 22f2820..3ba7c29 100755 --- a/automobiles_coupe/coupe_entities.lua +++ b/automobiles_coupe/coupe_entities.lua @@ -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") diff --git a/automobiles_coupe/coupe_forms.lua b/automobiles_coupe/coupe_forms.lua index 948b801..9abcfd2 100644 --- a/automobiles_coupe/coupe_forms.lua +++ b/automobiles_coupe/coupe_forms.lua @@ -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") diff --git a/automobiles_roadster/roadster_entities.lua b/automobiles_roadster/roadster_entities.lua index a0d7b4d..09c886e 100755 --- a/automobiles_roadster/roadster_entities.lua +++ b/automobiles_roadster/roadster_entities.lua @@ -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") diff --git a/automobiles_roadster/roadster_forms.lua b/automobiles_roadster/roadster_forms.lua index 1ebfe05..65e1e19 100644 --- a/automobiles_roadster/roadster_forms.lua +++ b/automobiles_roadster/roadster_forms.lua @@ -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")