Various fixes and checks

Fixed 'leaving while on bike' crash, fixed glowing smoke, added setting to enable/disable custom plates
master
Extex101 2020-10-17 10:20:36 -07:00 committed by GitHub
parent 029dbbdc7f
commit 46c677e9d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -44,7 +44,7 @@ function biker.get_plate(name)
AidanLCB = {"LCB-"..randomNumber(3), def_plate(), "Gold-"..randomNumber(3)},
irondude = {"Iron-"..randomNumber(3), def_plate(), "Fox-"..randomNumber(3), "cndl-"..randomNumber(3)},
}
if biker.custom_plates and custom_plates[name] then
if custom_plates[name] and biker.custom_plates then
return custom_plates[name][math.random(#custom_plates[name])]
end
return def_plate()
@ -134,18 +134,18 @@ function biker.dist(v1, v2)
--if v1 - v2 > -math.rad(45) and v1 - v2 < math.rad(45) then return v1 - v2 end
return biker.clamp(-shortAngleDist(v1, v2), math.rad(-55), math.rad(55))
end
local function force_detach(player)
local function force_detach(player, leave)
local attached_to = player:get_attach()
if not player:is_player() then return end
if attached_to then
local entity = attached_to:get_luaentity()
if entity.driver and entity.driver == player then
if entity.driver then
entity.driver = nil
end
local name = player:get_player_name()
player:set_detach()
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
if entity.info then
if entity.info and not leave then
player_api.set_model(player, entity.info.model)
end
end
@ -231,6 +231,7 @@ function biker.drive(entity, dtime)
entity.v = get_v(velo) * get_sign(entity.v)
-- process controls
if entity.driver then
if not entity.driver:is_player() then return end
if entity.v then
local newv = entity.object:getvelocity()
if not entity.crash then entity.crash = false end
@ -253,11 +254,12 @@ function biker.drive(entity, dtime)
if not entity.lastv then
entity.lastv = {x=0,y=0,z=0}
end
local driverlook = entity.driver:get_look_yaw()
local rots = entity.object:get_rotation()
local j = rots.y
local k = rots.x
local newrot = j
local rrot = entity.driver:get_look_yaw() - rot_steer
local rrot = driverlook - rot_steer
local ctrl = entity.driver:get_player_control()
if ctrl.up and not ctrl.sneak then
if get_sign(entity.v) >= 0 then
@ -279,8 +281,8 @@ function biker.drive(entity, dtime)
elseif get_sign(entity.v) > 0 and entity.v > (biker.max_speed/10)-1 then
entity.v = entity.v - biker.braking/10
minetest.sound_play("motorbike_screech", {
max_hear_distance = 48,
gain = 0.5,
max_hear_distance = 45,
gain = 0.2,
object = entity.object,
})
local num = 1
@ -293,7 +295,7 @@ function biker.drive(entity, dtime)
velocity = {x=math.random(-num, num), y=math.random(0, num), z=math.random(-num, num)},
acceleration = {x=math.random(-num, num), y=math.random(0, num), z=math.random(-num, num)},
expirationtime = time,
glow = 20,
--glow = 20,
size = math.random(10, 20),
collisiondetection = false,
vertical = false,
@ -450,7 +452,7 @@ function biker.drive(entity, dtime)
end
minetest.register_on_leaveplayer(function(player)
biker.detach(player)
force_detach(player, true)
end)
minetest.register_on_dieplayer(function(player)
biker.detach(player)