Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Vote System.
- Made by Grandelf.
- ]]--
- local VoteItem = 99832 -- Change VoteItem ID. This item will give you the option to call a vote, so be carefull to who you give it.
- -- Dont change below here, unless you know what you're doing
- local Agree = "#yes"
- local Disagree = "#no"
- local Yes = 0
- local No = 0
- local VoteCalled = false
- local VoteNames = {}
- function VoteItemOnTalk(pUnit, event, player)
- pUnit:GossipCreateMenu(44, player, 0)
- pUnit:GossipMenuAddItem(30, "Call a vote", 1, 1)
- pUnit:GossipMenuAddItem(0, "Close the vote", 2, 0)
- pUnit:GossipMenuAddItem(0, "No thanks", 3, 0)
- pUnit:GossipSendMenu(player)
- end
- function VoteItemOnSelect(pUnit, event, player, id, intid, code, pMisc)
- if (intid == 1) then
- if (VoteCalled == true) then
- player:SendBroadcastMessage("A vote has already been called, close it before opening a new one")
- player:GossipComplete()
- else
- local plrs = GetPlayersInWorld()
- for k, v in pairs(plrs) do
- v:SendBroadcastMessage(""..code.." \nIf you agree typ #yes if you disagree typ #no")
- VoteCalled = true
- player:GossipComplete()
- end
- end
- elseif (intid == 2) then
- if (VoteCalled == true) then
- VoteCalled = false
- local plrs = GetPlayersInWorld()
- for k, v in pairs(plrs) do
- v:SendBroadcastMessage("The vote has been closed, "..Yes.." have voted yes, and "..No.." have voted no")
- Yes = 0
- No = 0
- VoteNames = {}
- player:GossipComplete()
- end
- else
- player:SendBroadcastMessage("You have to call a vote before closing it")
- player:GossipComplete()
- end
- elseif (intid == 3) then
- player:GossipComplete()
- end
- end
- function VoteSystem(event, player, message, type, language)
- if (message == Agree) then
- if (VoteCalled == true) then
- if (table.find(VoteNames, player:GetName()) == true) then
- player:SendBroadcastMessage("You have already voted for this poll")
- else
- table.insert(VoteNames, player:GetName())
- Yes = Yes + 1
- end
- else
- player:SendBroadcastMessage("No vote is called at this moment")
- end
- elseif (message == Disagree) then
- if (VoteCalled == true) then
- if (table.find(VoteNames, player:GetName()) == true) then
- player:SendBroadcastMessage("You have already voted for this poll")
- else
- table.insert(VoteNames, player:GetName())
- No = No + 1
- end
- else
- player:SendBroadcastMessage("No vote is called at this moment")
- end
- end
- end
- function table.find(t, v)
- if type(t) == "table" and v then
- for k, val in pairs(t) do
- if v == val then
- return true
- end
- end
- end
- return false
- end
- RegisterServerHook(16, "VoteSystem")
- RegisterItemGossipEvent(VoteItem, 1, "VoteItemOnTalk")
- RegisterItemGossipEvent(VoteItem, 2, "VoteItemOnSelect")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement