forked from mtcontrib/hangglider
Added option to shoot down hanggliders flying in restricted airspace
Added a /area_flak command to declare areas as closed airspace. Any hanggliders attempting to fly in such an area will get shot down within two seconds, which will lead to a massive loss of health to the occupant (death if flying higher than 6 meters) and the loss of the hangglider. The closed airspace behaviour depends on the areas mod.
This commit is contained in:
parent
1555555ac4
commit
8381bda2b4
@ -49,4 +49,5 @@ Textures:
|
|||||||
Default wood and wool textures from minetest-game.
|
Default wood and wool textures from minetest-game.
|
||||||
|
|
||||||
Models and sounds:
|
Models and sounds:
|
||||||
CC BY-SA (4.0) by Piezo_.
|
CC BY-SA (4.0) by Piezo_.
|
||||||
|
hangglider_flak_shot: tnt_explode sound from minetest_game (CC BY-SA 3.0)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
default
|
default
|
||||||
wool
|
wool
|
||||||
minetest_systemd?
|
minetest_systemd?
|
||||||
|
areas?
|
||||||
|
72
init.lua
72
init.lua
@ -39,6 +39,13 @@
|
|||||||
-- Removed airbreak penalty, as any 'advantage' seems minimal after new adjustments
|
-- Removed airbreak penalty, as any 'advantage' seems minimal after new adjustments
|
||||||
|
|
||||||
|
|
||||||
|
-- Modifications by gpcf
|
||||||
|
-- 2018-12-09
|
||||||
|
-- get shot down while flying over protected areas marked as no-fly-zones (flak, from German Flugabwehrkanone)
|
||||||
|
-- set these areas with the /area_flak command
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local HUD_Overlay = true --show glider struts as overlay on HUD
|
local HUD_Overlay = true --show glider struts as overlay on HUD
|
||||||
local debug = false --show debug info in top-center of hud
|
local debug = false --show debug info in top-center of hud
|
||||||
local moveModelUp = false
|
local moveModelUp = false
|
||||||
@ -87,6 +94,31 @@ minetest.register_entity("hangglider:airstopper", { --A one-instant entity that
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if areas then
|
||||||
|
hangglider.flak = true
|
||||||
|
-- chat command definition essentially copied from areas mod.
|
||||||
|
minetest.register_chatcommand("area_flak",{
|
||||||
|
params = "<ID>",
|
||||||
|
description = "Toggle airspace restrictions for area <ID>",
|
||||||
|
func = function(name, param)
|
||||||
|
local id = tonumber(param)
|
||||||
|
if not id then
|
||||||
|
return false, "Invalid usage, see /help area_flak."
|
||||||
|
end
|
||||||
|
|
||||||
|
if not areas:isAreaOwner(id, name) then
|
||||||
|
return false, "Area "..id.." does not exist"
|
||||||
|
.." or is not owned by you."
|
||||||
|
end
|
||||||
|
local open = not areas.areas[id].flak
|
||||||
|
-- Save false as nil to avoid inflating the DB.
|
||||||
|
areas.areas[id].flak = open or nil
|
||||||
|
areas:save()
|
||||||
|
return true, ("Area's airspace %s."):format(open and "closed" or "opened")
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
if minetestd and minetestd.services.gravityctl.enabled then
|
if minetestd and minetestd.services.gravityctl.enabled then
|
||||||
minetestd.gravityctl.register_gravity_effect("hangglider",
|
minetestd.gravityctl.register_gravity_effect("hangglider",
|
||||||
function(player)
|
function(player)
|
||||||
@ -102,6 +134,28 @@ minetestd.gravityctl.register_gravity_effect("hangglider",
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
hangglider.can_fly = function (pname, pos)
|
||||||
|
-- Checks if the player will get shot down at the position
|
||||||
|
if minetest.is_protected(vector.round(pos), pname) then
|
||||||
|
if hangglider.flak then
|
||||||
|
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
||||||
|
if area.flak then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
hangglider.shot_sound = function (pos)
|
||||||
|
minetest.sound_play("hangglider_flak_shot", {
|
||||||
|
pos = pos,
|
||||||
|
max_hear_distance = 30,
|
||||||
|
gain = 10.0,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
local step_v
|
local step_v
|
||||||
minetest.register_entity("hangglider:glider", {
|
minetest.register_entity("hangglider:glider", {
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
@ -110,7 +164,7 @@ minetest.register_entity("hangglider:glider", {
|
|||||||
immortal = true,
|
immortal = true,
|
||||||
static_save = false,
|
static_save = false,
|
||||||
textures = {"wool_white.png","default_wood.png"},
|
textures = {"wool_white.png","default_wood.png"},
|
||||||
on_step = function(self, _)
|
on_step = function(self, dtime)
|
||||||
local canExist = false
|
local canExist = false
|
||||||
if self.object:get_attach() then
|
if self.object:get_attach() then
|
||||||
local player = self.object:get_attach("parent")
|
local player = self.object:get_attach("parent")
|
||||||
@ -139,6 +193,20 @@ minetest.register_entity("hangglider:glider", {
|
|||||||
]]end
|
]]end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if not hangglider.can_fly(pname,pos) then
|
||||||
|
if not self.warned then -- warning shot
|
||||||
|
self.warned = 0
|
||||||
|
hangglider.shot_sound(pos)
|
||||||
|
minetest.chat_send_player(pname, "Protected area! You will be shot down in two seconds by anti-aircraft guns!")
|
||||||
|
end
|
||||||
|
self.warned = self.warned + dtime
|
||||||
|
if self.warned > 2 then -- shoot down
|
||||||
|
player:set_hp(1)
|
||||||
|
player:get_inventory():remove_item("main", ItemStack("hangglider:hangglider"))
|
||||||
|
hangglider.shot_sound(pos)
|
||||||
|
canExist = false
|
||||||
|
end
|
||||||
|
end
|
||||||
if not canExist then
|
if not canExist then
|
||||||
player:set_physics_override({
|
player:set_physics_override({
|
||||||
jump = 1,
|
jump = 1,
|
||||||
@ -267,4 +335,4 @@ minetest.register_craft({
|
|||||||
{"default:stick", "", "default:stick"},
|
{"default:stick", "", "default:stick"},
|
||||||
{"", "default:stick", ""},
|
{"", "default:stick", ""},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
BIN
sounds/hangglider_flak_shot.ogg
Normal file
BIN
sounds/hangglider_flak_shot.ogg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user