mirror of
https://github.com/APercy/automobiles_pck
synced 2025-06-16 05:48:02 +02:00
creating new shared methods
This commit is contained in:
parent
ccb95e1195
commit
b11a4c95e3
@ -34,7 +34,7 @@ minetest.register_craftitem("automobiles_coupe:coupe", {
|
|||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
|
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
|
||||||
automobiles_lib.setText(ent, "Coupe")
|
automobiles_lib.setText(ent, "Coupe")
|
||||||
automobiles_lib.create_inventory(ent, coupe.trunk_slots, owner)
|
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -301,6 +301,9 @@ minetest.register_entity("automobiles_coupe:coupe", {
|
|||||||
_inv_id = "",
|
_inv_id = "",
|
||||||
_change_color = automobiles_lib.paint,
|
_change_color = automobiles_lib.paint,
|
||||||
_intensity = 4,
|
_intensity = 4,
|
||||||
|
_trunk_slots = 8,
|
||||||
|
_engine_sound = "coupe_engine",
|
||||||
|
_max_fuel = 10,
|
||||||
|
|
||||||
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
||||||
return minetest.serialize({
|
return minetest.serialize({
|
||||||
@ -431,7 +434,7 @@ minetest.register_entity("automobiles_coupe:coupe", {
|
|||||||
local inv = minetest.get_inventory({type = "detached", name = self._inv_id})
|
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 the game was closed the inventories have to be made anew, instead of just reattached
|
||||||
if not inv then
|
if not inv then
|
||||||
automobiles_lib.create_inventory(self, coupe.trunk_slots)
|
automobiles_lib.create_inventory(self, self._trunk_slots)
|
||||||
else
|
else
|
||||||
self.inv = inv
|
self.inv = inv
|
||||||
end
|
end
|
||||||
@ -646,7 +649,7 @@ minetest.register_entity("automobiles_coupe:coupe", {
|
|||||||
self._last_engine_sound_update = self._last_engine_sound_update + dtime
|
self._last_engine_sound_update = self._last_engine_sound_update + dtime
|
||||||
if self._last_engine_sound_update > 0.300 then
|
if self._last_engine_sound_update > 0.300 then
|
||||||
self._last_engine_sound_update = 0
|
self._last_engine_sound_update = 0
|
||||||
coupe.engine_set_sound_and_animation(self, longit_speed)
|
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -682,121 +685,9 @@ minetest.register_entity("automobiles_coupe:coupe", {
|
|||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_punch = function(self, puncher, ttime, toolcaps, dir, damage)
|
on_punch = automobiles_lib.on_punch,
|
||||||
if not puncher or not puncher:is_player() then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local name = puncher:get_player_name()
|
on_rightclick = automobiles_lib.on_rightclick,
|
||||||
--[[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, coupe.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
|
|
||||||
coupe.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
|
|
||||||
coupe.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, coupe.trunk_slots)
|
|
||||||
else
|
|
||||||
--is the owner, okay, lets attach
|
|
||||||
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 = 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,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
--dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_global_definitions.lua")
|
|
||||||
--dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_hud.lua")
|
|
||||||
|
|
||||||
-- destroy the coupe
|
|
||||||
function coupe.destroy(self, puncher)
|
|
||||||
automobiles_lib.remove_light(self)
|
|
||||||
if self.sound_handle then
|
|
||||||
minetest.sound_stop(self.sound_handle)
|
|
||||||
self.sound_handle = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.driver_name then
|
|
||||||
-- detach the driver first (puncher must be driver)
|
|
||||||
if puncher then
|
|
||||||
puncher:set_detach()
|
|
||||||
puncher:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
|
||||||
if minetest.global_exists("player_api") then
|
|
||||||
player_api.player_attached[self.driver_name] = nil
|
|
||||||
-- player should stand again
|
|
||||||
player_api.set_animation(puncher, "stand")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.driver_name = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
|
||||||
|
|
||||||
if self.front_suspension then self.front_suspension:remove() end
|
|
||||||
if self.lf_wheel then self.lf_wheel:remove() end
|
|
||||||
if self.rf_wheel then self.rf_wheel:remove() end
|
|
||||||
if self.rear_suspension then self.rear_suspension:remove() end
|
|
||||||
if self.lr_wheel then self.lr_wheel:remove() end
|
|
||||||
if self.rr_wheel then self.rr_wheel:remove() end
|
|
||||||
if self.steering then self.steering:remove() end
|
|
||||||
if self.steering_axis then self.steering_axis:remove() end
|
|
||||||
if self.driver_seat then self.driver_seat:remove() end
|
|
||||||
if self.passenger_seat then self.passenger_seat:remove() end
|
|
||||||
if self.fuel_gauge then self.fuel_gauge:remove() end
|
|
||||||
if self.lights then self.lights:remove() end
|
|
||||||
if self.r_lights then self.r_lights:remove() end
|
|
||||||
if self.reverse_lights then self.reverse_lights:remove() end
|
|
||||||
if self.turn_l_light then self.turn_l_light:remove() end
|
|
||||||
if self.turn_r_light then self.turn_r_light:remove() end
|
|
||||||
|
|
||||||
automobiles_lib.destroy_inventory(self)
|
|
||||||
self.object:remove()
|
|
||||||
|
|
||||||
pos.y=pos.y+2
|
|
||||||
|
|
||||||
--minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_coupe:coupe')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
|
||||||
end
|
|
||||||
|
|
||||||
function coupe.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.03) or (math.abs(self._longit_speed) + 0.03 < math.abs(_longit_speed)) then
|
|
||||||
--minetest.chat_send_all('test2')
|
|
||||||
coupe.engineSoundPlay(self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function coupe.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 = "automobiles_engine"},
|
|
||||||
{object = self.object, gain = 8,
|
|
||||||
pitch = 1 + ((self._longit_speed/10)/2),
|
|
||||||
max_hear_distance = 10,
|
|
||||||
loop = true,})
|
|
||||||
end
|
|
||||||
end
|
|
@ -7,8 +7,6 @@ coupe.LATER_DRAG_FACTOR = 18.0
|
|||||||
coupe.gravity = automobiles_lib.gravity
|
coupe.gravity = automobiles_lib.gravity
|
||||||
coupe.max_speed = 22
|
coupe.max_speed = 22
|
||||||
coupe.max_acc_factor = 8
|
coupe.max_acc_factor = 8
|
||||||
coupe.max_fuel = 10
|
|
||||||
coupe.trunk_slots = 8
|
|
||||||
|
|
||||||
COUPE_GAUGE_FUEL_POSITION = {x=0,y=6.2,z=15.8}
|
COUPE_GAUGE_FUEL_POSITION = {x=0,y=6.2,z=15.8}
|
||||||
|
|
||||||
@ -19,9 +17,8 @@ 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 .. "control.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.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_lib") .. DIR_DELIM .. "ground_detection.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_utilities.lua")
|
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "entities.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_entities.lua")
|
dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_entities.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_forms.lua")
|
|
||||||
dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_crafts.lua")
|
dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_crafts.lua")
|
||||||
|
|
||||||
|
|
||||||
|
BIN
automobiles_coupe/sounds/coupe_engine.ogg
Executable file → Normal file
BIN
automobiles_coupe/sounds/coupe_engine.ogg
Executable file → Normal file
Binary file not shown.
118
automobiles_lib/entities.lua
Normal file
118
automobiles_lib/entities.lua
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
|
||||||
|
function automobiles_lib.on_rightclick (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
|
||||||
|
automobiles_lib.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, self._trunk_slots)
|
||||||
|
else
|
||||||
|
--is the owner, okay, lets attach
|
||||||
|
automobiles_lib.attach_driver(self, clicker)
|
||||||
|
-- sound
|
||||||
|
self.sound_handle = minetest.sound_play({name = self._engine_sound},
|
||||||
|
{object = self.object, gain = 1.5, 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
|
||||||
|
|
||||||
|
function automobiles_lib.on_punch (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, self._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
|
||||||
|
|
||||||
|
local paint_f = automobiles_lib.set_paint
|
||||||
|
if self._painting_function then paint_f = self._painting_function end
|
||||||
|
if paint_f(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("automobiles_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
|
||||||
|
automobiles_lib.destroy(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
56
automobiles_coupe/coupe_forms.lua → automobiles_lib/formspecs.lua
Executable file → Normal file
56
automobiles_coupe/coupe_forms.lua → automobiles_lib/formspecs.lua
Executable file → Normal file
@ -1,9 +1,6 @@
|
|||||||
|
|
||||||
--------------
|
|
||||||
-- Manual --
|
|
||||||
--------------
|
|
||||||
|
|
||||||
function coupe.getCarFromPlayer(player)
|
function automobiles_lib.getCarFromPlayer(player)
|
||||||
local seat = player:get_attach()
|
local seat = player:get_attach()
|
||||||
if seat then
|
if seat then
|
||||||
local car = seat:get_attach()
|
local car = seat:get_attach()
|
||||||
@ -12,43 +9,46 @@ function coupe.getCarFromPlayer(player)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function coupe.driver_formspec(name)
|
function automobiles_lib.driver_formspec(name)
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local vehicle_obj = coupe.getCarFromPlayer(player)
|
if player then
|
||||||
if vehicle_obj == nil then
|
local vehicle_obj = automobiles_lib.getCarFromPlayer(player)
|
||||||
return
|
if vehicle_obj == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local ent = vehicle_obj:get_luaentity()
|
||||||
|
|
||||||
|
if ent then
|
||||||
|
local yaw = "false"
|
||||||
|
if ent._yaw_by_mouse then yaw = "true" end
|
||||||
|
|
||||||
|
local basic_form = table.concat({
|
||||||
|
"formspec_version[3]",
|
||||||
|
"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, "automobiles_lib:driver_main", basic_form)
|
||||||
|
end
|
||||||
end
|
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,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
|
end
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if formname == "coupe:driver_main" then
|
if formname == "automobiles_lib:driver_main" then
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local car_obj = coupe.getCarFromPlayer(player)
|
local car_obj = automobiles_lib.getCarFromPlayer(player)
|
||||||
if car_obj then
|
if car_obj then
|
||||||
local ent = car_obj:get_luaentity()
|
local ent = car_obj:get_luaentity()
|
||||||
if ent then
|
if ent then
|
||||||
if fields.go_out then
|
if fields.go_out then
|
||||||
|
|
||||||
if ent._passenger then --any pax?
|
if ent._passenger then --any pax?
|
||||||
local pax_obj = minetest.get_player_by_name(ent._passenger)
|
local pax_obj = minetest.get_player_by_name(ent._passenger)
|
||||||
automobiles_lib.dettach_pax(ent, pax_obj)
|
automobiles_lib.dettach_pax(ent, pax_obj)
|
||||||
end
|
end
|
||||||
|
ent._is_flying = 0
|
||||||
automobiles_lib.dettach_driver(ent, player)
|
automobiles_lib.dettach_driver(ent, player)
|
||||||
end
|
end
|
||||||
if fields.lights then
|
if fields.lights then
|
||||||
@ -67,6 +67,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.close_formspec(name, "coupe:driver_main")
|
minetest.close_formspec(name, "automobiles_lib:driver_main")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
@ -355,6 +355,85 @@ function automobiles_lib.put_light(self)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function automobiles_lib.destroy(self, puncher)
|
||||||
|
automobiles_lib.remove_light(self)
|
||||||
|
if self.sound_handle then
|
||||||
|
minetest.sound_stop(self.sound_handle)
|
||||||
|
self.sound_handle = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.driver_name then
|
||||||
|
-- detach the driver first (puncher must be driver)
|
||||||
|
if puncher then
|
||||||
|
puncher:set_detach()
|
||||||
|
puncher:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
|
if minetest.global_exists("player_api") then
|
||||||
|
player_api.player_attached[self.driver_name] = nil
|
||||||
|
-- player should stand again
|
||||||
|
player_api.set_animation(puncher, "stand")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.driver_name = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
|
if self.front_suspension then self.front_suspension:remove() end
|
||||||
|
if self.lf_wheel then self.lf_wheel:remove() end
|
||||||
|
if self.rf_wheel then self.rf_wheel:remove() end
|
||||||
|
if self.rear_suspension then self.rear_suspension:remove() end
|
||||||
|
if self.lr_wheel then self.lr_wheel:remove() end
|
||||||
|
if self.rr_wheel then self.rr_wheel:remove() end
|
||||||
|
if self.steering then self.steering:remove() end
|
||||||
|
if self.steering_axis then self.steering_axis:remove() end
|
||||||
|
if self.driver_seat then self.driver_seat:remove() end
|
||||||
|
if self.passenger_seat then self.passenger_seat:remove() end
|
||||||
|
if self.fuel_gauge then self.fuel_gauge:remove() end
|
||||||
|
if self.lights then self.lights:remove() end
|
||||||
|
if self.r_lights then self.r_lights:remove() end
|
||||||
|
if self.reverse_lights then self.reverse_lights:remove() end
|
||||||
|
if self.turn_l_light then self.turn_l_light:remove() end
|
||||||
|
if self.turn_r_light then self.turn_r_light:remove() end
|
||||||
|
|
||||||
|
automobiles_lib.destroy_inventory(self)
|
||||||
|
self.object:remove()
|
||||||
|
|
||||||
|
pos.y=pos.y+2
|
||||||
|
|
||||||
|
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine')
|
||||||
|
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
||||||
|
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
||||||
|
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
||||||
|
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
||||||
|
end
|
||||||
|
|
||||||
|
function automobiles_lib.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.03) or (math.abs(self._longit_speed) + 0.03 < math.abs(_longit_speed)) then
|
||||||
|
--minetest.chat_send_all('test2')
|
||||||
|
automobiles_lib.engineSoundPlay(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function automobiles_lib.engineSoundPlay(self)
|
||||||
|
--sound
|
||||||
|
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
||||||
|
if self.object then
|
||||||
|
local snd_pitch = 1 + ((self._longit_speed/10)/2)
|
||||||
|
if self._transmission_state == 1 then
|
||||||
|
snd_pitch = 1 + (self._longit_speed/10)
|
||||||
|
end
|
||||||
|
|
||||||
|
self.sound_handle = minetest.sound_play({name = self._engine_sound},
|
||||||
|
{object = self.object, gain = 4,
|
||||||
|
pitch = snd_pitch,
|
||||||
|
max_hear_distance = 15,
|
||||||
|
loop = true,})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("automobiles_lib:light", {
|
minetest.register_node("automobiles_lib:light", {
|
||||||
drawtype = "airlike",
|
drawtype = "airlike",
|
||||||
--tile_images = {"automobiles_light.png"},
|
--tile_images = {"automobiles_light.png"},
|
||||||
@ -461,6 +540,7 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.
|
|||||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection.lua")
|
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "painter.lua")
|
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "painter.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "inventory_management.lua")
|
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "inventory_management.lua")
|
||||||
|
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "formspecs.lua")
|
||||||
|
|
||||||
-- engine
|
-- engine
|
||||||
minetest.register_craftitem("automobiles_lib:engine",{
|
minetest.register_craftitem("automobiles_lib:engine",{
|
||||||
|
BIN
automobiles_lib/sounds/automobiles_collision.ogg
Executable file
BIN
automobiles_lib/sounds/automobiles_collision.ogg
Executable file
Binary file not shown.
@ -35,7 +35,7 @@ minetest.register_craftitem("automobiles_trans_am:trans_am", {
|
|||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
|
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
|
||||||
automobiles_lib.setText(ent, "Trans Am")
|
automobiles_lib.setText(ent, "Trans Am")
|
||||||
automobiles_lib.create_inventory(ent, trans_am.trunk_slots, owner)
|
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ local function paint(self, colstr)
|
|||||||
self.object:set_properties({textures=l_textures})
|
self.object:set_properties({textures=l_textures})
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_paint(self, puncher, itmstck)
|
function trans_am.set_paint(self, puncher, itmstck)
|
||||||
local item_name = ""
|
local item_name = ""
|
||||||
if itmstck then item_name = itmstck:get_name() end
|
if itmstck then item_name = itmstck:get_name() end
|
||||||
|
|
||||||
@ -365,6 +365,10 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
|
|||||||
_car_gravity = -automobiles_lib.gravity,
|
_car_gravity = -automobiles_lib.gravity,
|
||||||
--acc control
|
--acc control
|
||||||
_transmission_state = 1,
|
_transmission_state = 1,
|
||||||
|
_painting_function = trans_am.set_paint,
|
||||||
|
_trunk_slots = 12,
|
||||||
|
_engine_sound = "trans_am_engine",
|
||||||
|
_max_fuel = 10,
|
||||||
|
|
||||||
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
||||||
return minetest.serialize({
|
return minetest.serialize({
|
||||||
@ -496,7 +500,7 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
|
|||||||
local inv = minetest.get_inventory({type = "detached", name = self._inv_id})
|
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 the game was closed the inventories have to be made anew, instead of just reattached
|
||||||
if not inv then
|
if not inv then
|
||||||
automobiles_lib.create_inventory(self, trans_am.trunk_slots)
|
automobiles_lib.create_inventory(self, self._trunk_slots)
|
||||||
else
|
else
|
||||||
self.inv = inv
|
self.inv = inv
|
||||||
end
|
end
|
||||||
@ -752,7 +756,7 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
|
|||||||
self._last_engine_sound_update = self._last_engine_sound_update + dtime
|
self._last_engine_sound_update = self._last_engine_sound_update + dtime
|
||||||
if self._last_engine_sound_update > 0.300 then
|
if self._last_engine_sound_update > 0.300 then
|
||||||
self._last_engine_sound_update = 0
|
self._last_engine_sound_update = 0
|
||||||
trans_am.engine_set_sound_and_animation(self, longit_speed)
|
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -798,121 +802,8 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
|
|||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_punch = function(self, puncher, ttime, toolcaps, dir, damage)
|
on_punch = automobiles_lib.on_punch,
|
||||||
if not puncher or not puncher:is_player() then
|
on_rightclick = automobiles_lib.on_rightclick,
|
||||||
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, trans_am.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 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
|
|
||||||
trans_am.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
|
|
||||||
trans_am.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, trans_am.trunk_slots)
|
|
||||||
else
|
|
||||||
--is the owner, okay, lets attach
|
|
||||||
automobiles_lib.attach_driver(self, clicker)
|
|
||||||
-- sound
|
|
||||||
self.sound_handle = minetest.sound_play({name = trans_am.engine_sound},
|
|
||||||
{object = self.object, gain = 1.5, 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,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
|
|
||||||
--------------
|
|
||||||
-- Manual --
|
|
||||||
--------------
|
|
||||||
|
|
||||||
function trans_am.getCarFromPlayer(player)
|
|
||||||
local seat = player:get_attach()
|
|
||||||
if seat then
|
|
||||||
local car = seat:get_attach()
|
|
||||||
return car
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function trans_am.driver_formspec(name)
|
|
||||||
local player = minetest.get_player_by_name(name)
|
|
||||||
local vehicle_obj = trans_am.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 flight = "false"
|
|
||||||
if ent._is_flying == 1 then flight = "true" end
|
|
||||||
|
|
||||||
local basic_form = table.concat({
|
|
||||||
"formspec_version[3]",
|
|
||||||
"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]"
|
|
||||||
if ent._trans_am_type == 1 then basic_form = basic_form.."checkbox[1,4.0;flight;Flight Mode;"..flight.."]" end
|
|
||||||
basic_form = basic_form.."checkbox[1,5.5;yaw;Direction by mouse;"..yaw.."]"
|
|
||||||
|
|
||||||
minetest.show_formspec(name, "trans_am:driver_main", basic_form)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
||||||
if formname == "trans_am:driver_main" then
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local car_obj = trans_am.getCarFromPlayer(player)
|
|
||||||
if car_obj then
|
|
||||||
local ent = car_obj:get_luaentity()
|
|
||||||
if ent then
|
|
||||||
if fields.go_out then
|
|
||||||
if ent._passenger then --any pax?
|
|
||||||
local pax_obj = minetest.get_player_by_name(ent._passenger)
|
|
||||||
automobiles_lib.dettach_pax(ent, pax_obj)
|
|
||||||
end
|
|
||||||
ent._is_flying = 0
|
|
||||||
automobiles_lib.dettach_driver(ent, player)
|
|
||||||
end
|
|
||||||
if fields.lights then
|
|
||||||
if ent._show_lights == true then
|
|
||||||
ent._show_lights = false
|
|
||||||
else
|
|
||||||
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
|
|
||||||
if fields.flight then
|
|
||||||
if ent._is_flying == 1 then
|
|
||||||
ent._is_flying = 0
|
|
||||||
else
|
|
||||||
ent._is_flying = 1
|
|
||||||
end
|
|
||||||
trans_am.turn_flight_mode(ent)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.close_formspec(name, "trans_am:driver_main")
|
|
||||||
end
|
|
||||||
end)
|
|
@ -7,10 +7,7 @@ trans_am.LATER_DRAG_FACTOR = 6.0
|
|||||||
trans_am.gravity = automobiles_lib.gravity
|
trans_am.gravity = automobiles_lib.gravity
|
||||||
trans_am.max_speed = 40
|
trans_am.max_speed = 40
|
||||||
trans_am.max_acc_factor = 12
|
trans_am.max_acc_factor = 12
|
||||||
trans_am.max_fuel = 10
|
|
||||||
trans_am.trunk_slots = 12
|
|
||||||
trans_am.ideal_step = 0.2
|
trans_am.ideal_step = 0.2
|
||||||
trans_am.engine_sound = "trans_am_engine"
|
|
||||||
|
|
||||||
trans_am_GAUGE_FUEL_POSITION = {x=-4,y=6.8,z=16.6}
|
trans_am_GAUGE_FUEL_POSITION = {x=-4,y=6.8,z=16.6}
|
||||||
|
|
||||||
@ -21,9 +18,8 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.l
|
|||||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.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_lib") .. DIR_DELIM .. "ground_detection.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua")
|
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_trans_am") .. DIR_DELIM .. "utilities.lua")
|
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "entities.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_trans_am") .. DIR_DELIM .. "entities.lua")
|
dofile(minetest.get_modpath("automobiles_trans_am") .. DIR_DELIM .. "entities.lua")
|
||||||
dofile(minetest.get_modpath("automobiles_trans_am") .. DIR_DELIM .. "forms.lua")
|
|
||||||
dofile(minetest.get_modpath("automobiles_trans_am") .. DIR_DELIM .. "crafts.lua")
|
dofile(minetest.get_modpath("automobiles_trans_am") .. DIR_DELIM .. "crafts.lua")
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
-- destroy the trans_am
|
|
||||||
function trans_am.destroy(self, puncher)
|
|
||||||
automobiles_lib.remove_light(self)
|
|
||||||
if self.sound_handle then
|
|
||||||
minetest.sound_stop(self.sound_handle)
|
|
||||||
self.sound_handle = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.driver_name then
|
|
||||||
-- detach the driver first (puncher must be driver)
|
|
||||||
if puncher then
|
|
||||||
puncher:set_detach()
|
|
||||||
puncher:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
|
||||||
if minetest.global_exists("player_api") then
|
|
||||||
player_api.player_attached[self.driver_name] = nil
|
|
||||||
-- player should stand again
|
|
||||||
player_api.set_animation(puncher, "stand")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.driver_name = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
|
||||||
|
|
||||||
if self.front_suspension then self.front_suspension:remove() end
|
|
||||||
if self.lf_wheel then self.lf_wheel:remove() end
|
|
||||||
if self.rf_wheel then self.rf_wheel:remove() end
|
|
||||||
if self.rear_suspension then self.rear_suspension:remove() end
|
|
||||||
if self.lr_wheel then self.lr_wheel:remove() end
|
|
||||||
if self.rr_wheel then self.rr_wheel:remove() end
|
|
||||||
if self.driver_seat then self.driver_seat:remove() end
|
|
||||||
if self.passenger_seat then self.passenger_seat:remove() end
|
|
||||||
if self.fuel_gauge then self.fuel_gauge:remove() end
|
|
||||||
if self.lights then self.lights:remove() end
|
|
||||||
if self.r_lights then self.r_lights:remove() end
|
|
||||||
if self.turn_l_light then self.turn_l_light:remove() end
|
|
||||||
if self.turn_r_light then self.turn_r_light:remove() end
|
|
||||||
if self.reverse_lights then self.reverse_lights:remove() end
|
|
||||||
|
|
||||||
automobiles_lib.destroy_inventory(self)
|
|
||||||
self.object:remove()
|
|
||||||
|
|
||||||
pos.y=pos.y+2
|
|
||||||
|
|
||||||
--minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_trans_am:trans_am')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
|
||||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
|
|
||||||
end
|
|
||||||
|
|
||||||
function trans_am.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.03) or (math.abs(self._longit_speed) + 0.03 < math.abs(_longit_speed)) then
|
|
||||||
--minetest.chat_send_all('test2')
|
|
||||||
trans_am.engineSoundPlay(self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function trans_am.engineSoundPlay(self)
|
|
||||||
--sound
|
|
||||||
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
|
||||||
if self.object then
|
|
||||||
local snd_pitch = 1 + ((self._longit_speed/10)/2)
|
|
||||||
if self._transmission_state == 1 then
|
|
||||||
snd_pitch = 1 + (self._longit_speed/10)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.sound_handle = minetest.sound_play({name = trans_am.engine_sound},
|
|
||||||
{object = self.object, gain = 4,
|
|
||||||
pitch = snd_pitch,
|
|
||||||
max_hear_distance = 15,
|
|
||||||
loop = true,})
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user