From 02583495f11e812f57d9f66950c61ec8e55e3c05 Mon Sep 17 00:00:00 2001 From: whosit Date: Tue, 26 Nov 2024 21:53:21 +0300 Subject: [PATCH] if you're not shooting, you're not part of any games, also if afk --- game.lua | 42 ++++++++++++++++++++++++------------------ internal.lua | 1 + mod.conf | 2 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/game.lua b/game.lua index 21c8d67..a1988bd 100644 --- a/game.lua +++ b/game.lua @@ -220,33 +220,39 @@ function snowgame.register_hit(shooter_name, target_name) local s_game = games_by_player[shooter_name] local t_game = games_by_player[target_name] - if s_game and t_game and (s_game ~= t_game) then - -- if both player but different games, merge - s_game:merge(t_game) - end - local game = s_game or t_game - if not game then - -- none are playing, make a new one - game = Game() - end if not s_game then - -- add shooter to current - game:add_player(shooter_name) - game:register_shot(shooter_name) + -- somehow landed a hit before being in a game + -- probably because left and rejoined? + s_game = Game() + s_game:add_player(shooter_name) + s_game:register_shot(shooter_name) -- if was in the game, then shot was registered in on_use end - if not t_game then - -- add target to current (if played diff game, was merged) - game:add_player(target_name) + + if afk_api.is_afk(target_name, yl_snowball.AFK_TIME) then + -- don't count hits on afk people + return end - game:register_hit(shooter_name, target_name) + + if s_game and t_game then + if (s_game ~= t_game) then + -- if both playing, but different games, then merge + s_game:merge(t_game) + end + -- either same game, or was merged into one + s_game:register_hit(shooter_name, target_name) + end + end function snowgame.register_shot(shooter_name) local s_game = games_by_player[shooter_name] - if s_game then - s_game:register_shot(shooter_name) + if not s_game then + -- started shooting first time, started a game + s_game = Game() + s_game:add_player(shooter_name) end + s_game:register_shot(shooter_name) end diff --git a/internal.lua b/internal.lua index f665718..fd29023 100644 --- a/internal.lua +++ b/internal.lua @@ -13,6 +13,7 @@ yl_snowball.COOLDOWN = 0.4 -- TODO make configurable yl_snowball.SNOWBALL_SPEED = 17 -- 17 was good yl_snowball.SNOWBALL_GRAVITY = -8 -- -8 was good +yl_snowball.AFK_TIME = 3*60 local player_last_throw_time = {} diff --git a/mod.conf b/mod.conf index 1fc07c2..28e32f0 100644 --- a/mod.conf +++ b/mod.conf @@ -2,4 +2,4 @@ description = Adds throwable snowballs and a snowball minigame author = whosit title = yl_snowball name = yl_snowball -depends = ballistics, futil, y_bows \ No newline at end of file +depends = ballistics, futil, y_bows, afk_api \ No newline at end of file