18 Kasım 2018, 22:34:17

Gönderen Konu: [YARDIM] Votemanager Sağ Alt Alma  (Okunma sayısı 430 defa)

0 Üye ve 1 Ziyaretçi konuyu incelemekte.

boatz

  • Yeni Üye
  • *
  • Default Avatar
  • İleti: 77
  • :) Herkes Ederi Kadar Kimse Fazlasını İstemesin
[YARDIM] Votemanager Sağ Alt Alma
« : 12 Mart 2017, 22:09:54 »
Merhaba Arkadaşlar Votemanageri Bir Türlü Sağ Alta Alamıyorum Yardım Edebilecek Varmı Lütfen? Client'ini Atıyim Yardım Edebilen Olursa Çok Sevinirim

Kod: Lua
  1. screenWidth, screenHeight = guiGetScreenSize()
  2. local rootElement = getRootElement()
  3.  
  4. local voteWindow
  5. local boundVoteKeys = {}
  6. local nameFromVoteID = {}
  7. local voteIDFromName = {}
  8. local optionLabels = {}
  9.  
  10. local isVoteActive
  11. local hasAlreadyVoted = false
  12. local isChangeAllowed = false
  13.  
  14. local timeLabel
  15. local finishTime
  16.  
  17. local cacheVoteNumber
  18. local cacheTimer
  19. last = 1
  20.  
  21.  
  22. local timeCache = false
  23. local function updateTime()
  24.         local seconds = math.ceil((finishTime - getTickCount()) / 1000)
  25.         if timeCache ~= seconds and seconds > -1 then
  26.                 if tostring(seconds) == "-0" then
  27.                         seconds = 0
  28.                 end
  29.                 timeCache = seconds
  30.  
  31.                 countdown_text = tostring(seconds)
  32.         end
  33. end
  34.  
  35. addEvent("doShowPoll", true)
  36. addEvent("doSendVote", true)
  37. addEvent("doStopPoll", true)
  38.  
  39. addEventHandler("doShowPoll", rootElement, function(pollData, pollOptions, pollTime)
  40.         --clear the send vote cache
  41.         cacheVoteNumber = ""
  42.         --clear the bound keys table
  43.         boundVoteKeys = {}
  44.         --store the vote option names in the array nameFromVoteID
  45.         nameFromVoteID = pollOptions
  46.         --then build a reverse table
  47.         voteIDFromName = {}
  48.  
  49.         --Reset
  50.         titleSuffix = ""
  51.         optionsVotes = {}
  52.                
  53.         --determine if we have to append nomination number
  54.         local nominationString = ""
  55.         if pollData.nomination > 1 then
  56.                 nominationString = " (nomination "..pollData.nomination..")"
  57.         end
  58.                
  59.         isChangeAllowed = pollData.allowchange
  60.  
  61.         -- layout.title.width  = layout.window.width - 20
  62.         -- layout.option.width = layout.window.width
  63.         -- layout.cancel.width = layout.window.width
  64.         -- layout.time.width   = layout.window.width
  65.                
  66.         local screenX, screenY = guiGetScreenSize()
  67.        
  68.         --Bind options to keys
  69.         for index, option in ipairs(pollOptions) do
  70.                 --Bind 10th option to 0-key
  71.                 if index == 10 then
  72.                         index = 0
  73.                         break
  74.                 end
  75.  
  76.                 --bind the number key and add it to the bound keys table
  77.                 local optionKey = tostring(index)
  78.                 bindKey(optionKey, "down", sendVote_bind)
  79.                 bindKey("num_"..optionKey, "down", sendVote_bind)
  80.                        
  81.                 table.insert(boundVoteKeys, optionKey)
  82.         end
  83.                
  84.         if isChangeAllowed then
  85.                 bindKey("backspace", "down", sendVote_bind)
  86.         end
  87.  
  88.         --Set table up
  89.         optionTable = pollOptions
  90.  
  91.         --Calculate window width
  92.         local highestWidth = 0
  93.         for i,opt in ipairs(optionTable) do
  94.                 local _w = dxGetTextWidth(i ..". ".. opt .." (000)", 1.00, fontBold) + textXoffset + 20
  95.                 highestWidth = math.max(_w, highestWidth)
  96.         end
  97.         backgroundWidth = math.max(backgroundMinWidth, highestWidth)
  98.  
  99.         description_text = pollData.title
  100.  
  101.         setPollVisible(true)
  102.         isVoteActive = true
  103.         finishTime = getTickCount() + pollTime
  104.         addEventHandler("onClientRender", rootElement, updateTime)
  105. end)
  106.  
  107. function setOption(number)
  108.         if number == -1 then
  109.                 selectedVote = false
  110.         else
  111.                 selectedVote = number
  112.         end
  113. end
  114.  
  115. addEventHandler("doStopPoll", rootElement, function()
  116.         isVoteActive = false
  117.         hasAlreadyVoted = false
  118.  
  119.         for i, key in ipairs(boundVoteKeys) do
  120.                 unbindKey(key, "down", sendVote_bind)
  121.                 unbindKey("num_"..key, "down", sendVote_bind)
  122.         end
  123.                
  124.         unbindKey("backspace", "down", sendVote_bind)
  125.         setPollVisible(false)
  126.         removeEventHandler("onClientRender", rootElement, updateTime)
  127. end)
  128.  
  129. function sendVote_bind(key)
  130.         if key ~= "backspace" then
  131.                 key = key:gsub('num_', '')
  132.                 if #nameFromVoteID < 10 then
  133.                         return sendVote(tonumber(key))
  134.                 else
  135.                         cacheVoteNumber = cacheVoteNumber .. key
  136.                         if #cacheVoteNumber > 1 then
  137.                                 if isTimer(cacheTimer) then
  138.                                         killTimer(cacheTimer)
  139.                                 end
  140.                                 cacheVoteNumber = tonumber(cacheVoteNumber)
  141.                                 if nameFromVoteID[cacheVoteNumber] then
  142.                                         if cacheVoteNumber < 10 then
  143.                                                 return sendVote(cacheVoteNumber)
  144.                                         else
  145.                                                 cacheTimer = setTimer(sendVote, 500, 1, cacheVoteNumber)
  146.                                         end
  147.                                         cacheVoteNumber = key
  148.                                 else
  149.                                         cacheVoteNumber = ""
  150.                                 end
  151.                         else           
  152.                                 cacheTimer = setTimer(sendVote, 500, 1, tonumber(cacheVoteNumber))
  153.                         end
  154.                 end
  155.         else
  156.                 return sendVote(-1)
  157.         end
  158. end
  159.  
  160. function sendVote(voteID)
  161.         if not isVoteActive then
  162.                 return
  163.         end
  164.        
  165.         --if option changing is not allowed, unbind the keys
  166.         if not isChangeAllowed and voteID ~= -1 then
  167.                 for i, key in ipairs(boundVoteKeys) do
  168.                         unbindKey(key, "down", sendVote_bind)
  169.                         unbindKey("num_"..key, "down", sendVote_bind)
  170.                 end
  171.         end
  172.        
  173.         --if the player hasn't voted already (or if vote change is allowed anyway), update the vote text
  174.         if not hasAlreadyVoted or isChangeAllowed then
  175.                 if voteID ~= -1 then
  176.                         setOption(voteID)
  177.                 end
  178.         end
  179.  
  180.         if voteID == -1 then
  181.                 setOption(voteID)
  182.         end
  183.        
  184.         --clear the send vote cache
  185.         cacheVoteNumber = ""
  186.         hasAlreadyVoted = voteID
  187.        
  188.         --send the vote to the server
  189.         triggerServerEvent("onClientSendVote", localPlayer, voteID)
  190. end
  191. addEventHandler("doSendVote", rootElement, sendVote)
  192.  
  193. addCommandHandler("vote", function(command, ...)
  194.         --join all passed parameters separated by spaces
  195.         local voteString = table.concat({...}, ' ')
  196.         --try to get the voteID number
  197.         local voteID = tonumber(voteString) or voteIDFromName[voteString]
  198.         --if vote number is valid, send it
  199.         if voteID and (nameFromVoteID[voteID] or voteID == -1) then
  200.                 sendVote(voteID)
  201.         end
  202. end)
  203.  
  204. addCommandHandler("cancelvote", function ()
  205.         sendVote(-1)
  206. end)
  207.  
  208. function table.insertUnique(t,val)
  209.         for k,v in pairs(t) do
  210.                 if v == val then
  211.                         return
  212.                 end
  213.         end
  214.         table.insert(t,val)
  215. end
  216.  
  217. -- GUI --
  218. local screenW, screenH = guiGetScreenSize()
  219.  
  220. optionTable =  {
  221.         "Option text",
  222.         "Option text",
  223.         "Option text",
  224. }
  225. option_amount = #optionTable -- This changes with poll
  226. selectedVote = false
  227. backgroundWidth = 535 -- should change with text width
  228. backgroundMinWidth = 400
  229. backgroundHeight = 400 -- should change with option amounts
  230. backgroundX = screenW/2-(backgroundWidth/2)
  231. backgroundY = screenH -- used to hide before animation
  232. title_height = 55
  233. descriptionYoffset = 40
  234. textXoffset = 22
  235. descriptionHeight = 40
  236. first_option_text_Yoffset = 65
  237. option_text_height = 30
  238. countdown_text_height = 35
  239. unvote_text_height = 55
  240. backgroundHeight = (option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height+unvote_text_height+2
  241. trueBackgroundY = false -- True Y position where it should go after anim
  242.  
  243. font = "default"
  244. fontBold = "default-bold"
  245. bigFont = "default-bold"
  246.  
  247. countdown_text = "10"
  248. description_text = "Vote Description text:"
  249. local titleSuffix = ""
  250. local optionVotes = {}
  251.  
  252. local isPostGUI = true
  253. local function draw()
  254.         --Background
  255.         dxDrawRectangle(backgroundX, backgroundY, backgroundWidth, backgroundHeight, tocolor(0, 0, 0, 200), isPostGUI,false)
  256.  
  257.         --Title
  258.         dxDrawRectangle(backgroundX, backgroundY, backgroundWidth, title_height, tocolor(72, 118, 255, 300), isPostGUI,false)
  259.  
  260.         --Title glass (?)
  261.         dxDrawRectangle(backgroundX, backgroundY, backgroundWidth, 17.5, tocolor(65, 105, 225, 300), isPostGUI,false)
  262.  
  263.         --Title
  264.         dxDrawText("Vote" .. titleSuffix, backgroundX, backgroundY, backgroundX + backgroundWidth, backgroundY+title_height, tocolor(95, 158, 160, 255), 1, bigFont, "center", "center", false, false, isPostGUI, false, false)
  265.  
  266.         --Description
  267.         dxDrawText(description_text, backgroundX+textXoffset, backgroundY+descriptionYoffset, backgroundX + backgroundWidth - 20, backgroundY+descriptionYoffset+descriptionHeight, tocolor(72, 209, 204, 255), 1, fontBold, "left", "top", false, true, isPostGUI, false, false)
  268.        
  269.         --Options
  270.         for i, option in ipairs(optionTable) do
  271.                 local votes = 0
  272.                 if optionVotes[i] ~= nil then
  273.                         votes = optionVotes[i]
  274.                 end
  275.  
  276.                 local text = i..". "..option .. " (".. tostring(votes) ..")"
  277.                 local curFont, curColor
  278.  
  279.                 --Selected option
  280.                 if i == selectedVote then
  281.                         dxDrawRectangle(backgroundX, backgroundY+first_option_text_Yoffset+(option_text_height*i), backgroundWidth, option_text_height, tocolor(0, 205, 205, 228), isPostGUI,false)
  282.                         curFont = bigFont
  283.                         curColor = tocolor(10, 10, 10, 255)
  284.                 else
  285.                         curFont = font
  286.                         curColor = tocolor(255, 255, 255, 255)
  287.                 end
  288.  
  289.                 dxDrawText(text, backgroundX+textXoffset, backgroundY + first_option_text_Yoffset + (option_text_height*i), backgroundX+backgroundWidth, backgroundY + first_option_text_Yoffset + (option_text_height*i) + option_text_height, curColor, 1.00, curFont, "left", "center", false, false, isPostGUI, false, false)
  290.         end
  291.  
  292.         --Countdown
  293.         local countdown = dxDrawText(countdown_text, backgroundX, backgroundY+(option_text_height*option_amount)+option_text_height+first_option_text_Yoffset, backgroundX+backgroundWidth, backgroundY+(option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height, tocolor(220, 20, 60, 356), 1, bigFont, "center", "center", false, false, isPostGUI, false, false)
  294.         if isChangeAllowed then
  295.                 local unvote_text = dxDrawText("(backspace to cancel)", backgroundX, backgroundY+(option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height, backgroundX+backgroundWidth, backgroundY+(option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height+unvote_text_height, tocolor(27, 139, 180, 255), 1.00, "arial", "center", "center", false, false, isPostGUI, false, false)
  296.         end
  297. end
  298.  
  299. addEvent('showVotesAmount', true)
  300. addEventHandler('showVotesAmount', resourceRoot, function(playersWhoVoted, votesNeeded, maxVoters, optionVotesTable)
  301.         titleSuffix = " " .. tostring(playersWhoVoted) .. "/" .. tostring(maxVoters)
  302.         optionVotes = optionVotesTable
  303. end)
  304.  
  305. anim = {}
  306. anim.popWindowUp = {}
  307. anim.popWindowDown = {}
  308. breakAnimation = false -- If poll comes up within animation then break it and start new one
  309. function setPollVisible(bool)
  310.         if bool then
  311.                 -- reset vars
  312.                 breakAnimation = true
  313.                 option_amount = #optionTable -- This changes with poll
  314.                 selectedVote = false
  315.                 backgroundX = screenW/2-(backgroundWidth/30)
  316.                 backgroundY = screenH -- used to hide before animation
  317.                 backgroundHeight = (option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height+unvote_text_height+15
  318.                 trueBackgroundY = (screenH * 0.7) - backgroundHeight -- True Y position where it should go after anim
  319.  
  320.                 -- animations
  321.                 anim.popWindowUp.startTime = getTickCount()
  322.                 anim.popWindowUp.startSize = {backgroundX,screenH}
  323.                 anim.popWindowUp.endSize = {backgroundX,trueBackgroundY}
  324.                 anim.popWindowUp.endTime = anim.popWindowUp.startTime + 600
  325.                 addEventHandler("onClientRender", root, draw)
  326.                 addEventHandler("onClientRender", getRootElement(), popWindowUp)
  327.         else
  328.                 anim.popWindowDown.startTime = getTickCount()
  329.                 anim.popWindowDown.startSize = {backgroundX,trueBackgroundY}
  330.                 anim.popWindowDown.endSize = {backgroundX,screenH}
  331.                 anim.popWindowDown.endTime = anim.popWindowDown.startTime + 700
  332.                 addEventHandler("onClientRender", getRootElement(), popWindowDown)
  333.         end
  334. end
  335.  
  336. function popWindowUp()
  337.         local now = getTickCount()
  338.         local elapsedTime = now - anim.popWindowUp.startTime
  339.         local duration = anim.popWindowUp.endTime - anim.popWindowUp.startTime
  340.         local progress = elapsedTime / duration
  341.  
  342.         local width, height, _ = interpolateBetween(
  343.                 anim.popWindowUp.startSize[1], anim.popWindowUp.startSize[2], 0,
  344.                 anim.popWindowUp.endSize[1], anim.popWindowUp.endSize[2],  0,
  345.                 progress, "InOutBack")
  346.  
  347.         backgroundY = height
  348.  
  349.         if now >= anim.popWindowUp.endTime then
  350.                 breakAnimation = false
  351.  
  352.                 removeEventHandler("onClientRender", getRootElement(), popWindowUp)
  353.         end
  354. end
  355.  
  356. function popWindowDown()
  357.         local now = getTickCount()
  358.         local elapsedTime = now - anim.popWindowDown.startTime
  359.         local duration = anim.popWindowDown.endTime - anim.popWindowDown.startTime
  360.         local progress = elapsedTime / duration
  361.  
  362.         local width, height, _ = interpolateBetween(
  363.                 anim.popWindowDown.startSize[1], anim.popWindowDown.startSize[2], 10,
  364.                 anim.popWindowDown.endSize[1], anim.popWindowDown.endSize[2], 10,
  365.                 progress, "InOutBack")
  366.  
  367.         backgroundY = height
  368.  
  369.         if now >= anim.popWindowDown.endTime or breakAnimation then
  370.                 breakAnimation = false
  371.                 backgroundY = screenH
  372.                 removeEventHandler("onClientRender", root, draw)
  373.                 removeEventHandler("onClientRender", getRootElement(), popWindowDown)
  374.         end
  375. end
  376.  
  377. -- showit = false
  378. -- setTimer(function() showPoll(not showit) showit = not showit end,5000,0)
  379.  
  380. local function createFonts()
  381.         local fontsLoad = {
  382.                 {"fonts/Roboto-Bold.ttf", 13, true, "cleartype"},
  383.                 {"fonts/Roboto-Regular.ttf", 13, false, "cleartype"},
  384.         }
  385.         local f = fontsLoad[1]
  386.         local b = fontsLoad[2]
  387.         bigFont = dxCreateFont(f[1], 20, f[3], f[4]) or "default-bold"
  388.         fontBold = dxCreateFont(f[1], f[2], f[3], f[4]) or "default-bold"
  389.         font = dxCreateFont(b[1], b[2], b[3], b[4]) or "default"
  390. end
  391. addEventHandler("onClientResourceStart", resourceRoot, createFonts)

Spoiler for Hiden:
« Son Düzenleme: 12 Mart 2017, 23:38:17 Gönderen: Narkoz »
Linkleri Görebilmek İçin Kayıt Olun veya Giriş Yapın
 

MTASA-TURK | Türkiye'nin En Güncel MTA Platformu

[YARDIM] Votemanager Sağ Alt Alma
« : 12 Mart 2017, 22:09:54 »

CruzerGq

  • Süper Moderatör
  • *
  • İleti: 501
    • MTASATURK
Ynt: [Yardım]Votemanager Sağ Alt Alma
« Yanıtla #1 : 12 Mart 2017, 22:32:20 »
@Konu İçeriği Düzenlendi.

Paneli dx olarak gui editorden çiz. Ordaki kordinaltları al ve 255. ve 267. satırları düzenle. Ama paneli her ekrana göre yapmayı unutma. :)
« Son Düzenleme: 12 Mart 2017, 22:37:25 Gönderen: CruzerGq »
 
Mesajı Beğenenler: boatz

boatz

  • Yeni Üye
  • *
  • Default Avatar
  • İleti: 77
  • :) Herkes Ederi Kadar Kimse Fazlasını İstemesin
Ynt: [Yardım]Votemanager Sağ Alt Alma
« Yanıtla #2 : 12 Mart 2017, 22:36:03 »
Linkleri Görebilmek İçin Kayıt Olun veya Giriş Yapın
@Konu İçeriği Düzenlendi.
Kb Kodlara Spolier Açmaıy bilmiyorum uğraştırdım seni :)
Linkleri Görebilmek İçin Kayıt Olun veya Giriş Yapın
 

ertrldtcu

  • Deneyimli Üye
  • *
  • İleti: 448
Ynt: [Yardım]Votemanager Sağ Alt Alma
« Yanıtla #3 : 12 Mart 2017, 22:36:20 »
Dene :)
Kod: Lua
  1. screenWidth, screenHeight = guiGetScreenSize()
  2. local rootElement = getRootElement()
  3.  
  4. local voteWindow
  5. local boundVoteKeys = {}
  6. local nameFromVoteID = {}
  7. local voteIDFromName = {}
  8. local optionLabels = {}
  9.  
  10. local isVoteActive
  11. local hasAlreadyVoted = false
  12. local isChangeAllowed = false
  13.  
  14. local timeLabel
  15. local finishTime
  16.  
  17. local cacheVoteNumber
  18. local cacheTimer
  19. last = 1
  20.  
  21.  
  22. local timeCache = false
  23. local function updateTime()
  24.         local seconds = math.ceil((finishTime - getTickCount()) / 1000)
  25.         if timeCache ~= seconds and seconds > -1 then
  26.                 if tostring(seconds) == "-0" then
  27.                         seconds = 0
  28.                 end
  29.                 timeCache = seconds
  30.  
  31.                 countdown_text = tostring(seconds)
  32.         end
  33. end
  34.  
  35. addEvent("doShowPoll", true)
  36. addEvent("doSendVote", true)
  37. addEvent("doStopPoll", true)
  38.  
  39. addEventHandler("doShowPoll", rootElement, function(pollData, pollOptions, pollTime)
  40.         --clear the send vote cache
  41.         cacheVoteNumber = ""
  42.         --clear the bound keys table
  43.         boundVoteKeys = {}
  44.         --store the vote option names in the array nameFromVoteID
  45.         nameFromVoteID = pollOptions
  46.         --then build a reverse table
  47.         voteIDFromName = {}
  48.  
  49.         --Reset
  50.         titleSuffix = ""
  51.         optionsVotes = {}
  52.                
  53.         --determine if we have to append nomination number
  54.         local nominationString = ""
  55.         if pollData.nomination > 1 then
  56.                 nominationString = " (nomination "..pollData.nomination..")"
  57.         end
  58.                
  59.         isChangeAllowed = pollData.allowchange
  60.  
  61.         -- layout.title.width  = layout.window.width - 20
  62.         -- layout.option.width = layout.window.width
  63.         -- layout.cancel.width = layout.window.width
  64.         -- layout.time.width   = layout.window.width
  65.                
  66.         local screenX, screenY = guiGetScreenSize()
  67.        
  68.         --Bind options to keys
  69.         for index, option in ipairs(pollOptions) do
  70.                 --Bind 10th option to 0-key
  71.                 if index == 10 then
  72.                         index = 0
  73.                         break
  74.                 end
  75.  
  76.                 --bind the number key and add it to the bound keys table
  77.                 local optionKey = tostring(index)
  78.                 bindKey(optionKey, "down", sendVote_bind)
  79.                 bindKey("num_"..optionKey, "down", sendVote_bind)
  80.                        
  81.                 table.insert(boundVoteKeys, optionKey)
  82.         end
  83.                
  84.         if isChangeAllowed then
  85.                 bindKey("backspace", "down", sendVote_bind)
  86.         end
  87.  
  88.         --Set table up
  89.         optionTable = pollOptions
  90.  
  91.         --Calculate window width
  92.         local highestWidth = 0
  93.         for i,opt in ipairs(optionTable) do
  94.                 local _w = dxGetTextWidth(i ..". ".. opt .." (000)", 1.00, fontBold) + textXoffset + 20
  95.                 highestWidth = math.max(_w, highestWidth)
  96.         end
  97.         backgroundWidth = math.max(backgroundMinWidth, highestWidth)
  98.  
  99.         description_text = pollData.title
  100.  
  101.         setPollVisible(true)
  102.         isVoteActive = true
  103.         finishTime = getTickCount() + pollTime
  104.         addEventHandler("onClientRender", rootElement, updateTime)
  105. end)
  106.  
  107. function setOption(number)
  108.         if number == -1 then
  109.                 selectedVote = false
  110.         else
  111.                 selectedVote = number
  112.         end
  113. end
  114.  
  115. addEventHandler("doStopPoll", rootElement, function()
  116.         isVoteActive = false
  117.         hasAlreadyVoted = false
  118.  
  119.         for i, key in ipairs(boundVoteKeys) do
  120.                 unbindKey(key, "down", sendVote_bind)
  121.                 unbindKey("num_"..key, "down", sendVote_bind)
  122.         end
  123.                
  124.         unbindKey("backspace", "down", sendVote_bind)
  125.         setPollVisible(false)
  126.         removeEventHandler("onClientRender", rootElement, updateTime)
  127. end)
  128.  
  129. function sendVote_bind(key)
  130.         if key ~= "backspace" then
  131.                 key = key:gsub('num_', '')
  132.                 if #nameFromVoteID < 10 then
  133.                         return sendVote(tonumber(key))
  134.                 else
  135.                         cacheVoteNumber = cacheVoteNumber .. key
  136.                         if #cacheVoteNumber > 1 then
  137.                                 if isTimer(cacheTimer) then
  138.                                         killTimer(cacheTimer)
  139.                                 end
  140.                                 cacheVoteNumber = tonumber(cacheVoteNumber)
  141.                                 if nameFromVoteID[cacheVoteNumber] then
  142.                                         if cacheVoteNumber < 10 then
  143.                                                 return sendVote(cacheVoteNumber)
  144.                                         else
  145.                                                 cacheTimer = setTimer(sendVote, 500, 1, cacheVoteNumber)
  146.                                         end
  147.                                         cacheVoteNumber = key
  148.                                 else
  149.                                         cacheVoteNumber = ""
  150.                                 end
  151.                         else            
  152.                                 cacheTimer = setTimer(sendVote, 500, 1, tonumber(cacheVoteNumber))
  153.                         end
  154.                 end
  155.         else
  156.                 return sendVote(-1)
  157.         end
  158. end
  159.  
  160. function sendVote(voteID)
  161.         if not isVoteActive then
  162.                 return
  163.         end
  164.        
  165.         --if option changing is not allowed, unbind the keys
  166.         if not isChangeAllowed and voteID ~= -1 then
  167.                 for i, key in ipairs(boundVoteKeys) do
  168.                         unbindKey(key, "down", sendVote_bind)
  169.                         unbindKey("num_"..key, "down", sendVote_bind)
  170.                 end
  171.         end
  172.        
  173.         --if the player hasn't voted already (or if vote change is allowed anyway), update the vote text
  174.         if not hasAlreadyVoted or isChangeAllowed then
  175.                 if voteID ~= -1 then
  176.                         setOption(voteID)
  177.                 end
  178.         end
  179.  
  180.         if voteID == -1 then
  181.                 setOption(voteID)
  182.         end
  183.        
  184.         --clear the send vote cache
  185.         cacheVoteNumber = ""
  186.         hasAlreadyVoted = voteID
  187.        
  188.         --send the vote to the server
  189.         triggerServerEvent("onClientSendVote", localPlayer, voteID)
  190. end
  191. addEventHandler("doSendVote", rootElement, sendVote)
  192.  
  193. addCommandHandler("vote", function(command, ...)
  194.         --join all passed parameters separated by spaces
  195.         local voteString = table.concat({...}, ' ')
  196.         --try to get the voteID number
  197.         local voteID = tonumber(voteString) or voteIDFromName[voteString]
  198.         --if vote number is valid, send it
  199.         if voteID and (nameFromVoteID[voteID] or voteID == -1) then
  200.                 sendVote(voteID)
  201.         end
  202. end)
  203.  
  204. addCommandHandler("cancelvote", function ()
  205.         sendVote(-1)
  206. end)
  207.  
  208. function table.insertUnique(t,val)
  209.         for k,v in pairs(t) do
  210.                 if v == val then
  211.                         return
  212.                 end
  213.         end
  214.         table.insert(t,val)
  215. end
  216.  
  217. -- GUI --
  218. local screenW, screenH = guiGetScreenSize()
  219.  
  220. optionTable =  {
  221.         "Option text",
  222.         "Option text",
  223.         "Option text",
  224. }
  225. option_amount = #optionTable -- This changes with poll
  226. selectedVote = false
  227. backgroundWidth = 535 -- should change with text width
  228. backgroundMinWidth = 400
  229. backgroundHeight = 400 -- should change with option amounts
  230. backgroundX = screenW-backgroundWidth
  231. backgroundY = screenH -- used to hide before animation
  232. title_height = 55
  233. descriptionYoffset = 40
  234. textXoffset = 22
  235. descriptionHeight = 40
  236. first_option_text_Yoffset = 65
  237. option_text_height = 30
  238. countdown_text_height = 35
  239. unvote_text_height = 55
  240. backgroundHeight = (option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height+unvote_text_height+2
  241. trueBackgroundY = false -- True Y position where it should go after anim
  242.  
  243. font = "default"
  244. fontBold = "default-bold"
  245. bigFont = "default-bold"
  246.  
  247. countdown_text = "10"
  248. description_text = "Vote Description text:"
  249. local titleSuffix = ""
  250. local optionVotes = {}
  251.  
  252. local isPostGUI = true
  253. local function draw()
  254.         --Background
  255.         dxDrawRectangle(backgroundX, backgroundY, backgroundWidth, backgroundHeight, tocolor(0, 0, 0, 200), isPostGUI,false)
  256.  
  257.         --Title
  258.         dxDrawRectangle(backgroundX, backgroundY, backgroundWidth, title_height, tocolor(72, 118, 255, 300), isPostGUI,false)
  259.  
  260.         --Title glass (?)
  261.         dxDrawRectangle(backgroundX, backgroundY, backgroundWidth, 17.5, tocolor(65, 105, 225, 300), isPostGUI,false)
  262.  
  263.         --Title
  264.         dxDrawText("Vote" .. titleSuffix, backgroundX, backgroundY, backgroundX + backgroundWidth, backgroundY+title_height, tocolor(95, 158, 160, 255), 1, bigFont, "center", "center", false, false, isPostGUI, false, false)
  265.  
  266.         --Description
  267.         dxDrawText(description_text, backgroundX+textXoffset, backgroundY+descriptionYoffset, backgroundX + backgroundWidth - 20, backgroundY+descriptionYoffset+descriptionHeight, tocolor(72, 209, 204, 255), 1, fontBold, "left", "top", false, true, isPostGUI, false, false)
  268.        
  269.         --Options
  270.         for i, option in ipairs(optionTable) do
  271.                 local votes = 0
  272.                 if optionVotes[i] ~= nil then
  273.                         votes = optionVotes[i]
  274.                 end
  275.  
  276.                 local text = i..". "..option .. " (".. tostring(votes) ..")"
  277.                 local curFont, curColor
  278.  
  279.                 --Selected option
  280.                 if i == selectedVote then
  281.                         dxDrawRectangle(backgroundX, backgroundY+first_option_text_Yoffset+(option_text_height*i), backgroundWidth, option_text_height, tocolor(0, 205, 205, 228), isPostGUI,false)
  282.                         curFont = bigFont
  283.                         curColor = tocolor(10, 10, 10, 255)
  284.                 else
  285.                         curFont = font
  286.                         curColor = tocolor(255, 255, 255, 255)
  287.                 end
  288.  
  289.                 dxDrawText(text, backgroundX+textXoffset, backgroundY + first_option_text_Yoffset + (option_text_height*i), backgroundX+backgroundWidth, backgroundY + first_option_text_Yoffset + (option_text_height*i) + option_text_height, curColor, 1.00, curFont, "left", "center", false, false, isPostGUI, false, false)
  290.         end
  291.  
  292.         --Countdown
  293.         local countdown = dxDrawText(countdown_text, backgroundX, backgroundY+(option_text_height*option_amount)+option_text_height+first_option_text_Yoffset, backgroundX+backgroundWidth, backgroundY+(option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height, tocolor(220, 20, 60, 356), 1, bigFont, "center", "center", false, false, isPostGUI, false, false)
  294.         if isChangeAllowed then
  295.                 local unvote_text = dxDrawText("(backspace to cancel)", backgroundX, backgroundY+(option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height, backgroundX+backgroundWidth, backgroundY+(option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height+unvote_text_height, tocolor(27, 139, 180, 255), 1.00, "arial", "center", "center", false, false, isPostGUI, false, false)
  296.         end
  297. end
  298.  
  299. addEvent('showVotesAmount', true)
  300. addEventHandler('showVotesAmount', resourceRoot, function(playersWhoVoted, votesNeeded, maxVoters, optionVotesTable)
  301.         titleSuffix = " " .. tostring(playersWhoVoted) .. "/" .. tostring(maxVoters)
  302.         optionVotes = optionVotesTable
  303. end)
  304.  
  305. anim = {}
  306. anim.popWindowUp = {}
  307. anim.popWindowDown = {}
  308. breakAnimation = false -- If poll comes up within animation then break it and start new one
  309. function setPollVisible(bool)
  310.         if bool then
  311.                 -- reset vars
  312.                 breakAnimation = true
  313.                 option_amount = #optionTable -- This changes with poll
  314.                 selectedVote = false
  315.                 backgroundX = screenW/2-(backgroundWidth/30)
  316.                 backgroundY = screenH -- used to hide before animation
  317.                 backgroundHeight = (option_text_height*option_amount)+option_text_height+first_option_text_Yoffset+countdown_text_height+unvote_text_height+15
  318.                 trueBackgroundY = (screenH * 0.7) - backgroundHeight -- True Y position where it should go after anim
  319.  
  320.                 -- animations
  321.                 anim.popWindowUp.startTime = getTickCount()
  322.                 anim.popWindowUp.startSize = {backgroundX,screenH}
  323.                 anim.popWindowUp.endSize = {backgroundX,trueBackgroundY}
  324.                 anim.popWindowUp.endTime = anim.popWindowUp.startTime + 600
  325.                 addEventHandler("onClientRender", root, draw)
  326.                 addEventHandler("onClientRender", getRootElement(), popWindowUp)
  327.         else
  328.                 anim.popWindowDown.startTime = getTickCount()
  329.                 anim.popWindowDown.startSize = {backgroundX,trueBackgroundY}
  330.                 anim.popWindowDown.endSize = {backgroundX,screenH}
  331.                 anim.popWindowDown.endTime = anim.popWindowDown.startTime + 700
  332.                 addEventHandler("onClientRender", getRootElement(), popWindowDown)
  333.         end
  334. end
  335.  
  336. function popWindowUp()
  337.         local now = getTickCount()
  338.         local elapsedTime = now - anim.popWindowUp.startTime
  339.         local duration = anim.popWindowUp.endTime - anim.popWindowUp.startTime
  340.         local progress = elapsedTime / duration
  341.  
  342.         local width, height, _ = interpolateBetween(
  343.                 anim.popWindowUp.startSize[1], anim.popWindowUp.startSize[2], 0,
  344.                 anim.popWindowUp.endSize[1], anim.popWindowUp.endSize[2],  0,
  345.                 progress, "InOutBack")
  346.  
  347.         backgroundY = height
  348.  
  349.         if now >= anim.popWindowUp.endTime then
  350.                 breakAnimation = false
  351.  
  352.                 removeEventHandler("onClientRender", getRootElement(), popWindowUp)
  353.         end
  354. end
  355.  
  356. function popWindowDown()
  357.         local now = getTickCount()
  358.         local elapsedTime = now - anim.popWindowDown.startTime
  359.         local duration = anim.popWindowDown.endTime - anim.popWindowDown.startTime
  360.         local progress = elapsedTime / duration
  361.  
  362.         local width, height, _ = interpolateBetween(
  363.                 anim.popWindowDown.startSize[1], anim.popWindowDown.startSize[2], 10,
  364.                 anim.popWindowDown.endSize[1], anim.popWindowDown.endSize[2], 10,
  365.                 progress, "InOutBack")
  366.  
  367.         backgroundY = height
  368.  
  369.         if now >= anim.popWindowDown.endTime or breakAnimation then
  370.                 breakAnimation = false
  371.                 backgroundY = screenH
  372.                 removeEventHandler("onClientRender", root, draw)
  373.                 removeEventHandler("onClientRender", getRootElement(), popWindowDown)
  374.         end
  375. end
  376.  
  377. -- showit = false
  378. -- setTimer(function() showPoll(not showit) showit = not showit end,5000,0)
  379.  
  380. local function createFonts()
  381.         local fontsLoad = {
  382.                 {"fonts/Roboto-Bold.ttf", 13, true, "cleartype"},
  383.                 {"fonts/Roboto-Regular.ttf", 13, false, "cleartype"},
  384.         }
  385.         local f = fontsLoad[1]
  386.         local b = fontsLoad[2]
  387.         bigFont = dxCreateFont(f[1], 20, f[3], f[4]) or "default-bold"
  388.         fontBold = dxCreateFont(f[1], f[2], f[3], f[4]) or "default-bold"
  389.         font = dxCreateFont(b[1], b[2], b[3], b[4]) or "default"
  390. end
  391. addEventHandler("onClientResourceStart", resourceRoot, createFonts)
Script yazmak için kod bilmek yetmez.
 

boatz

  • Yeni Üye
  • *
  • Default Avatar
  • İleti: 77
  • :) Herkes Ederi Kadar Kimse Fazlasını İstemesin
Ynt: [Yardım]Votemanager Sağ Alt Alma
« Yanıtla #4 : 12 Mart 2017, 22:43:37 »
Olmadı :S Yine Aynı Yerde

Mesaj Birleştirildi: [time]Mart 13, 2017, 12:08:38 ÖÖ[/time]
@GÜNCEL, Yardım Edebilicek Yok Mu PLS#

Mesaj Birleştirildi: 13 Mart 2017, 04:03:50
Karıştıra Karıştıra Yaptım Teşekkürler Konu Kilit Lütfen :)
« Son Düzenleme: 13 Mart 2017, 04:03:50 Gönderen: boatz »
Linkleri Görebilmek İçin Kayıt Olun veya Giriş Yapın
 

CruzerGq

  • Süper Moderatör
  • *
  • İleti: 501
    • MTASATURK
Ynt: [YARDIM] Votemanager Sağ Alt Alma
« Yanıtla #5 : 13 Mart 2017, 08:17:08 »
Konu sahibinin isteği üzerine @Konu Kilit.
 

MTASA-TURK | Türkiye'nin En Güncel MTA Platformu

Ynt: [YARDIM] Votemanager Sağ Alt Alma
« Yanıtla #5 : 13 Mart 2017, 08:17:08 »