Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not process.info "chatbox" then process.spawn(chatbox.run, "chatbox") end
- local messages = {
- "Ah, %s. I have been expecting you.",
- "Welcome back!",
- "Hi.",
- "Hello!",
- "Hey %s!",
- "Hi %s.",
- "WELCOME" .. ("!"):rep(10),
- "Good morning!",
- "Good evening, %s.",
- "Beneficent salutations.",
- "Good morrow, good %s."
- }
- local data = persistence "gchat"
- data.players = data.players or {}
- local function set_optin(player, thing, yesno)
- if not data.players[player] then data.players[player] = {} end
- local playerdata = data.players[player]
- if not playerdata.optin then playerdata.optin = {} end
- playerdata.optin[thing] = yesno
- chatbox.tell(player, ("Optin status for %s: %s"):format(thing, tostring(yesno)))
- data:save()
- end
- local function get_optin(player, thing)
- return data.players[player] and data.players[player].optin and data.players[player].optin[thing]
- end
- while true do
- local event, player, command, arguments = os.pullEvent ()
- if event == "join" and get_optin(player, "hi") then
- local x = messages[math.random(1, #messages)]
- if type(x) == "string" then x = x:format(player)
- elseif type(x) == "function" then x = x(player, messages) end
- print(player, x)
- sleep(1)
- chatbox.tell(player, x)
- elseif event == "command" then
- print(player, command, textutils.serialise(arguments))
- if command == "hi" then
- local sub = arguments[1]
- if sub == "optin" then
- set_optin(player, "hi", true)
- elseif sub == "optout" then
- set_optin(player, "hi", false)
- else
- chatbox.tell(player, "Command not found.")
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement