Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- --- INSTRUCTIONS ---
- Arguments: dialogue (file), any non-nil value (allows it to play more than once)
- Make a file for dialogue, it must follow this format strictly:
- Do not add quote marks around strings, just leave them bare.
- line 1: name, like "Announcer"
- line 2: radius, how far people can read the messages
- line 3: A color. Valid values are "black", "dark_blue", "dark_green",
- "dark_aqua", "dark_red", "dark_purple", "gold", "gray", "dark_gray",
- "blue", "green", "aqua", "red", "light_purple", "yellow", "white", and
- "reset" (cancels out the effects of colors used by parent objects).
- Technically, "bold", "underline", "italic", "strikethrough", and
- "obfuscated" are also accepted, but it may be better practice to use
- the tags below for such formats.
- line 4: This line and following lines are dialogue. Dialogue is defined like so:
- "03 Hello, world!"
- The first number, which must be two digits, is the timing. This specifies
- how long the system will wait before writing the rest of the line. The rest
- of the line is simply dialogue, nothing fancy about it.
- http://minecraft.gamepedia.com/Commands#Raw_JSON_text
- After this file has been created, simply call it as an argument with this program.
- --]]
- tArgs = {...}
- --- Dialogue class
- local dia = { }
- dia.conf = { }
- dia.conf.name = "Announcer"
- dia.conf.radius = 10
- dia.conf.color = "gray"
- dia.conf.timings = { }
- dia.conf.dialogue = {
- "03 Test.",
- }
- function dia:say()
- for n, i in pairs(self.conf.dialogue) do
- os.sleep(self.conf.timings[n])
- commands.exec("tellraw @a[r=" .. self.conf.radius .. "] { text:\"[" .. self.conf.name .. "] " .. i .. "\", color:" .. self.conf.color .. ", italic:true }")
- end
- end
- function dia:chkfile(cnffile)
- if not fs.exists(cnffile) then
- local h = fs.open(cnffile, "w")
- h.write("f")
- h.close()
- end
- end
- function dia:cnf(ar)
- local cnffile = "talk.reg"
- if ar[2] == nil then
- self:chkfile(cnffile)
- local h = fs.open(cnffile , "r")
- if h.readLine() == "f" then
- h.close()
- h = fs.open(cnffile, "w")
- h.write("t")
- h.close()
- return false
- else
- return true
- end
- else
- return false
- end
- end
- function dia:enter_config(ar)
- local d = nil
- local c = 1
- if ar[1] ~= nil then
- local h = fs.open(tostring(ar[1]), "r")
- self.conf.name = h.readLine()
- self.conf.radius = tonumber(h.readLine())
- self.conf.color = h.readLine()
- while(true) do
- d = h.readLine()
- if d ~= nil then
- self.conf.dialogue[c] = string.sub(d, 4)
- self.conf.timings[c] = tonumber(string.sub(d, 1, 2))
- c = c + 1
- else break end
- end
- h.close()
- end
- end
- function dia:main(ar)
- self:enter_config(ar)
- while(true) do
- local event, param = os.pullEvent()
- if event == "redstone" and redstone.getInput("back") == true then
- if self:cnf(ar) == false then
- self:say()
- if ar[2] == nil then break end
- else break end
- else end
- os.sleep(0.1)
- end
- end
- --- Entry
- local p = dia
- p:main(tArgs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement