Fix sitting code

master
random-geek 2018-10-27 22:27:50 -07:00
parent 3138927900
commit 6a80c34d51
5 changed files with 38 additions and 69 deletions

View File

@ -1,10 +1,10 @@
function ma_pops_furniture.sit(pos, node, clicker)
local meta = minetest.get_meta(pos)
local param2 = node.param2
local sitting = meta:get_string("is_sit")
local name = clicker:get_player_name()
if name == meta:get_string("is_sit") then
print 'player should be standing.'
if sitting == name then
meta:set_string("is_sit", "")
pos.y = pos.y-0.5
clicker:setpos(pos)
@ -12,12 +12,11 @@ function ma_pops_furniture.sit(pos, node, clicker)
clicker:set_physics_override(1, 1, 1)
default.player_attached[name] = false
default.player_set_animation(clicker, "stand", 30)
else
elseif sitting == "" and not default.player_attached[name] then
meta:set_string("is_sit", clicker:get_player_name())
print 'player should be sitting.'
clicker:setpos(pos)
clicker:set_eye_offset({x=0,y=-7,z=2}, {x=0,y=0,z=0})
clicker:set_physics_override(0, 0, 0)
clicker:setpos(pos)
default.player_attached[name] = true
default.player_set_animation(clicker, "sit", 30)
if param2 == 0 then
@ -28,7 +27,20 @@ function ma_pops_furniture.sit(pos, node, clicker)
clicker:set_look_yaw(6.28)
elseif param2 == 3 then
clicker:set_look_yaw(4.75)
else return end
end
end
end
function ma_pops_furniture.dig_chair(pos, node, meta, digger)
local sitting = meta.fields.is_sit or nil
if sitting and sitting ~= "" then
local player = minetest.get_player_by_name(sitting)
pos.y = pos.y-0.5
player:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
player:set_physics_override(1, 1, 1)
default.player_attached[sitting] = false
default.player_set_animation(player, "stand", 30)
end
end

View File

@ -1,6 +1,5 @@
ma_pops_furniture = {}
dofile(minetest.get_modpath('ma_pops_furniture')..'/sit.lua')
dofile(minetest.get_modpath('ma_pops_furniture')..'/functions.lua')
dofile(minetest.get_modpath('ma_pops_furniture')..'/formspecs.lua')
dofile(minetest.get_modpath('ma_pops_furniture')..'/crafts.lua')

View File

@ -440,9 +440,8 @@ minetest.register_node('ma_pops_furniture:toilet_open', {
{-.35, 0, .2, .35, .5, .5},
}
},
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end,
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
on_punch = function (pos, node, puncher)
node.name = "ma_pops_furniture:toilet_close"
minetest.set_node(pos, node)
@ -471,9 +470,8 @@ minetest.register_node('ma_pops_furniture:toilet_close', {
{-.35, 0, .2, .35, .5, .5},
}
},
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end,
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
on_punch = function (pos, node, puncher)
node.name = "ma_pops_furniture:toilet_open"
minetest.set_node(pos, node)
@ -724,9 +722,8 @@ minetest.register_node('ma_pops_furniture:chair_'..material, {
paramtype = 'light',
paramtype2 = 'facedir',
sounds = default.node_sound_wood_defaults(),
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end,
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
node_box = {
type = "fixed",
fixed = {
@ -1380,9 +1377,8 @@ minetest.register_node("ma_pops_furniture:chair2_"..color, {
paramtype2 = "facedir",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, furniture = 1, fall_damage_add_percent=-80, bouncy=80},
sounds = {wood = {name="furn_bouncy", gain=0.8}},
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end,
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
node_box = {
type = "fixed",
fixed = {
@ -1414,9 +1410,8 @@ minetest.register_node("ma_pops_furniture:chair2_rainbow", {
paramtype2 = "facedir",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, furniture = 1, fall_damage_add_percent=-80, bouncy=80},
sounds = {wood = {name="furn_bouncy", gain=0.8}},
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end,
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
node_box = {
type = "fixed",
fixed = {

32
sit.lua
View File

@ -1,32 +0,0 @@
function ma_pops_furniture.sit(pos, node, clicker)
do return end -- delete it when the engine is stabler for the player's physics
local meta = minetest.get_meta(pos)
local param2 = node.param2
local name = clicker:get_player_name()
if name == meta:get_string("is_sit") then
meta:set_string("is_sit", "")
pos.y = pos.y-0.5
clicker:setpos(pos)
clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
clicker:set_physics_override(1, 1, 1)
default.player_attached[name] = false
default.player_set_animation(clicker, "stand", 30)
else
meta:set_string("is_sit", clicker:get_player_name())
clicker:set_eye_offset({x=0,y=-7,z=2}, {x=0,y=0,z=0})
clicker:set_physics_override(0, 0, 0)
clicker:setpos(pos)
default.player_attached[name] = true
default.player_set_animation(clicker, "sit", 30)
if param2 == 0 then
clicker:set_look_yaw(3.15)
elseif param2 == 1 then
clicker:set_look_yaw(7.9)
elseif param2 == 2 then
clicker:set_look_yaw(6.28)
elseif param2 == 3 then
clicker:set_look_yaw(4.75)
else return end
end
end

View File

@ -47,9 +47,8 @@ minetest.register_node('ma_pops_furniture:sofa_'..color, {
paramtype = "light",
paramtype2 = "facedir",
sounds = {wood = {name="furn_bouncy", gain=0.8}},
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end,
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
selection_box = {
type = 'fixed',
fixed = {
@ -96,9 +95,8 @@ minetest.register_node('ma_pops_furniture:sofa_l_'..color, {
{.65, -.15, -.45, .45, .3, .25},
}
},
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end,
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
})
minetest.register_node('ma_pops_furniture:sofa_m_'..color, {
@ -125,9 +123,8 @@ minetest.register_node('ma_pops_furniture:sofa_m_'..color, {
{-.5, 0, .5, .5, .5, .2},
}
},
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end,
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
})
minetest.register_node('ma_pops_furniture:sofa_r_'..color, {
@ -156,9 +153,8 @@ minetest.register_node('ma_pops_furniture:sofa_r_'..color, {
{-.65, -.15, -.45, -.45, .3, .25},
}
},
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end,
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
})
minetest.register_node('ma_pops_furniture:sofa_c_'..color, {
@ -186,8 +182,7 @@ minetest.register_node('ma_pops_furniture:sofa_c_'..color, {
{-.5, 0, .5, .5, .5, .2},
}
},
on_rightclick = function(pos, node, clicker)
ma_pops_furniture.sit(pos, node, clicker)
end
on_rightclick = ma_pops_furniture.sit,
after_dig_node = ma_pops_furniture.dig_chair,
})
end