Compare commits

...

23 Commits

Author SHA1 Message Date
Alexsandro Percy ccb0ed37b2 renamed catrelle tl to 4f 2023-12-04 06:45:50 -03:00
Alexsandro Percy af6bbd3c5f removed wrong dependency 2023-12-04 06:31:44 -03:00
Alexsandro Percy 9922656705 changed trunk limit of catrelle TL and added recipe 2023-12-03 19:59:15 -03:00
Alexsandro Percy d987350f6e fixes and added a second catrelle 2023-12-03 19:54:49 -03:00
Alexsandro Percy 2abf853b18 improved 3D models 2023-12-03 11:21:06 -03:00
Alexsandro Percy a8cbaf8687 added old entities removal 2023-12-02 20:03:41 -03:00
Alexsandro Percy b14dd24921 compatibilizing on_activite method on cars for future improvements 2023-12-02 19:35:16 -03:00
Alexsandro Percy a857d7db7d fix fuel and changed movement method 2023-10-10 21:02:21 -03:00
Alexsandro Percy 94e931175c fix vert acceleration 2023-10-10 19:39:56 -03:00
Alexsandro Percy 24fd569596 fixed the friction calc 2023-10-10 18:03:03 -03:00
Alexsandro Percy c7e74ddaf7
Merge pull request #19 from jeremyshannon/main
Use add_velocity instead of set_velocity, to get rid of movement jitter
2023-10-10 17:47:31 -03:00
Jeremy e9bbb1d001 Use add_velocity instead of set_velocity, to get rid of movement jitter 2023-09-30 18:37:10 -07:00
Alexsandro Percy 7a73f477b0 fixed painting only by owner or server admin 2023-09-28 19:03:30 -03:00
Alexsandro Percy 8e6cba2238
Merge pull request #18 from MoNTE48/patch1
Fix 'Unable to register same mod storage twice' error
2023-09-25 17:48:49 -03:00
Maksym H 1d19d349a9 Fix 'Unable to register same mod storage twice' error 2023-09-25 20:49:01 +03:00
Alexsandro Percy 511a972d55 added noob mode 2023-09-12 16:52:48 -03:00
Alexsandro Percy f7fcd544cf added command to transfer vehicle ownership 2023-09-12 15:54:44 -03:00
Alexsandro Percy a6c20e86f6 improved motorcycles 2023-09-12 15:35:08 -03:00
Alexsandro Percy 352d0e6a70 added valet parking priv 2023-09-12 13:39:46 -03:00
Alexsandro Percy cf29e4fa22 more cars updated 2023-09-12 13:26:39 -03:00
Alexsandro Percy 870389bc44 improved catrelle 2023-09-12 11:39:25 -03:00
Alexsandro Percy 3cadbc5487 improved buggy 2023-09-12 11:19:56 -03:00
Alexsandro Percy b11a4c95e3 creating new shared methods 2023-09-12 10:42:51 -03:00
58 changed files with 1259 additions and 2808 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

@ -167,28 +167,6 @@ initial_properties = {
})
minetest.register_entity('automobiles_buggy:pivot_mesh',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pivot_mesh.b3d",
textures = {"automobiles_black.png",},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity('automobiles_buggy:steering',{
initial_properties = {
physical = false,
@ -211,35 +189,13 @@ initial_properties = {
})
minetest.register_entity('automobiles_buggy:pointer',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pointer.b3d",
visual_size = {x = 0.8, y = 0.8, z = 0.8},
textures = {"automobiles_white.png"},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity("automobiles_buggy:buggy", {
initial_properties = {
physical = true,
collide_with_objects = true,
collisionbox = {-0.1, -0.45, -0.1, 0.1, 1, 0.1},
selectionbox = {-1.5, 0.0, -1.5, 1.5, 2, 1.5},
stepheight = 0.7,
stepheight = 0.7 + automobiles_lib.extra_stepheight,
visual = "mesh",
mesh = "automobiles_buggy_body.b3d",
--use_texture_alpha = true,
@ -296,132 +252,41 @@ 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({
stored_owner = self.owner,
stored_hp = self.hp,
stored_color = self._color,
stored_steering = self._steering_angle,
stored_energy = self._energy,
--race data
stored_last_checkpoint = self._last_checkpoint,
stored_total_laps = self._total_laps,
stored_race_id = self._race_id,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
})
end,
_vehicle_name = "Buggy",
_drive_wheel_pos = {x=-4.26,y=6.01,z=14.18},
_drive_wheel_angle = 15,
_steering_ent = 'automobiles_buggy:steering',
_rag_extended_ent = 'automobiles_buggy:rag',
_seat_pos = {{x=-4.25,y=0.48,z=9.5},{x=4.25,y=0.48,z=9.5}},
_front_suspension_ent = 'automobiles_buggy:front_suspension',
_front_suspension_pos = {x=0,y=-0.7,z=23},
_front_wheel_ent = 'automobiles_buggy:f_wheel',
_front_wheel_xpos = 8,
_front_wheel_frames = {x = 1, y = 13},
_rear_suspension_ent = 'automobiles_buggy:rear_suspension',
_rear_suspension_pos = {x=0,y=0,z=0},
_rear_wheel_ent = 'automobiles_buggy:r_wheel',
_rear_wheel_xpos = 8,
_rear_wheel_frames = {x = 1, y = 13},
_fuel_gauge_pos = {x=0,y=4.65,z=15.17},
_front_lights = 'automobiles_buggy:f_lights',
_rear_lights = 'automobiles_buggy:r_lights',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
end,
on_activate = function(self, staticdata, dtime_s)
if staticdata ~= "" and staticdata ~= nil then
local data = minetest.deserialize(staticdata) or {}
self.owner = data.stored_owner
self.hp = data.stored_hp
self._color = data.stored_color
self._steering_angle = data.stored_steering
self._energy = data.stored_energy
--minetest.debug("loaded: ", self.energy)
--race data
self._last_checkpoint = data.stored_last_checkpoint
self._total_laps = data.stored_total_laps
self._race_id = data.stored_race_id
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
automobiles_lib.setText(self, "Buggy")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local rag=minetest.add_entity(self.object:get_pos(),'automobiles_buggy:rag')
rag:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.rag = rag
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_buggy:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=-0.7,z=23},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_buggy:f_wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-buggy.front_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lf_wheel:set_animation({x = 1, y = 13}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_buggy:f_wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=buggy.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 13}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_buggy:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_buggy:r_wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-buggy.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lr_wheel:set_animation({x = 1, y = 13}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_buggy:r_wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=buggy.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 13}, 0, 0, true)
self.rr_wheel = rr_wheel
local steering_axis=minetest.add_entity(pos,'automobiles_buggy:pivot_mesh')
steering_axis:set_attach(self.object,'',{x=-4.26,y=6.01,z=14.18},{x=15,y=0,z=0})
self.steering_axis = steering_axis
local steering=minetest.add_entity(self.steering_axis:get_pos(),'automobiles_buggy:steering')
steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.steering = steering
local driver_seat=minetest.add_entity(pos,'automobiles_buggy:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.25,y=0.48,z=9.5},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_buggy:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.25,y=0.48,z=9.5},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_buggy:pointer')
fuel_gauge:set_attach(self.object,'',BUGGY_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_buggy:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
local r_lights = minetest.add_entity(pos,'automobiles_buggy:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -571,8 +436,8 @@ minetest.register_entity("automobiles_buggy:buggy", {
--whell turn
self.steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=self._steering_angle*2})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-buggy.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=buggy.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
if math.abs(self._steering_angle)>5 then
local turn_rate = math.rad(40)
@ -610,12 +475,12 @@ 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
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',BUGGY_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --
@ -623,7 +488,8 @@ minetest.register_entity("automobiles_buggy:buggy", {
if stop ~= true then
--self.object:set_velocity(velocity)
self.object:set_acceleration(accel)
self.object:add_velocity(vector.multiply(accel,dtime))
--self.object:set_acceleration(accel)
else
if stop == true then
self.object:set_acceleration({x=0,y=0,z=0})
@ -646,121 +512,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,21 +7,14 @@ 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}
buggy.front_wheel_xpos = 8
buggy.rear_wheel_xpos = 8
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.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 .. "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

@ -35,7 +35,7 @@ minetest.register_craftitem("automobiles_catrelle:catrelle", {
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
automobiles_lib.setText(ent, "Catrelle")
automobiles_lib.create_inventory(ent, catrelle.trunk_slots, owner)
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
end
end
@ -43,11 +43,49 @@ minetest.register_craftitem("automobiles_catrelle:catrelle", {
end,
})
-- catrelle TL
minetest.register_craftitem("automobiles_catrelle:catrelle_4f", {
description = S("Catrelle 4F"),
inventory_image = "automobiles_catrelle.png",
liquids_pointable = false,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
local pointed_pos = pointed_thing.above
--pointed_pos.y=pointed_pos.y+0.2
local car = minetest.add_entity(pointed_pos, "automobiles_catrelle:catrelle_4f")
if car and placer then
local ent = car:get_luaentity()
local owner = placer:get_player_name()
if ent then
ent.owner = owner
ent._catrelle_type = 1
--minetest.chat_send_all("owner: " .. ent.owner)
car:set_yaw(placer:get_look_horizontal())
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
automobiles_lib.setText(ent, "Catrelle 4F")
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
end
end
return itemstack
end,
})
--
-- crafting
--
if minetest.get_modpath("default") then
minetest.register_craft({
output = "automobiles_catrelle:catrelle_4f",
recipe = {
{"automobiles_catrelle:catrelle", "default:glass", "default:steelblock"},
}
})
minetest.register_craft({
output = "automobiles_catrelle:catrelle",
recipe = {

View File

@ -1,3 +1,61 @@
function catrelle.extra_parts(self)
local pos = self.object:get_pos()
local back_seat = minetest.add_entity(pos,'automobiles_catrelle:back_seat')
back_seat:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.back_seat = back_seat
end
-- destroy the delorean
function catrelle.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.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
if self.back_seat then self.back_seat:remove() end
automobiles_lib.seats_destroy(self)
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
--
-- entity
--
@ -166,16 +224,17 @@ initial_properties = {
})
minetest.register_entity('automobiles_catrelle:pivot_mesh',{
minetest.register_entity('automobiles_catrelle:back_seat',{
initial_properties = {
physical = false,
collide_with_objects=false,
physical = true,
collide_with_objects=true,
collisionbox = {-0.5, 0, -0.5, 0.5, 1, 0.5},
pointable=false,
visual = "mesh",
mesh = "automobiles_pivot_mesh.b3d",
mesh = "automobiles_catrelle_seat.b3d",
textures = {"automobiles_black.png",},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
@ -185,38 +244,20 @@ initial_properties = {
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
--[[on_step = function(self, dtime, moveresult)
minetest.chat_send_all(dump(moveresult))
end,]]--
})
minetest.register_entity('automobiles_catrelle:pointer',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pointer.b3d",
visual_size = {x = 0.5, y = 0.5, z = 0.5},
textures = {"automobiles_white.png"},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity("automobiles_catrelle:catrelle", {
catrelle.car_properties1 = {
initial_properties = {
physical = true,
collide_with_objects = true,
collisionbox = {-0.1, -0.4, -0.1, 0.1, 1.8, 0.1},
selectionbox = {-2.0, 0.0, -2.0, 2.0, 2, 2.0},
stepheight = 0.65,
stepheight = 0.65 + automobiles_lib.extra_stepheight,
visual = "mesh",
mesh = "automobiles_catrelle_body.b3d",
--use_texture_alpha = true,
@ -230,6 +271,8 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
"automobiles_painting.png", --interior 1
"automobiles_dark_grey.png", --interior 2
"automobiles_black.png", --painel1
"automobiles_painting.png", --lat glass interno
"automobiles_painting.png", --lat glass externo
"automobiles_catrelle_fuel.png", --combustivel
"automobiles_catrelle_glass.png", --parabrisa
"automobiles_metal.png", --para choques
@ -252,7 +295,7 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
lastvelocity = vector.new(),
time_total = 0,
_passenger = nil,
_color = "#0063b0",
_color = "#07B6BC",
_steering_angle = 0,
_engine_running = false,
_last_checkpoint = "",
@ -278,139 +321,39 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
_intensity = 4,
_car_gravity = -automobiles_lib.gravity,
_is_flying = 0,
_trunk_slots = 32,
_engine_sound = "automobiles_engine",
_max_fuel = 10,
get_staticdata = function(self) -- unloaded/unloads ... is now saved
return minetest.serialize({
stored_owner = self.owner,
stored_hp = self.hp,
stored_color = self._color,
stored_steering = self._steering_angle,
stored_energy = self._energy,
--race data
stored_last_checkpoint = self._last_checkpoint,
stored_total_laps = self._total_laps,
stored_race_id = self._race_id,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
stored_catrelle_type = self._catrelle_type,
stored_car_gravity = self._car_gravity,
})
end,
_vehicle_name = "Catrelle",
_drive_wheel_pos = {x=-4.0, y=8.00, z=21},
_drive_wheel_angle = 15,
_seat_pos = {{x=-4.0,y=3,z=15},{x=4.0,y=3,z=15}},
_front_suspension_ent = 'automobiles_catrelle:front_suspension',
_front_suspension_pos = {x=0,y=-0.2,z=29},
_front_wheel_ent = 'automobiles_catrelle:wheel',
_front_wheel_xpos = 7.5,
_front_wheel_frames = {x = 1, y = 49},
_rear_suspension_ent = 'automobiles_catrelle:rear_suspension',
_rear_suspension_pos = {x=0,y=-0.2,z=0},
_rear_wheel_ent = 'automobiles_catrelle:wheel',
_rear_wheel_xpos = 7.5,
_rear_wheel_frames = {x = 1, y = 49},
_fuel_gauge_pos = {x=-4.47,y=8.50,z=20.5},
_front_lights = 'automobiles_catrelle:f_lights',
_rear_lights = 'automobiles_catrelle:r_lights',
_turn_left_lights = 'automobiles_catrelle:turn_left_light',
_turn_right_lights = 'automobiles_catrelle:turn_right_light',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
end,
on_activate = function(self, staticdata, dtime_s)
if staticdata ~= "" and staticdata ~= nil then
local data = minetest.deserialize(staticdata) or {}
self.owner = data.stored_owner
self.hp = data.stored_hp
self._color = data.stored_color
self._steering_angle = data.stored_steering
self._energy = data.stored_energy
--minetest.debug("loaded: ", self.energy)
--race data
self._last_checkpoint = data.stored_last_checkpoint
self._total_laps = data.stored_total_laps
self._race_id = data.stored_race_id
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
self._catrelle_type = data.stored_catrelle_type
self._car_gravity = data.stored_car_gravity or -automobiles_lib.gravity
automobiles_lib.setText(self, "catrelle")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_catrelle:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=-0.2,z=30.5},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_catrelle:wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-catrelle.front_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_catrelle:wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=catrelle.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_catrelle:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=-0.2,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_catrelle:wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-catrelle.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_catrelle:wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=catrelle.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rr_wheel = rr_wheel
self.object:set_bone_position("drive_adjust", {x=-4.0, y=8.00, z=21}, {x=15, y=0, z=0})
local driver_seat=minetest.add_entity(pos,'automobiles_catrelle:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.0,y=3,z=15},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_catrelle:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.0,y=3,z=15},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_catrelle:pointer')
fuel_gauge:set_attach(self.object,'',catrelle_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_catrelle:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
local r_lights = minetest.add_entity(pos,'automobiles_catrelle:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
local turn_l_light = minetest.add_entity(pos,'automobiles_catrelle:turn_left_light')
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
local turn_r_light = minetest.add_entity(pos,'automobiles_catrelle:turn_right_light')
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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, catrelle.trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -536,10 +479,10 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
local angle_factor = self._steering_angle / 10
--whell turn
self.lf_wheel:set_attach(self.front_suspension,'',{x=-catrelle.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=catrelle.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-catrelle.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=catrelle.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
--check if the tyres is touching the pavement
local noded = automobiles_lib.nodeatpos(automobiles_lib.pos_shift(curr_pos,{y=-0.5}))
@ -630,12 +573,12 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
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
catrelle.engine_set_sound_and_animation(self, longit_speed)
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
end
end
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',catrelle_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --
@ -650,7 +593,8 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
if stop ~= true then
--self.object:set_velocity(velocity)
self.object:set_acceleration(accel)
self.object:add_velocity(vector.multiply(accel,dtime))
--self.object:set_acceleration(accel)
else
if stop == true then
self.object:set_acceleration({x=0,y=0,z=0})
@ -674,121 +618,23 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
end,
on_punch = function(self, puncher, ttime, toolcaps, dir, damage)
if not puncher or not puncher:is_player() then
return
end
on_punch = automobiles_lib.on_punch,
on_rightclick = automobiles_lib.on_rightclick,
}
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
minetest.register_entity("automobiles_catrelle:catrelle", catrelle.car_properties1)
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, catrelle.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
catrelle.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
catrelle.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, catrelle.trunk_slots)
else
--is the owner, okay, lets attach
automobiles_lib.attach_driver(self, clicker)
-- sound
self.sound_handle = minetest.sound_play({name = catrelle.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,
})
catrelle.car_properties2 = automobiles_lib.properties_copy(catrelle.car_properties1)
catrelle.car_properties2._vehicle_name = "Catrelle 4F"
catrelle.car_properties2.initial_properties = automobiles_lib.properties_copy(catrelle.car_properties1.initial_properties)
catrelle.car_properties2.initial_properties.textures = automobiles_lib.properties_copy(catrelle.car_properties1.initial_properties.textures)
catrelle.car_properties2.initial_properties.textures[9] = "automobiles_alpha.png"
catrelle.car_properties2.initial_properties.textures[10] = "automobiles_catrelle_lat_glass.png"
catrelle.car_properties2._seat_pos = {{x=-4.0,y=3,z=15},{x=4.0,y=3,z=15}, {x=-4.0,y=3,z=7},{x=4.0,y=3,z=7}}
catrelle.car_properties2._color = "#0063b0"
catrelle.car_properties2._trunk_slots = 16
catrelle.car_properties2._extra_items_function = catrelle.extra_parts
catrelle.car_properties2._destroy_function = catrelle.destroy
minetest.register_entity("automobiles_catrelle:catrelle_4f", catrelle.car_properties2)

View File

@ -1,83 +0,0 @@
--------------
-- Manual --
--------------
function catrelle.getCarFromPlayer(player)
local seat = player:get_attach()
if seat then
local car = seat:get_attach()
return car
end
return nil
end
function catrelle.driver_formspec(name)
local player = minetest.get_player_by_name(name)
local vehicle_obj = catrelle.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._catrelle_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, "catrelle:driver_main", basic_form)
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "catrelle:driver_main" then
local name = player:get_player_name()
local car_obj = catrelle.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
catrelle.turn_flight_mode(ent)
end
end
end
minetest.close_formspec(name, "catrelle:driver_main")
end
end)

View File

@ -7,23 +7,13 @@ catrelle.LATER_DRAG_FACTOR = 8.0
catrelle.gravity = automobiles_lib.gravity
catrelle.max_speed = 14
catrelle.max_acc_factor = 5
catrelle.max_fuel = 10
catrelle.trunk_slots = 32
catrelle.ideal_step = 0.2
catrelle.engine_sound = "automobiles_engine"
catrelle_GAUGE_FUEL_POSITION = {x=-4.47,y=8.50,z=20.5}
catrelle.front_wheel_xpos = 7.5
catrelle.rear_wheel_xpos = 7.5
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.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 .. "control.lua")
dofile(minetest.get_modpath("automobiles_catrelle") .. DIR_DELIM .. "utilities.lua")
dofile(minetest.get_modpath("automobiles_catrelle") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("automobiles_catrelle") .. DIR_DELIM .. "forms.lua")
dofile(minetest.get_modpath("automobiles_catrelle") .. DIR_DELIM .. "crafts.lua")

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -1,74 +0,0 @@
-- destroy the catrelle
function catrelle.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
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_catrelle:catrelle')
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 catrelle.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')
catrelle.engineSoundPlay(self)
end
end
end
function catrelle.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 = catrelle.engine_sound},
{object = self.object, gain = 2,
pitch = 1 + ((self._longit_speed/10)/2),
max_hear_distance = 10,
loop = true,})
end
end

View File

@ -34,7 +34,7 @@ minetest.register_craftitem("automobiles_coupe:coupe", {
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
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

View File

@ -175,28 +175,6 @@ initial_properties = {
})
minetest.register_entity('automobiles_coupe:pivot_mesh',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pivot_mesh.b3d",
textures = {"automobiles_black.png",},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity('automobiles_coupe:steering',{
initial_properties = {
physical = false,
@ -219,35 +197,13 @@ initial_properties = {
})
minetest.register_entity('automobiles_coupe:pointer',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pointer.b3d",
visual_size = {x = 0.5, y = 0.5, z = 0.5},
textures = {"automobiles_white.png"},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity("automobiles_coupe:coupe", {
initial_properties = {
physical = true,
collide_with_objects = true,
collisionbox = {-0.1, -0.2, -0.1, 0.1, 1, 0.1},
selectionbox = {-1.5, 0.0, -1.5, 1.5, 2, 1.5},
stepheight = 0.65,
stepheight = 0.65 + automobiles_lib.extra_stepheight,
visual = "mesh",
mesh = "automobiles_coupe_body.b3d",
--use_texture_alpha = true,
@ -301,144 +257,41 @@ minetest.register_entity("automobiles_coupe:coupe", {
_inv_id = "",
_change_color = automobiles_lib.paint,
_intensity = 4,
_trunk_slots = 8,
_engine_sound = "coupe_engine",
_max_fuel = 10,
get_staticdata = function(self) -- unloaded/unloads ... is now saved
return minetest.serialize({
stored_owner = self.owner,
stored_hp = self.hp,
stored_color = self._color,
stored_steering = self._steering_angle,
stored_energy = self._energy,
--race data
stored_last_checkpoint = self._last_checkpoint,
stored_total_laps = self._total_laps,
stored_race_id = self._race_id,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
})
end,
_vehicle_name = "Coupe",
_drive_wheel_pos = {x=-4.26,y=6.01,z=14.18},
_drive_wheel_angle = 15,
_steering_ent = 'automobiles_coupe:steering',
_seat_pos = {{x=-4.25,y=0.48,z=9.5},{x=4.25,y=0.48,z=9.5}},
_front_suspension_ent = 'automobiles_coupe:front_suspension',
_front_suspension_pos = {x=0,y=1.5,z=24.5},
_front_wheel_ent = 'automobiles_lib:wheel',
_front_wheel_xpos = 9.5,
_front_wheel_frames = {x = 1, y = 49},
_rear_suspension_ent = 'automobiles_coupe:rear_suspension',
_rear_suspension_pos = {x=0,y=1.5,z=0},
_rear_wheel_ent = 'automobiles_lib:wheel',
_rear_wheel_xpos = 9.5,
_rear_wheel_frames = {x = 1, y = 49},
_fuel_gauge_pos = {x=0,y=6.2,z=15.8},
_front_lights = 'automobiles_coupe:f_lights',
_rear_lights = 'automobiles_coupe:r_lights',
_reverse_lights = 'automobiles_coupe:reverse_lights',
_turn_left_lights = 'automobiles_coupe:turn_left_light',
_turn_right_lights = 'automobiles_coupe:turn_right_light',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
end,
on_activate = function(self, staticdata, dtime_s)
if staticdata ~= "" and staticdata ~= nil then
local data = minetest.deserialize(staticdata) or {}
self.owner = data.stored_owner
self.hp = data.stored_hp
self._color = data.stored_color
self._steering_angle = data.stored_steering
self._energy = data.stored_energy
--minetest.debug("loaded: ", self.energy)
--race data
self._last_checkpoint = data.stored_last_checkpoint
self._total_laps = data.stored_total_laps
self._race_id = data.stored_race_id
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
automobiles_lib.setText(self, "Coupe")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_coupe:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=1.5,z=24.5},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_lib:wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-coupe.front_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_lib:wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=coupe.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_coupe:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=1.5,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_lib:wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-coupe.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_lib:wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=coupe.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rr_wheel = rr_wheel
local steering_axis=minetest.add_entity(pos,'automobiles_coupe:pivot_mesh')
steering_axis:set_attach(self.object,'',{x=-4.26,y=6.01,z=14.18},{x=15,y=0,z=0})
self.steering_axis = steering_axis
local steering=minetest.add_entity(self.steering_axis:get_pos(),'automobiles_coupe:steering')
steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.steering = steering
local driver_seat=minetest.add_entity(pos,'automobiles_coupe:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.25,y=0.48,z=9.5},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_coupe:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.25,y=0.48,z=9.5},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_coupe:pointer')
fuel_gauge:set_attach(self.object,'',COUPE_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_coupe:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
local r_lights = minetest.add_entity(pos,'automobiles_coupe:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
local reverse_lights = minetest.add_entity(pos,'automobiles_coupe:reverse_lights')
reverse_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.reverse_lights = reverse_lights
self.reverse_lights:set_properties({is_visible=true})
local turn_l_light = minetest.add_entity(pos,'automobiles_coupe:turn_left_light')
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
local turn_r_light = minetest.add_entity(pos,'automobiles_coupe:turn_right_light')
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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, coupe.trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -587,8 +440,8 @@ minetest.register_entity("automobiles_coupe:coupe", {
--whell turn
self.steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=self._steering_angle*2})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-coupe.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=coupe.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
if math.abs(self._steering_angle)>5 then
local turn_rate = math.rad(40)
@ -646,12 +499,12 @@ minetest.register_entity("automobiles_coupe:coupe", {
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
coupe.engine_set_sound_and_animation(self, longit_speed)
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
end
end
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',COUPE_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --
@ -659,7 +512,8 @@ minetest.register_entity("automobiles_coupe:coupe", {
if stop ~= true then
--self.object:set_velocity(velocity)
self.object:set_acceleration(accel)
self.object:add_velocity(vector.multiply(accel,dtime))
--self.object:set_acceleration(accel)
else
if stop == true then
self.object:set_acceleration({x=0,y=0,z=0})
@ -682,121 +536,8 @@ minetest.register_entity("automobiles_coupe:coupe", {
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, 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,
on_punch = automobiles_lib.on_punch,
on_rightclick = automobiles_lib.on_rightclick,
})

View File

@ -1,72 +0,0 @@
--------------
-- Manual --
--------------
function coupe.getCarFromPlayer(player)
local seat = player:get_attach()
if seat then
local car = seat:get_attach()
return car
end
return nil
end
function coupe.driver_formspec(name)
local player = minetest.get_player_by_name(name)
local vehicle_obj = coupe.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 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
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "coupe:driver_main" then
local name = player:get_player_name()
local car_obj = coupe.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
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
end
end
minetest.close_formspec(name, "coupe:driver_main")
end
end)

View File

@ -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

View File

@ -7,21 +7,12 @@ coupe.LATER_DRAG_FACTOR = 18.0
coupe.gravity = automobiles_lib.gravity
coupe.max_speed = 22
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.front_wheel_xpos = 9.5
coupe.rear_wheel_xpos = 9.5
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.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 .. "ground_detection.lua")
dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_utilities.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")

BIN
automobiles_coupe/sounds/coupe_engine.ogg Executable file → Normal file

Binary file not shown.

View File

@ -29,13 +29,13 @@ minetest.register_craftitem("automobiles_delorean:delorean", {
local owner = placer:get_player_name()
if ent then
ent.owner = owner
ent._delorean_type = 0
ent._car_type = 0
--minetest.chat_send_all("owner: " .. ent.owner)
car:set_yaw(placer:get_look_horizontal())
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
automobiles_lib.setText(ent, "Delorean")
automobiles_lib.create_inventory(ent, delorean.trunk_slots, owner)
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
end
end
@ -62,14 +62,14 @@ minetest.register_craftitem("automobiles_delorean:time_machine", {
local owner = placer:get_player_name()
if ent then
ent.owner = owner
ent._delorean_type = 1
--minetest.chat_send_all("delorean: " .. ent._delorean_type)
ent._car_type = 1
--minetest.chat_send_all("delorean: " .. ent._car_type)
--minetest.chat_send_all("owner: " .. ent.owner)
car:set_yaw(placer:get_look_horizontal())
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
automobiles_lib.setText(ent, "Delorean")
automobiles_lib.create_inventory(ent, delorean.trunk_slots, owner)
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
end
end

View File

@ -1,3 +1,26 @@
function delorean.set_kit(self)
local normal_kit = nil
if self.normal_kit then self.normal_kit:remove() end
local pos = self.object:get_pos()
if self._car_type == 0 or self._car_type == nil then
normal_kit = minetest.add_entity(pos,'automobiles_delorean:normal_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.normal_kit = normal_kit
self.normal_kit:set_properties({is_visible=true})
elseif self._car_type == 1 then
--time machine
normal_kit = minetest.add_entity(pos,'automobiles_delorean:time_machine_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.normal_kit = normal_kit
self.normal_kit:set_properties({is_visible=true})
local instruments = minetest.add_entity(pos,'automobiles_delorean:time_machine_kit_instruments')
instruments:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.instruments = instruments
self.instruments:set_properties({is_visible=true})
end
end
--
-- entity
--
@ -306,57 +329,13 @@ initial_properties = {
})
minetest.register_entity('automobiles_delorean:pivot_mesh',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pivot_mesh.b3d",
textures = {"automobiles_black.png",},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity('automobiles_delorean:pointer',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pointer.b3d",
visual_size = {x = 0.5, y = 0.5, z = 0.5},
textures = {"automobiles_white.png"},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity("automobiles_delorean:delorean", {
initial_properties = {
physical = true,
collide_with_objects = true,
collisionbox = {-0.1, -0.2, -0.1, 0.1, 1, 0.1},
selectionbox = {-1.5, 0.0, -1.5, 1.5, 2, 1.5},
stepheight = 0.65,
stepheight = 0.65 + automobiles_lib.extra_stepheight,
visual = "mesh",
mesh = "automobiles_delorean_body.b3d",
--use_texture_alpha = true,
@ -420,150 +399,46 @@ minetest.register_entity("automobiles_delorean:delorean", {
_inv_id = "",
_change_color = automobiles_lib.paint,
_intensity = 4,
_delorean_type = 0,
_car_type = 0,
_car_gravity = -automobiles_lib.gravity,
_is_flying = 0,
_trunk_slots = 8,
_engine_sound = "delorean_engine",
_max_fuel = 10,
_formspec_function = delorean.driver_formspec,
_destroy_function = delorean.destroy,
get_staticdata = function(self) -- unloaded/unloads ... is now saved
return minetest.serialize({
stored_owner = self.owner,
stored_hp = self.hp,
stored_color = self._color,
stored_steering = self._steering_angle,
stored_energy = self._energy,
--race data
stored_last_checkpoint = self._last_checkpoint,
stored_total_laps = self._total_laps,
stored_race_id = self._race_id,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
stored_delorean_type = self._delorean_type,
stored_car_gravity = self._car_gravity,
})
end,
_vehicle_name = "Delorean",
_drive_wheel_pos = {x=-4.66, y=6.31, z=15.69},
_drive_wheel_angle = 15,
_seat_pos = {{x=-4.65,y=0.48,z=9.5},{x=4.65,y=0.48,z=9.5}},
_front_suspension_ent = 'automobiles_delorean:front_suspension',
_front_suspension_pos = {x=0,y=1.5,z=27.7057},
_front_wheel_ent = 'automobiles_delorean:wheel',
_front_wheel_xpos = 9.5,
_front_wheel_frames = {x = 1, y = 49},
_rear_suspension_ent = 'automobiles_delorean:rear_suspension',
_rear_suspension_pos = {x=0,y=1.5,z=0},
_rear_wheel_ent = 'automobiles_delorean:wheel',
_rear_wheel_xpos = 9.5,
_rear_wheel_frames = {x = 1, y = 49},
_fuel_gauge_pos = {x=-4.66,y=6.2,z=17.9},
_front_lights = 'automobiles_delorean:f_lights',
_rear_lights = 'automobiles_delorean:r_lights',
_reverse_lights = 'automobiles_delorean:reverse_lights',
_turn_left_lights = 'automobiles_delorean:turn_left_light',
_turn_right_lights = 'automobiles_delorean:turn_right_light',
_extra_items_function = delorean.set_kit, --uses _car_type do change "skin"
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
end,
on_activate = function(self, staticdata, dtime_s)
if staticdata ~= "" and staticdata ~= nil then
local data = minetest.deserialize(staticdata) or {}
self.owner = data.stored_owner
self.hp = data.stored_hp
self._color = data.stored_color
self._steering_angle = data.stored_steering
self._energy = data.stored_energy
--minetest.debug("loaded: ", self.energy)
--race data
self._last_checkpoint = data.stored_last_checkpoint
self._total_laps = data.stored_total_laps
self._race_id = data.stored_race_id
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
self._delorean_type = data.stored_delorean_type
self._car_gravity = data.stored_car_gravity or -automobiles_lib.gravity
automobiles_lib.setText(self, "Delorean")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_delorean:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=1.5,z=27.7057},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_delorean:wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-delorean.front_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_delorean:wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=delorean.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_delorean:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=1.5,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_delorean:wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-delorean.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_delorean:wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=delorean.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rr_wheel = rr_wheel
self.object:set_bone_position("drive_adjust", {x=-4.66, y=6.31, z=15.69}, {x=15, y=0, z=0})
local driver_seat=minetest.add_entity(pos,'automobiles_delorean:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.65,y=0.48,z=9.5},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_delorean:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.65,y=0.48,z=9.5},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_delorean:pointer')
fuel_gauge:set_attach(self.object,'',DELOREAN_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_delorean:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
--normal or time machine?
delorean.set_kit(self)
local r_lights = minetest.add_entity(pos,'automobiles_delorean:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
local reverse_lights = minetest.add_entity(pos,'automobiles_delorean:reverse_lights')
reverse_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.reverse_lights = reverse_lights
self.reverse_lights:set_properties({is_visible=true})
local turn_l_light = minetest.add_entity(pos,'automobiles_delorean:turn_left_light')
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
local turn_r_light = minetest.add_entity(pos,'automobiles_delorean:turn_right_light')
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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, delorean.trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -664,7 +539,7 @@ minetest.register_entity("automobiles_delorean:delorean", {
--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,
@ -792,12 +667,12 @@ minetest.register_entity("automobiles_delorean:delorean", {
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
delorean.engine_set_sound_and_animation(self, longit_speed)
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
end
end
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',DELOREAN_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --
@ -812,7 +687,8 @@ minetest.register_entity("automobiles_delorean:delorean", {
if stop ~= true then
--self.object:set_velocity(velocity)
self.object:set_acceleration(accel)
self.object:add_velocity(vector.multiply(accel,dtime))
--self.object:set_acceleration(accel)
else
if stop == true then
self.object:set_acceleration({x=0,y=0,z=0})
@ -850,121 +726,8 @@ minetest.register_entity("automobiles_delorean:delorean", {
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, delorean.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
delorean.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
delorean.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, delorean.trunk_slots)
else
--is the owner, okay, lets attach
automobiles_lib.attach_driver(self, clicker)
-- sound
self.sound_handle = minetest.sound_play({name = delorean.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,
on_punch = automobiles_lib.on_punch,
on_rightclick = automobiles_lib.on_rightclick,
})

View File

@ -1,26 +1,3 @@
function delorean.set_kit(self)
local normal_kit = nil
if self.normal_kit then self.normal_kit:remove() end
local pos = self.object:get_pos()
if self._delorean_type == 0 or self._delorean_type == nil then
normal_kit = minetest.add_entity(pos,'automobiles_delorean:normal_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.normal_kit = normal_kit
self.normal_kit:set_properties({is_visible=true})
elseif self._delorean_type == 1 then
--time machine
normal_kit = minetest.add_entity(pos,'automobiles_delorean:time_machine_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.normal_kit = normal_kit
self.normal_kit:set_properties({is_visible=true})
local instruments = minetest.add_entity(pos,'automobiles_delorean:time_machine_kit_instruments')
instruments:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.instruments = instruments
self.instruments:set_properties({is_visible=true})
end
end
function delorean.gravity_auto_correction(self, dtime)
local factor = 1
--minetest.chat_send_player(self.driver_name, "antes: " .. self._car_gravity)
@ -71,16 +48,16 @@ end
function delorean.set_wheels_mode(self, angle_factor)
if not self._is_flying or self._is_flying == 0 then
--whell turn
self.lf_wheel:set_attach(self.front_suspension,'',{x=-delorean.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=delorean.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-delorean.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=delorean.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
else
local extra_space = 0.5
self.lf_wheel:set_attach(self.front_suspension,'',{x=-delorean.front_wheel_xpos-extra_space,y=0,z=0},{x=0,y=0,z=90})
self.rf_wheel:set_attach(self.front_suspension,'',{x=delorean.front_wheel_xpos+extra_space,y=0,z=0},{x=0,y=180,z=-90})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-delorean.rear_wheel_xpos-extra_space,y=0,z=0},{x=0,y=0,z=90})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=delorean.rear_wheel_xpos+extra_space,y=0,z=0},{x=0,y=180,z=-90})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos-extra_space,y=0,z=0},{x=0,y=0,z=90})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos+extra_space,y=0,z=0},{x=0,y=180,z=-90})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos-extra_space,y=0,z=0},{x=0,y=0,z=90})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos+extra_space,y=0,z=0},{x=0,y=180,z=-90})
end
end
@ -95,7 +72,7 @@ function delorean.turn_flight_mode(self)
end
function delorean.set_mode(self, is_attached, curr_pos, velocity, player, dtime)
if self._delorean_type == 1 then
if self._car_type == 1 then
local ent_propertioes = self.normal_kit:get_properties()
if ent_propertioes.mesh ~= "automobiles_delorean_time_machine_accessories.b3d" then
delorean.set_kit(self)

View File

@ -33,7 +33,7 @@ function delorean.driver_formspec(name)
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._delorean_type == 1 then basic_form = basic_form.."checkbox[1,4.0;flight;Flight Mode;"..flight.."]" end
if ent._car_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, "delorean:driver_main", basic_form)

View File

@ -7,25 +7,17 @@ delorean.LATER_DRAG_FACTOR = 8.0
delorean.gravity = automobiles_lib.gravity
delorean.max_speed = 30
delorean.max_acc_factor = 8
delorean.max_fuel = 10
delorean.trunk_slots = 8
delorean.ideal_step = 0.2
delorean.engine_sound = "delorean_engine"
DELOREAN_GAUGE_FUEL_POSITION = {x=-4.66,y=6.2,z=17.9}
delorean.front_wheel_xpos = 9.5
delorean.rear_wheel_xpos = 9.5
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.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 .. "control.lua")
dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "forms.lua")
dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "control.lua")
dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "flight.lua")
dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "utilities.lua")
dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "forms.lua")
dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "crafts.lua")

View File

@ -54,24 +54,3 @@ function delorean.destroy(self, puncher)
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 delorean.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')
delorean.engineSoundPlay(self)
end
end
end
function delorean.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 = delorean.engine_sound},
{object = self.object, gain = 2,
pitch = 1 + ((self._longit_speed/10)/2),
max_hear_distance = 10,
loop = true,})
end
end

View File

@ -7,9 +7,9 @@ function automobiles_lib.physics(self)
-- dumb friction
if self.isonground and not self.isinliquid then
--minetest.chat_send_all('okay')
self.object:set_velocity({x=vel.x*friction,
y=vel.y,
z=vel.z*friction})
self.object:add_velocity({x=vel.x*friction-vel.x,
y=0,
z=vel.z*friction-vel.z})
end
-- bounciness
@ -33,7 +33,7 @@ function automobiles_lib.physics(self)
self.collided = false
end
self.object:set_velocity(vnew)
self.object:add_velocity(vector.subtract(vel, vnew))
end
-- buoyancy

View File

@ -0,0 +1,355 @@
minetest.register_entity('automobiles_lib:pivot_mesh',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pivot_mesh.b3d",
textures = {"automobiles_black.png",},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity('automobiles_lib:pointer',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pointer.b3d",
visual_size = {x = 0.5, y = 0.5, z = 0.5},
textures = {"automobiles_white.png"},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
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
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 or
(self.driver_name == nil and
( minetest.check_player_privs(clicker, "valet_parking") or minetest.check_player_privs(clicker, {server=true}) )
) 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
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, pitch = base_pitch, max_hear_distance = 30, loop = true,})
end
else
--minetest.chat_send_all("clicou")
--a passenger
if not player_api.player_attached[name] then
--there is no passenger, so lets attach
if self.driver_name then
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 you are the psenger, so deattach
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
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
local was_refueled = automobiles_lib.loadFuel(self, puncher:get_player_name(), false, self._max_fuel)
if was_refueled 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
local destroy_f = automobiles_lib.destroy
if self._destroy_function then destroy_f = self._destroy_function end
destroy_f(self)
end
end
end
function automobiles_lib.get_staticdata(self)
return minetest.serialize({
stored_owner = self.owner,
stored_hp = self.hp,
stored_color = self._color,
stored_det_color = self._det_color,
stored_steering = self._steering_angle,
stored_energy = self._energy,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
stored_car_type = self._car_type,
stored_car_gravity = self._car_gravity,
--race data
stored_last_checkpoint = self._last_checkpoint,
stored_total_laps = self._total_laps,
stored_race_id = self._race_id,
})
end
function automobiles_lib.on_activate(self, staticdata, dtime_s)
if staticdata ~= "" and staticdata ~= nil then
local data = minetest.deserialize(staticdata) or {}
self.owner = data.stored_owner
self.hp = data.stored_hp
self._color = data.stored_color
self._det_color = data.stored_det_color
self._steering_angle = data.stored_steering
self._energy = data.stored_energy
--minetest.debug("loaded: ", self.energy)
--race data
self._last_checkpoint = data.stored_last_checkpoint
self._total_laps = data.stored_total_laps
self._race_id = data.stored_race_id
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
self._car_type = data.stored_car_type
self._car_gravity = data.stored_car_gravity or -automobiles_lib.gravity
automobiles_lib.setText(self, self._vehicle_name)
end
if self._painting_load then
self._painting_load(self, self._color)
else
automobiles_lib.paint(self, self._color)
end
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),self._front_suspension_ent)
front_suspension:set_attach(self.object,'',self._front_suspension_pos,{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,self._front_wheel_ent)
lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lf_wheel:set_animation(self._front_wheel_frames, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,self._front_wheel_ent)
rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation(self._front_wheel_frames, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),self._rear_suspension_ent)
rear_suspension:set_attach(self.object,'',self._rear_suspension_pos,{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,self._rear_wheel_ent)
lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lr_wheel:set_animation(self._rear_wheel_frames, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,self._rear_wheel_ent)
rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation(self._rear_wheel_frames, 0, 0, true)
self.rr_wheel = rr_wheel
if self._steering_ent then
local steering_axis=minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
steering_axis:set_attach(self.object,'',self._drive_wheel_pos,{x=self._drive_wheel_angle,y=0,z=0})
self.steering_axis = steering_axis
local steering=minetest.add_entity(self.steering_axis:get_pos(), self._steering_ent)
steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.steering = steering
else
self.object:set_bone_position("drive_adjust", self._drive_wheel_pos, {x=self._drive_wheel_angle, y=0, z=0})
end
if self._rag_retracted_ent then
local rag_rect=minetest.add_entity(self.object:get_pos(),self._rag_retracted_ent)
rag_rect:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.rag_rect = rag_rect
self.rag_rect:set_properties({is_visible=false})
end
if self._rag_extended_ent then
local rag=minetest.add_entity(self.object:get_pos(),self._rag_extended_ent)
rag:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.rag = rag
end
automobiles_lib.seats_create(self)
--[[local driver_seat=minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
driver_seat:set_attach(self.object,'',self._seat_pos[1],{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
passenger_seat:set_attach(self.object,'',self._seat_pos[2],{x=0,y=0,z=0})
self.passenger_seat = passenger_seat]]--
local pointer_entity = 'automobiles_lib:pointer'
if self._gauge_pointer_ent then pointer_entity = self._gauge_pointer_ent end
local fuel_gauge=minetest.add_entity(pos, pointer_entity)
fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
if self._front_lights then
local lights = minetest.add_entity(pos,self._front_lights)
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
end
if self._rear_lights then
local r_lights = minetest.add_entity(pos,self._rear_lights)
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
end
if self._reverse_lights then
local reverse_lights = minetest.add_entity(pos,self._reverse_lights)
reverse_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.reverse_lights = reverse_lights
self.reverse_lights:set_properties({is_visible=true})
end
if self._turn_left_lights then
local turn_l_light = minetest.add_entity(pos,self._turn_left_lights)
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
end
if self._turn_right_lights then
local turn_r_light = minetest.add_entity(pos,self._turn_right_lights)
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
end
if self._extra_items_function then
self._extra_items_function(self)
end
self.object:set_armor_groups({immortal=1})
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, self._trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end

View File

@ -0,0 +1,78 @@
function automobiles_lib.getCarFromPlayer(player)
local seat = player:get_attach()
if seat then
local car = seat:get_attach()
return car
end
return nil
end
function automobiles_lib.driver_formspec(name)
local player = minetest.get_player_by_name(name)
if player then
local vehicle_obj = automobiles_lib.getCarFromPlayer(player)
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
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "automobiles_lib:driver_main" then
local name = player:get_player_name()
local car_obj = automobiles_lib.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)
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
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
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
end
end
minetest.close_formspec(name, "automobiles_lib:driver_main")
end
end)

View File

@ -13,7 +13,6 @@ end
function automobiles_lib.loadFuel(self, player_name, free, max_fuel)
free = free or false
local player = minetest.get_player_by_name(player_name)
local inv = player:get_inventory()
@ -22,6 +21,7 @@ function automobiles_lib.loadFuel(self, player_name, free, max_fuel)
if itmstck then item_name = itmstck:get_name() end
local fuel = automobiles_lib.contains(automobiles_lib.fuel, item_name)
--minetest.chat_send_all(dump(fuel))
if fuel or free == true then
local stack = ItemStack(item_name .. " 1")
if self._energy < max_fuel then

View File

@ -98,7 +98,8 @@ function automobiles_lib.ground_get_distances(self, radius, axis_distance)
self._last_front_detection = rear_obstacle_level.y
--here we need to set the collision effect
self.object:set_acceleration({x=0,y=0,z=0})
self.object:set_velocity({x=0,y=0,z=0})
local oldvel = self.object:get_velocity()
self.object:add_velocity(vector.subtract(vector.new(), oldvel))
end
end
@ -141,6 +142,7 @@ function automobiles_lib.eval_interception(initial_pos, end_pos)
if pos then
local nodename = minetest.get_node(thing.under).name
local drawtype = get_nodedef_field(nodename, "drawtype")
if drawtype ~= "plantlike" then
if initial_pos.y >= pos.y then
ret_y = pos.y

View File

@ -1,7 +1,11 @@
-- Minetest 5.4.1 : automobiles
local S = minetest.get_translator(minetest.get_current_modname())
automobiles_lib = {}
automobiles_lib = {
storage = minetest.get_mod_storage()
}
local storage = automobiles_lib.storage
automobiles_lib.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1,
['biofuel:phial_fuel'] = 0.25, ['biofuel:fuel_can'] = 10,
@ -10,6 +14,16 @@ automobiles_lib.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1,
automobiles_lib.gravity = 9.8
automobiles_lib.is_creative = minetest.settings:get_bool("creative_mode", false)
local load_noob_mode = storage:get_int("noob_mode")
automobiles_lib.noob_mode = false
automobiles_lib.extra_stepheight = 0
-- 1 == true ---- 2 == false
if load_noob_mode == 1 then
automobiles_lib.load_noob_mode = true
automobiles_lib.extra_stepheight = 1
end
--cars colors
automobiles_lib.colors ={
black='#2b2b2b',
@ -49,6 +63,14 @@ function automobiles_lib.minmax(v,m)
return math.min(math.abs(v),m)*minekart.sign(v)
end
function automobiles_lib.properties_copy(origin_table)
local tablecopy = {}
for k, v in pairs(origin_table) do
tablecopy[k] = v
end
return tablecopy
end
--returns 0 for old, 1 for new
function automobiles_lib.detect_player_api(player)
local player_proterties = player:get_properties()
@ -69,6 +91,28 @@ function automobiles_lib.detect_player_api(player)
return 0
end
function automobiles_lib.seats_create(self)
if self.object then
local pos = self.object:get_pos()
self._passengers_base = {}
self._passengers = {}
if self._seat_pos then
local max_seats = table.getn(self._seat_pos)
for i=1, max_seats do
self._passengers_base[i] = minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
if not self._seats_rot then
self._passengers_base[i]:set_attach(self.object,'',self._seat_pos[i],{x=0,y=0,z=0})
else
self._passengers_base[i]:set_attach(self.object,'',self._seat_pos[i],{x=0,y=self._seats_rot[i],z=0})
end
end
self.driver_seat = self._passengers_base[1] --sets pilot seat reference
self.passenger_seat = self._passengers_base[2] --sets copilot seat reference
end
end
end
-- attach player
function automobiles_lib.attach_driver(self, player)
local name = player:get_player_name()
@ -142,103 +186,112 @@ function automobiles_lib.attach_pax(self, player, onside)
local onside = onside or false
local name = player:get_player_name()
if onside == true then
if self._passenger == nil then
self._passenger = name
local eye_y = -4
if automobiles_lib.detect_player_api(player) == 1 then
eye_y = 2.5
end
-- attach the driver
player:set_attach(self.passenger_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
local eye_y = -4
if automobiles_lib.detect_player_api(player) == 1 then
eye_y = 2.5
end
player:set_eye_offset({x = 0, y = eye_y, z = 0}, {x = 0, y = eye_y, z = -30})
player_api.player_attached[name] = true
-- make the pax sit
if self._passenger == nil then
self._passenger = name
minetest.after(0.2, function()
player = minetest.get_player_by_name(name)
if player then
local speed = 30.01
local mesh = player:get_properties().mesh
if mesh then
local character = player_api.registered_models[mesh]
if character and character.animation_speed then
speed = character.animation_speed + 0.01
end
-- attach the driver
player:set_attach(self.passenger_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
player:set_eye_offset({x = 0, y = eye_y, z = 0}, {x = 0, y = eye_y, z = -30})
player_api.player_attached[name] = true
-- make the pax sit
minetest.after(0.2, function()
player = minetest.get_player_by_name(name)
if player then
local speed = 30.01
local mesh = player:get_properties().mesh
if mesh then
local character = player_api.registered_models[mesh]
if character and character.animation_speed then
speed = character.animation_speed + 0.01
end
player_api.set_animation(player, "sit", speed)
if emote then emote.start(player:get_player_name(), "sit") end
end
end)
end
player_api.set_animation(player, "sit", speed)
if emote then emote.start(player:get_player_name(), "sit") end
end
end)
else
--randomize the seat
--[[local t = {1,2,3,4,5,6,7,8,9,10}
local max_seats = table.getn(self._seat_pos) --driver and front passenger
t = {} -- new array
for i=1, max_seats do --(the first are for the driver
t[i] = i
end
for i = 1, #t*2 do
local a = math.random(#t)
local b = math.random(#t)
t[a],t[b] = t[b],t[a]
end
--for i = 1,10,1 do
for k,v in ipairs(t) do
i = t[k]
if self._passengers[i] == nil then
if self._passengers[i] == nil and i > 2 then
--minetest.chat_send_all(self.driver_name)
self._passengers[i] = name
player:set_attach(self._passengers_base[i], "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
if i > 2 then
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 3, z = -30})
else
player:set_eye_offset({x = 0, y = -4, z = 0}, {x = 0, y = 3, z = -30})
end
player:set_eye_offset({x = 0, y = eye_y, z = 0}, {x = 0, y = 3, z = -30})
player_api.player_attached[name] = true
-- make the driver sit
-- make the pax sit
minetest.after(0.2, function()
player = minetest.get_player_by_name(name)
if player then
player_api.set_animation(player, "sit")
--apply_physics_override(player, {speed=0,gravity=0,jump=0})
local speed = 30.01
local mesh = player:get_properties().mesh
if mesh then
local character = player_api.registered_models[mesh]
if character and character.animation_speed then
speed = character.animation_speed + 0.01
end
end
player_api.set_animation(player, "sit", speed)
if emote then emote.start(player:get_player_name(), "sit") end
end
end)
break
end
end]]--
end
end
end
function automobiles_lib.dettach_pax(self, player)
if player then
local name = player:get_player_name() --self._passenger
if not player then return end
local name = player:get_player_name() --self._passenger
-- passenger clicked the object => driver gets off the vehicle
if self._passenger == name then
self._passenger = nil
else
--[[for i = 10,1,-1
do
if self._passengers[i] == name then
self._passengers[i] = nil
break
end
end]]--
end
-- detach the player
if player then
--player:set_properties({physical=true})
player:set_detach()
player_api.player_attached[name] = nil
player_api.set_animation(player, "stand")
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
--remove_physics_override(player, {speed=1,gravity=1,jump=1})
end
else
-- passenger clicked the object => driver gets off the vehicle
if self._passenger == name then
self._passenger = nil
self._passengers[2] = nil
else
local max_seats = table.getn(self._seat_pos)
for i = max_seats,1,-1
do
if self._passengers[i] == name then
self._passengers[i] = nil
break
end
end
end
-- detach the player
if player then
local pos = player:get_pos()
player:set_detach()
player_api.player_attached[name] = nil
player_api.set_animation(player, "stand")
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
--remove_physics_override(player, {speed=1,gravity=1,jump=1})
end
end
@ -355,6 +408,97 @@ function automobiles_lib.put_light(self)
end
function automobiles_lib.seats_destroy(self)
local max_seats = table.getn(self._passengers_base)
for i=1, max_seats do
if self._passengers_base[i] then self._passengers_base[i]:remove() end
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.seats_destroy(self)
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 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
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", {
drawtype = "airlike",
--tile_images = {"automobiles_light.png"},
@ -372,6 +516,12 @@ minetest.register_node("automobiles_lib:light", {
})
function automobiles_lib.set_paint(self, puncher, itmstck)
local is_admin = false
is_admin = minetest.check_player_privs(puncher, {server=true})
if not (self.owner == puncher:get_player_name() or is_admin == true) then
return
end
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
@ -461,6 +611,8 @@ 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 .. "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",{
@ -514,3 +666,86 @@ initial_properties = {
end,
})
minetest.register_privilege("valet_parking", {
description = "Gives a valet parking priv for a player",
give_to_singleplayer = true
})
minetest.register_chatcommand("transfer_vehicle", {
params = "<new_owner>",
description = "Transfer the property of a vehicle to another player",
privs = {interact=true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
local target_player = minetest.get_player_by_name(param)
local attached_to = player:get_attach()
if attached_to ~= nil then
if target_player ~= nil then
local seat = attached_to:get_attach()
if seat ~= nil then
local entity = seat:get_luaentity()
if entity then
if entity.owner == name or minetest.check_player_privs(name, {protection_bypass=true}) then
entity.owner = param
minetest.chat_send_player(name,core.colorize('#00ff00', " >>> This vehicle now is property of: "..param))
automobiles_lib.setText(entity, "vehicle")
else
minetest.chat_send_player(name,core.colorize('#ff0000', " >>> only the owner or moderators can transfer this vehicle"))
end
end
end
else
minetest.chat_send_player(name,core.colorize('#ff0000', " >>> the target player must be logged in"))
end
else
minetest.chat_send_player(name,core.colorize('#ff0000', " >>> you are not inside a vehicle to perform the command"))
end
end
})
minetest.register_chatcommand("noobfy_the_vehicles", {
params = "<true/false>",
description = "Enable/disable the NOOB mode for the vehicles",
privs = {server=true},
func = function(name, param)
local command = param
if command == "false" then
automobiles_lib.noob_mode = false
automobiles_lib.extra_stepheight = 0
minetest.chat_send_player(name, ">>> Noob mode is disabled - A restart is required to changes take full effect")
else
automobiles_lib.noob_mode = true
automobiles_lib.extra_stepheight = 1
minetest.chat_send_player(name, ">>> Noob mode is enabled - A restart is required to changes take full effect")
end
local save = 2
if automobiles_lib.noob_mode == true then save = 1 end
storage:set_int("noob_mode", save)
end,
})
local old_entities = {
"automobiles_buggy:pivot_mesh",
"automobiles_buggy:pointer",
"automobiles_catrelle:pivot_mesh",
"automobiles_catrelle:pointer",
"automobiles_catrelle:catrelle_tl",
"automobiles_coupe:pivot_mesh",
"automobiles_coupe:pointer",
"automobiles_delorean:pivot_mesh",
"automobiles_delorean:pointer",
"automobiles_roadster:pivot_mesh",
"automobiles_trans_am:pivot_mesh",
"automobiles_trans_am:pointer",
}
for _,entity_name in ipairs(old_entities) do
minetest.register_entity(":"..entity_name, {
on_activate = function(self, staticdata)
self.object:remove()
end,
})
end

View File

@ -1,50 +1,72 @@
local storage = minetest.get_mod_storage()
local storage = automobiles_lib.storage
automobiles_lib.modname = minetest.get_current_modname()
--function to format formspec for mineclone. In case of minetest, just returns an empty string
local function get_itemslot_bg(a, b, c, d)
if mcl_formspec then
return mcl_formspec.get_itemslot_bg(a,b,c,d)
end
return ""
end
local function get_formspec_by_size(self, size)
local background = default.gui_bg .. default.gui_bg_img .. default.gui_slots
local background = ""
local hotbar = ""
local is_minetest_game = false
if is_minetest_game then
background = background .. default.gui_bg .. default.gui_bg_img .. default.gui_slots
hotbar = default.get_hotbar_bg(0,4.85)
end
local default_inventory_formspecs = {
["2"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;3.0,0;3,1;]" .. get_itemslot_bg(3.0, 0, 2, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["3"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;2.5,0;3,1;]" .. get_itemslot_bg(2.5, 0, 3, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["4"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;2,0;4,1;]" ..
"list[current_player;main;0,2;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;2,0;4,1;]" .. get_itemslot_bg(2.0, 0, 4, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["6"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,1;]"..
"list[current_player;main;0,2;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,1;]".. get_itemslot_bg(1.0, 0, 6, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["8"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,1;]"..
"list[current_player;main;0,2;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,1;]".. get_itemslot_bg(0, 0, 8, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["12"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,2;]"..
"list[current_player;main;0,3;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,2;]".. get_itemslot_bg(1, 0, 6, 2) ..
"list[current_player;main;0,3;8,4;]" .. get_itemslot_bg(0, 3, 8, 4) ..
"listring[]",
["16"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,2;]"..
"list[current_player;main;0,3;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,2;]".. get_itemslot_bg(0, 0, 8, 2) ..
"list[current_player;main;0,3;8,4;]" .. get_itemslot_bg(0, 3, 8, 4) ..
"listring[]",
["24"]="size[8,8]".. background ..
"list[context:" .. self._inv_id .. ";main;0,0;8,3;]"..
"list[current_player;main;0,4;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,3;]".. get_itemslot_bg(0, 0, 8, 3) ..
"list[current_player;main;0,4;8,4;]" .. get_itemslot_bg(0, 4, 8, 4) ..
"listring[]",
["32"]="size[8,9]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0.3;8,4;]"..
"list[current_player;main;0,4.85;8,1;]"..
"list[current_player;main;0,6.08;8,3;8]"..
"listring[context;main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85),
"list[detached:" .. self._inv_id .. ";main;0,0.3;8,4;]".. get_itemslot_bg(0, 0.3, 8, 4) ..
"list[current_player;main;0,5;8,4;]".. get_itemslot_bg(0, 5, 8, 4) ..
"listring[]" ..
hotbar,
["50"]="size[10,10]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;10,5;]"..
"list[current_player;main;1,6;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;0,0;10,5;]".. get_itemslot_bg(0, 0, 10, 5) ..
"list[current_player;main;1,6;8,4;]" .. get_itemslot_bg(1, 6, 8, 4) ..
"listring[]",
}
@ -94,8 +116,8 @@ function automobiles_lib.remove_inventory(self)
local pos = self.object:get_pos()
for k, v in pairs(inv_content) do
local count = 0
for i = 0,v:get_count()-1,1
do
for i = 0,v:get_count()-1,1
do
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},v:get_name())
count = count + 1
if count >= 5 then break end
@ -177,7 +199,7 @@ function automobiles_lib.list_inventory(self)
local inventory = automobiles_lib.get_inventory(self)
if inventory then
local list = inventory.get_list("main")
minetest.chat_send_all(dump(list))
end
end

Binary file not shown.

View File

@ -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,10 @@ 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_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")

View File

@ -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

View File

@ -98,7 +98,7 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", {
collide_with_objects = true,
collisionbox = {-0.1, -0.4, -0.1, 0.1, 1, 0.1},
selectionbox = {-1, 1, -1, 1, -1, 1},
stepheight = 0.8,
stepheight = 0.8 + automobiles_lib.extra_stepheight,
visual = "mesh",
mesh = "automobiles_motorcycle_body.b3d",
--use_texture_alpha = true,
@ -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
@ -442,12 +452,13 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", {
if stop ~= true then
--self.object:set_velocity(velocity)
self.object:set_acceleration(accel)
self.object:add_velocity(vector.multiply(accel,dtime))
--self.object:set_acceleration(accel)
else
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 +488,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,
})

View File

@ -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

View File

@ -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

View File

@ -7,21 +7,14 @@ roadster.LATER_DRAG_FACTOR = 30.0
roadster.gravity = automobiles_lib.gravity
roadster.max_speed = 12
roadster.max_acc_factor = 5
roadster.max_fuel = 10
roadster.trunk_slots = 8
ROADSTER_GAUGE_FUEL_POSITION = {x=0,y=8.04,z=17.84}
roadster.front_wheel_xpos = 10.26
roadster.rear_wheel_xpos = 10.26
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.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 .. "ground_detection.lua")
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_forms.lua")
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_utilities.lua")
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_entities.lua")
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_forms.lua")
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_crafts.lua")

View File

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

View File

@ -143,28 +143,6 @@ initial_properties = {
})
minetest.register_entity('automobiles_roadster:pivot_mesh',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pivot_mesh.b3d",
textures = {"automobiles_black.png",},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity('automobiles_roadster:steering',{
initial_properties = {
physical = false,
@ -215,7 +193,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
collide_with_objects = true,
collisionbox = {-0.1, -0.5, -0.1, 0.1, 1, 0.1},
selectionbox = {-1.5, 0.0, -1.5, 1.5, 2, 1.5},
stepheight = 0.6,
stepheight = 0.6 + automobiles_lib.extra_stepheight,
visual = "mesh",
mesh = "automobiles_roadster.b3d",
--use_texture_alpha = true,
@ -277,132 +255,42 @@ minetest.register_entity("automobiles_roadster:roadster", {
_inv_id = "",
_change_color = automobiles_lib.paint,
_intensity = 4,
_trunk_slots = 8,
_engine_sound = "roadster_engine",
_max_fuel = 10,
_formspec_function = roadster.driver_formspec,
_destroy_function = roadster.destroy,
get_staticdata = function(self) -- unloaded/unloads ... is now saved
return minetest.serialize({
stored_owner = self.owner,
stored_hp = self.hp,
stored_color = self._color,
stored_steering = self._steering_angle,
stored_energy = self._energy,
--race data
stored_last_checkpoint = self._last_checkpoint,
stored_total_laps = self._total_laps,
stored_race_id = self._race_id,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
})
end,
_vehicle_name = "Roadster",
_drive_wheel_pos = {x=-4.25,y=12,z=14},
_drive_wheel_angle = 70,
_steering_ent = 'automobiles_roadster:steering',
_rag_extended_ent = 'automobiles_roadster:top1',
_rag_retracted_ent = 'automobiles_roadster:top2',
_seat_pos = {{x=-4.25,y=7.12,z=9.5},{x=4.25,y=7.12,z=9.5}},
_front_suspension_ent = 'automobiles_roadster:front_suspension',
_front_suspension_pos = {x=0,y=0,z=24.22},
_front_wheel_ent = 'automobiles_roadster:wheel',
_front_wheel_xpos = 10.26,
_front_wheel_frames = {x = 2, y = 13},
_rear_suspension_ent = 'automobiles_roadster:rear_suspension',
_rear_suspension_pos = {x=0,y=0,z=0},
_rear_wheel_ent = 'automobiles_roadster:wheel',
_rear_wheel_xpos = 10.26,
_rear_wheel_frames = {x = 2, y = 13},
_fuel_gauge_pos = {x=0,y=8.04,z=17.84},
_gauge_pointer_ent = 'automobiles_roadster:pointer',
_front_lights = 'automobiles_roadster:lights',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
end,
on_activate = function(self, staticdata, dtime_s)
if staticdata ~= "" and staticdata ~= nil then
local data = minetest.deserialize(staticdata) or {}
self.owner = data.stored_owner
self.hp = data.stored_hp
self._color = data.stored_color
self._steering_angle = data.stored_steering
self._energy = data.stored_energy
--minetest.debug("loaded: ", self.energy)
--race data
self._last_checkpoint = data.stored_last_checkpoint
self._total_laps = data.stored_total_laps
self._race_id = data.stored_race_id
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
automobiles_lib.setText(self, "Roadster")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local top1=minetest.add_entity(self.object:get_pos(),'automobiles_roadster:top1')
top1:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.top1 = top1
local top2=minetest.add_entity(self.object:get_pos(),'automobiles_roadster:top2')
top2:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.top2 = top2
self.top2:set_properties({is_visible=false})
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_roadster:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=0,z=24.22},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_roadster:wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-roadster.front_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lf_wheel:set_animation({x = 2, y = 13}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_roadster:wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=roadster.front_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 2, y = 13}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_roadster:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_roadster:wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-roadster.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lr_wheel:set_animation({x = 2, y = 13}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_roadster:wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=roadster.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 2, y = 13}, 0, 0, true)
self.rr_wheel = rr_wheel
local steering_axis=minetest.add_entity(pos,'automobiles_roadster:pivot_mesh')
steering_axis:set_attach(self.object,'',{x=-4.25,y=12,z=14},{x=70,y=0,z=0})
self.steering_axis = steering_axis
local steering=minetest.add_entity(self.steering_axis:get_pos(),'automobiles_roadster:steering')
steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.steering = steering
local driver_seat=minetest.add_entity(pos,'automobiles_roadster:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.25,y=7.12,z=9.5},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_roadster:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.25,y=7.12,z=9.5},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_roadster:pointer')
fuel_gauge:set_attach(self.object,'',ROADSTER_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_roadster:lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=false})
self.object:set_armor_groups({immortal=1})
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, roadster.trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -436,12 +324,12 @@ minetest.register_entity("automobiles_roadster:roadster", {
if self._show_rag == true then
self.object:set_bone_position("windshield", {x=0, z=15.8317, y=15.0394}, {x=145, y=0, z=0})
self.top2:set_properties({is_visible=true})
self.top1:set_properties({is_visible=false})
self.rag_rect:set_properties({is_visible=true})
self.rag:set_properties({is_visible=false})
else
self.object:set_bone_position("windshield", {x=0, z=15.8317, y=15.0394}, {x=0, y=0, z=0})
self.top2:set_properties({is_visible=false})
self.top1:set_properties({is_visible=true})
self.rag_rect:set_properties({is_visible=false})
self.rag:set_properties({is_visible=true})
end
local player = nil
@ -543,8 +431,8 @@ minetest.register_entity("automobiles_roadster:roadster", {
--whell turn
self.steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=self._steering_angle*2})
self.lf_wheel:set_attach(self.front_suspension,'',{x=roadster.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=-roadster.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle+angle_factor,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle+angle_factor,z=0})
if math.abs(self._steering_angle)>5 then
local turn_rate = math.rad(40)
@ -582,12 +470,12 @@ minetest.register_entity("automobiles_roadster:roadster", {
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
roadster.engine_set_sound_and_animation(self, longit_speed)
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
end
end
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',ROADSTER_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --
@ -595,7 +483,8 @@ minetest.register_entity("automobiles_roadster:roadster", {
if stop ~= true then
--self.object:set_velocity(velocity)
self.object:set_acceleration(accel)
self.object:add_velocity(vector.multiply(accel,dtime))
--self.object:set_acceleration(accel)
else
if stop == true then
self.object:set_acceleration({x=0,y=0,z=0})
@ -618,121 +507,8 @@ minetest.register_entity("automobiles_roadster:roadster", {
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, roadster.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
roadster.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
roadster.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, roadster.trunk_slots)
else
--is the owner, okay, lets attach
automobiles_lib.attach_driver(self, clicker)
-- sound
self.sound_handle = minetest.sound_play({name = "roadster_engine"},
{object = self.object, gain = 0.5, pitch = 0.6, 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 roadster.getCarFromPlayer(player)
local seat = player:get_attach()
if seat then
local car = seat:get_attach()
return car
end
return nil
end
function roadster.driver_formspec(name)
local player = minetest.get_player_by_name(name)
local vehicle_obj = roadster.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 == "roadster:driver_main" then
local name = player:get_player_name()
local car_obj = roadster.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 roadster.destroy(self, puncher)
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_roadster:wheel')
end
function roadster.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')
roadster.engineSoundPlay(self)
end
end
end
function roadster.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 = "roadster_engine"},
{object = self.object, gain = 0.5,
pitch = 0.6 + ((self._longit_speed/10)/2),
max_hear_distance = 10,
loop = true,})
end
end

View File

@ -35,7 +35,7 @@ minetest.register_craftitem("automobiles_trans_am:trans_am", {
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
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

View File

@ -189,51 +189,7 @@ initial_properties = {
})
minetest.register_entity('automobiles_trans_am:pivot_mesh',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pivot_mesh.b3d",
textures = {"automobiles_black.png",},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity('automobiles_trans_am:pointer',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pointer.b3d",
visual_size = {x = 0.5, y = 0.5, z = 0.5},
textures = {"automobiles_white.png"},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
local function paint(self, colstr)
function trans_am.paint(self, colstr)
automobiles_lib.paint_with_mask(self, colstr, self._det_color, "automobiles_trans_am_painting.png", "automobiles_trans_am_marks.png")
local l_textures = self.initial_properties.textures
@ -243,17 +199,23 @@ local function paint(self, colstr)
for _, texture in ipairs(l_textures) do
local indx = texture:find(target_texture)
if indx then
l_textures[_] = target_texture.."^[multiply:".. self._det_color
l_textures[_] = target_texture.."^[multiply:".. self._det_color --apply the deatil color color
end
local indx = texture:find(accessorie_texture)
if indx then
l_textures[_] = accessorie_texture.."^[multiply:".. colstr
l_textures[_] = accessorie_texture.."^[multiply:".. colstr --here changes the main color
end
end
self.object:set_properties({textures=l_textures})
end
function set_paint(self, puncher, itmstck)
function trans_am.set_paint(self, puncher, itmstck)
local is_admin = false
is_admin = minetest.check_player_privs(puncher, {server=true})
if not (self.owner == puncher:get_player_name() or is_admin == true) then
return
end
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
@ -262,7 +224,7 @@ function set_paint(self, puncher, itmstck)
local meta = itmstck:get_meta()
local colstr = meta:get_string("paint_color")
self._det_color = colstr
paint(self, self._color)
trans_am.paint(self, self._color)
return true
else
--painting with dyes
@ -280,7 +242,7 @@ function set_paint(self, puncher, itmstck)
--minetest.chat_send_all(color ..' '.. dump(colstr))
if colstr then
self._det_color = colstr
paint(self, self._color)
trans_am.paint(self, self._color)
itmstck:set_count(itmstck:get_count()-1)
puncher:set_wielded_item(itmstck)
return true
@ -297,7 +259,7 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
collide_with_objects = true,
collisionbox = {-0.1, -0.2, -0.1, 0.1, 1.8, 0.1},
selectionbox = {-2.0, 0.0, -2.0, 2.0, 2, 2.0},
stepheight = 0.65,
stepheight = 0.65 + automobiles_lib.extra_stepheight,
visual = "mesh",
mesh = "automobiles_trans_am_body.b3d",
--use_texture_alpha = true,
@ -360,150 +322,47 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
_turn_light_timer = 0,
_inv = nil,
_inv_id = "",
_change_color = paint,
_change_color = trans_am.paint,
_intensity = 4,
_car_gravity = -automobiles_lib.gravity,
--acc control
_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
return minetest.serialize({
stored_owner = self.owner,
stored_hp = self.hp,
stored_color = self._color,
stored_det_color = self._det_color,
stored_steering = self._steering_angle,
stored_energy = self._energy,
--race data
stored_last_checkpoint = self._last_checkpoint,
stored_total_laps = self._total_laps,
stored_race_id = self._race_id,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
stored_trans_am_type = self._trans_am_type,
stored_car_gravity = self._car_gravity,
})
end,
_vehicle_name = "Trans Am",
_painting_load = trans_am.paint,
_drive_wheel_pos = {x=-4.0, y=6.50, z=15.06},
_drive_wheel_angle = 15,
_seat_pos = {{x=-4.0,y=0.8,z=9},{x=4.0,y=0.8,z=9}},
_front_suspension_ent = 'automobiles_trans_am:front_suspension',
_front_suspension_pos = {x=0,y=1.5,z=27.0},
_front_wheel_ent = 'automobiles_trans_am:wheel',
_front_wheel_xpos = 9.5,
_front_wheel_frames = {x = 1, y = 49},
_rear_suspension_ent = 'automobiles_trans_am:rear_suspension',
_rear_suspension_pos = {x=0,y=1.5,z=0},
_rear_wheel_ent = 'automobiles_trans_am:wheel',
_rear_wheel_xpos = 9.5,
_rear_wheel_frames = {x = 1, y = 49},
_fuel_gauge_pos = {x=-4,y=6.8,z=16.6},
_front_lights = 'automobiles_trans_am:f_lights',
_rear_lights = 'automobiles_trans_am:r_lights',
_reverse_lights = 'automobiles_trans_am:reverse_lights',
_turn_left_lights = 'automobiles_trans_am:turn_left_light',
_turn_right_lights = 'automobiles_trans_am:turn_right_light',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
end,
on_activate = function(self, staticdata, dtime_s)
if staticdata ~= "" and staticdata ~= nil then
local data = minetest.deserialize(staticdata) or {}
self.owner = data.stored_owner
self.hp = data.stored_hp
self._color = data.stored_color
self._det_color = data.stored_det_color
self._steering_angle = data.stored_steering
self._energy = data.stored_energy
--minetest.debug("loaded: ", self.energy)
--race data
self._last_checkpoint = data.stored_last_checkpoint
self._total_laps = data.stored_total_laps
self._race_id = data.stored_race_id
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
self._trans_am_type = data.stored_trans_am_type
self._car_gravity = data.stored_car_gravity or -automobiles_lib.gravity
automobiles_lib.setText(self, "Trans Am")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
paint(self, self._color)
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_trans_am:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=1.5,z=27.0},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_trans_am:wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-trans_am.front_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_trans_am:wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=trans_am.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_trans_am:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=1.5,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_trans_am:wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-trans_am.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_trans_am:wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=trans_am.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rr_wheel = rr_wheel
self.object:set_bone_position("drive_adjust", {x=-4.0, y=6.50, z=15.06}, {x=15, y=0, z=0})
local driver_seat=minetest.add_entity(pos,'automobiles_trans_am:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.0,y=0.8,z=9},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_trans_am:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.0,y=0.8,z=9},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_trans_am:pointer')
fuel_gauge:set_attach(self.object,'',trans_am_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_trans_am:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
local r_lights = minetest.add_entity(pos,'automobiles_trans_am:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
local reverse_lights = minetest.add_entity(pos,'automobiles_trans_am:reverse_lights')
reverse_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.reverse_lights = reverse_lights
self.reverse_lights:set_properties({is_visible=true})
local turn_l_light = minetest.add_entity(pos,'automobiles_trans_am:turn_left_light')
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
local turn_r_light = minetest.add_entity(pos,'automobiles_trans_am:turn_right_light')
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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, trans_am.trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -653,10 +512,10 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
--whell turn
if self.lf_wheel and self.rf_wheel and self.lr_wheel and self.rr_wheel then
self.lf_wheel:set_attach(self.front_suspension,'',{x=-trans_am.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=trans_am.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-trans_am.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=trans_am.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
end
--check if the tyres is touching the pavement
@ -752,13 +611,13 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
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
trans_am.engine_set_sound_and_animation(self, longit_speed)
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
end
end
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
if self.fuel_gauge then
self.fuel_gauge:set_attach(self.object,'',trans_am_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
end
----------------------------
-- end energy consumption --
@ -774,7 +633,8 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
if stop ~= true then
--self.object:set_velocity(velocity)
self.object:set_acceleration(accel)
self.object:add_velocity(vector.multiply(accel,dtime))
--self.object:set_acceleration(accel)
else
if stop == true then
self.object:set_acceleration({x=0,y=0,z=0})
@ -798,121 +658,8 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
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, 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,
on_punch = automobiles_lib.on_punch,
on_rightclick = automobiles_lib.on_rightclick,
})

View File

@ -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)

View File

@ -7,23 +7,13 @@ trans_am.LATER_DRAG_FACTOR = 6.0
trans_am.gravity = automobiles_lib.gravity
trans_am.max_speed = 40
trans_am.max_acc_factor = 12
trans_am.max_fuel = 10
trans_am.trunk_slots = 12
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.front_wheel_xpos = 9.5
trans_am.rear_wheel_xpos = 9.5
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.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 .. "control.lua")
dofile(minetest.get_modpath("automobiles_trans_am") .. DIR_DELIM .. "utilities.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")

View File

@ -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

View File

@ -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,10 @@ 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_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")

View File

@ -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

View File

@ -98,7 +98,7 @@ minetest.register_entity("automobiles_vespa:vespa", {
collide_with_objects = true,
collisionbox = {-0.1, -0.24, -0.1, 0.1, 1, 0.1},
selectionbox = {-1, 1, -1, 1, -1, 1},
stepheight = 0.8,
stepheight = 0.8 + automobiles_lib.extra_stepheight,
visual = "mesh",
mesh = "automobiles_vespa_body.b3d",
--use_texture_alpha = true,
@ -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
@ -437,12 +447,13 @@ minetest.register_entity("automobiles_vespa:vespa", {
if stop ~= true then
--self.object:set_velocity(velocity)
self.object:set_acceleration(accel)
self.object:add_velocity(vector.multiply(accel,dtime))
--self.object:set_acceleration(accel)
else
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 +482,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,
})

View File

@ -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

View File

@ -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