Skip to content

Commit 4ae9c18

Browse files
committed
Adjust noclip hurt detection (take both feet & head node into account)
1 parent 9049126 commit 4ae9c18

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

noclip_hurt.lua

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
local timer = 0
22

3+
local function is_solid_node(pos)
4+
local ndef = core.registered_nodes[core.get_node(pos).name]
5+
return ndef
6+
and ndef.walkable == true
7+
and ndef.groups.disable_suffocation ~= 1
8+
and ndef.drawtype == "normal"
9+
end
10+
311
core.register_globalstep(function(dtime)
412

513
timer = timer + dtime
614
if timer < 1 then return end
715
timer = 0
816

9-
for _, player in pairs(core.get_connected_players()) do
10-
17+
for _, player in ipairs(core.get_connected_players()) do
1118
local pos = player:get_pos()
12-
pos.y = pos.y + 0.5
13-
local node = core.get_node(pos)
14-
local ndef = core.registered_nodes[node.name]
1519

16-
if ndef and ndef.walkable == true
17-
and ndef.damage_per_second == 0
18-
and ndef.groups.disable_suffocation ~= 1
19-
and ndef.drawtype == "normal"
20-
and not core.check_player_privs(player:get_player_name(), { noclip = true })
21-
then
20+
pos.y = pos.y + 0.5
21+
if is_solid_node(pos) then
22+
pos.y = pos.y + 1 -- Player's head
23+
if is_solid_node(pos)
24+
and player:get_hp() > 0
25+
and not core.check_player_privs(player:get_player_name(), { noclip = true }) then
2226

23-
if player:get_hp() > 0 then
24-
player:set_hp(player:get_hp() - 4, { suffocation = true })
27+
player:set_hp(player:get_hp() - 1, { suffocation = true })
2528
end
2629
end
2730
end

0 commit comments

Comments
 (0)