From dfebe9a5ef4c892fd8eebbed4b508b7ce64f8841 Mon Sep 17 00:00:00 2001 From: kdxcxs Date: Wed, 29 Mar 2023 11:03:13 +0800 Subject: [PATCH 1/2] feat: print with candidate name --- rounds.lua | 6 +++--- sandbox.lua | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/rounds.lua b/rounds.lua index 9c3b46c..8dea818 100644 --- a/rounds.lua +++ b/rounds.lua @@ -360,7 +360,7 @@ function Rounds:ChooseHeros(chooser_scripts, attributes, bot_scripts) local cur_team_id = AVAILABLE_TEAMS[i] for _, candidate_id in ipairs(cur_candidates) do - local chooser = Sandbox:LoadChooseHeroScript(chooser_scripts[candidate_id]) + local chooser = Sandbox:LoadChooseHeroScript(chooser_scripts[candidate_id], Candidates[candidate_id]) local hero_name = Sandbox:RunChooseHero(chooser) local player_id = self.candidate_to_player[candidate_id] local player_owner = PlayerResource:GetPlayer(player_id) @@ -562,11 +562,11 @@ function Rounds:BeginRound(bot_scripts) } ) - for candidate_num, _ in pairs(Candidates) do + for candidate_num, candidate_name in pairs(Candidates) do local hero = self.heros[candidate_num] if hero then local script = bot_scripts[candidate_num] - BotScriptEnv:AttachScriptOnUnit(hero, script) + BotScriptEnv:AttachScriptOnUnit(hero, script, candidate_name) end end end diff --git a/sandbox.lua b/sandbox.lua index e891f85..331915a 100644 --- a/sandbox.lua +++ b/sandbox.lua @@ -22,10 +22,13 @@ function Sandbox:SetupGameInfo(game_info) self.game_info = game_info end -function Sandbox:LoadScript(user_script, quota, env) +function Sandbox:LoadScript(user_script, quota, env, candidate_name) for k, v in pairs(self.public_api) do env[k] = v end + env["print"] = function (...) + return print("[Sandbox.".. candidate_name .."]", ...) + end for k, v in pairs(self.game_info) do env[k] = v end @@ -53,12 +56,12 @@ function Sandbox:RunFunctionWrap(func, ...) return results[2] end -function Sandbox:LoadChooseHeroScript(user_script) - return self:LoadScript(user_script, 100000, {}) +function Sandbox:LoadChooseHeroScript(user_script, candidate_name) + return self:LoadScript(user_script, 100000, {}, candidate_name) end -function Sandbox:LoadActionScript(user_script) - return self:LoadScript(user_script, 500000, {}) +function Sandbox:LoadActionScript(user_script, candidate_name) + return self:LoadScript(user_script, 500000, {}, candidate_name) end function Sandbox:RunChooseHero(choose_func) @@ -84,7 +87,6 @@ function Sandbox:SandboxPublicAPI() Vector = Vector, QAngle = QAngle, GetGameTime = GetGameTime, - print = print, -- TODO: remove this } return api end From 9c7d3f7ac046c5e86785f6753fca4594f9f5ff0b Mon Sep 17 00:00:00 2001 From: kdxcxs Date: Wed, 29 Mar 2023 11:19:24 +0800 Subject: [PATCH 2/2] doc: add changelog to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 150825b..ec1407b 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,4 @@ All other information should be explored by reading the source code! - [2023/3/28 09:11] fix: ban nonhero units for hero choosing.([#31](https://github.com/Escapingbug/dotaxctf/pull/31),reporter: 114@x1ct34m) - [2023/3/28 09:16] feat: clean up items when round ends.([#30](https://github.com/Escapingbug/dotaxctf/pull/30)) - [2023/3/29 08:46] fix: place history.scores updates to correct loc.([#32](https://github.com/Escapingbug/dotaxctf/pull/32), reporter: AAA剑圣) +- [2023/3/29 11:18] feat: print with [Sandbox.candidate_name] banner to support checking specified hero's log.([#33](https://github.com/Escapingbug/dotaxctf/pull/33))