Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function splitStr(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do
- count = count + 1
- end
- return count
- end
- function getItemData()
- local unused, output = commands.exec("/entitydata @e[type=Item,r=3] {}")
- if output[1] == nil then
- return nil
- end
- local str = ""..output[1]
- return str
- end
- function isBadgeCase(data)
- if data == nil then
- return false
- else
- return string.find(data, "badgecase") ~= nil
- end
- end
- function getCaseOwner(data)
- local unused, start = string.find(data, "Username")
- if start == nil then
- return ""
- end
- start = start + 3
- local fromStart = string.sub(data, start)
- return string.sub(fromStart, 0, string.find(fromStart, "\"") - 1)
- end
- function getPlayerName()
- local unused, output = commands.exec("/entitydata @p {}")
- local str = ""..output[1]
- return string.sub(str, 0, string.find(str, "is") - 2)
- end
- function getBadges(data)
- local str = data
- local begin = string.find(str,"Badges:")
- if begin == nil then
- return {}
- end
- str = string.sub(str,begin)
- local start = string.find(str, "\"") + 1
- local fromstart = string.sub(str,string.find(str, "\"") + 1)
- local finish = string.find(fromstart.."", "\"") - 1
- local badgesStr = string.sub(fromstart, 1, finish)
- return splitStr(badgesStr, ',')
- end
- function containsDuplicates(T)
- for i = 1, tablelength(T) do
- for j = i + 1, tablelength(T) do
- if(T[i] == T[j]) then
- return true
- end
- end
- end
- return false
- end
- --------------------main--------------------
- local scoreboardCommand = "/scoreboard players tag @p add Has8Badges"
- local itemData = getItemData()
- local playerName = getPlayerName()
- if isBadgeCase(itemData) then
- if getCaseOwner(itemData) == playerName then
- local badges = getBadges(itemData)
- if tablelength(badges) >= 8 then
- if not containsDuplicates(badges) then
- commands.exec(scoreboardCommand)
- commands.exec("/tell @p Congratulations! You are now officially recognized as having all 8 Gym Badges!")
- else
- commands.exec("/tell @p One or more of your badges are the same badge!")
- end
- else
- commands.exec("/tell @p You don't have 8 badges!")
- end
- else
- commands.exec("/tell @p This is not your badge case!")
- end
- else
- commands.exec("/tell @p Please drop your badge case on the ground!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement