Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.78 KB | None | 0 0
  1. --Vote revealer by Cheeseot, improved upon & ported to V5 by Dracer
  2.  
  3. local activeVotes = {};
  4. local font = draw.CreateFont('Arial', 14, 14);
  5. local votecolor = {};
  6. local animend = 0;
  7. local votername = ""
  8. local votetype = 0
  9. local votetarget = ""
  10. local enemyvote = 0
  11. local yescount = 0
  12. local nocount = 0
  13. local voteresult = 0
  14. local displayed = 0
  15. local g_Group = gui.Groupbox(gui.Reference("MISC", "Enhancement"), "Vote Revealer", 327,315, 297)
  16. local g_BroadcastMode = gui.Combobox(g_Group, "msc_voterevealer_broadcast", "Vote Revealer Broadcast Mode", "Off", "Broadcast Team", "Broadcast All", "Broadcast Console")
  17. local g_Draw = gui.Checkbox(g_Group, "msc_voterevealer_draw", "Vote Revealer Draw", false)
  18. local g_DrawVotes = gui.Checkbox(g_Group, "msc_voterevealer_drawvotes", "Vote Revealer Draw Votes", false)
  19. g_Draw:SetValue(true)
  20. g_DrawVotes:SetValue(true)
  21.  
  22. local timer = timer or {}
  23. local timers = {}
  24.  
  25. local function timerCreate(name, delay, times, func)
  26.  
  27. table.insert(timers, {["name"] = name, ["delay"] = delay, ["times"] = times, ["func"] = func, ["lastTime"] = globals.RealTime()})
  28.  
  29. end
  30.  
  31. local function timerRemove(name)
  32.  
  33. for k,v in pairs(timers or {}) do
  34.  
  35. if (name == v["name"]) then table.remove(timers, k) end
  36.  
  37. end
  38.  
  39. end
  40.  
  41. local function timerTick()
  42.  
  43. for k,v in pairs(timers or {}) do
  44.  
  45. if (v["times"] <= 0) then table.remove(timers, k) end
  46.  
  47. if (v["lastTime"] + v["delay"] <= globals.RealTime()) then
  48. timers[k]["lastTime"] = globals.RealTime()
  49. timers[k]["times"] = timers[k]["times"] - 1
  50. v["func"]()
  51. end
  52.  
  53. end
  54.  
  55. end
  56.  
  57. callbacks.Register( "Draw", "timerTick", timerTick);
  58.  
  59. local function startTimer()
  60. timerCreate("sleep", 4, 1, function() animend = 1; enemyvote = 0; voteresult = 0; displayed = 0 end)
  61. end
  62.  
  63. local function getVoteEnd(um)
  64. if gui.GetValue("misc.master") == false then return end
  65. if um:GetID() == 47 or um:GetID() == 48 then
  66. startTimer()
  67. yescount = 0
  68. nocount = 0
  69. enemyvote = 2
  70.  
  71. if um:GetID() == 47 then
  72. voteresult = 1
  73. if (g_BroadcastMode:GetValue() == 1) then
  74. client.ChatTeamSay("Vote Passed")
  75. elseif (g_BroadcastMode:GetValue() == 2) then
  76. client.ChatSay("Vote Passed")
  77. elseif (g_BroadcastMode:GetValue() == 3) then
  78. print("Vote Passed")
  79. end
  80. end
  81. if um:GetID() == 48 then
  82. voteresult = 2
  83. if (g_BroadcastMode:GetValue() == 1) then
  84. client.ChatTeamSay("Vote Failed")
  85. elseif (g_BroadcastMode:GetValue() == 2) then
  86. client.ChatSay("Vote Failed")
  87. elseif (g_BroadcastMode:GetValue() == 3) then
  88. print("Vote Failed")
  89. end
  90. end
  91. end
  92.  
  93. if um:GetID() == 46 then
  94. local localPlayer = entities.GetLocalPlayer();
  95. local team = um:GetInt(1)
  96. local idx = um:GetInt(2)
  97. votetype = um:GetInt(3)
  98. votetarget = um:GetString(5)
  99. votername = client.GetPlayerNameByIndex(idx)
  100. if localPlayer:GetTeamNumber() ~= team and votetype ~= 1 then
  101. enemyvote = 1
  102. displayed = 1
  103. end
  104.  
  105. if votetype == 0 then
  106. votetypename = "kick player: "
  107. elseif votetype == 6 then
  108. votetypename = "Surrender"
  109. elseif votetype == 13 then
  110. votetypename = "Call a timeout"
  111. end
  112.  
  113. if (g_BroadcastMode:GetValue() == 1) then
  114. client.ChatTeamSay(votername .. " wants to " .. votetypename .. votetarget)
  115. elseif (g_BroadcastMode:GetValue() == 2) then
  116. client.ChatSay(votername .. " wants to " .. votetypename .. votetarget)
  117. elseif (g_BroadcastMode:GetValue() == 3) then
  118. print(votername .. " wants to " .. votetypename .. votetarget)
  119. end
  120. end
  121. end;
  122.  
  123. callbacks.Register("DispatchUserMessage", getVoteEnd)
  124.  
  125. -- Vote revealer by Cheeseot
  126.  
  127.  
  128. local function add(time, ...)
  129. table.insert(activeVotes, {
  130. ["text"] = { ... },
  131. ["time"] = time,
  132. ["delay"] = globals.RealTime() + time,
  133. ["color"] = {votecolor, {10, 10, 10}},
  134. ["x_pad"] = -11,
  135. ["x_pad_b"] = -11,
  136. })
  137. end
  138.  
  139. local function getMultiColorTextSize(lines)
  140. local fw = 0
  141. local fh = 0;
  142. for i = 1, #lines do
  143. draw.SetFont(font);
  144. local w, h = draw.GetTextSize(lines[i][4])
  145. fw = fw + w
  146. fh = h;
  147. end
  148. return fw, fh
  149. end
  150.  
  151. local function drawMultiColorText(x, y, lines)
  152. local x_pad = 0
  153. for i = 1, #lines do
  154. local line = lines[i];
  155. local r, g, b, msg = line[1], line[2], line[3], line[4]
  156. draw.SetFont(font);
  157. draw.Color(r, g, b, 255);
  158. draw.Text(x + x_pad, y, msg);
  159. local w, _ = draw.GetTextSize(msg)
  160. x_pad = x_pad + w
  161. end
  162. end
  163.  
  164. local function showVotes(count, color, text, layer)
  165. local y = 650 + (42 * (count - 1));
  166. local w, h = getMultiColorTextSize(text)
  167. local mw = w < 50 and 50 or w
  168. if globals.RealTime() < layer.delay then
  169. if layer.x_pad < mw then layer.x_pad = layer.x_pad + (mw - layer.x_pad) * 0.05 end
  170. if layer.x_pad > mw then layer.x_pad = mw end
  171. if layer.x_pad > mw / 1.09 then
  172. if layer.x_pad_b < mw - 6 then
  173. layer.x_pad_b = layer.x_pad_b + ((mw - 6) - layer.x_pad_b) * 0.05
  174. end
  175. end
  176. if layer.x_pad_b > mw - 6 then
  177. layer.x_pad_b = mw - 6
  178. end
  179. elseif animend == 1 then
  180. if layer.x_pad_b > -11 then
  181. layer.x_pad_b = layer.x_pad_b - (((mw - 5) - layer.x_pad_b) * 0.05) + 0.01
  182. end
  183. if layer.x_pad_b < (mw - 11) and layer.x_pad >= 0 then
  184. layer.x_pad = layer.x_pad - (((mw + 1) - layer.x_pad) * 0.05) + 0.01
  185. end
  186. if layer.x_pad < 0 then
  187. table.remove(activeVotes, count)
  188. end
  189. end
  190. local c1 = color[1]
  191. local c2 = color[2]
  192. local a = 255;
  193. if(g_DrawVotes:GetValue()) then
  194. draw.Color(c1[1], c1[2], c1[3], a);
  195. draw.FilledRect(layer.x_pad - layer.x_pad, y, layer.x_pad + 28, (h + y) + 20);
  196. draw.Color(c2[1], c2[2], c2[3], a);
  197. draw.FilledRect(layer.x_pad_b - layer.x_pad, y, layer.x_pad_b + 22, (h + y) + 20);
  198. drawMultiColorText(layer.x_pad_b - mw + 18, y + 9, text)
  199. end
  200. end
  201.  
  202. -- Vote revealer by Cheeseot
  203.  
  204.  
  205. local function voteCast(e)
  206. if gui.GetValue("misc.master") == false then return end
  207. if (e:GetName() == "vote_cast") then
  208. timerRemove("sleep")
  209. animend = 0;
  210. local index = e:GetInt("entityid");
  211. local vote = e:GetInt("vote_option");
  212. local name = client.GetPlayerNameByIndex(index)
  213.  
  214. local votearray = {};
  215. local namearray = {};
  216. if vote == 0 then
  217. votearray = { 150, 185, 1, "YES" }
  218. namearray = { 150, 185, 1, name }
  219. votecolor = { 150, 185, 1}
  220. yescount = yescount + 1
  221. elseif vote == 1 then
  222. votearray = { 185, 20, 1, "NO" }
  223. namearray = { 185, 20, 1, name }
  224. votecolor = { 185, 20, 1}
  225. nocount = nocount + 1
  226. else
  227. votearray = { 150, 150, 150, "??" }
  228. namearray = { 150, 150, 150, name }
  229. votecolor = { 150, 150, 150}
  230. end
  231.  
  232. if (g_BroadcastMode:GetValue() == 1) then
  233. client.ChatTeamSay(name .. " voted: " .. votearray[4])
  234. elseif (g_BroadcastMode:GetValue() == 2) then
  235. client.ChatSay(name .. " voted: " .. votearray[4])
  236. elseif (g_BroadcastMode:GetValue() == 3) then
  237. print(name .. " voted: " .. votearray[4])
  238. end
  239.  
  240. add(3,
  241. namearray,
  242. { 255, 255, 255, " voted: " },
  243. votearray,
  244. { 255, 255, 255, " " });
  245. end
  246. end;
  247.  
  248. callbacks.Register('FireGameEvent', voteCast)
  249.  
  250. local function makeVote()
  251. for index, votes in pairs(activeVotes) do
  252. showVotes(index, votes.color, votes.text, votes)
  253. end
  254. end;
  255.  
  256. callbacks.Register('Draw', makeVote)
  257.  
  258. client.AllowListener("vote_cast")
  259.  
  260.  
  261. local function drawVote()
  262. if gui.GetValue("misc.master") == false then return end
  263. local font2 = draw.CreateFont('Arial', 20, 20);
  264. draw.SetFont(font2)
  265. local votetypename = ""
  266. if(g_Draw:GetValue()) then
  267. if enemyvote == 1 then
  268. if votetype == 0 then
  269. votetypename = "kick player: "
  270. elseif votetype == 6 then
  271. votetypename = "Surrender"
  272. elseif votetype == 13 then
  273. votetypename = "Call a timeout"
  274. else return
  275. end
  276. draw.Color(255,150,0,255)
  277. draw.FilledRect(0, 525, draw.GetTextSize(votername .. " wants to " .. votetypename .. votetarget) + 30, 625)
  278. draw.Color(10,10,10,255)
  279. draw.FilledRect(0, 525, draw.GetTextSize(votername .. " wants to " .. votetypename .. votetarget) + 20, 625)
  280. draw.Color(150,185,1,255)
  281. draw.Text(5 + (draw.GetTextSize(votername .. " wants to " .. votetypename .. votetarget) / 2) - 25 - (draw.GetTextSize(" Yes")), 595, yescount .. " Yes")
  282. draw.Color(185,20,1,255)
  283. draw.Text(5 + (draw.GetTextSize(votername .. " wants to " .. votetypename .. votetarget) / 2) + 25 , 595, nocount .. " No")
  284. draw.Color(255,150,0,255)
  285. draw.Text(5, 550, votername)
  286. draw.Color(255,255,255,255)
  287. draw.Text(draw.GetTextSize(votername .. " ") + 5, 550, "wants to ")
  288. if votetype == 0 then draw.Color(255,255,255,255) else draw.Color(255,150,0,255) end
  289. draw.Text(draw.GetTextSize(votername .. " wants to ") + 5, 550, votetypename)
  290. draw.Color(255,150,0,255)
  291. draw.Text(draw.GetTextSize(votername .. " wants to " .. votetypename) + 5, 550, votetarget)
  292. elseif enemyvote == 2 and displayed == 1 then
  293. if voteresult == 1 then
  294. draw.Color(150,185,1,255)
  295. draw.FilledRect(0, 525, draw.GetTextSize(votername .. " wants to " .. votetypename .. votetarget) + 30, 625)
  296. draw.Color(10,10,10,255)
  297. draw.FilledRect(0, 525, draw.GetTextSize(votername .. " wants to " .. votetypename .. votetarget) + 20, 625)
  298. draw.Color(150,185,1,255)
  299. draw.Text(5, 575 - 10 , "Vote Passed.")
  300. elseif voteresult == 2 then
  301. draw.Color(185,20,1,255)
  302. draw.FilledRect(0, 525, draw.GetTextSize("Vote Failed.") + 110, 625)
  303. draw.Color(10,10,10,255)
  304. draw.FilledRect(0, 525, draw.GetTextSize("Vote Failed.") + 100, 625)
  305. draw.Color(185,20,1,255)
  306. draw.Text(50, 575 - 10, "Vote Failed.")
  307. end
  308. end
  309. end
  310. end
  311.  
  312. callbacks.Register("Draw", drawVote)
  313.  
  314. local function reset()
  315. if entities.GetLocalPlayer() == nil then
  316. enemyvote = 0;
  317. activeVotes = {};
  318. displayed = 0;
  319. end
  320. end
  321. callbacks.Register("Draw", reset)
  322.  
  323. -- Vote revealer by Cheeseot, improved upon & ported to V5 by Dracer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement