mirror of
https://github.com/APercy/automobiles_pck
synced 2025-06-15 13:28:02 +02:00
improved motorcycles
This commit is contained in:
parent
352d0e6a70
commit
a6c20e86f6
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
|
||||
function automobiles_lib.on_rightclick (self, clicker)
|
||||
if not clicker or not clicker:is_player() then
|
||||
return
|
||||
--return
|
||||
end
|
||||
|
||||
local name = clicker:get_player_name()
|
||||
@ -23,10 +23,14 @@ function automobiles_lib.on_rightclick (self, clicker)
|
||||
automobiles_lib.show_vehicle_trunk_formspec(self, clicker, self._trunk_slots)
|
||||
else
|
||||
--is the owner, okay, lets attach
|
||||
automobiles_lib.attach_driver(self, clicker)
|
||||
local attach_driver_f = automobiles_lib.attach_driver
|
||||
if self._attach then attach_driver_f = self._attach end
|
||||
attach_driver_f(self, clicker)
|
||||
-- sound
|
||||
local base_pitch = 1
|
||||
if self._base_pitch then base_pitch = self._base_pitch end
|
||||
self.sound_handle = minetest.sound_play({name = self._engine_sound},
|
||||
{object = self.object, gain = 1.5, pitch = 1, max_hear_distance = 30, loop = true,})
|
||||
{object = self.object, gain = 1, pitch = base_pitch, max_hear_distance = 30, loop = true,})
|
||||
end
|
||||
else
|
||||
--minetest.chat_send_all("clicou")
|
||||
@ -34,13 +38,17 @@ function automobiles_lib.on_rightclick (self, clicker)
|
||||
if self._passenger == nil then
|
||||
--there is no passenger, so lets attach
|
||||
if self.driver_name then
|
||||
automobiles_lib.attach_pax(self, clicker, true)
|
||||
local attach_pax_f = automobiles_lib.attach_pax
|
||||
if self._attach_pax then attach_pax_f = self._attach_pax end
|
||||
attach_pax_f(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)
|
||||
local dettach_pax_f = automobiles_lib.dettach_pax
|
||||
if self._dettach_pax then dettach_pax_f = self._dettach_pax end
|
||||
dettach_pax_f(self, clicker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -46,10 +46,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
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)
|
||||
|
||||
local dettach_pax_f = automobiles_lib.dettach_pax
|
||||
if ent._dettach_pax then attach_driver_f = ent._dettach_pax end
|
||||
dettach_pax_f(ent, pax_obj)
|
||||
end
|
||||
ent._is_flying = 0
|
||||
automobiles_lib.dettach_driver(ent, player)
|
||||
|
||||
local dettach_f = automobiles_lib.dettach_driver
|
||||
if ent._dettach then dettach_f = ent._dettach end
|
||||
dettach_f(ent, player)
|
||||
end
|
||||
if fields.lights then
|
||||
if ent._show_lights == true then
|
||||
|
@ -421,7 +421,10 @@ 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)
|
||||
local base_pitch = 1
|
||||
if self._base_pitch then base_pitch = self._base_pitch end
|
||||
|
||||
local snd_pitch = base_pitch + ((self._longit_speed/10)/2)
|
||||
if self._transmission_state == 1 then
|
||||
snd_pitch = 1 + (self._longit_speed/10)
|
||||
end
|
||||
@ -541,6 +544,7 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection
|
||||
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 .. "formspecs.lua")
|
||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "entities.lua")
|
||||
|
||||
-- engine
|
||||
minetest.register_craftitem("automobiles_lib:engine",{
|
||||
|
@ -7,8 +7,6 @@ motorcycle.LATER_DRAG_FACTOR = 25.0
|
||||
motorcycle.gravity = automobiles_lib.gravity
|
||||
motorcycle.max_speed = 20
|
||||
motorcycle.max_acc_factor = 8
|
||||
motorcycle.max_fuel = 5
|
||||
motorcycle.trunk_slots = 0
|
||||
|
||||
motorcycle.front_wheel_xpos = 0
|
||||
motorcycle.rear_wheel_xpos = 0
|
||||
@ -17,10 +15,11 @@ 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_lib") .. DIR_DELIM .. "entities.lua")
|
||||
dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_forms.lua")
|
||||
dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_player.lua")
|
||||
dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_utilities.lua")
|
||||
dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_entities.lua")
|
||||
dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_forms.lua")
|
||||
dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_crafts.lua")
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@ minetest.register_craftitem("automobiles_motorcycle:motorcycle", {
|
||||
itemstack:take_item()
|
||||
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
|
||||
automobiles_lib.setText(ent, "motorcycle")
|
||||
automobiles_lib.create_inventory(ent, motorcycle.trunk_slots, owner)
|
||||
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -154,6 +154,16 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", {
|
||||
_inv_id = "",
|
||||
_change_color = automobiles_lib.paint,
|
||||
_intensity = 2,
|
||||
_base_pitch = 0.5,
|
||||
_trunk_slots = 0,
|
||||
_engine_sound = "motorcycle_engine",
|
||||
_max_fuel = 5,
|
||||
_formspec_function = motorcycle.driver_formspec,
|
||||
_destroy_function = motorcycle.destroy,
|
||||
_attach = motorcycle.attach_driver_stand,
|
||||
_dettach = motorcycle.dettach_driver_stand,
|
||||
_attach_pax = motorcycle.attach_pax_stand,
|
||||
_dettach_pax = motorcycle.dettach_pax_stand,
|
||||
|
||||
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
||||
return minetest.serialize({
|
||||
@ -225,7 +235,7 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", {
|
||||
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, motorcycle.trunk_slots)
|
||||
automobiles_lib.create_inventory(self, self._trunk_slots)
|
||||
else
|
||||
self.inv = inv
|
||||
end
|
||||
@ -342,7 +352,7 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", {
|
||||
--self.damage = self.damage + impact --sum the impact value directly to damage meter
|
||||
if self._last_time_collision_snd > 0.3 then
|
||||
self._last_time_collision_snd = 0
|
||||
minetest.sound_play("collision", {
|
||||
minetest.sound_play("automobiles_collision", {
|
||||
to_player = self.driver_name,
|
||||
--pos = curr_pos,
|
||||
--max_hear_distance = 5,
|
||||
@ -430,7 +440,7 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", {
|
||||
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
|
||||
motorcycle.engine_set_sound_and_animation(self, longit_speed)
|
||||
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
|
||||
end
|
||||
end
|
||||
|
||||
@ -447,7 +457,7 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", {
|
||||
if stop == true then
|
||||
self.object:set_acceleration({x=0,y=0,z=0})
|
||||
self.object:set_velocity({x=0,y=0,z=0})
|
||||
if self._longit_speed > 0 then motorcycle.engineSoundPlay(self) end
|
||||
if self._longit_speed > 0 then automobiles_lib.engineSoundPlay(self) end
|
||||
end
|
||||
end
|
||||
|
||||
@ -477,121 +487,8 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", {
|
||||
|
||||
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, motorcycle.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
|
||||
motorcycle.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
|
||||
motorcycle.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, motorcycle.trunk_slots)
|
||||
else
|
||||
--is the owner, okay, lets attach
|
||||
motorcycle.attach_driver_stand(self, clicker)
|
||||
-- sound
|
||||
self.sound_handle = minetest.sound_play({name = "motorcycle_engine"},
|
||||
{object = self.object, gain = 1, pitch = 0.5, 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
|
||||
motorcycle.attach_pax_stand(self, clicker)
|
||||
end
|
||||
else
|
||||
--there is a passeger
|
||||
if self._passenger == name then
|
||||
--if you are the psenger, so deattach
|
||||
motorcycle.dettach_pax_stand(self, clicker)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_punch = automobiles_lib.on_punch,
|
||||
on_rightclick = automobiles_lib.on_rightclick,
|
||||
})
|
||||
|
||||
|
||||
|
@ -1,20 +1,8 @@
|
||||
|
||||
--------------
|
||||
-- Manual --
|
||||
--------------
|
||||
|
||||
function motorcycle.getCarFromPlayer(player)
|
||||
local seat = player:get_attach()
|
||||
if seat then
|
||||
local car = seat:get_attach()
|
||||
return car
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function motorcycle.driver_formspec(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local vehicle_obj = motorcycle.getCarFromPlayer(player)
|
||||
local vehicle_obj = automobiles_lib.getCarFromPlayer(player)
|
||||
if vehicle_obj == nil then
|
||||
return
|
||||
end
|
||||
@ -37,7 +25,7 @@ end
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "motorcycle:driver_main" then
|
||||
local name = player:get_player_name()
|
||||
local car_obj = motorcycle.getCarFromPlayer(player)
|
||||
local car_obj = automobiles_lib.getCarFromPlayer(player)
|
||||
if car_obj then
|
||||
local ent = car_obj:get_luaentity()
|
||||
if ent then
|
||||
|
@ -43,24 +43,3 @@ function motorcycle.destroy(self, puncher)
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_motorcycle:wheel')
|
||||
end
|
||||
|
||||
function motorcycle.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.06) or (math.abs(self._longit_speed) + 0.06 < math.abs(_longit_speed)) then
|
||||
--minetest.chat_send_all('test2')
|
||||
motorcycle.engineSoundPlay(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function motorcycle.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 = "motorcycle_engine"},
|
||||
{object = self.object, gain = 1,
|
||||
pitch = 0.5 + ((self._longit_speed/10)/2),
|
||||
max_hear_distance = 30,
|
||||
loop = true,})
|
||||
end
|
||||
end
|
||||
|
@ -7,8 +7,6 @@ vespa.LATER_DRAG_FACTOR = 30.0
|
||||
vespa.gravity = automobiles_lib.gravity
|
||||
vespa.max_speed = 20
|
||||
vespa.max_acc_factor = 6
|
||||
vespa.max_fuel = 3
|
||||
vespa.trunk_slots = 0
|
||||
|
||||
vespa.front_wheel_xpos = 0
|
||||
vespa.rear_wheel_xpos = 0
|
||||
@ -17,10 +15,11 @@ 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_lib") .. DIR_DELIM .. "entities.lua")
|
||||
dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_forms.lua")
|
||||
dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_player.lua")
|
||||
dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_utilities.lua")
|
||||
dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_entities.lua")
|
||||
dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_forms.lua")
|
||||
dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_crafts.lua")
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -38,7 +38,7 @@ minetest.register_craftitem("automobiles_vespa:vespa", {
|
||||
itemstack:take_item()
|
||||
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
|
||||
automobiles_lib.setText(ent, "vespa")
|
||||
automobiles_lib.create_inventory(ent, vespa.trunk_slots, owner)
|
||||
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -149,6 +149,16 @@ minetest.register_entity("automobiles_vespa:vespa", {
|
||||
_inv_id = "",
|
||||
_change_color = automobiles_lib.paint,
|
||||
_intensity = 2,
|
||||
_base_pitch = 0.7,
|
||||
_trunk_slots = 0,
|
||||
_engine_sound = "vespa_engine",
|
||||
_max_fuel = 3,
|
||||
_formspec_function = vespa.driver_formspec,
|
||||
_destroy_function = vespa.destroy,
|
||||
_attach = vespa.attach_driver_stand,
|
||||
_dettach = vespa.dettach_driver_stand,
|
||||
_attach_pax = vespa.attach_pax_stand,
|
||||
_dettach_pax = vespa.dettach_pax_stand,
|
||||
|
||||
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
||||
return minetest.serialize({
|
||||
@ -220,7 +230,7 @@ minetest.register_entity("automobiles_vespa:vespa", {
|
||||
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, vespa.trunk_slots)
|
||||
automobiles_lib.create_inventory(self, self._trunk_slots)
|
||||
else
|
||||
self.inv = inv
|
||||
end
|
||||
@ -425,7 +435,7 @@ minetest.register_entity("automobiles_vespa:vespa", {
|
||||
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
|
||||
vespa.engine_set_sound_and_animation(self, longit_speed)
|
||||
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
|
||||
end
|
||||
end
|
||||
|
||||
@ -442,7 +452,7 @@ minetest.register_entity("automobiles_vespa:vespa", {
|
||||
if stop == true then
|
||||
self.object:set_acceleration({x=0,y=0,z=0})
|
||||
self.object:set_velocity({x=0,y=0,z=0})
|
||||
if self._longit_speed > 0 then vespa.engineSoundPlay(self) end
|
||||
if self._longit_speed > 0 then automobiles_lib.engineSoundPlay(self) end
|
||||
end
|
||||
end
|
||||
|
||||
@ -471,121 +481,8 @@ minetest.register_entity("automobiles_vespa:vespa", {
|
||||
|
||||
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, vespa.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
|
||||
vespa.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
|
||||
vespa.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, vespa.trunk_slots)
|
||||
else
|
||||
--is the owner, okay, lets attach
|
||||
vespa.attach_driver_stand(self, clicker)
|
||||
-- sound
|
||||
self.sound_handle = minetest.sound_play({name = "vespa_engine"},
|
||||
{object = self.object, gain = 0.3, pitch = 0.7, 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
|
||||
vespa.attach_pax_stand(self, clicker)
|
||||
end
|
||||
else
|
||||
--there is a passeger
|
||||
if self._passenger == name then
|
||||
--if you are the psenger, so deattach
|
||||
vespa.dettach_pax_stand(self, clicker)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_punch = automobiles_lib.on_punch,
|
||||
on_rightclick = automobiles_lib.on_rightclick,
|
||||
})
|
||||
|
||||
|
||||
|
@ -1,20 +1,8 @@
|
||||
|
||||
--------------
|
||||
-- Manual --
|
||||
--------------
|
||||
|
||||
function vespa.getCarFromPlayer(player)
|
||||
local seat = player:get_attach()
|
||||
if seat then
|
||||
local car = seat:get_attach()
|
||||
return car
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function vespa.driver_formspec(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local vehicle_obj = vespa.getCarFromPlayer(player)
|
||||
local vehicle_obj = automobiles_lib.getCarFromPlayer(player)
|
||||
if vehicle_obj == nil then
|
||||
return
|
||||
end
|
||||
@ -37,7 +25,7 @@ end
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "vespa:driver_main" then
|
||||
local name = player:get_player_name()
|
||||
local car_obj = vespa.getCarFromPlayer(player)
|
||||
local car_obj = automobiles_lib.getCarFromPlayer(player)
|
||||
if car_obj then
|
||||
local ent = car_obj:get_luaentity()
|
||||
if ent then
|
||||
|
@ -43,24 +43,3 @@ function vespa.destroy(self, puncher)
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_vespa:wheel')
|
||||
end
|
||||
|
||||
function vespa.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')
|
||||
vespa.engineSoundPlay(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vespa.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 = "vespa_engine"},
|
||||
{object = self.object, gain = 0.3,
|
||||
pitch = 0.7 + ((self._longit_speed/10)/2),
|
||||
max_hear_distance = 30,
|
||||
loop = true,})
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user