Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved flight permissions #16

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
globals = {
"areas",
"hangglider",
}

read_globals = {
Expand Down
20 changes: 18 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
hangglider = {}

local has_player_monoids = minetest.get_modpath("player_monoids")
local has_areas = minetest.get_modpath("areas")
Expand Down Expand Up @@ -73,7 +74,17 @@ local function remove_physics_overrides(player)
end
end

local function can_fly(pos, name)
-- 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 friendly_airspace(pos, name)
if not enable_flak then
return true
end
Expand Down Expand Up @@ -142,7 +153,7 @@ local function hangglider_step(self, dtime)
})
end
end
if not can_fly(pos, name) then
if not friendly_airspace(pos, name) then
if not self.flak_timer then
self.flak_timer = 0
shoot_flak_sound(pos)
Expand All @@ -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)
Expand All @@ -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) then
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
Expand Down