mirror of
https://github.com/APercy/automobiles_pck
synced 2025-06-15 13:28:02 +02:00
found and fixed the vespa shaking bug after the 5.9.1. And a complete refactory for the vespa
This commit is contained in:
parent
83b7aa7dca
commit
7153935a4a
@ -5,9 +5,9 @@ automobiles_lib.vector_up = vector.new(0, 1, 0)
|
||||
function automobiles_lib.check_road_is_ok(obj, max_acc_factor)
|
||||
local pos_below = obj:get_pos()
|
||||
pos_below.y = pos_below.y - 0.1
|
||||
local node_below = minetest.get_node(pos_below).name
|
||||
--minetest.chat_send_all(node_below)
|
||||
local nodedef = minetest.registered_nodes[node_below]
|
||||
local node_below = core.get_node(pos_below).name
|
||||
--core.chat_send_all(node_below)
|
||||
local nodedef = core.registered_nodes[node_below]
|
||||
if nodedef.liquidtype == "none" then
|
||||
local slow_nodes = {
|
||||
['default:ice '] = 0.01,
|
||||
@ -37,18 +37,27 @@ function automobiles_lib.set_yaw_by_mouse(self, dir, steering_limit)
|
||||
local command = (rot_y - dir) * intensity
|
||||
if command < -90 then command = -90
|
||||
elseif command > 90 then command = 90 end
|
||||
--minetest.chat_send_all("rotation y: "..rot_y.." - dir: "..dir.." - command: "..(rot_y - dir))
|
||||
--core.chat_send_all("rotation y: "..rot_y.." - dir: "..dir.." - command: "..(rot_y - dir))
|
||||
|
||||
--minetest.chat_send_all("rotation y: "..rot_y.." - dir: "..dir.." - command: "..command)
|
||||
--core.chat_send_all("rotation y: "..rot_y.." - dir: "..dir.." - command: "..command)
|
||||
|
||||
return (-command * steering_limit)/90
|
||||
end
|
||||
|
||||
function automobiles_lib.control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, max_acc_factor, max_speed, steering_limit, steering_speed)
|
||||
self._last_time_command = self._last_time_command + dtime
|
||||
hull_direction = hull_direction or 0
|
||||
longit_speed = longit_speed or 0
|
||||
longit_drag = longit_drag or 0
|
||||
later_drag = later_drag or 0
|
||||
max_acc_factor = max_acc_factor or 0
|
||||
max_speed = max_speed or 0
|
||||
steering_limit = steering_limit or 0
|
||||
steering_speed = steering_speed or 0
|
||||
|
||||
if self._last_time_command > 1 then self._last_time_command = 1 end
|
||||
|
||||
local player = minetest.get_player_by_name(self.driver_name)
|
||||
local player = core.get_player_by_name(self.driver_name)
|
||||
local retval_accel = accel;
|
||||
local stop = false
|
||||
|
||||
@ -61,7 +70,7 @@ function automobiles_lib.control(self, dtime, hull_direction, longit_speed, long
|
||||
if longit_speed < max_speed and ctrl.up then
|
||||
--get acceleration factor
|
||||
acc = automobiles_lib.check_road_is_ok(self.object, max_acc_factor)
|
||||
--minetest.chat_send_all('engineacc: '.. engineacc)
|
||||
--core.chat_send_all('engineacc: '.. engineacc)
|
||||
if acc > 1 and acc < max_acc_factor and longit_speed > 0 then
|
||||
--improper road will reduce speed
|
||||
acc = -1
|
||||
@ -111,7 +120,7 @@ function automobiles_lib.control(self, dtime, hull_direction, longit_speed, long
|
||||
self._engine_running = false
|
||||
-- sound and animation
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
core.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
--self.engine:set_animation_frame_speed(0)
|
||||
@ -119,7 +128,7 @@ function automobiles_lib.control(self, dtime, hull_direction, longit_speed, long
|
||||
elseif self._engine_running == false and self._energy > 0 then
|
||||
self._engine_running = true
|
||||
-- sound and animation
|
||||
self.sound_handle = minetest.sound_play({name = "engine"},
|
||||
self.sound_handle = core.sound_play({name = "engine"},
|
||||
{object = self.object, gain = 2.0, pitch = 1.0, max_hear_distance = 32, loop = true,})
|
||||
--self.engine:set_animation_frame_speed(30)
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ initial_properties = {
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_pivot_mesh.b3d",
|
||||
textures = {"automobiles_black.png",},
|
||||
textures = {"automobiles_alpha.png",},
|
||||
},
|
||||
|
||||
on_activate = function(self,std)
|
||||
@ -237,33 +237,37 @@ function automobiles_lib.on_activate(self, staticdata, dtime_s)
|
||||
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
|
||||
if self._front_wheel_ent then
|
||||
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 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
|
||||
end
|
||||
|
||||
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
|
||||
if self._rear_wheel_ent then
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
if self._steering_ent then
|
||||
@ -293,19 +297,13 @@ function automobiles_lib.on_activate(self, staticdata, dtime_s)
|
||||
|
||||
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._gauge_pointer_ent then
|
||||
pointer_entity = self._gauge_pointer_ent
|
||||
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
|
||||
end
|
||||
|
||||
if self._front_lights then
|
||||
local lights = minetest.add_entity(pos,self._front_lights)
|
||||
@ -368,6 +366,9 @@ function automobiles_lib.on_step(self, dtime)
|
||||
if self._last_time_drift_snd > 2.0 then self._last_time_drift_snd = 2.0 end
|
||||
--[[end sound control]]--
|
||||
|
||||
--in case it's not declared
|
||||
self._max_acc_factor = self._max_acc_factor or 1
|
||||
|
||||
local rotation = self.object:get_rotation()
|
||||
local yaw = rotation.y
|
||||
local newyaw=yaw
|
||||
@ -432,7 +433,7 @@ function automobiles_lib.on_step(self, dtime)
|
||||
self._setmode(self, is_attached, curr_pos, velocity, player, dtime)
|
||||
end
|
||||
|
||||
local is_breaking = false
|
||||
local is_braking = false
|
||||
if is_attached then
|
||||
local ctrl = player:get_player_control()
|
||||
if ctrl.jump then
|
||||
@ -449,7 +450,7 @@ function automobiles_lib.on_step(self, dtime)
|
||||
end
|
||||
end
|
||||
if ctrl.down then
|
||||
is_breaking = true
|
||||
is_braking = true
|
||||
if self.r_lights then self.r_lights:set_properties({textures={"automobiles_rear_lights_full.png"}, glow=15}) end
|
||||
end
|
||||
if self.reverse_lights then
|
||||
@ -468,14 +469,14 @@ function automobiles_lib.on_step(self, dtime)
|
||||
if self._show_lights == true then
|
||||
--self.lights:set_properties({is_visible=true})
|
||||
self.lights:set_properties({textures={"automobiles_front_lights.png"}, glow=15})
|
||||
if is_breaking == false then
|
||||
if is_braking == false then
|
||||
if self.r_lights then self.r_lights:set_properties({textures={"automobiles_rear_lights.png"}, glow=10}) end
|
||||
end
|
||||
automobiles_lib.put_light(self)
|
||||
else
|
||||
--self.lights:set_properties({is_visible=false})
|
||||
self.lights:set_properties({textures={"automobiles_grey.png"}, glow=0})
|
||||
if is_breaking == false then
|
||||
if is_braking == false then
|
||||
if self.r_lights then self.r_lights:set_properties({textures={"automobiles_rear_lights_off.png"}, glow=0}) end
|
||||
end
|
||||
automobiles_lib.remove_light(self)
|
||||
@ -518,14 +519,17 @@ function automobiles_lib.on_step(self, dtime)
|
||||
local transmission_state = automobiles_lib.get_transmission_state(longit_speed, self._max_speed)
|
||||
|
||||
local target_acc_factor = acc_factor
|
||||
if transmission_state == 1 then
|
||||
target_acc_factor = (self._max_acc_factor/3)
|
||||
|
||||
if self._have_transmission ~= false then
|
||||
if transmission_state == 1 then
|
||||
target_acc_factor = (self._max_acc_factor/3)
|
||||
end
|
||||
if transmission_state == 2 then
|
||||
target_acc_factor = (self._max_acc_factor/2)
|
||||
end
|
||||
self._transmission_state = transmission_state
|
||||
end
|
||||
if transmission_state == 2 then
|
||||
target_acc_factor = (self._max_acc_factor/2)
|
||||
end
|
||||
self._transmission_state = transmission_state
|
||||
--minetest.chat_send_all(transmission_state)
|
||||
--core.chat_send_all(transmission_state)
|
||||
|
||||
--control
|
||||
local control = automobiles_lib.control
|
||||
@ -557,7 +561,7 @@ function automobiles_lib.on_step(self, dtime)
|
||||
if noded.drawtype ~= 'liquid' then
|
||||
local min_later_speed = self._min_later_speed or 3
|
||||
local speed_for_smoke = min_later_speed / 2
|
||||
if (later_speed > speed_for_smoke or later_speed < -speed_for_smoke) then
|
||||
if (later_speed > speed_for_smoke or later_speed < -speed_for_smoke) and not self._is_motorcycle then
|
||||
automobiles_lib.add_smoke(curr_pos, yaw, self._rear_wheel_xpos)
|
||||
if automobiles_lib.extra_drift == false then --disables the sound when playing drift game.. it's annoying
|
||||
if self._last_time_drift_snd >= 2.0 and (later_speed > min_later_speed or later_speed < -min_later_speed) then
|
||||
@ -658,8 +662,11 @@ function automobiles_lib.on_step(self, dtime)
|
||||
if self._energy <= 0 then
|
||||
self._engine_running = false
|
||||
self._is_flying = 0
|
||||
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
||||
--minetest.chat_send_player(self.driver_name, "Out of fuel")
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
minetest.chat_send_player(self.driver_name, "Out of fuel")
|
||||
end
|
||||
else
|
||||
self._last_engine_sound_update = self._last_engine_sound_update + dtime
|
||||
if self._last_engine_sound_update > 0.300 then
|
||||
@ -715,6 +722,12 @@ function automobiles_lib.on_step(self, dtime)
|
||||
if h_vel_compensation < 0 then h_vel_compensation = 0 end
|
||||
if h_vel_compensation > max_pitch then h_vel_compensation = max_pitch end
|
||||
newpitch = newpitch + (velocity.y * math.rad(max_pitch - h_vel_compensation))
|
||||
else
|
||||
if self._is_motorcycle then
|
||||
local turn_effect_speed = longit_speed
|
||||
if turn_effect_speed > 10 then turn_effect_speed = 10 end
|
||||
newroll = (-self._steering_angle/100)*(turn_effect_speed/10)
|
||||
end
|
||||
end
|
||||
|
||||
self.object:set_rotation({x=newpitch,y=newyaw,z=newroll})
|
||||
|
@ -48,7 +48,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
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
|
||||
if ent._dettach_pax then dettach_pax_f = ent._dettach_pax end
|
||||
dettach_pax_f(ent, pax_obj)
|
||||
end
|
||||
ent._is_flying = 0
|
||||
|
@ -682,6 +682,7 @@ end
|
||||
-- very basic transmission emulation for the car
|
||||
function automobiles_lib.get_transmission_state(curr_speed, max_speed)
|
||||
local retVal = 1
|
||||
max_speed = max_speed or 100
|
||||
if curr_speed >= (max_speed/4) then retVal = 2 end
|
||||
if curr_speed >= (max_speed/2) then retVal = 3 end
|
||||
return retVal
|
||||
|
@ -2,14 +2,7 @@
|
||||
-- constants
|
||||
--
|
||||
vespa={}
|
||||
vespa._LONGIT_DRAG_FACTOR = 0.15*0.15
|
||||
vespa._LATER_DRAG_FACTOR = 30.0
|
||||
vespa.gravity = automobiles_lib.gravity
|
||||
vespa.max_speed = 20
|
||||
vespa.max_acc_factor = 6
|
||||
|
||||
vespa.front_wheel_xpos = 0
|
||||
vespa.rear_wheel_xpos = 0
|
||||
|
||||
vespa.S = nil
|
||||
|
||||
@ -27,10 +20,7 @@ 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_crafts.lua")
|
||||
|
||||
|
||||
|
0
automobiles_vespa/vespa_crafts.lua
Normal file → Executable file
0
automobiles_vespa/vespa_crafts.lua
Normal file → Executable file
@ -1,7 +1,56 @@
|
||||
--
|
||||
-- entity
|
||||
--
|
||||
local S = vespa.S
|
||||
|
||||
|
||||
minetest.register_entity('automobiles_vespa:front_suspension',{
|
||||
initial_properties = {
|
||||
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",
|
||||
textures = {"automobiles_alpha.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,
|
||||
|
||||
--[[on_step = function(self, dtime, moveresult)
|
||||
minetest.chat_send_all(dump(moveresult))
|
||||
end,]]--
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_vespa:rear_suspension',{
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
collide_with_objects=true,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_pivot_mesh.b3d",
|
||||
textures = {"automobiles_alpha.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_vespa:lights',{
|
||||
initial_properties = {
|
||||
@ -49,57 +98,13 @@ initial_properties = {
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_vespa: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_vespa: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_vespa:vespa", {
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
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 + automobiles_lib.extra_stepheight,
|
||||
selectionbox = {-1.0, 0.0, -1.0, 1.0, 1, 1.0},
|
||||
stepheight = 0.65 + automobiles_lib.extra_stepheight,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_vespa_body.b3d",
|
||||
--use_texture_alpha = true,
|
||||
@ -121,7 +126,7 @@ minetest.register_entity("automobiles_vespa:vespa", {
|
||||
sound_handle = nil,
|
||||
owner = "",
|
||||
static_save = true,
|
||||
infotext = S("A very nice vespa!"),
|
||||
infotext = "A very nice vespa!",
|
||||
hp = 50,
|
||||
buoyancy = 2,
|
||||
physics = automobiles_lib.physics,
|
||||
@ -141,136 +146,87 @@ minetest.register_entity("automobiles_vespa:vespa", {
|
||||
_roll = math.rad(0),
|
||||
_pitch = 0,
|
||||
_longit_speed = 0,
|
||||
_show_rag = false,
|
||||
_show_lights = false,
|
||||
_light_old_pos = nil,
|
||||
_last_ground_check = 0,
|
||||
_last_light_move = 0,
|
||||
_last_engine_sound_update = 0,
|
||||
_turn_light_timer = 0,
|
||||
_inv = nil,
|
||||
_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,
|
||||
_base_pitch = 0.7,
|
||||
|
||||
_vehicle_name = "Vespa",
|
||||
_drive_wheel_pos = {x=-4.26,y=6.01,z=14.18},
|
||||
_drive_wheel_angle = 15,
|
||||
_seat_pos = {{x=0.0,y=-1.1,z=5.5},{x=0.0,y=1,z=0.09}},
|
||||
--_seat_pos = {{x=-4.25,y=-1.1,z=5.5},{x=4.25,y=1,z=5.5}},
|
||||
|
||||
_front_suspension_ent = 'automobiles_coupe:front_suspension',
|
||||
_front_suspension_pos = {x=0,y=1.5,z=14.5},
|
||||
--_front_wheel_ent = 'automobiles_lib:wheel',
|
||||
_front_wheel_xpos = 0,
|
||||
_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 = 0,
|
||||
_rear_wheel_frames = {x = 1, y = 49},
|
||||
|
||||
--_fuel_gauge_pos = {x=0,y=6.2,z=15.8},
|
||||
_front_lights = 'automobiles_vespa:lights',
|
||||
_rear_lights = 'automobiles_vespa:r_lights',
|
||||
--_reverse_lights = 'automobiles_coupe:reverse_lights',
|
||||
--_turn_left_lights = 'automobiles_coupe:turn_left_light',
|
||||
--_turn_right_lights = 'automobiles_coupe:turn_right_light',
|
||||
--_textures_turn_lights_off = {"automobiles_turn.png", },
|
||||
--_textures_turn_lights_on = { "automobiles_turn_on.png", },
|
||||
|
||||
_LONGIT_DRAG_FACTOR = 0.15*0.15,
|
||||
_LATER_DRAG_FACTOR = 50.0,
|
||||
_max_acc_factor = 6,
|
||||
_max_speed = 15,
|
||||
_min_later_speed = 5,
|
||||
_have_transmission = false,
|
||||
_is_motorcycle = true,
|
||||
|
||||
_attach = vespa.attach_driver_stand,
|
||||
_dettach = vespa.dettach_driver_stand,
|
||||
_attach_pax = vespa.attach_pax_stand,
|
||||
_dettach_pax = vespa.dettach_pax_stand,
|
||||
_LONGIT_DRAG_FACTOR = vespa._LONGIT_DRAG_FACTOR,
|
||||
_LATER_DRAG_FACTOR = vespa._LATER_DRAG_FACTOR,
|
||||
_formspec_function = vespa.driver_formspec,
|
||||
|
||||
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,
|
||||
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, "vespa")
|
||||
end
|
||||
|
||||
self.object:set_animation({x = 1, y = 41}, 0, 0, true)
|
||||
|
||||
automobiles_lib.paint(self, self._color)
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
local lights = minetest.add_entity(pos,'automobiles_vespa: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 rlights = minetest.add_entity(pos,'automobiles_vespa:r_lights')
|
||||
rlights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
self.rlights = rlights
|
||||
self.rlights:set_properties({is_visible=true})
|
||||
|
||||
local driver_seat=minetest.add_entity(pos,'automobiles_vespa:pivot_mesh')
|
||||
driver_seat:set_attach(self.object,'',{x=0.0,y=-1.1,z=5.5},{x=0,y=0,z=0})
|
||||
self.driver_seat = driver_seat
|
||||
|
||||
local passenger_seat=minetest.add_entity(pos,'automobiles_vespa:pivot_mesh')
|
||||
passenger_seat:set_attach(self.object,'',{x=0.0,y=1,z=0.09},{x=0,y=0,z=0})
|
||||
self.passenger_seat = passenger_seat
|
||||
|
||||
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
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
automobiles_lib.on_activate(self, staticdata, dtime_s)
|
||||
|
||||
self.object:set_bone_position("guidao", {x=0, y=0, z=14}, {x=22, y=180, z=0})
|
||||
self.lights:set_bone_position("guidao", {x=0, y=0, z=14}, {x=22, y=180, z=0})
|
||||
|
||||
automobiles_lib.actfunc(self, staticdata, dtime_s)
|
||||
end,
|
||||
self.object:set_animation(self._rear_wheel_frames, 0, 0, true)
|
||||
end,
|
||||
|
||||
on_step = function(self, dtime)
|
||||
automobiles_lib.stepfunc(self, dtime)
|
||||
--[[sound play control]]--
|
||||
self._last_time_collision_snd = self._last_time_collision_snd + dtime
|
||||
if self._last_time_collision_snd > 1 then self._last_time_collision_snd = 1 end
|
||||
--[[end sound control]]--
|
||||
automobiles_lib.on_step(self, dtime)
|
||||
|
||||
local rotation = self.object:get_rotation()
|
||||
local yaw = rotation.y
|
||||
local newyaw=yaw
|
||||
local pitch = rotation.x
|
||||
|
||||
local hull_direction = minetest.yaw_to_dir(yaw)
|
||||
local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector
|
||||
local velocity = self.object:get_velocity()
|
||||
|
||||
local longit_speed = automobiles_lib.dot(velocity,hull_direction)
|
||||
local fuel_weight_factor = (5 - self._energy)/5000
|
||||
local longit_drag = vector.multiply(hull_direction,(longit_speed*longit_speed) *
|
||||
(vespa._LONGIT_DRAG_FACTOR - fuel_weight_factor) * -1 * automobiles_lib.sign(longit_speed))
|
||||
|
||||
local later_speed = automobiles_lib.dot(velocity,nhdir)
|
||||
local later_drag = vector.multiply(nhdir,later_speed*
|
||||
later_speed*vespa._LATER_DRAG_FACTOR*-1*automobiles_lib.sign(later_speed))
|
||||
|
||||
local accel = vector.add(longit_drag,later_drag)
|
||||
local stop = nil
|
||||
local angle_factor = self._steering_angle / 10
|
||||
local anim_speed = self._longit_speed * (15 - angle_factor)
|
||||
--core.chat_send_all(dump(anim_speed))
|
||||
self.object:set_animation_frame_speed(anim_speed)
|
||||
--whell turn
|
||||
self.object:set_bone_position("eixo_direcao", {x=0, y=0, z=0}, {x=0, y=-self._steering_angle-angle_factor, z=0})
|
||||
self.lights:set_bone_position("eixo_direcao", {x=0, y=0, z=0}, {x=0, y=-self._steering_angle-angle_factor, z=0})
|
||||
|
||||
local player = nil
|
||||
local is_attached = false
|
||||
@ -287,211 +243,16 @@ minetest.register_entity("automobiles_vespa:vespa", {
|
||||
end
|
||||
end
|
||||
|
||||
local is_breaking = false
|
||||
if is_attached then
|
||||
local ctrl = player:get_player_control()
|
||||
if ctrl.aux1 then
|
||||
--sets the engine running - but sets a delay also, cause keypress
|
||||
if self._last_time_command > 0.8 then
|
||||
self._last_time_command = 0
|
||||
--[[minetest.sound_play({name = "automobiles_horn"},
|
||||
{object = self.object, gain = 0.6, pitch = 1.0, max_hear_distance = 32, loop = false,})]]--
|
||||
end
|
||||
end
|
||||
if ctrl.down then
|
||||
is_breaking = true
|
||||
self.lights:set_properties({textures={"automobiles_vespa_lights.png",}, glow=32})
|
||||
self.rlights:set_properties({textures={"automobiles_vespa_rear_lights_full.png",}, glow=32})
|
||||
end
|
||||
|
||||
else
|
||||
--desligado
|
||||
self.lights:set_properties({textures={"automobiles_grey.png",}, glow=0})
|
||||
self.rlights:set_properties({textures={"automobiles_rear_lights_off.png",}, glow=0})
|
||||
end
|
||||
|
||||
self._last_light_move = self._last_light_move + dtime
|
||||
if self._last_light_move > 0.15 then
|
||||
self._last_light_move = 0
|
||||
if self._show_lights == true then
|
||||
--self.lights:set_properties({is_visible=true})
|
||||
self.lights:set_properties({textures={"automobiles_vespa_lights.png",}, glow=32})
|
||||
self.rlights:set_properties({textures={"automobiles_vespa_rear_lights_full.png",}, glow=32})
|
||||
if is_breaking == false then
|
||||
self.lights:set_properties({textures={"automobiles_vespa_lights.png",}, glow=32})
|
||||
self.rlights:set_properties({textures={"automobiles_vespa_rear_lights_full.png",}, glow=10})
|
||||
end
|
||||
|
||||
--turn the light on just when needed to avoid lag
|
||||
local target_pos = self.object:get_pos()
|
||||
target_pos.y = target_pos.y + 2
|
||||
local light_now = minetest.get_node_light(target_pos)
|
||||
if light_now < 12 then
|
||||
automobiles_lib.put_light(self)
|
||||
end
|
||||
else
|
||||
if is_breaking == false then
|
||||
--desligado
|
||||
self.lights:set_properties({textures={"automobiles_grey.png",}, glow=0})
|
||||
self.rlights:set_properties({textures={"automobiles_rear_lights_off.png",}, glow=0})
|
||||
end
|
||||
automobiles_lib.remove_light(self)
|
||||
end
|
||||
end
|
||||
|
||||
local curr_pos = self.object:get_pos()
|
||||
local steering_angle_max = 30
|
||||
self.object:move_to(curr_pos)
|
||||
if is_attached then --and self.driver_name == self.owner then
|
||||
self._show_lights = true
|
||||
if self.driver_mesh then self.driver_mesh:set_properties({is_visible=true}) end
|
||||
local impact = automobiles_lib.get_hipotenuse_value(velocity, self.lastvelocity)
|
||||
if impact > 1 then
|
||||
--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", {
|
||||
to_player = self.driver_name,
|
||||
--pos = curr_pos,
|
||||
--max_hear_distance = 5,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
})
|
||||
end
|
||||
--[[if self.damage > 100 then --if acumulated damage is greater than 100, adieu
|
||||
automobiles_lib.destroy(self)
|
||||
end]]--
|
||||
end
|
||||
|
||||
--control
|
||||
local steering_speed = 80
|
||||
if math.abs(longit_speed) > 3 then
|
||||
local mid_speed = (steering_speed/2)
|
||||
steering_speed = mid_speed + mid_speed / math.abs(longit_speed*0.25)
|
||||
end
|
||||
|
||||
local control = automobiles_lib.control
|
||||
if self._control_function then
|
||||
control = self._control_function
|
||||
end
|
||||
accel, stop = control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, motorcycle.max_acc_factor, motorcycle.max_speed, steering_angle_max, steering_speed)
|
||||
else
|
||||
if self.driver_mesh then self.driver_mesh:set_properties({is_visible=false}) end
|
||||
self._show_lights = false
|
||||
if self.sound_handle ~= nil then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
end
|
||||
|
||||
local angle_factor = self._steering_angle / 10
|
||||
self.object:set_animation_frame_speed(longit_speed * (15 - angle_factor))
|
||||
|
||||
--whell turn
|
||||
self.object:set_bone_position("eixo_direcao", {x=0, y=0, z=0}, {x=0, y=-self._steering_angle-angle_factor, z=0})
|
||||
self.lights:set_bone_position("eixo_direcao", {x=0, y=0, z=0}, {x=0, y=-self._steering_angle-angle_factor, z=0})
|
||||
|
||||
if player then
|
||||
-- -30 direita -> steering_angle_max
|
||||
-- +30 esquerda
|
||||
local arm_range = 2
|
||||
local range = steering_angle_max * 2
|
||||
local armZ = -((self._steering_angle+steering_angle_max) * arm_range) / 60
|
||||
|
||||
--player:set_bone_position("Arm_Left", {x=3.0, y=5, z=-arm_range-armZ}, {x=240-(self._steering_angle/2), y=0, z=0})
|
||||
--player:set_bone_position("Arm_Right", {x=-3.0, y=5, z=armZ}, {x=240+(self._steering_angle/2), y=0, z=0})
|
||||
if self.driver_mesh then
|
||||
self.driver_mesh:set_bone_position("Arm_Left", {x=3.0, y=5, z=-armZ-0.5}, {x=76-(self._steering_angle/2), y=0, z=0})
|
||||
self.driver_mesh:set_bone_position("Arm_Right", {x=-3.0, y=5, z=armZ+1.5}, {x=76+(self._steering_angle/2), y=0, z=0})
|
||||
end
|
||||
end
|
||||
|
||||
if math.abs(self._steering_angle)>5 then
|
||||
local turn_rate = math.rad(40)
|
||||
newyaw = yaw + dtime*(1 - 1 / (math.abs(longit_speed) + 1)) *
|
||||
self._steering_angle / 20 * turn_rate * automobiles_lib.sign(longit_speed)
|
||||
end
|
||||
|
||||
--[[
|
||||
accell correction
|
||||
under some circunstances the acceleration exceeds the max value accepted by set_acceleration and
|
||||
the game crashes with an overflow, so limiting the max acceleration in each axis prevents the crash
|
||||
]]--
|
||||
local max_factor = 25
|
||||
local acc_adjusted = 10
|
||||
if accel.x > max_factor then accel.x = acc_adjusted end
|
||||
if accel.x < -max_factor then accel.x = -acc_adjusted end
|
||||
if accel.z > max_factor then accel.z = acc_adjusted end
|
||||
if accel.z < -max_factor then accel.z = -acc_adjusted end
|
||||
-- end correction
|
||||
|
||||
-- calculate energy consumption --
|
||||
----------------------------------
|
||||
if self._energy > 0 then
|
||||
local zero_reference = vector.new()
|
||||
local acceleration = automobiles_lib.get_hipotenuse_value(accel, zero_reference)
|
||||
--minetest.chat_send_all(acceleration)
|
||||
local consumed_power = acceleration/150000
|
||||
self._energy = self._energy - consumed_power;
|
||||
end
|
||||
if self._energy <= 0 then
|
||||
self._engine_running = false
|
||||
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
||||
minetest.chat_send_player(self.driver_name, S("Out of fuel"))
|
||||
else
|
||||
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
|
||||
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
|
||||
end
|
||||
end
|
||||
|
||||
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
|
||||
----------------------------
|
||||
-- end energy consumption --
|
||||
|
||||
accel.y = -automobiles_lib.gravity
|
||||
|
||||
if stop ~= true then
|
||||
--self.object:set_velocity(velocity)
|
||||
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 automobiles_lib.engineSoundPlay(self) end
|
||||
end
|
||||
end
|
||||
|
||||
self._last_ground_check = self._last_ground_check + dtime
|
||||
if self._last_ground_check > 0.18 then
|
||||
self._last_ground_check = 0
|
||||
automobiles_lib.ground_get_distances(self, 0.6, 1.63)
|
||||
end
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
local turn_effect_speed = longit_speed
|
||||
if turn_effect_speed > 10 then turn_effect_speed = 10 end
|
||||
local newroll = (-self._steering_angle/100)*(turn_effect_speed/10)
|
||||
|
||||
if is_attached == false then
|
||||
self.object:set_bone_position("descanso", {x=0, y=-0.4, z=6.2}, {x=-90, y=0, z=0})
|
||||
else
|
||||
self.object:set_bone_position("descanso", {x=0, y=-0.4, z=6.2}, {x=0, y=0, z=0})
|
||||
end
|
||||
|
||||
self.object:set_rotation({x=newpitch,y=newyaw,z=newroll})
|
||||
|
||||
--saves last velocity for collision detection (abrupt stop)
|
||||
self.lastvelocity = self.object:get_velocity()
|
||||
self._longit_speed = longit_speed
|
||||
|
||||
end,
|
||||
end,
|
||||
|
||||
on_punch = automobiles_lib.on_punch,
|
||||
on_rightclick = automobiles_lib.on_rightclick,
|
||||
on_rightclick = automobiles_lib.on_rightclick,
|
||||
})
|
||||
|
||||
|
||||
|
@ -1,52 +0,0 @@
|
||||
local S = vespa.S
|
||||
|
||||
function vespa.driver_formspec(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local vehicle_obj = automobiles_lib.getCarFromPlayer(player)
|
||||
if vehicle_obj == nil then
|
||||
return
|
||||
end
|
||||
local ent = vehicle_obj:get_luaentity()
|
||||
|
||||
local basic_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[6,6]",
|
||||
}, "")
|
||||
|
||||
local yaw = "false"
|
||||
if ent._yaw_by_mouse then yaw = "true" end
|
||||
|
||||
basic_form = basic_form.."button[1,1.0;4,1;go_out;" .. S("Go Offboard") .. "]"
|
||||
basic_form = basic_form.."checkbox[1,3.0;yaw;" .. S("Direction by mouse") .. ";"..yaw.."]"
|
||||
|
||||
minetest.show_formspec(name, "vespa:driver_main", basic_form)
|
||||
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 = 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)
|
||||
vespa.dettach_pax_stand(ent, pax_obj)
|
||||
end
|
||||
|
||||
vespa.dettach_driver_stand(ent, player)
|
||||
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, "vespa:driver_main")
|
||||
end
|
||||
end)
|
@ -34,7 +34,8 @@ function vespa.attach_driver_stand(self, player)
|
||||
--minetest.chat_send_all(dump(self.driver_properties))
|
||||
|
||||
-- attach the driver
|
||||
player:set_attach(self.driver_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
local x_pos = -4 --WHY?! because after the 5.9.1 version the motorcycle got an strange shaking. But when I move it from the center, it ceases. Then I use the camera center bug.
|
||||
player:set_attach(self.driver_seat, "", {x = x_pos, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player:set_eye_offset({x = 0, y = 0, z = 1.5}, {x = 0, y = 3, z = -30})
|
||||
player_api.player_attached[name] = true
|
||||
|
||||
@ -45,7 +46,7 @@ function vespa.attach_driver_stand(self, player)
|
||||
--create the dummy mesh
|
||||
local pos = player:get_pos()
|
||||
local driver_mesh=minetest.add_entity(pos,'automobiles_vespa:player_mesh')
|
||||
driver_mesh:set_attach(player,'',{x=0.0,y=-0.0,z=0.0},{x=0,y=0,z=0})
|
||||
driver_mesh:set_attach(player,'',{x=4.0,y=-0.0,z=0.0},{x=0,y=0,z=0})
|
||||
self.driver_mesh = driver_mesh
|
||||
self.driver_mesh:set_properties({is_visible=false})
|
||||
|
||||
@ -121,7 +122,7 @@ function vespa.attach_pax_stand(self, player)
|
||||
self._passenger = name
|
||||
|
||||
-- attach the driver
|
||||
player:set_attach(self.passenger_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player:set_attach(self.passenger_seat, "", {x = 4, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player:set_eye_offset({x = 0, y = 3, z = 0}, {x = 0, y = 3, z = -30})
|
||||
player_api.player_attached[name] = true
|
||||
|
||||
@ -131,7 +132,8 @@ function vespa.attach_pax_stand(self, player)
|
||||
--create the dummy mesh
|
||||
local pos = player:get_pos()
|
||||
local pax_mesh=minetest.add_entity(pos,'automobiles_vespa:player_mesh')
|
||||
pax_mesh:set_attach(player,'',{x=0.0,y=-0.0,z=0.0},{x=0,y=0,z=0})
|
||||
local x_pos = -4 --WHY?! because after the 5.9.1 version the motorcycle got an strange shaking. But when I move it from the center, it ceases. Then I use the camera center bug.
|
||||
pax_mesh:set_attach(player,'',{x=x_pos,y=-0.0,z=0.0},{x=0,y=0,z=0})
|
||||
self.pax_mesh = pax_mesh
|
||||
self.pax_mesh:set_properties({is_visible=false})
|
||||
|
||||
|
@ -1,70 +0,0 @@
|
||||
--dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_global_definitions.lua")
|
||||
--dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_hud.lua")
|
||||
|
||||
-- destroy the vespa
|
||||
function vespa.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.driver_seat then self.driver_seat:remove() end
|
||||
if self.passenger_seat then self.passenger_seat:remove() end
|
||||
if self.lights then self.lights:remove() end
|
||||
if self.rlights then self.rlights:remove() end
|
||||
if self.driver_mesh then self.driver_mesh:remove() end
|
||||
if self.pax_mesh then self.pax_mesh:remove() end
|
||||
|
||||
automobiles_lib.destroy_inventory(self)
|
||||
|
||||
pos.y=pos.y+2
|
||||
|
||||
if automobiles_lib.can_collect_car == false then
|
||||
--minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_vespa:vespa')
|
||||
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_vespa:wheel')
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_vespa:wheel')
|
||||
else
|
||||
local lua_ent = self.object:get_luaentity()
|
||||
local staticdata = lua_ent:get_staticdata(self)
|
||||
local obj_name = lua_ent.name
|
||||
local player = puncher
|
||||
|
||||
local stack = ItemStack(obj_name)
|
||||
local stack_meta = stack:get_meta()
|
||||
stack_meta:set_string("staticdata", staticdata)
|
||||
|
||||
if player then
|
||||
local inv = player:get_inventory()
|
||||
if inv then
|
||||
if inv:room_for_item("main", stack) then
|
||||
inv:add_item("main", stack)
|
||||
else
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack)
|
||||
end
|
||||
end
|
||||
else
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack)
|
||||
end
|
||||
end
|
||||
|
||||
self.object:remove()
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user