-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetbots.lua
More file actions
64 lines (54 loc) · 1.46 KB
/
netbots.lua
File metadata and controls
64 lines (54 loc) · 1.46 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local mq = require('mq')
local array = require('array')
local str = require('str')
local netbots = {}
function netbots.Peers()
---@diagnostic disable-next-line: missing-parameter
local peers = str.Split(mq.TLO.NetBots.Client(), ' ')
return peers
end
function netbots.IsPeer(name)
return array.HasValue(netbots.Peers(), name)
end
function netbots.PeerIds()
---@diagnostic disable-next-line: undefined-field
return array.Mapped(netbots.Peers(), function(name) return tonumber(mq.TLO.NetBots(name).ID()) end)
end
function netbots.PeerPetIds()
local value = {}
for i, name in ipairs(netbots.Peers()) do
local id = mq.TLO.NetBots(name).PetID()
if id ~= nil and id ~= 0 then
table.insert(value, tonumber(id))
end
end
return value
end
function netbots.PeerById(id)
---@diagnostic disable-next-line: undefined-field
return array.FirstOrNil(netbots.Peers(), function(name) return id == mq.TLO.NetBots(name).ID() end)
end
function netbots.PeerByName(name)
for i, peer in ipairs(netbots.Peers()) do
if peer:lower() == name:lower() then
return peer
end
end
return ''
end
function netbots.PeerByPetId(id)
for i, name in ipairs(netbots.Peers()) do
if id == mq.TLO.NetBots(name).PetID() then
return name
end
end
return ''
end
function netbots.TargetIdByPeerId(id)
local peer = netbots.PeerById(id)
if peer ~= nil then
return mq.TLO.NetBots(peer).TargetID()
end
return 0
end
return netbots