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:
parent
906402e763
commit
dbd0d395c6
10
README.md
10
README.md
@ -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/)
|
# 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).
|
- 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)
|
![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
|
## 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
|
v2.3.0 2/12/2021
|
||||||
|
|
||||||
- Improved formatting in `README.md`.
|
- Improved formatting in `README.md`.
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
|
vehicle_mash = { }
|
||||||
vehicle_mash = {}
|
|
||||||
local drive = lib_mount.drive
|
|
||||||
|
|
||||||
function vehicle_mash.register_vehicle(name, def)
|
function vehicle_mash.register_vehicle(name, def)
|
||||||
minetest.register_entity(name, {
|
minetest.register_entity(name, {
|
||||||
@ -14,6 +12,7 @@ function vehicle_mash.register_vehicle(name, def)
|
|||||||
driver_eye_offset = def.driver_eye_offset,
|
driver_eye_offset = def.driver_eye_offset,
|
||||||
driver_detach_pos_offset = def.driver_detach_pos_offset,
|
driver_detach_pos_offset = def.driver_detach_pos_offset,
|
||||||
number_of_passengers = def.number_of_passengers,
|
number_of_passengers = def.number_of_passengers,
|
||||||
|
|
||||||
passenger_attach_at = def.passenger_attach_at,
|
passenger_attach_at = def.passenger_attach_at,
|
||||||
passenger_eye_offset = def.passenger_eye_offset,
|
passenger_eye_offset = def.passenger_eye_offset,
|
||||||
passenger_detach_pos_offset = def.passenger_detach_pos_offset,
|
passenger_detach_pos_offset = def.passenger_detach_pos_offset,
|
||||||
@ -52,6 +51,10 @@ function vehicle_mash.register_vehicle(name, def)
|
|||||||
removed = false,
|
removed = false,
|
||||||
offset = {x=0, y=0, z=0},
|
offset = {x=0, y=0, z=0},
|
||||||
owner = "",
|
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)
|
on_rightclick = function(self, clicker)
|
||||||
if not clicker or not clicker:is_player() then
|
if not clicker or not clicker:is_player() then
|
||||||
return
|
return
|
||||||
@ -60,40 +63,29 @@ function vehicle_mash.register_vehicle(name, def)
|
|||||||
if self.driver then
|
if self.driver then
|
||||||
-- if clicker is driver detach passengers and driver
|
-- if clicker is driver detach passengers and driver
|
||||||
if clicker == self.driver then
|
if clicker == self.driver then
|
||||||
if self.passenger then
|
for i = 1, self.number_of_passengers do -- Detaches all passengers with the new Library Mount API.
|
||||||
lib_mount.detach(self.passenger, self.offset)
|
local passenger = self.passengers[i]
|
||||||
end
|
if passenger.player then
|
||||||
|
lib_mount.detach(passenger.player, passenger.eye_offset)
|
||||||
if self.passenger2 then
|
end
|
||||||
lib_mount.detach(self.passenger2, self.offset)
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.passenger3 then
|
|
||||||
lib_mount.detach(self.passenger3, self.offset)
|
|
||||||
end
|
end
|
||||||
-- detach driver
|
-- detach driver
|
||||||
lib_mount.detach(self.driver, self.offset)
|
lib_mount.detach(self.driver, self.offset)
|
||||||
-- if clicker is not the driver
|
-- if clicker is not the driver
|
||||||
else
|
else
|
||||||
-- if clicker is passenger
|
-- if clicker is passenger
|
||||||
-- detach passengers
|
-- detach passengers with the new Library Mount API
|
||||||
if clicker == self.passenger then
|
for i = 1, self.number_of_passengers do
|
||||||
lib_mount.detach(self.passenger, self.offset)
|
local passenger = self.passengers[i]
|
||||||
|
if clicker == passenger.player then
|
||||||
elseif clicker == self.passenger2 then
|
lib_mount.detach(passenger.player, passenger.eye_offset)
|
||||||
lib_mount.detach(self.passenger2, self.offset)
|
break
|
||||||
|
else
|
||||||
elseif clicker == self.passenger3 then
|
-- Attach passengers with the new Library Mount API
|
||||||
lib_mount.detach(self.passenger3, self.offset)
|
if not passenger.player then -- If there's no current passenger, attach if possible.
|
||||||
-- if clicker is not passenger
|
lib_mount.attach(self, clicker, true, i)
|
||||||
else
|
break -- We've already attached the player, no need to continue.
|
||||||
-- attach a passenger if possible
|
end
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -106,7 +98,26 @@ function vehicle_mash.register_vehicle(name, def)
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_activate = function(self, staticdata, dtime_s)
|
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)
|
local tmp = minetest.deserialize(staticdata)
|
||||||
if tmp then
|
if tmp then
|
||||||
for _,stat in pairs(tmp) do
|
for _,stat in pairs(tmp) do
|
||||||
@ -127,7 +138,7 @@ function vehicle_mash.register_vehicle(name, def)
|
|||||||
end
|
end
|
||||||
return core.serialize(tmp)
|
return core.serialize(tmp)
|
||||||
end,
|
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
|
if not puncher or not puncher:is_player() or self.removed or self.driver then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -141,12 +152,24 @@ function vehicle_mash.register_vehicle(name, def)
|
|||||||
puncher:get_inventory():add_item("main", self.name)
|
puncher:get_inventory():add_item("main", self.name)
|
||||||
end
|
end
|
||||||
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
|
-- Automatically set `enable_crash` to true if there's no value found
|
||||||
if def.enable_crash == nil then
|
if def.enable_crash == nil then
|
||||||
def.enable_crash = true
|
def.enable_crash = true
|
||||||
end
|
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
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
22
init.lua
22
init.lua
@ -71,6 +71,11 @@ else
|
|||||||
passenger3_attach_at = {x=-4,y=3.7,z=-3.5},
|
passenger3_attach_at = {x=-4,y=3.7,z=-3.5},
|
||||||
passenger3_eye_offset = {x=4, y=3, z=0},
|
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 and recipe
|
||||||
drop_on_destroy = {"vehicle_mash:tire 2", "vehicle_mash:windshield",
|
drop_on_destroy = {"vehicle_mash:tire 2", "vehicle_mash:windshield",
|
||||||
"vehicle_mash:battery", "vehicle_mash:motor"},
|
"vehicle_mash:battery", "vehicle_mash:motor"},
|
||||||
@ -127,6 +132,11 @@ else
|
|||||||
passenger3_attach_at = {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,
|
||||||
|
|
||||||
-- drop and recipe
|
-- drop and recipe
|
||||||
drop_on_destroy = {"vehicle_mash:motor", "vehicle_mash:battery"},
|
drop_on_destroy = {"vehicle_mash:motor", "vehicle_mash:battery"},
|
||||||
recipe = nil
|
recipe = nil
|
||||||
@ -178,7 +188,12 @@ else
|
|||||||
passenger2_eye_offset = {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_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 = {
|
local boat_names = {
|
||||||
@ -227,6 +242,11 @@ else
|
|||||||
passenger3_attach_at = {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,
|
||||||
|
|
||||||
-- recipe
|
-- recipe
|
||||||
recipe = nil
|
recipe = nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user