Advertisement
Handoncloud

Untitled

Jul 19th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1. local players, canVote, voted = {}, true, {}
  2.  
  3. ui.addPopup(20, 1, 'Você deseja votar?', nil, 20, 20, 200, true)
  4.  
  5. for n in pairs(tfm.get.room.playerList) do
  6.     table.insert(players, n)
  7. end
  8.  
  9. function checkVotes()
  10.     if #voted == #players then
  11.         canVote = false
  12.         for i = 1, #voted do
  13.             print(voted[i][1]..' '..(voted[i][2] == "yes" and "upvoted" or "downvoted")..'.')
  14.         end
  15.     end
  16. end
  17.  
  18. function eventNewPlayer(n)
  19.     if canVote then
  20.         local found = false
  21.         for i = 1, #players do
  22.             if players[i] == n then
  23.                 found = true
  24.                 break
  25.             end
  26.         end
  27.         if not found then
  28.             table.insert(players, n)
  29.         end
  30.     end
  31. end
  32.  
  33. function eventPlayerLeft(n)
  34.     local idx
  35.     for i = 1, #players do
  36.         if players[i] == n then
  37.             idx = i
  38.             break
  39.         end
  40.     end
  41.     local vidx
  42.     for i = 1, #voted do
  43.         if voted[i][1] == n then
  44.             vidx = i
  45.             break
  46.         end
  47.     end
  48.     table.remove(players, idx)
  49.     table.remove(voted, vidx)
  50.    
  51. end
  52.  
  53. function eventPopupAnswer(id, n, answer)
  54.     if canVote and id == 20 then
  55.         table.insert(voted, {n, answer})
  56.         checkVotes()
  57.     end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement