Seperate area flak and custom checks

This commit is contained in:
Niklp 2024-03-01 15:31:00 +01:00
parent 7e8832f523
commit 4e40e3400c
No known key found for this signature in database
GPG Key ID: 05D6F5035E66267A
2 changed files with 11 additions and 4 deletions

View File

@ -37,7 +37,9 @@ When using a hang glider in an area with flak enabled, you will get shot down a
#### Custom "can fly" checks #### Custom "can fly" checks
```lua ```lua
hangglider.add_fly_check(function(name, pos) hangglider.add_fly_check(function(name, player)
-- `name` is the playername
-- `player` is the PlayerRef
-- Add your code here -- Add your code here
-- Must return `true` (can fly) or `false` (can't fly) -- Must return `true` (can fly) or `false` (can't fly)
return true return true

View File

@ -80,7 +80,7 @@ function hangglider.add_fly_check(func)
table.insert(fly_checks, func) table.insert(fly_checks, func)
end end
local function can_fly(name, pos) local function can_fly_area(name, pos)
-- Area flak check -- Area flak check
if enable_flak then if enable_flak then
local flak = false local flak = false
@ -95,10 +95,12 @@ local function can_fly(name, pos)
return false return false
end end
end end
end
local function can_fly_custom(name, player)
-- Custom checks set by other mods -- Custom checks set by other mods
for _, func in ipairs(fly_checks) do for _, func in ipairs(fly_checks) do
local ret = func(name, pos) local ret = func(name, player)
if ret == false then if ret == false then
return false return false
end end
@ -157,7 +159,7 @@ local function hangglider_step(self, dtime)
}) })
end end
end end
if not can_fly(name, pos) then if not can_fly_area(name, pos) 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)
@ -172,6 +174,9 @@ local function hangglider_step(self, dtime)
gliding = false gliding = false
end end
end end
if not can_fly_custom(name, player) then
gliding = false
end
if not gliding then if not gliding then
remove_physics_overrides(player) remove_physics_overrides(player)
hanggliding_players[name] = nil hanggliding_players[name] = nil