From 6b3141fd69754acc1a057c5f6ec33320863df7c7 Mon Sep 17 00:00:00 2001 From: David Leal Date: Thu, 19 Jan 2023 13:46:49 -0600 Subject: [PATCH] Complete multiple passenger support (#14) --- framework.lua | 26 ++------------------- init.lua | 65 +++++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 54 deletions(-) diff --git a/framework.lua b/framework.lua index 5ecf20a..ae14e24 100644 --- a/framework.lua +++ b/framework.lua @@ -1,5 +1,3 @@ -vehicle_mash = { } - function vehicle_mash.register_vehicle(name, def) minetest.register_entity(name, { terrain_type = def.terrain_type, @@ -13,17 +11,7 @@ function vehicle_mash.register_vehicle(name, def) driver_detach_pos_offset = def.driver_detach_pos_offset, number_of_passengers = def.number_of_passengers, - passenger_attach_at = def.passenger_attach_at, - passenger_eye_offset = def.passenger_eye_offset, - passenger_detach_pos_offset = def.passenger_detach_pos_offset, - - passenger2_attach_at = def.passenger2_attach_at, - passenger2_eye_offset = def.passenger2_eye_offset, - passenger2_detach_pos_offset = def.passenger2_detach_pos_offset, - - passenger3_attach_at = def.passenger3_attach_at, - passenger3_eye_offset = def.passenger3_eye_offset, - passenger3_detach_pos_offset = def.passenger3_detach_pos_offset, + passengers = def.passengers, enable_crash = def.enable_crash, visual = def.visual, @@ -103,21 +91,11 @@ function vehicle_mash.register_vehicle(name, def) else self.object:set_armor_groups({fleshy = 0, immortal = 1}) -- Else, make vehicle immortal end + if def.hp_min and def.hp_max then self.object:set_hp(math.random(def.hp_min, def.hp_max), "Set HP to vehicle") end - if self.driver then - self.driver:set_armor_groups({immortal = 0, fleshy = self.driver:get_armor_groups()}) - end - -- Support for passengers - for i = 1, self.number_of_passengers do - local passenger = self.passengers[i] - if passenger.player then - passenger.player:set_armor_groups({immortal = 0, fleshy = passenger.player:get_armor_groups()}) - end - end - local tmp = minetest.deserialize(staticdata) if tmp then for _,stat in pairs(tmp) do diff --git a/init.lua b/init.lua index dc28b69..b651319 100755 --- a/init.lua +++ b/init.lua @@ -1,3 +1,5 @@ +vehicle_mash = { } + -- Fix `player_api` eye height model if desired if minetest.settings:get_bool("vehicle_mash.player_api_fix") == true or minetest.settings:get_bool("vehicle_mash.player_api_fix") == nil then player_api.registered_models["character.b3d"].animations.sit.eye_height = 1.47 @@ -62,14 +64,21 @@ else driver_attach_at = {x=3.5,y=3.7,z=3.5}, driver_eye_offset = {x=-4, y=0, z=0}, number_of_passengers = 3, - passenger_attach_at = {x=3.5,y=3.7,z=-3.5}, - passenger_eye_offset = {x=4, y=0, z=0}, - passenger2_attach_at = {x=-4,y=3.7,z=3.5}, - passenger2_eye_offset = {x=-4, y=3, z=0}, - - passenger3_attach_at = {x=-4,y=3.7,z=-3.5}, - passenger3_eye_offset = {x=4, y=3, z=0}, + passengers = { + { + attach_at = {x=3.5,y=3.7,z=-3.5}, + eye_offset = {x=4, y=0, z=0}, + }, + { + attach_at = {x=-4,y=3.7,z=3.5}, + eye_offset = {x=-4, y=3, z=0}, + }, + { + attach_at = {x=-4,y=3.7,z=-3.5}, + eye_offset = {x=4, y=3, z=0}, + }, + }, -- HP/Armor stuff. Uncomment to enable. -- min_hp = 10, @@ -91,7 +100,7 @@ else "nyan_ride", "oerkki_bliss", "road_master", } --- Load all CAR01's cars if enabled + -- Load all CAR01's cars if enabled for _, name in ipairs(car01_names) do local check_enabled = minetest.settings:get_bool("vehicle_mash.enable_" .. name .. "_car") if check_enabled or check_enabled == nil then @@ -123,14 +132,13 @@ else driver_attach_at = {x=0,y=0,z=-2.0}, driver_eye_offset = {x=0, y=0, z=0}, number_of_passengers = 0, - passenger_attach_at = {x=0,y=0,z=0}, - passenger_eye_offset = {x=0, y=0, z=0}, - passenger2_attach_at = {x=0,y=0,z=0}, - passenger2_eye_offset = {x=0, y=0, z=0}, - - passenger3_attach_at = {x=0,y=0,z=0}, - passenger3_eye_offset = {x=0, y=0, z=0}, + passengers = { + { + attach_at = {x=0,y=0,z=0}, + eye_offset = {x=0, y=0, z=0}, + }, + }, -- HP/Armor stuff. Uncomment to enable. -- min_hp = 10, @@ -181,14 +189,12 @@ else driver_attach_at = {x=0.5,y=1,z=-3}, driver_eye_offset = {x=0, y=0, z=0}, number_of_passengers = 0, - passenger_attach_at = {x=0,y=0,z=0}, - passenger_eye_offset = {x=0, y=0, z=0}, - - passenger2_attach_at = {x=0,y=0,z=0}, - passenger2_eye_offset = {x=0, y=0, z=0}, - - passenger3_attach_at = {x=0,y=0,z=0}, - passenger3_eye_offset = {x=0, y=0, z=0}, + passengers = { + { + attach_at = {x=0,y=0,z=0}, + eye_offset = {x=0, y=0, z=0}, + }, + }, -- HP/Armor stuff. Uncomment to enable. -- min_hp = 10, @@ -233,14 +239,13 @@ else driver_attach_at = {x=-2,y=6.3,z=0}, driver_eye_offset = {x=0, y=0, z=0}, number_of_passengers = 0, - passenger_attach_at = {x=0,y=0,z=0}, - passenger_eye_offset = {x=0, y=0, z=0}, - passenger2_attach_at = {x=0,y=0,z=0}, - passenger2_eye_offset = {x=0, y=0, z=0}, - - passenger3_attach_at = {x=0,y=0,z=0}, - passenger3_eye_offset = {x=0, y=0, z=0}, + passengers = { + { + attach_at = {x=0,y=0,z=0}, + eye_offset = {x=0, y=0, z=0}, + }, + }, -- HP/Armor stuff. Uncomment to enable. -- min_hp = 10,