Skip to content

Commit

Permalink
Beds: Preserve player physics (#2789)
Browse files Browse the repository at this point in the history
  • Loading branch information
appgurueu committed Feb 1, 2021
1 parent ecfebe3 commit 6a9cbca
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mods/beds/functions.lua
Expand Up @@ -61,7 +61,6 @@ local function lay_down(player, pos, bed_pos, state, skip)
-- stand up
if state ~= nil and not state then
local p = beds.pos[name] or nil
beds.player[name] = nil
beds.bed_position[name] = nil
-- skip here to prevent sending player specific changes (used for leaving players)
if skip then
Expand All @@ -72,10 +71,16 @@ local function lay_down(player, pos, bed_pos, state, skip)
end

-- physics, eye_offset, etc
local physics_override = assert(beds.player[name].physics_override)
beds.player[name] = nil
player:set_physics_override({
speed = physics_override.speed,
jump = physics_override.jump,
gravity = physics_override.gravity
})
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
player:set_look_horizontal(math.random(1, 180) / 100)
player_api.player_attached[name] = false
player:set_physics_override({speed = 1, jump = 1, gravity = 1})
hud_flags.wielditem = true
player_api.set_animation(player, "stand" , 30)

Expand All @@ -98,7 +103,7 @@ local function lay_down(player, pos, bed_pos, state, skip)

beds.pos[name] = pos
beds.bed_position[name] = bed_pos
beds.player[name] = 1
beds.player[name] = {physics_override = player:get_physics_override()}

-- physics, eye_offset, etc
player:set_eye_offset({x = 0, y = -13, z = 0}, {x = 0, y = 0, z = 0})
Expand Down

0 comments on commit 6a9cbca

Please sign in to comment.