Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Assets--
- local rep = game.ReplicatedStorage
- local assets = rep.Assets
- --Maps--
- local maps = assets.Maps
- --Signals--
- local signals = assets.Signals
- local event = signals.Event
- local fevent = signals.FEvent
- --Static Variables--
- local mapVotes = {}
- --Game Variables--
- local Game = workspace.Game
- local stats = Game.Stats
- local settings = {
- mapVoteTime=15;
- mapVoteDelay=120;
- playersRequired=1;
- }
- --Primary Events--
- --[[
- ARRAY = mapVotes
- MapArray
- Id
- mapName
- players
- players=UserId
- --]]
- event.OnServerEvent:connect(function(player,variables)
- if variables.reason == "voteOnMap" then
- --First check if a player already voted on a map, if so change vote
- for a,b in pairs(mapVotes) do
- for d,c in pairs(b.players) do
- if c.player == player.UserId then
- table.remove(b.players,d)
- break
- end
- end
- end
- --Add player to the map votes.
- for a,b in pairs(mapVotes) do
- if b.id == variables.itemNum then
- table.insert(b.players,{player=player.UserId})
- end
- end
- elseif variables.reason == "removeFromVote" then
- for a,b in pairs(mapVotes) do
- for d,c in pairs(b.players) do
- if c.player == player.UserId then
- table.remove(b.players, d)
- break
- end
- end
- end
- end
- end)
- function getMap()
- local randomMap = maps:GetChildren()[math.random(1,#maps:GetChildren())]
- for a,b in pairs(mapVotes) do
- if b.mapName == randomMap.Name then
- return getMap()
- end
- end
- return randomMap.Name
- end
- while wait() do
- if #game.Players:GetPlayers() < settings.playersRequired then
- local playersNeeded = settings.playersRequired-#game.Players:GetPlayers()
- stats.Status.Value = playersNeeded.." "..((playersNeeded==1 and "Player")or "Players").." needed to play!"
- else
- --Assign maps
- mapVotes={}
- for a,b in pairs(Game.Special.VotingPads:GetChildren()) do
- table.insert(mapVotes, {id=tonumber(b.Name:match("%d+")); MapName=getMap(); players={};})
- end
- --Fire clients, start sending in votes.
- event:FireAllClients({reason="startVoting"})
- --Do main loop
- local start = tick()
- while wait() do
- if tick()-start >= settings.mapVoteTime then break end
- local secondsLeft = math.floor(settings.mapVoteTime-(tick()-start))
- stats.Status.Value = secondsLeft.." "..((secondsLeft==1 and "Second") or "Seconds").." Left to Vote!"
- for a,b in pairs(Game.Special.VotingPads:GetChildren()) do
- local playersVoting, mName
- for d,c in pairs(mapVotes) do
- if c.id == tonumber(b.Name:match("%d+")) then
- playersVoting=#c.players
- mName=c.MapName
- break
- end
- end
- b.sGui.Title.Text = mName.." - "..playersVoting.." "..((playersVoting==1 and "Voter") or "Voters")
- end
- end
- --Get winner
- table.sort(mapVotes, function(a,b) return #a.players>#b.players end)
- for a,b in pairs(Game.Special.VotingPads:GetChildren()) do
- if tonumber(b.Name:match("%d+")) == mapVotes[1].id then
- b.sGui.Title.Text = "Winner!"
- stats.Status.Value = mapVotes[1].MapName.." has been chosen!"
- else
- b.sGui.Title.Text = "Lost Vote!"
- end
- end
- wait(settings.mapVoteDelay)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement