Advertisement
Guest User

heh

a guest
Nov 28th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. local QuestionVGUI = {}
  2. local PanelNum = 0
  3. local VoteVGUI = {}
  4. local function MsgDoVote(question,voteid,timeleft)
  5. local _, chatY = chat.GetChatBoxPos()
  6.  
  7. if timeleft == 0 then
  8. timeleft = 100
  9. end
  10. local OldTime = CurTime()
  11. if not IsValid(LocalPlayer()) then return end -- Sent right before player initialisation
  12. LocalPlayer():EmitSound("Town.d1_town_02_elevbell1", 100, 100)
  13. local panel = vgui.Create("DFrame")
  14. panel:SetPos(3 + PanelNum, chatY - 145)
  15. panel:SetTitle("Vote")
  16. panel:SetSize(140, 140)
  17. panel:SetSizable(false)
  18. panel.btnClose:SetVisible(false)
  19. panel:SetDraggable(false)
  20. function panel:Close()
  21. PanelNum = PanelNum - 140
  22. VoteVGUI[voteid .. "vote"] = nil
  23. local num = 0
  24. for k,v in SortedPairs(VoteVGUI) do
  25. v:SetPos(num, ScrH() / 2 - 50)
  26. num = num + 140
  27. end
  28. for k,v in SortedPairs(QuestionVGUI) do
  29. v:SetPos(num, ScrH() / 2 - 50)
  30. num = num + 300
  31. end
  32. self:Remove()
  33. end
  34. function panel:Think()
  35. self:SetTitle("Time: ".. tostring(math.Clamp(math.ceil(timeleft - (CurTime() - OldTime)), 0, 9999)))
  36. if timeleft - (CurTime() - OldTime) <= 0 then
  37. panel:Close()
  38. end
  39. end
  40. panel:SetKeyboardInputEnabled(false)
  41. panel:SetMouseInputEnabled(true)
  42. panel:SetVisible(true)
  43. for i = 22, string.len(question), 22 do
  44. if not string.find(string.sub(question, i - 20, i), "\n", 1, true) then
  45. question = string.sub(question, 1, i) .. "\n".. string.sub(question, i + 1, string.len(question))
  46. end
  47. end
  48. local label = vgui.Create("DLabel")
  49. label:SetParent(panel)
  50. label:SetPos(5, 25)
  51. label:SetText(question)
  52. label:SizeToContents()
  53. label:SetVisible(true)
  54. local nextHeight = label:GetTall() > 78 and label:GetTall() - 78 or 0 // make panel taller for divider and buttons
  55. panel:SetTall(panel:GetTall() + nextHeight)
  56. local divider = vgui.Create("Divider")
  57. divider:SetParent(panel)
  58. divider:SetPos(2, panel:GetTall() - 30)
  59. divider:SetSize(180, 2)
  60. divider:SetVisible(true)
  61. local ybutton = vgui.Create("Button")
  62. ybutton:SetParent(panel)
  63. ybutton:SetPos(25, panel:GetTall() - 25)
  64. ybutton:SetSize(40, 20)
  65. ybutton:SetCommand("!")
  66. ybutton:SetText("Yes")
  67. ybutton:SetVisible(true)
  68. ybutton.DoClick = function()
  69. LocalPlayer():ConCommand("vote " .. voteid .. " yea\n")
  70. panel:Close()
  71. end
  72. local nbutton = vgui.Create("Button")
  73. nbutton:SetParent(panel)
  74. nbutton:SetPos(70, panel:GetTall() - 25)
  75. nbutton:SetSize(40, 20)
  76. nbutton:SetCommand("!")
  77. nbutton:SetText("No")
  78. nbutton:SetVisible(true)
  79. nbutton.DoClick = function()
  80. LocalPlayer():ConCommand("vote " .. voteid .. " nay\n")
  81. panel:Close()
  82. end
  83. PanelNum = PanelNum + 140
  84. VoteVGUI[voteid .. "vote"] = panel
  85. //panel:SetSkin(GAMEMODE.Config.DarkRPSkin)
  86. end
  87. usermessage.Hook("DoVote", MsgDoVote)
  88. local function KillVoteVGUI(msg)
  89. local id = msg:ReadShort()
  90. if VoteVGUI[id .. "vote"] and VoteVGUI[id .. "vote"]:IsValid() then
  91. VoteVGUI[id.."vote"]:Close()
  92. end
  93. end
  94. usermessage.Hook("KillVoteVGUI", KillVoteVGUI)
  95. local function MsgDoQuestion(msg)
  96. local question = msg:ReadString()
  97. local quesid = msg:ReadString()
  98. local timeleft = msg:ReadFloat()
  99. if timeleft == 0 then
  100. timeleft = 100
  101. end
  102. local OldTime = CurTime()
  103. LocalPlayer():EmitSound("Town.d1_town_02_elevbell1", 100, 100)
  104. local panel = vgui.Create("DFrame")
  105. panel:SetPos(3 + PanelNum, ScrH() / 2 - 50)--Times 140 because if the quesion is the second screen, the first screen is always a vote screen.
  106. panel:SetSize(300, 140)
  107. panel:SetSizable(false)
  108. panel.btnClose:SetVisible(false)
  109. panel:SetKeyboardInputEnabled(false)
  110. panel:SetMouseInputEnabled(true)
  111. panel:SetVisible(true)
  112. function panel:Close()
  113. PanelNum = PanelNum - 300
  114. QuestionVGUI[quesid .. "ques"] = nil
  115. local num = 0
  116. for k,v in SortedPairs(VoteVGUI) do
  117. v:SetPos(num, ScrH() / 2 - 50)
  118. num = num + 140
  119. end
  120. for k,v in SortedPairs(QuestionVGUI) do
  121. v:SetPos(num, ScrH() / 2 - 50)
  122. num = num + 300
  123. end
  124. self:Remove()
  125. end
  126. function panel:Think()
  127. self:SetTitle("time" .. math.Clamp(math.ceil(timeleft - (CurTime() - OldTime)), 0, 9999))
  128. if timeleft - (CurTime() - OldTime) <= 0 then
  129. panel:Close()
  130. end
  131. end
  132. local label = vgui.Create("DLabel")
  133. label:SetParent(panel)
  134. label:SetPos(5, 30)
  135. label:SetSize(380, 40)
  136. label:SetText(question)
  137. label:SetVisible(true)
  138. local divider = vgui.Create("Divider")
  139. divider:SetParent(panel)
  140. divider:SetPos(2, 80)
  141. divider:SetSize(380, 2)
  142. divider:SetVisible(true)
  143. local ybutton = vgui.Create("DButton")
  144. ybutton:SetParent(panel)
  145. ybutton:SetPos(105, 100)
  146. ybutton:SetSize(40, 20)
  147. ybutton:SetText("Yes")
  148. ybutton:SetVisible(true)
  149. ybutton.DoClick = function()
  150. LocalPlayer():ConCommand("ans " .. quesid .. " 1\n")
  151. panel:Close()
  152. end
  153. local nbutton = vgui.Create("DButton")
  154. nbutton:SetParent(panel)
  155. nbutton:SetPos(155, 100)
  156. nbutton:SetSize(40, 20)
  157. nbutton:SetText("No")
  158. nbutton:SetVisible(true)
  159. nbutton.DoClick = function()
  160. LocalPlayer():ConCommand("ans " .. quesid .. " 2\n")
  161. panel:Close()
  162. end
  163. PanelNum = PanelNum + 300
  164. QuestionVGUI[quesid .. "ques"] = panel
  165. panel:SetSkin(GAMEMODE.Config.DarkRPSkin)
  166. end
  167. usermessage.Hook("DoQuestion", MsgDoQuestion)
  168. local function KillQuestionVGUI(msg)
  169. local id = msg:ReadString()
  170. if QuestionVGUI[id .. "ques"] and QuestionVGUI[id .. "ques"]:IsValid() then
  171. QuestionVGUI[id .. "ques"]:Close()
  172. end
  173. end
  174. usermessage.Hook("KillQuestionVGUI", KillQuestionVGUI)
  175. local function DoVoteAnswerQuestion(ply, cmd, args)
  176. if not args[1] then return end
  177. local vote = 0
  178. if tonumber(args[1]) == 1 or string.lower(args[1]) == "yes" or string.lower(args[1]) == "true" then vote = 1 end
  179. for k,v in pairs(VoteVGUI) do
  180. if ValidPanel(v) then
  181. local ID = string.sub(k, 1, -5)
  182. VoteVGUI[k]:Close()
  183. RunConsoleCommand("vote", ID, vote)
  184. return
  185. end
  186. end
  187. for k,v in pairs(QuestionVGUI) do
  188. if ValidPanel(v) then
  189. local ID = string.sub(k, 1, -5)
  190. QuestionVGUI[k]:Close()
  191. RunConsoleCommand("ans", ID, vote)
  192. return
  193. end
  194. end
  195. end
  196. concommand.Add("rp_vote", DoVoteAnswerQuestion)
  197.  
  198. MsgDoVote("DWAYNE wants to be Mayor",5,60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement