-
Notifications
You must be signed in to change notification settings - Fork 2
/
Player Commands.pluto
49 lines (43 loc) · 1.39 KB
/
Player Commands.pluto
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
pluto_class PlayerProvider
function getPlayerNames(include_user: bool): table
local names = {}
for self:getPlayers(include_user) as p do
table.insert(names, players.get_name(p))
end
return names
end
end
pluto_class PlayerProviderAll extends PlayerProvider
function getPlayers(include_user: bool)
return players.list_all_with_excludes(include_user)
end
end
pluto_class PlayerProviderSingle extends PlayerProvider
function __construct(p, list)
self.p = p
self.m_list = list
end
function getPlayers(include_user: bool)
return { self.p }
end
end
local function build_player_commands(pp, list)
list:action("Player Action", {"luaplyaction"}, "", function()
util.toast("Player action used for: "..table.concat(pp:getPlayerNames(true), ", "))
end)
if pp instanceof PlayerProviderSingle then
list:action("Individual Player Action", {}, "", function()
util.toast("Individual player action used for: "..players.get_name(pp.p))
end)
end
do
local nested = list:list("A List")
nested:action("Nested Action", {}, "", function()
util.toast("Nested action used for: "..table.concat(pp:getPlayerNames(true), ", "))
end)
end
end
build_player_commands(pluto_new PlayerProviderAll(), menu.ref_by_path("Players>All Players"))
players.add_command_hook(function(p, list)
build_player_commands(pluto_new PlayerProviderSingle(p), list)
end)