mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-01-08 08:50:20 +01:00
tweak mob hear function
This commit is contained in:
parent
64c6085f09
commit
1dd81eb008
33
api.lua
33
api.lua
@ -18,7 +18,7 @@ end
|
||||
|
||||
mobs = {
|
||||
mod = "redo",
|
||||
version = "20240917",
|
||||
version = "20241001",
|
||||
spawning_mobs = {},
|
||||
translate = S,
|
||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||
@ -4743,14 +4743,16 @@ if settings:get_bool("mobs_can_hear") ~= false then
|
||||
|
||||
local def = {} ; param = param or {}
|
||||
|
||||
-- store sound position
|
||||
-- store sound position (ignore player and object positioning as background)
|
||||
if param.pos then
|
||||
def.pos = param.pos
|
||||
elseif param.object then
|
||||
def.pos = param.object:get_pos()
|
||||
elseif param.to_player then
|
||||
local player = minetest.get_player_by_name(param.to_player)
|
||||
def.pos = player and player:get_pos()
|
||||
-- elseif param.object then
|
||||
-- def.pos = param.object:get_pos()
|
||||
-- def.object = param.object
|
||||
-- elseif param.to_player then
|
||||
-- local player = minetest.get_player_by_name(param.to_player)
|
||||
-- def.pos = player and player:get_pos()
|
||||
-- def.player = param.to_player
|
||||
end
|
||||
|
||||
-- if no position found use default function
|
||||
@ -4767,12 +4769,7 @@ if settings:get_bool("mobs_can_hear") ~= false then
|
||||
def.gain = spec.gain or param.gain or 1.0
|
||||
end
|
||||
|
||||
-- store player name or object reference
|
||||
if param.to_player then
|
||||
def.player = param.to_player
|
||||
elseif param.object then
|
||||
def.object = param.object
|
||||
end
|
||||
--print("==", def.sound)
|
||||
|
||||
def.max_hear_distance = param.max_hear_distance or 32
|
||||
|
||||
@ -4793,13 +4790,13 @@ if settings:get_bool("mobs_can_hear") ~= false then
|
||||
def.distance = get_distance(def.pos, obj:get_pos())
|
||||
|
||||
local bit = def.gain / def.max_hear_distance
|
||||
local rem = def.max_hear_distance - def.distance
|
||||
|
||||
-- loudness ranges from 0 (cannot hear) to 1.0 (close to source)
|
||||
def.loudness = (bit * rem) / def.gain
|
||||
def.loudness = def.gain - (bit * def.distance)
|
||||
|
||||
-- run custom on_sound function
|
||||
ent.on_sound(ent, def)
|
||||
-- run custom on_sound function if heard
|
||||
if def.loudness > 0 then
|
||||
ent.on_sound(ent, def)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
9
api.txt
9
api.txt
@ -348,13 +348,12 @@ enhance mob functionality and have them do many interesting things:
|
||||
'on_sound' (self, def) called when mob is inside the hearing distance of
|
||||
a sound, passes a def table containing:
|
||||
'sound' the sound being played,
|
||||
'pos' position the sound originated,
|
||||
'pos' position the sound originated (only sounds with pos detected),
|
||||
'gain' original gain of sound,
|
||||
'distance' distance of mob from sound source,
|
||||
'loudness' how loud sound is to mob (0 = cant hear, 1.0 = near sound), this
|
||||
would be used as the main value inside on_sound function,
|
||||
'player' player name sound originated,
|
||||
'object' object reference sound originated,
|
||||
'loudness' how loud sound is to mob (percentage of gain heard at distance)
|
||||
'player' player name sound originated, [NOT IN USE]
|
||||
'object' object reference sound originated, [NOT IN USE]
|
||||
'max_hear_distance' max distance sound can be heard from source.
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user