Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require "component"
- local unicode = require "unicode"
- local event = require "event"
- local ser = require "serialization"
- local gpu = component.gpu
- local cb = component.command_block
- local chat = component.chat_box
- --local debug = component.debug
- local running = true
- local voteTimer = nil
- local voting = false
- local maxPlayers = 10
- local currentVote = nil
- local voteInitiaterPlayer = nil
- local positiveVote = 0
- local negativeVote = 0
- local votePlayers = {}
- local positiveWords = {
- ["+"] = true,
- ["плюс"] = true,
- ["да"] = true,
- ["за"] = true,
- ["угу"] = true
- }
- local negativeWords = {
- ["-"] = true,
- ["минус"] = true,
- ["негативно"] = true,
- ["нет"] = true
- }
- local function reset()
- if (voteTimer) then event.cancel(voteTimer) end
- voting = false
- currentVote = nil
- voteInitiaterPlayer = nil
- positiveVotePlayers = 0
- negativeVotePlayers = 0
- votePlayers = {}
- running = false
- end
- local offRainVote = {
- voteName = "ОТКЛЮЧЕНИЕ ДОЖДЯ",
- voteAcceptText = "Дождь отключен по решению большинства игроков.",
- voteRejectText = "Недостаточно голосов за отключение дождя.",
- cmd = '/tellraw @a {text:"Дождь типа отключен", color:dark_red}',
- voteTime = 20
- }
- local setDayVote = {
- voteName = "ВКЛЮЧИТЬ ДЕНЬ",
- voteAcceptText = "День включен по решению большинства игроков.",
- voteRejectText = "Недостаточно голосов для включения дня.",
- cmd = '/tellraw @a {text:"Как пройти в библиотеку?", color:dark_red}',
- voteTime = 20
- }
- local function checkResult()
- if ( positiveVote > negativeVote ) then
- cb.setCommand(currentVote.cmd)
- cb.executeCommand()
- chat.say(currentVote.voteAcceptText .. ".")
- else
- chat.say("Голосование отменено: " .. currentVote.voteRejectText .. ".")
- end
- reset()
- end
- local function startVoteTimer(time)
- voteTimer = event.timer(time, checkResult)
- end
- local function stopVoteTimer()
- if (voteTimer) then event.cancel(voteTimer) end
- end
- local topics = {
- ["начать голосование: отключить дождь"] = offRainVote,
- ["начать голосование: включить день"] = setDayVote
- }
- while ( running ) do
- local e = {event.pull()}
- if ( e[1] == "chat_message" ) then
- local msg = unicode.lower(e[4])
- if ( not voting ) then
- currentVote = topics[msg]
- voteInitiaterPlayer = e[3]
- if ( currentVote ) then
- voting = true
- startVoteTimer(currentVote.voteTime)
- chat.say('Началось голосование: "' .. currentVote.voteName .. '". Инициатор: ' .. voteInitiaterPlayer .. ".")
- end
- else
- if ( positiveWords[msg] and not votePlayers[ e[3] ] ) then
- positiveVote = positiveVote + 1
- votePlayers[ e[3] ] = true
- chat.say('Голосов "ЗА/ПРОТИВ": ' .. positiveVote .. "/" .. negativeVote)
- elseif ( negativeWords[msg] and not votePlayers[ e[3] ] ) then
- negativeVote = negativeVote + 1
- votePlayers[ e[3] ] = true
- chat.say('Голосов "ЗА/ПРОТИВ": ' .. positiveVote .. "/" .. negativeVote)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement