Fix grapples being usable by firing before punching flag (#632)

Check for player carrying flag in grapple entity's on_step as well.
This commit is contained in:
ANAND 2020-05-19 12:50:22 +05:30 committed by GitHub
parent e9343d9d56
commit baf5f17878
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -69,3 +69,21 @@ end
check_grapple("shooter_hook:grapple_gun_loaded") check_grapple("shooter_hook:grapple_gun_loaded")
check_grapple("shooter_hook:grapple_gun") check_grapple("shooter_hook:grapple_gun")
check_grapple("shooter_hook:grapple_hook") check_grapple("shooter_hook:grapple_hook")
-- Override grappling hook entity to check if player has flag before teleporting
local old_grapple_step = minetest.registered_entities["shooter_hook:hook"].on_step
minetest.registered_entities["shooter_hook:hook"].on_step = function(self, dtime, ...)
-- Remove entity if player has flag
-- This is to prevent players from firing the hook, and then punching the flag
if ctf_flag.has_flag(self.user) then
local player = minetest.get_player_by_name(self.user)
if player then
player:get_inventory():add_item("main", "shooter_hook:grapple_hook")
end
minetest.chat_send_player(self.user,
"You can't use grapples whilst carrying the flag")
self.object:remove()
return
end
return old_grapple_step(self, dtime, ...)
end