]> git.lizzy.rs Git - Crafter.git/blob - mods/player_mechanics/suffocation.lua
Suffocation & home priv
[Crafter.git] / mods / player_mechanics / suffocation.lua
1 local time = 0
2
3 minetest.register_globalstep(function(dtime)
4         time = time + dtime
5
6         if time < 0.5 then
7                 return
8         end
9         
10         time = 0
11
12         for _, player in ipairs(minetest.get_connected_players()) do
13                 local name = player:get_player_name()
14                 local pos = player:get_pos()
15                 local node_head = minetest.get_node(vector.add(pos, vector.new(0, 1.5, 0))).name
16
17                 -- Is player suffocating inside node? (Only for solid full opaque cube type nodes
18                 -- without group disable_suffocation=1)
19                 local ndef = minetest.registered_nodes[node_head]
20
21                 if ndef
22                 and (ndef.walkable == nil or ndef.walkable == true)
23                 and (ndef.collision_box == nil or ndef.collision_box.type == "regular")
24                 and (ndef.node_box == nil or ndef.node_box.type == "regular")
25                 and (ndef.groups.disable_suffocation ~= 1)
26                 and (node_head ~= "ignore")
27                 and (not minetest.check_player_privs(name, {noclip = true})) then
28                         if player:get_hp() > 0 then
29                                 player:set_hp(player:get_hp() - 1)
30                         end
31                 end
32
33         end
34
35 end)