-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbot_script_env.lua
More file actions
30 lines (25 loc) · 840 Bytes
/
bot_script_env.lua
File metadata and controls
30 lines (25 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
if BotScriptEnv == nil then
BotScriptEnv = class({})
BotScript = class({})
end
function BotScript:Init(script_content, candidate_name)
-- print("bot script: " .. script_content)
self.run_bot = Sandbox:LoadActionScript(script_content, candidate_name)
self.ctx = {}
self.candidate_name = candidate_name
end
function BotScript:OnThink(entity)
self.ctx = Sandbox:RunAction(self.run_bot, entity, self.ctx, self.candidate_name)
return 0.1
end
function BotScriptEnv:AttachScriptOnUnit(unit, script_string, candidate_name)
print("attaching to unit " .. tostring(unit))
if not unit then
print("no unit")
return
end
local bot_script = BotScript()
bot_script:Init(script_string, candidate_name)
unit:SetThink("OnThink", bot_script)
end
GameRules.BotScriptEnv = BotScriptEnv