-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add API to register custom "can fly checks" #14
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm (didn't check for perf issues if multiple mods would resolve a player from name in the callback though, shouldn't be much i think 🤷)
Yeah performance issues was one thought I had, that's why I opened an issue instead of implementing it immediately. Also, the |
The function passes now
Fixed. |
Oh I forgot about this one... Still not quite complete yet I think, I'll do some tests tomorrow. |
LGTM. I'm not stocked about the naming of |
In another glider mod I'm going for this approach: -- Allow other mods to register custom flight checks
-- to disallow flying in certain areas or materials
-- such as on the moon or without priv in certain area
-- The function's signature is: (name, driver, luaent)
-- name: (string) player's name
-- driver: (PlayerObjRef) the player object
-- luaent: (nil or luaentity) the glider luaentity. When set,
-- player is already flying. When not, player would like to
-- take off.
-- The function must return true to indicate that player may
-- fly. A second return value of int may be provided to
-- indicate damage to player from which damage to glider
-- is also applied. Sensible values are from -20 to 20.
-- Negative meaning healing.
local flight_checks = {}
function glider.register_flight_check(func)
flight_checks[#flight_checks + 1] = func
end
local function custum_flight_checks(name, driver, luaent)
local i = #flight_checks
if i == 0 then
return true, 0
end
local has_fails = false
local damage = 0
local res_bool, res_int
repeat
res_bool, res_int = flight_checks[i](name, driver, luaent)
if not res_bool then
has_fails = true
end
if type(res_int) == "number" then
damage = damage + math_max(-20, math_min(20, res_int))
end
i = i - 1
until i == 0
return not has_fails, damage
end Allowing mods to cause damage to glider cumulative and also allowing them to manipulate the luaentity. I also hope to extend the Edit: in this mod, damage to glider isn't that interesting and damage to player can be done directly to player object. What I'm pointing out, is the cumulative effect. |
@OgelGames Rebased on master. |
Closes #13