Advertisement
Guest User

Grandelf

a guest
Nov 20th, 2009
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.77 KB | None | 0 0
  1. --[[
  2.            
  3.             Vote System.
  4.                 Made by Grandelf.
  5.        
  6. ]]--
  7.  
  8. 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.
  9.  
  10. -- Dont change below here, unless you know what you're doing
  11.  
  12. local Agree = "#yes"
  13. local Disagree = "#no"
  14.  
  15. local Yes = 0
  16. local No = 0
  17.  
  18. local VoteCalled = false
  19. local VoteNames = {}
  20.  
  21. function VoteItemOnTalk(pUnit, event, player)
  22.     pUnit:GossipCreateMenu(44, player, 0)
  23.     pUnit:GossipMenuAddItem(30, "Call a vote", 1, 1)
  24.     pUnit:GossipMenuAddItem(0, "Close the vote", 2, 0)
  25.     pUnit:GossipMenuAddItem(0, "No thanks", 3, 0)
  26.     pUnit:GossipSendMenu(player)
  27. end
  28.  
  29. function VoteItemOnSelect(pUnit, event, player, id, intid, code, pMisc)
  30.     if (intid == 1) then
  31.         if (VoteCalled == true) then
  32.             player:SendBroadcastMessage("A vote has already been called, close it before opening a new one")
  33.             player:GossipComplete()
  34.         else   
  35.           local plrs = GetPlayersInWorld()
  36.             for k, v in pairs(plrs) do
  37.                 v:SendBroadcastMessage(""..code.." \nIf you agree typ #yes if you disagree typ #no")
  38.                 VoteCalled = true
  39.                 player:GossipComplete()
  40.             end
  41.         end
  42.     elseif (intid == 2) then
  43.         if (VoteCalled == true) then
  44.             VoteCalled = false
  45.             local plrs = GetPlayersInWorld()
  46.             for k, v in pairs(plrs) do
  47.                 v:SendBroadcastMessage("The vote has been closed, "..Yes.." have voted yes, and "..No.." have voted no")
  48.                 Yes = 0
  49.                 No = 0
  50.                 VoteNames = {}
  51.                 player:GossipComplete()
  52.             end
  53.         else
  54.             player:SendBroadcastMessage("You have to call a vote before closing it")
  55.             player:GossipComplete()
  56.         end
  57.     elseif (intid == 3) then
  58.         player:GossipComplete()
  59.     end
  60. end
  61.  
  62. function VoteSystem(event, player, message, type, language)
  63.     if (message == Agree) then
  64.         if (VoteCalled == true) then
  65.             if (table.find(VoteNames, player:GetName()) == true) then
  66.                 player:SendBroadcastMessage("You have already voted for this poll")
  67.             else
  68.                 table.insert(VoteNames, player:GetName())
  69.                 Yes = Yes + 1
  70.             end
  71.         else
  72.             player:SendBroadcastMessage("No vote is called at this moment")
  73.         end
  74.     elseif (message == Disagree) then
  75.         if (VoteCalled == true) then
  76.             if (table.find(VoteNames, player:GetName()) == true) then
  77.                 player:SendBroadcastMessage("You have already voted for this poll")
  78.             else
  79.                 table.insert(VoteNames, player:GetName())
  80.                 No = No + 1        
  81.             end
  82.         else
  83.             player:SendBroadcastMessage("No vote is called at this moment")
  84.         end
  85.     end
  86. end
  87.  
  88. function table.find(t, v)
  89.     if type(t) == "table" and v then
  90.         for k, val in pairs(t) do
  91.             if v == val then
  92.                 return true
  93.             end
  94.         end
  95.     end
  96.     return false
  97. end
  98.  
  99.  
  100. RegisterServerHook(16, "VoteSystem")
  101.  
  102. RegisterItemGossipEvent(VoteItem, 1, "VoteItemOnTalk")
  103. RegisterItemGossipEvent(VoteItem, 2, "VoteItemOnSelect")       
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement