mirror of
https://github.com/mt-mods/hangglider.git
synced 2024-11-13 22:10:38 +01:00
add hook for other mods
provide a way for other mods to decide where gliders are permited
This commit is contained in:
parent
2c708abd88
commit
0872a9161f
16
init.lua
16
init.lua
|
@ -1,3 +1,4 @@
|
|||
hangglider = {}
|
||||
|
||||
local has_player_monoids = minetest.get_modpath("player_monoids")
|
||||
local has_areas = minetest.get_modpath("areas")
|
||||
|
@ -73,6 +74,16 @@ local function remove_physics_overrides(player)
|
|||
end
|
||||
end
|
||||
|
||||
-- expose so other mods can override/hook-into
|
||||
-- to disallow flying in certain areas or materials
|
||||
-- such as on the moon or without priv in certain area
|
||||
-- pos: (vector) position of player
|
||||
-- name: (string) player's name
|
||||
-- in_flight: (bool) is already airborne
|
||||
function hangglider.allowed_to_fly(pos, name, in_flight) --luacheck: no unused args
|
||||
return true
|
||||
end
|
||||
|
||||
local function can_fly(pos, name)
|
||||
if not enable_flak then
|
||||
return true
|
||||
|
@ -156,6 +167,8 @@ local function hangglider_step(self, dtime)
|
|||
shoot_flak_sound(pos)
|
||||
gliding = false
|
||||
end
|
||||
elseif not hangglider.allowed_to_fly(pos, name, true) then
|
||||
gliding = false
|
||||
end
|
||||
if not gliding then
|
||||
remove_physics_overrides(player)
|
||||
|
@ -177,6 +190,9 @@ local function hangglider_use(stack, player)
|
|||
local pos = player:get_pos()
|
||||
local name = player:get_player_name()
|
||||
if not hanggliding_players[name] then
|
||||
if not hangglider.allowed_to_fly(pos, name, false)
|
||||
return
|
||||
end
|
||||
minetest.sound_play("hanggliger_equip", {pos = pos, max_hear_distance = 8, gain = 1.0}, true)
|
||||
local entity = minetest.add_entity(pos, "hangglider:glider")
|
||||
if entity then
|
||||
|
|
Loading…
Reference in New Issue
Block a user