-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagentHelper.lua
More file actions
45 lines (34 loc) · 1019 Bytes
/
agentHelper.lua
File metadata and controls
45 lines (34 loc) · 1019 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-- Library of helper functions for agents
agentHelper = {}
function agentHelper.getClosestDistAmmoPack(agent)
local player = agent.player
local minDist = 9999999999
local closestAmmo
for i, obj in pairs(helper.getAllAmmoPacks()) do
local dist = helper.getMagnitude(obj.x - player.x, obj.y - player.y)
if (dist < minDist) and obj.active then
minDist = dist
closestAmmo = obj
end
end
return closestAmmo
end
function agentHelper.getClosestDistPlayer(agent)
local player = agent.player
local minDist = 9999999999
local closestPlayer
for i, obj in pairs(helper.getAllAlivePlayers()) do
if obj ~= player then
local dist = helper.getMagnitude(obj.x - player.x, obj.y - player.y)
if dist < minDist then
minDist = dist
closestPlayer = obj
end
end
end
return closestPlayer
end
function agentHelper.isFacingObject(agent, obj, threshold)
local player = agent.player
return helper.isFacingObject(player, obj, threshold)
end