2015-09-01 17:15:24 +02:00
|
|
|
local player_soundspec = {}
|
|
|
|
local player_lastsound = {}
|
|
|
|
local player_health = {}
|
2015-10-02 22:58:37 +02:00
|
|
|
local player_lastpos = {}
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2015-10-26 23:03:42 +01:00
|
|
|
local particlespawners = {}
|
|
|
|
|
2015-10-02 18:44:25 +02:00
|
|
|
local enable_flowing_water_sound = minetest.setting_getbool("enable_flowing_water_sound")
|
2015-10-02 19:07:07 +02:00
|
|
|
if enable_flowing_water_sound == nil then enable_flowing_water_sound = true end
|
2015-10-02 18:44:25 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
local function step(dtime)
|
2015-10-02 19:07:07 +02:00
|
|
|
local player_positions = {}
|
|
|
|
|
2015-10-02 01:27:22 +02:00
|
|
|
for _, player in ipairs(minetest.get_connected_players()) do
|
2015-09-01 17:15:24 +02:00
|
|
|
local player_pos=player:getpos()
|
|
|
|
local name=player:get_player_name()
|
|
|
|
|
2015-10-02 01:27:22 +02:00
|
|
|
if player_pos.x < -30000 or player_pos.x > 30000
|
|
|
|
or player_pos.y < -30000 or player_pos.y > 30000
|
|
|
|
or player_pos.z < -30000 or player_pos.z > 30000 then
|
|
|
|
minetest.chat_send_player(name, "Don't go past 30000m in any direction!")
|
2015-10-02 22:58:37 +02:00
|
|
|
player:setpos(player_lastpos[name])
|
2015-10-02 01:27:22 +02:00
|
|
|
end
|
|
|
|
|
2015-10-02 22:58:37 +02:00
|
|
|
player_lastpos[name] = player:getpos()
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if player:get_hp() < player_health[name] then
|
|
|
|
minetest.sound_play(
|
|
|
|
"default_hurt",
|
|
|
|
{
|
2015-09-07 01:12:52 +02:00
|
|
|
pos = player_pos,
|
2015-10-01 01:14:19 +02:00
|
|
|
max_hear_distance = 4,
|
2015-09-01 17:15:24 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
player_health[name] = player:get_hp()
|
|
|
|
|
|
|
|
player_pos.x=math.floor(player_pos.x+0.5)
|
|
|
|
player_pos.y=math.ceil(player_pos.y-0.3)
|
|
|
|
player_pos.z=math.floor(player_pos.z+0.5)
|
|
|
|
|
|
|
|
local nodename=minetest.get_node(player_pos).name
|
|
|
|
|
|
|
|
if player_lastsound[name] == nil then player_lastsound[name] = 100 end
|
|
|
|
|
|
|
|
player_lastsound[name] = player_lastsound[name] + dtime
|
|
|
|
|
2015-10-02 18:44:25 +02:00
|
|
|
local flowing_water_pos = nil
|
|
|
|
if enable_flowing_water_sound then
|
|
|
|
flowing_water_pos = minetest.find_node_near(player_pos, 16, "group:flowing_water")
|
|
|
|
end
|
|
|
|
|
2015-10-01 01:14:19 +02:00
|
|
|
if nodename == "default:water_source" or nodename == "default:river_water_source" then
|
2015-09-01 17:15:24 +02:00
|
|
|
if player_lastsound[name] > 3.3 then
|
|
|
|
player_soundspec[name]=minetest.sound_play(
|
|
|
|
"default_water",
|
|
|
|
{
|
2015-09-07 01:12:52 +02:00
|
|
|
pos = player_pos,
|
|
|
|
max_hear_distance = 16,
|
2015-09-01 17:15:24 +02:00
|
|
|
})
|
|
|
|
player_lastsound[name] = 0
|
|
|
|
end
|
2015-10-26 23:03:42 +01:00
|
|
|
|
|
|
|
particlespawners[name] = minetest.add_particlespawner(
|
|
|
|
{
|
|
|
|
amount = 5,
|
|
|
|
time = 0.1,
|
|
|
|
minpos = {x = player_pos.x - 0.2, y = player_pos.y - 0.3, z = player_pos.z - 0.3},
|
|
|
|
maxpos = {x = player_pos.x + 0.3, y = player_pos.y + 0.3, z = player_pos.z + 0.3},
|
|
|
|
minvel = {x = -0.5, y = 0, z = -0.5},
|
|
|
|
maxvel = {x = 0.5, y = 0, z = 0.5},
|
|
|
|
minacc = {x = -0.5, y = 4, z = -0.5},
|
|
|
|
maxacc = {x = 0.5, y = 1, z = 0.5},
|
|
|
|
minexptime = 0.3,
|
|
|
|
maxexptime = 0.8,
|
|
|
|
minsize = 0.7,
|
|
|
|
maxsize = 2.4,
|
|
|
|
texture = "bubble.png"
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.after(0.15, function() minetest.delete_particlespawner(particlespawners[name]) end)
|
2015-10-02 18:44:25 +02:00
|
|
|
elseif flowing_water_pos then
|
|
|
|
if player_lastsound[name] > 3.3 then
|
2015-10-26 23:03:42 +01:00
|
|
|
|
2015-10-02 19:07:07 +02:00
|
|
|
local c = true
|
|
|
|
for _, p in pairs(player_positions) do
|
|
|
|
if (p.x * player_pos.x) + (p.y * player_pos.y) + (p.z * player_pos.z) < 256 then
|
|
|
|
-- 256 is 16*16 for distance checking
|
|
|
|
c = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if c then
|
|
|
|
player_soundspec[name]=minetest.sound_play(
|
|
|
|
"default_water",
|
|
|
|
{
|
|
|
|
pos = flowing_water_pos,
|
|
|
|
max_hear_distance = 16,
|
|
|
|
})
|
|
|
|
player_lastsound[name] = 0
|
|
|
|
end
|
2015-10-02 18:44:25 +02:00
|
|
|
end
|
2015-09-01 17:15:24 +02:00
|
|
|
else
|
|
|
|
if player_soundspec[name] ~= nil then
|
|
|
|
minetest.sound_stop(player_soundspec[name])
|
|
|
|
|
|
|
|
player_lastsound[name] = 100
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local grass_pos=minetest.find_node_near(player_pos, 1, {"default:dirt_with_grass"})
|
|
|
|
|
2015-09-07 01:12:52 +02:00
|
|
|
if grass_pos ~= nil and math.random(1, 500) == 1 then
|
2015-09-01 17:15:24 +02:00
|
|
|
if grass_pos.x == player_pos.x and grass_pos.z == player_pos.z then
|
2015-09-24 18:53:09 +02:00
|
|
|
minetest.set_node(grass_pos, {name = "default:dirt_with_grass_footsteps"})
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-02 19:07:07 +02:00
|
|
|
|
|
|
|
table.insert(player_positions, player_pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_joinplayer(player)
|
|
|
|
local name=player:get_player_name()
|
|
|
|
|
|
|
|
player_health[name] = player:get_hp()
|
|
|
|
|
|
|
|
-- uncomment to enable player-on-player collisions
|
|
|
|
-- player:set_properties({physical = true})
|
|
|
|
|
2015-10-02 18:44:25 +02:00
|
|
|
-- uncomment to disable the sneak glitch
|
2015-09-01 17:15:24 +02:00
|
|
|
player:set_physics_override({sneak_glitch = false})
|
2015-10-02 22:58:37 +02:00
|
|
|
|
|
|
|
player_lastpos[name] = player:getpos()
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_leaveplayer(player)
|
|
|
|
local name=player:get_player_name()
|
|
|
|
|
|
|
|
player_soundspec[name] = nil
|
|
|
|
player_lastsound[name] = nil
|
|
|
|
player_health[name] = nil
|
2015-10-02 22:58:37 +02:00
|
|
|
player_lastpos[name] = nil
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(on_joinplayer)
|
|
|
|
minetest.register_on_leaveplayer(on_leaveplayer)
|
|
|
|
minetest.register_globalstep(step)
|
|
|
|
|
|
|
|
default.log("player", "loaded")
|