improved buggy

This commit is contained in:
Alexsandro Percy 2023-09-12 11:19:56 -03:00
parent b11a4c95e3
commit 3cadbc5487
7 changed files with 19 additions and 160 deletions

View File

@ -38,7 +38,7 @@ minetest.register_craftitem("automobiles_buggy:buggy", {
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
automobiles_lib.setText(ent, "buggy")
automobiles_lib.create_inventory(ent, buggy.trunk_slots, owner)
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
end
end

View File

@ -296,6 +296,11 @@ minetest.register_entity("automobiles_buggy:buggy", {
_inv_id = "",
_change_color = automobiles_lib.paint,
_intensity = 4,
_trunk_slots = 8,
_engine_sound = "buggy_engine",
_max_fuel = 10,
_formspec_function = buggy.driver_formspec,
_destroy_function = buggy.destroy,
get_staticdata = function(self) -- unloaded/unloads ... is now saved
return minetest.serialize({
@ -415,7 +420,7 @@ minetest.register_entity("automobiles_buggy:buggy", {
local inv = minetest.get_inventory({type = "detached", name = self._inv_id})
-- if the game was closed the inventories have to be made anew, instead of just reattached
if not inv then
automobiles_lib.create_inventory(self, buggy.trunk_slots)
automobiles_lib.create_inventory(self, self._trunk_slots)
else
self.inv = inv
end
@ -610,7 +615,7 @@ minetest.register_entity("automobiles_buggy:buggy", {
self._last_engine_sound_update = self._last_engine_sound_update + dtime
if self._last_engine_sound_update > 0.300 then
self._last_engine_sound_update = 0
buggy.engine_set_sound_and_animation(self, longit_speed)
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
end
end
@ -646,121 +651,8 @@ minetest.register_entity("automobiles_buggy:buggy", {
end,
on_punch = function(self, puncher, ttime, toolcaps, dir, damage)
if not puncher or not puncher:is_player() then
return
end
local name = puncher:get_player_name()
--[[if self.owner and self.owner ~= name and self.owner ~= "" then return end]]--
if self.owner == nil then
self.owner = name
end
if self.driver_name and self.driver_name ~= name then
-- do not allow other players to remove the object while there is a driver
return
end
local is_attached = false
if puncher:get_attach() == self.driver_seat then is_attached = true end
local itmstck=puncher:get_wielded_item()
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
--refuel procedure
--[[
refuel works it car is stopped and engine is off
]]--
local velocity = self.object:get_velocity()
local speed = automobiles_lib.get_hipotenuse_value(vector.new(), velocity)
if math.abs(speed) <= 0.1 then
if automobiles_lib.loadFuel(self, puncher:get_player_name(), false, buggy.max_fuel) then return end
end
-- end refuel
if is_attached == false then
-- deal with painting or destroying
if itmstck then
--race status restart
if item_name == "checkpoints:status_restarter" and self._engine_running == false then
--restart race current status
self._last_checkpoint = ""
self._total_laps = -1
self._race_id = ""
return
end
if automobiles_lib.set_paint(self, puncher, itmstck) == false then
local is_admin = false
is_admin = minetest.check_player_privs(puncher, {server=true})
--minetest.chat_send_all('owner '.. self.owner ..' - name '.. name)
if not self.driver and (self.owner == name or is_admin == true) and toolcaps and
toolcaps.damage_groups and toolcaps.damage_groups.fleshy then
self.hp = self.hp - 10
minetest.sound_play("collision", {
object = self.object,
max_hear_distance = 5,
gain = 1.0,
fade = 0.0,
pitch = 1.0,
})
end
end
end
if self.hp <= 0 then
buggy.destroy(self)
end
end
end,
on_rightclick = function(self, clicker)
if not clicker or not clicker:is_player() then
return
end
local name = clicker:get_player_name()
--[[if self.owner and self.owner ~= name and self.owner ~= "" then return end]]--
if self.owner == "" then
self.owner = name
end
if name == self.driver_name then
buggy.driver_formspec(name)
else
if name == self.owner then
if clicker:get_player_control().aux1 == true then
automobiles_lib.show_vehicle_trunk_formspec(self, clicker, buggy.trunk_slots)
else
--is the owner, okay, lets attach
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 = 30, loop = true,})
end
else
--minetest.chat_send_all("clicou")
--a passenger
if self._passenger == nil then
--there is no passenger, so lets attach
if self.driver_name then
automobiles_lib.attach_pax(self, clicker, true)
end
else
--there is a passeger
if self._passenger == name then
--if you are the psenger, so deattach
automobiles_lib.dettach_pax(self, clicker)
end
end
end
end
end,
on_punch = automobiles_lib.on_punch,
on_rightclick = automobiles_lib.on_rightclick,
})

View File

@ -1,20 +1,7 @@
--------------
-- Manual --
--------------
function buggy.getCarFromPlayer(player)
local seat = player:get_attach()
if seat then
local car = seat:get_attach()
return car
end
return nil
end
function buggy.driver_formspec(name)
local player = minetest.get_player_by_name(name)
local vehicle_obj = buggy.getCarFromPlayer(player)
local vehicle_obj = automobiles_lib.getCarFromPlayer(player)
if vehicle_obj == nil then
return
end
@ -39,7 +26,7 @@ end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "buggy:driver_main" then
local name = player:get_player_name()
local car_obj = buggy.getCarFromPlayer(player)
local car_obj = automobiles_lib.getCarFromPlayer(player)
if car_obj then
local ent = car_obj:get_luaentity()
if ent then

View File

@ -53,24 +53,3 @@ function buggy.destroy(self, puncher)
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_buggy:wheel')
end
function buggy.engine_set_sound_and_animation(self, _longit_speed)
--minetest.chat_send_all('test1 ' .. dump(self._engine_running) )
if self.sound_handle then
if (math.abs(self._longit_speed) > math.abs(_longit_speed) + 0.08) or (math.abs(self._longit_speed) + 0.08 < math.abs(_longit_speed)) then
--minetest.chat_send_all('test2')
buggy.engineSoundPlay(self)
end
end
end
function buggy.engineSoundPlay(self)
--sound
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
if self.object then
self.sound_handle = minetest.sound_play({name = "buggy_engine"},
{object = self.object, gain = 8,
pitch = 1 + ((self._longit_speed/10)/2),
max_hear_distance = 10,
loop = true,})
end
end

View File

@ -7,8 +7,6 @@ buggy.LATER_DRAG_FACTOR = 25.0
buggy.gravity = automobiles_lib.gravity
buggy.max_speed = 15
buggy.max_acc_factor = 5
buggy.max_fuel = 10
buggy.trunk_slots = 8
BUGGY_GAUGE_FUEL_POSITION = {x=0,y=4.65,z=15.17}
@ -19,9 +17,9 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.l
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection.lua")
dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_forms.lua")
dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_utilities.lua")
dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_entities.lua")
dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_forms.lua")
dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_crafts.lua")

View File

@ -686,7 +686,6 @@ minetest.register_entity("automobiles_coupe:coupe", {
end,
on_punch = automobiles_lib.on_punch,
on_rightclick = automobiles_lib.on_rightclick,
})

View File

@ -11,7 +11,9 @@ function automobiles_lib.on_rightclick (self, clicker)
end
if name == self.driver_name then
automobiles_lib.driver_formspec(name)
local formspec_f = automobiles_lib.driver_formspec
if self._formspec_function then formspec_f = self._formspec_function end
formspec_f(name)
else
if name == self.owner then
if clicker:get_player_control().aux1 == true then
@ -110,7 +112,9 @@ function automobiles_lib.on_punch (self, puncher, ttime, toolcaps, dir, damage)
end
if self.hp <= 0 then
automobiles_lib.destroy(self)
local destroy_f = automobiles_lib.destroy
if self._destroy_function then destroy_f = self._destroy_function end
destroy_f(self)
end
end