· 6 years ago · Mar 01, 2020, 09:10 PM
1--//CONFIGURATION
2local groupID = 4520330 --//The group ID to use PRS API in
3local gameKey = 'Hs8cxs1wqbmEn3LHOl8opp4-nEaxLZhdVXm6' --//Your PRS Game key.
4local rankID = 10 --//The Rank ID+ of users who can use it
5local AllowedUsers = {"Example1","Example2"} --//Allowed users (Bypasses rankID)
6local GroupService = game:GetService("GroupService")
7local GroupInfo = GroupService:GetGroupInfoAsync(groupID)
8local prefix = "!"
9
10-- Please do not edit past this point, as doing so might break the script. --
11local module = require(1896155381)(gameKey)
12local Group = require(1693864088)
13
14function GetIdFromName(rank)
15 for Index, Rank in pairs (GroupInfo.Roles) do
16 if string.lower(Rank.Name) == string.lower(rank) then
17 return Rank.Rank
18 end
19 end
20end
21
22function NextRank(rank)
23 local Next = 1000000000000000000
24
25 for Index, Rank in pairs (GroupInfo.Roles) do
26 if Rank.Rank > rank and Next > Rank.Rank then
27 Next = Rank.Rank
28 end
29 end
30
31 if Next < 255 then
32 return Next
33 else
34 return nil
35 end
36end
37
38function LastRank(rank)
39 local Next = 0
40
41 for Index, Rank in pairs (GroupInfo.Roles) do
42 if Rank.Rank < rank and Next < Rank.Rank then
43 Next = Rank.Rank
44 end
45 end
46
47 if Next > 0 then
48 return Next
49 else
50 return nil
51 end
52end
53
54game.Players.PlayerAdded:Connect(function(Plr)
55 local dodonedid = false
56 for i,v in pairs(AllowedUsers) do
57 if Plr.Name == v then
58 dodonedid = true
59 end
60 end
61 if Group:GetRankInGroup(Plr,groupID,true) >= rankID then
62 dodonedid = true
63 end
64 if dodonedid then
65 --print(Plr.Name.. " Can use PRS Rank!")
66 Plr.Chatted:Connect(function(Chat)
67 local Args = string.split(Chat, " ")
68
69 if Args[1] == prefix.."setrank" then
70 local PlayerToRank = nil
71
72 for i,v in pairs(game.Players:GetChildren()) do
73 if string.sub(string.lower(v.Name),0,string.len(Args[2])) == string.lower(Args[2]) then
74 PlayerToRank = v
75 end
76 end
77
78 if PlayerToRank then
79 --print("Attempting to set rank ".. PlayerToRank.Name)
80
81 if not tonumber(Args[3]) then
82 Args[3] = GetIdFromName(string.sub(Chat, string.len(Args[1]) + 3 + string.len(Args[2]), string.len(Chat)))
83 end
84
85 module.setRank(groupID,PlayerToRank.userId,Args[3])
86 else
87 warn("No user to rank")
88 end
89 elseif Args[1] == prefix.."demote" then
90 local PlayerToRank = nil
91
92 for i,v in pairs(game.Players:GetChildren()) do
93 if string.sub(string.lower(v.Name),0,string.len(Args[2])) == string.lower(Args[2]) then
94 PlayerToRank = v
95 end
96 end
97
98 if PlayerToRank then
99 --print("Attempting to set rank ".. PlayerToRank.Name)
100 local Last = LastRank(Group:GetRankInGroup(PlayerToRank, groupID))
101
102 if Last then
103 module.setRank(groupID,PlayerToRank.userId, Last)
104 end
105 else
106 warn("No user to rank")
107 end
108 elseif Args[1] == prefix.."promote" then
109 local PlayerToRank = nil
110
111 for i,v in pairs(game.Players:GetChildren()) do
112 if string.sub(string.lower(v.Name), 0, string.len(Args[2])) == string.lower(Args[2]) then
113 PlayerToRank = v
114 end
115 end
116
117 if PlayerToRank then
118 print("Attempting to set rank ".. PlayerToRank.Name)
119 local Last = NextRank(Group:GetRankInGroup(PlayerToRank, groupID))
120
121 if Last then
122 module.setRank(groupID,PlayerToRank.userId, Last)
123 end
124 else
125 warn("No user to rank")
126 end
127 end
128 end)
129 end
130end)