Properly track players' LMB keypresses

Fixes automatic fire continuing after player's death and respawn
This commit is contained in:
ANAND 2020-06-17 18:51:00 +05:30
parent b8b1c6d368
commit bc0fc7f43c
No known key found for this signature in database
GPG key ID: 3AD8A3C4A51AAB97
2 changed files with 7 additions and 4 deletions

View file

@ -551,3 +551,7 @@ end
shooter.set_shooting = function(name, is_shooting)
shooting[name] = is_shooting and true or nil
end
minetest.register_on_dieplayer(function(player)
shooting[player:get_player_name()] = nil
end)

View file

@ -67,11 +67,10 @@ minetest.register_entity("shooter:turret_entity", {
if shooter.config.automatic_weapons == true then
minetest.register_globalstep(function()
for _,player in pairs(minetest.get_connected_players()) do
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
if name then
shooter.set_shooting(name,
player:get_player_control().LMB == true)
if shooter.get_shooting(name) and not player:get_player_control().LMB then
shooter.set_shooting(name, nil)
end
end
end)