mirror of
https://github.com/mt-mods/hangglider.git
synced 2025-01-10 02:00:25 +01:00
add area FLAK for priv and xp protected areas
This commit is contained in:
parent
8fc1f596d2
commit
86c7d34d50
@ -7,5 +7,7 @@ read_globals = {
|
|||||||
"vector", "ItemStack",
|
"vector", "ItemStack",
|
||||||
|
|
||||||
"player_monoids",
|
"player_monoids",
|
||||||
|
"priv_protector",
|
||||||
"unifieddyes",
|
"unifieddyes",
|
||||||
|
"xp_redo",
|
||||||
}
|
}
|
||||||
|
66
init.lua
66
init.lua
@ -1,6 +1,14 @@
|
|||||||
|
|
||||||
local has_player_monoids = minetest.get_modpath("player_monoids")
|
local has_player_monoids = minetest.get_modpath("player_monoids")
|
||||||
local has_areas = minetest.get_modpath("areas")
|
local has_areas = minetest.get_modpath("areas")
|
||||||
|
local has_priv_protector = minetest.get_modpath("priv_protector")
|
||||||
|
and minetest.global_exists("priv_protector")
|
||||||
|
and priv_protector.get_area_priv
|
||||||
|
-- older versions of priv_protector and xp_redo don't have
|
||||||
|
-- the global and/or the functions yet
|
||||||
|
local has_xp_redo = minetest.get_modpath("xp_redo")
|
||||||
|
and minetest.global_exists("xp_redo")
|
||||||
|
and xp_redo.get_area_xp_limits and xp_redo.get_xp
|
||||||
|
|
||||||
local enable_hud_overlay = minetest.settings:get_bool("hangglider.enable_hud_overlay", true)
|
local enable_hud_overlay = minetest.settings:get_bool("hangglider.enable_hud_overlay", true)
|
||||||
local enable_flak = has_areas and minetest.settings:get_bool("hangglider.enable_flak", true)
|
local enable_flak = has_areas and minetest.settings:get_bool("hangglider.enable_flak", true)
|
||||||
@ -73,24 +81,61 @@ local function remove_physics_overrides(player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function can_fly(pos, name)
|
local function can_fly(pos, name, player_xp, player_privs)
|
||||||
if not enable_flak then
|
if not enable_flak then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local flak = false
|
|
||||||
|
local flak, open = false, false
|
||||||
|
local priv_excemption, xp_limit = false, false
|
||||||
|
local xp_area, priv_area
|
||||||
local owners = {}
|
local owners = {}
|
||||||
for _, area in pairs(areas:getAreasAtPos(pos)) do
|
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
||||||
|
-- open areas are friendly airspace(?)
|
||||||
|
if area.open then
|
||||||
|
open = true
|
||||||
|
end
|
||||||
|
if player_privs then
|
||||||
|
priv_area = priv_protector.get_area_priv(id)
|
||||||
|
if player_privs[priv_area] then
|
||||||
|
priv_excemption = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if player_xp then
|
||||||
|
xp_area = xp_redo.get_area_xp_limits(id)
|
||||||
|
if xp_area then
|
||||||
|
if (xp_area.min and player_xp < xp_area.min)
|
||||||
|
or (xp_area.max and player_xp > xp_area.max)
|
||||||
|
then
|
||||||
|
xp_limit = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
if area.flak then
|
if area.flak then
|
||||||
flak = true
|
flak = true
|
||||||
end
|
end
|
||||||
owners[area.owner] = true
|
owners[area.owner] = true
|
||||||
end
|
end
|
||||||
if flak and not owners[name] then
|
-- none of the areas has FLAK set -> friendly
|
||||||
return false
|
-- any of the overlapping areas is open -> friendly
|
||||||
end
|
-- owners of overlapping areas -> safe
|
||||||
|
if not flak or open or owners[name] then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- privilaged players -> safe
|
||||||
|
if player_privs and priv_excemption then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- xp limits -> unfriendly
|
||||||
|
if player_xp and not xp_limit then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local function safe_node_below(pos)
|
local function safe_node_below(pos)
|
||||||
local node = minetest.get_node_or_nil(vector.new(pos.x, pos.y - 0.5, pos.z))
|
local node = minetest.get_node_or_nil(vector.new(pos.x, pos.y - 0.5, pos.z))
|
||||||
if not node then
|
if not node then
|
||||||
@ -142,7 +187,7 @@ local function hangglider_step(self, dtime)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not can_fly(pos, name) then
|
if not can_fly(pos, name, self.xp, self.privs) then
|
||||||
if not self.flak_timer then
|
if not self.flak_timer then
|
||||||
self.flak_timer = 0
|
self.flak_timer = 0
|
||||||
shoot_flak_sound(pos)
|
shoot_flak_sound(pos)
|
||||||
@ -189,6 +234,13 @@ local function hangglider_use(stack, player)
|
|||||||
end
|
end
|
||||||
set_hud_overlay(player, name, "hangglider_overlay.png")
|
set_hud_overlay(player, name, "hangglider_overlay.png")
|
||||||
set_physics_overrides(player, {jump = 0, gravity = 0.25})
|
set_physics_overrides(player, {jump = 0, gravity = 0.25})
|
||||||
|
local luaentity = entity:get_luaentity()
|
||||||
|
if has_xp_redo then
|
||||||
|
luaentity.xp = xp_redo.get_xp(name)
|
||||||
|
end
|
||||||
|
if has_priv_protector then
|
||||||
|
luaentity.privs = minetest.get_player_privs(name)
|
||||||
|
end
|
||||||
hanggliding_players[name] = true
|
hanggliding_players[name] = true
|
||||||
if hangglider_uses > 0 then
|
if hangglider_uses > 0 then
|
||||||
stack:add_wear(65535 / hangglider_uses)
|
stack:add_wear(65535 / hangglider_uses)
|
||||||
|
2
mod.conf
2
mod.conf
@ -1,5 +1,5 @@
|
|||||||
name = hangglider
|
name = hangglider
|
||||||
description = Adds a functional hang glider for exploring
|
description = Adds a functional hang glider for exploring
|
||||||
depends = default, wool, dye
|
depends = default, wool, dye
|
||||||
optional_depends = areas, player_monoids, unifieddyes
|
optional_depends = areas, player_monoids, priv_protector, unifieddyes, xp_redo
|
||||||
min_minetest_version = 5.0
|
min_minetest_version = 5.0
|
||||||
|
Loading…
Reference in New Issue
Block a user