Version 2.4.0 (#12)

- Added new API support for `lib_mount`.
- Customizable HP/Armor for all vehicles. Players will be affected.
- Short and tweak the code.
- Cars can now be killed by players.
- Support for 3+ passengers (beta).
This commit is contained in:
David Leal 2022-12-18 16:22:44 -06:00 committed by GitHub
parent 906402e763
commit dbd0d395c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 37 deletions

View File

@ -1,6 +1,6 @@
# Vehicle Mash [![Build status](https://github.com/minetest-mods/vehicle_mash/workflows/build/badge.svg)](https://github.com/minetest-mods/vehicle_mash/actions) [![ContentDB](https://content.minetest.net/packages/Panquesito7/vehicle_mash/shields/downloads/)](https://content.minetest.net/packages/Panquesito7/vehicle_mash/)
- Current version: 2.3.0
- Current version: 2.4.0
- By [blert2112](https://github.com/blert2112), and handed over to [Panquesito7](https://github.com/Panquesito7).
![Screenshot](https://raw.githubusercontent.com/minetest-mods/vehicle_mash/master/screenshot.png)
@ -67,6 +67,14 @@ There are no pending tasks to do yet.
## Changelog
v2.4.0 1/12/2022
- Added new API support for `lib_mount`.
- Customizable HP/Armor for all vehicles. Players will be affected.
- Short and tweak the code.
- Cars can now be killed by players.
- Support for 3+ passengers (beta).
v2.3.0 2/12/2021
- Improved formatting in `README.md`.

View File

@ -1,6 +1,4 @@
vehicle_mash = {}
local drive = lib_mount.drive
vehicle_mash = { }
function vehicle_mash.register_vehicle(name, def)
minetest.register_entity(name, {
@ -14,6 +12,7 @@ function vehicle_mash.register_vehicle(name, def)
driver_eye_offset = def.driver_eye_offset,
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,
@ -52,6 +51,10 @@ function vehicle_mash.register_vehicle(name, def)
removed = false,
offset = {x=0, y=0, z=0},
owner = "",
hp_min = def.hp_min,
hp_max = def.hp_max,
armor = def.armor,
rpm_values = {{16, 16, .5}, {10, 10, .4}, {0, 5, .3}},
on_rightclick = function(self, clicker)
if not clicker or not clicker:is_player() then
return
@ -60,40 +63,29 @@ function vehicle_mash.register_vehicle(name, def)
if self.driver then
-- if clicker is driver detach passengers and driver
if clicker == self.driver then
if self.passenger then
lib_mount.detach(self.passenger, self.offset)
end
if self.passenger2 then
lib_mount.detach(self.passenger2, self.offset)
end
if self.passenger3 then
lib_mount.detach(self.passenger3, self.offset)
for i = 1, self.number_of_passengers do -- Detaches all passengers with the new Library Mount API.
local passenger = self.passengers[i]
if passenger.player then
lib_mount.detach(passenger.player, passenger.eye_offset)
end
end
-- detach driver
lib_mount.detach(self.driver, self.offset)
-- if clicker is not the driver
else
-- if clicker is passenger
-- detach passengers
if clicker == self.passenger then
lib_mount.detach(self.passenger, self.offset)
elseif clicker == self.passenger2 then
lib_mount.detach(self.passenger2, self.offset)
elseif clicker == self.passenger3 then
lib_mount.detach(self.passenger3, self.offset)
-- if clicker is not passenger
else
-- attach a passenger if possible
if self.passenger==nil and self.number_of_passengers >= 1 then
lib_mount.attach(self, clicker, true, 1)
elseif self.passenger2==nil and self.number_of_passengers >= 2 then
lib_mount.attach(self, clicker, true, 2)
elseif self.passenger3==nil and self.number_of_passengers >= 3 then
lib_mount.attach(self, clicker, true, 3)
-- detach passengers with the new Library Mount API
for i = 1, self.number_of_passengers do
local passenger = self.passengers[i]
if clicker == passenger.player then
lib_mount.detach(passenger.player, passenger.eye_offset)
break
else
-- Attach passengers with the new Library Mount API
if not passenger.player then -- If there's no current passenger, attach if possible.
lib_mount.attach(self, clicker, true, i)
break -- We've already attached the player, no need to continue.
end
end
end
end
@ -106,7 +98,26 @@ function vehicle_mash.register_vehicle(name, def)
end
end,
on_activate = function(self, staticdata, dtime_s)
self.object:set_armor_groups({immortal = 1})
if def.armor then
self.object:set_armor_groups({fleshy = def.armor}) -- Set armor groups to vehicle
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
@ -127,7 +138,7 @@ function vehicle_mash.register_vehicle(name, def)
end
return core.serialize(tmp)
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
if not puncher or not puncher:is_player() or self.removed or self.driver then
return
end
@ -141,12 +152,24 @@ function vehicle_mash.register_vehicle(name, def)
puncher:get_inventory():add_item("main", self.name)
end
end,
on_step = function(self, dtime)
on_step = function(self, dtime, moveresult, ...)
-- Automatically set `enable_crash` to true if there's no value found
if def.enable_crash == nil then
def.enable_crash = true
end
drive(self, dtime, false, nil, nil, 0, def.can_fly, def.can_go_down, def.can_go_up, def.enable_crash)
lib_mount.drive(self, dtime, false, nil, nil, 0, def.can_fly, def.can_go_down, def.can_go_up, def.enable_crash, moveresult)
end,
on_death = function(self, killer)
if self.driver then
lib_mount.detach(self.driver, self.offset)
end
for i = 1, self.number_of_passengers do -- Detaches all passengers with the new Library Mount API.
local passenger = self.passengers[i]
if passenger.player then
lib_mount.detach(passenger.player, passenger.eye_offset)
passenger.player:set_eye_offset({x = 0, y = 0, z = 0} ,{ x = 0, y = 0, z = 0 })
end
end
end
})

View File

@ -71,6 +71,11 @@ else
passenger3_attach_at = {x=-4,y=3.7,z=-3.5},
passenger3_eye_offset = {x=4, y=3, z=0},
-- HP/Armor stuff. Uncomment to enable.
-- min_hp = 10,
-- max_hp = 35,
-- armor = 25,
-- drop and recipe
drop_on_destroy = {"vehicle_mash:tire 2", "vehicle_mash:windshield",
"vehicle_mash:battery", "vehicle_mash:motor"},
@ -127,6 +132,11 @@ else
passenger3_attach_at = {x=0,y=0,z=0},
passenger3_eye_offset = {x=0, y=0, z=0},
-- HP/Armor stuff. Uncomment to enable.
-- min_hp = 10,
-- max_hp = 35,
-- armor = 25,
-- drop and recipe
drop_on_destroy = {"vehicle_mash:motor", "vehicle_mash:battery"},
recipe = nil
@ -178,7 +188,12 @@ else
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}
passenger3_eye_offset = {x=0, y=0, z=0},
-- HP/Armor stuff. Uncomment to enable.
-- min_hp = 10,
-- max_hp = 35,
-- armor = 25,
}
local boat_names = {
@ -227,6 +242,11 @@ else
passenger3_attach_at = {x=0,y=0,z=0},
passenger3_eye_offset = {x=0, y=0, z=0},
-- HP/Armor stuff. Uncomment to enable.
-- min_hp = 10,
-- max_hp = 35,
-- armor = 25,
-- recipe
recipe = nil
}