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

Add API to register custom "can fly checks" #14

Closed
wants to merge 1 commit into from
Closed

Conversation

Niklp09
Copy link
Member

@Niklp09 Niklp09 commented Feb 21, 2024

Closes #13

@Niklp09 Niklp09 added the enhancement New feature or request label Feb 21, 2024
@Niklp09 Niklp09 requested a review from OgelGames February 21, 2024 13:22
Copy link
Member

@BuckarooBanzay BuckarooBanzay left a 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 🤷)

@OgelGames
Copy link
Contributor

Yeah performance issues was one thought I had, that's why I opened an issue instead of implementing it immediately.

Also, the can_fly function is currently used for area flak, extra code needs to be added that prevents glider use without shooting you down.

@OgelGames OgelGames marked this pull request as draft March 1, 2024 04:18
@Niklp09
Copy link
Member Author

Niklp09 commented Mar 1, 2024

if multiple mods would resolve a player from name in the callback though

The function passes now name and player

the can_fly function is currently used for area flak [too]

Fixed.

@Niklp09 Niklp09 marked this pull request as ready for review March 1, 2024 14:33
@OgelGames
Copy link
Contributor

Oh I forgot about this one... Still not quite complete yet I think, I'll do some tests tomorrow.

@Niklp09 Niklp09 requested review from OgelGames and removed request for OgelGames March 15, 2024 10:11
@SwissalpS SwissalpS requested review from SwissalpS and removed request for SwissalpS April 11, 2024 05:09
@SwissalpS
Copy link
Contributor

LGTM. I'm not stocked about the naming of can_fly_area but there is no perfect name, so fine by me. can_fly_flak might be a bit more precise as area is a mod but also well, an area.

@SwissalpS
Copy link
Contributor

SwissalpS commented Apr 13, 2024

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 can_fly_flak() method to include area_xp and area_priv settings and not only ownership of area.

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 OgelGames self-assigned this Apr 18, 2024
@OgelGames OgelGames marked this pull request as draft April 18, 2024 13:32
@Niklp09 Niklp09 closed this Apr 18, 2024
@OgelGames OgelGames reopened this Apr 18, 2024
@Niklp09
Copy link
Member Author

Niklp09 commented Jul 15, 2024

@OgelGames Rebased on master.

@Niklp09 Niklp09 closed this Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow overriding can_fly function
4 participants