├── LICENSE ├── README.md └── vC-vote ├── client.lua ├── fxmanifest.lua ├── html ├── app.js ├── index.html ├── loading-buffering.gif └── style.css ├── inv-img └── votingpin.png ├── readme.md ├── server.lua ├── vCode.lua └── votes.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 vCode Scripts 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vC-vote 2 | Nopixel Inspired Voting Script, Detailed Config And Easy To Use. 3 | 4 | vCode Scripts https://github.com/vCodeScripts & https://discord.gg/37KhvMstyx 5 | 6 | What is This Script? This Script Allows You To Start Votings For An Election. It simplifies the whole process of voting and choosing a mayor/president in-game. Everytime you start a election you have to delete everything in votes.json and replace it with {} . This just clears out the table of who voted and for who. To add new candidates and change some settings you can always edit vCode.lua. This is the config of this script. 7 | 8 | Some Examples: 9 | 10 | Photo: https://prnt.sc/bkNn0jwDz2i9 11 | 12 | Video: https://streamable.com/e8y9jt 13 | 14 | Metadata Item Photo: https://prnt.sc/s2LvRV1XQ5P 15 | 16 | Installation: If you don't want to give a Voting Pin After Someone Voted, You Can Just Drag And Drop Our Script Into Your Resources Folder. 17 | FOR PEOPLE WHO WANT THE META-ITEM OPTION 18 | 19 | FIRST: Enable vCode.GiveItem in vCode.lua, you can do that by changing the option from false to true. 20 | 21 | Secondly, add this line of code into your items.lua (qb-core/shared/items.lua) ['votingpin'] = {['name'] = 'votingpin', ['label'] = 'I Voted!', ['weight'] = 0, ['type'] = 'item', ['image'] = 'votingpin.png', ['unique'] = false, ['useable'] = false, ['shouldClose'] = false, ['combinable'] = nil, ['description'] = 'You Voted'}, 22 | 23 | Then, Add The Image Inside The inv-img folder into your qb-inventory/html/images/ folder. 24 | 25 | Then Head On Into the js folder in qb-inventory/html. Open the app.js file. 26 | 27 | Once Opened, Search For FormatItemInfo. You Should find a function named FormatItemInfo. 28 | 29 | Paste The Below Given Code Into The Function 30 | 31 | else if (itemData.name == "votingpin") { console.log('geldi') $(".item-info-title").html(" 32 | 33 | " + itemData.label + " 34 | "); $(".item-info-description").html( " 35 | 36 | Election: " + itemData.info.election + " 37 | "); } 38 | 39 | Your Code Should Look Something Like This: https://prnt.sc/V1P80U12F3wO 40 | 41 | Then You Are Finished And Ready To Go, Startup Your Server And Have Fun. 42 | DISCLAIMER ! DONT FORGET TO RESTART YOUR SERVER AFTER YOU ADDED THE CHANGES IN items.lua 43 | 44 | Have Fun, 45 | 46 | whit3 and poyraz - vCode 2022 47 | -------------------------------------------------------------------------------- /vC-vote/client.lua: -------------------------------------------------------------------------------- 1 | local QBCore = exports['qb-core']:GetCoreObject() 2 | 3 | 4 | 5 | RegisterNUICallback('close', function() 6 | SetNuiFocus(false, false) 7 | end) 8 | 9 | RegisterNetEvent('vC-vote:closeScript', function() 10 | SetNuiFocus(false, false) 11 | SendNUIMessage({ 12 | type = "close", 13 | }) 14 | 15 | end) 16 | 17 | 18 | 19 | RegisterNUICallback('getConfig', function(data,cb) 20 | cb(vCode) 21 | end) 22 | 23 | RegisterNUICallback('voteForSomeone', function(data) 24 | TriggerServerEvent('vC-vote:voteWithData', data.id) 25 | end) 26 | 27 | RegisterNUICallback('error', function() 28 | QBCore.Functions.Notify('Please Choose A Candidate!', 'error') 29 | end) 30 | 31 | Citizen.CreateThread(function() 32 | while true do 33 | Citizen.Wait(1) 34 | local pos = GetEntityCoords(PlayerPedId()) 35 | for i=1, #vCode.Locations do 36 | 37 | local distance = GetDistanceBetweenCoords(pos, vCode.Locations[i], true) 38 | if distance < 3 then 39 | 40 | 41 | if IsControlJustPressed(0,38) then 42 | TryToVote() 43 | end 44 | else 45 | 46 | end 47 | 48 | end 49 | 50 | end 51 | end) 52 | 53 | 54 | function TryToVote() 55 | QBCore.Functions.TriggerCallback('vC-vote:hasPlayerVoted', function(hasVoted) 56 | if hasVoted then 57 | 58 | SendNUIMessage({ 59 | type = 'show', 60 | }) 61 | SetNuiFocus(true, true) 62 | else 63 | QBCore.Functions.Notify('You Have Already Voted!', 'error') 64 | end 65 | end) 66 | 67 | end 68 | 69 | -------------------------------------------------------------------------------- /vC-vote/fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version 'cerulean' 2 | game 'gta5' 3 | 4 | shared_script 'vCode.lua' 5 | 6 | client_script 'client.lua' 7 | server_script 'server.lua' 8 | 9 | ui_page 'html/index.html' 10 | files { 11 | 'html/*.*' 12 | } -------------------------------------------------------------------------------- /vC-vote/html/app.js: -------------------------------------------------------------------------------- 1 | selected = '' 2 | 3 | $(document).on('click', '.VoteForThis', function(){ 4 | $('.checkemoji').css('opacity', '0') 5 | $(this).find('.checkemoji').css('opacity', 1) 6 | selected = $(this).parent().attr('data-voteid') 7 | console.log(selected) 8 | }) 9 | 10 | addEventListener('message', function(event){ 11 | var poy = event.data; 12 | if (poy.type == 'show'){ 13 | $('.maincon').fadeIn(); 14 | SetupData(); 15 | } else if (poy.type == "close"){ 16 | $('.bottompart').fadeOut() 17 | setTimeout(function(){ 18 | $('.maincon').css('height', '30vh'); 19 | setTimeout(function(){ 20 | $('.maincon').fadeOut(); 21 | $('.checkemoji').css('opacity', '0') 22 | $('.congratsDiv').fadeOut(); 23 | 24 | }, 180) 25 | 26 | }, 180) 27 | } 28 | }) 29 | 30 | function LoadVoters(){ 31 | $('.loadinggif').fadeOut(); 32 | setTimeout(function(){ 33 | $('.maincon').css('height', '85vh') 34 | setTimeout(function(){$('.bottompart').fadeIn()}, 180) 35 | }, 200) 36 | 37 | } 38 | 39 | 40 | document.onkeydown = function(data){ 41 | if (data.which == 27){ 42 | $('.bottompart').fadeOut() 43 | setTimeout(function(){ 44 | $('.maincon').css('height', '30vh'); 45 | setTimeout(function(){ 46 | $('.maincon').fadeOut(); 47 | $('.checkemoji').css('opacity', '0') 48 | $('.congratsDiv').fadeOut(); 49 | 50 | }, 180) 51 | 52 | }, 180) 53 | 54 | $.post('https://vC-vote/close') 55 | } 56 | } 57 | 58 | 59 | function SetupData(){ 60 | $.post('https://vC-vote/getConfig', JSON.stringify({}), function(vCode){ 61 | $('.voteName').html(vCode.ElectionName) 62 | $('.hashtag').html(vCode.ElectionHashtag) 63 | $('.voteCon').html('') 64 | 65 | 66 | $.each(vCode.Options, function (index, data) { 67 | console.log(index,data) 68 | htmlsorgu = `
69 | ${data.name} 70 | ${data.desc} 71 | 74 |
` 75 | $('.voteCon').append(htmlsorgu) 76 | }) 77 | LoadVoters(); 78 | }) 79 | } 80 | 81 | $(document).on('click','.Vote', function(){ 82 | if (selected != ''){ 83 | $.post('https://vC-vote/voteForSomeone', JSON.stringify({id:selected})) 84 | $('.bottompart').hide() 85 | $('.votingForText').html('Voted For:') 86 | $('.maincon').css('height', '30vh'); 87 | setTimeout(function(){ 88 | $('.congratsDiv').fadeIn(); 89 | setTimeout(function(){ 90 | $('.maincon').fadeOut(); 91 | $.post('https://vC-vote/close'); 92 | $('.congratsDiv').fadeOut(); 93 | }, 3000) 94 | 95 | }, 250) 96 | 97 | } else { 98 | $.post('https://vC-vote/error') 99 | } 100 | }) 101 | -------------------------------------------------------------------------------- /vC-vote/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | vCode-vote 8 | 9 | 10 | 11 | 12 | 13 |
14 | Voting For: 15 |
16 | 17 |
18 | 19 |
20 | #Elections 21 | 22 |
23 |
24 | Mayor Elections 25 | You May Only Pick One Candidate! 26 | 30 | 31 |
32 |
33 |
34 | 35 |
36 |
37 | 38 | 39 | -------------------------------------------------------------------------------- /vC-vote/html/loading-buffering.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vCodeScripts/vC-vote/3c8a4750247ac8b43bfe156a8c11227a5f043ebf/vC-vote/html/loading-buffering.gif -------------------------------------------------------------------------------- /vC-vote/html/style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap'); 2 | body { 3 | font-family: 'Roboto', sans-serif; 4 | padding: 0; 5 | margin: 0; 6 | box-sizing: border-box; 7 | color: white; 8 | background: none !important; 9 | } 10 | 11 | .maincon { 12 | display: none; 13 | width: 67vh; 14 | height: 40vh; 15 | border-radius: 3px; 16 | background-color: #1F282F; 17 | position: absolute; 18 | left: 50%; 19 | top: 50%; 20 | transform: translate(-50%, -50%); 21 | transition: height 1s; 22 | } 23 | .loadinggif { 24 | width: 7%; 25 | position: absolute; 26 | top: 50%; 27 | left: 50%; 28 | 29 | transform: translate(-50%); 30 | } 31 | .votingForText { 32 | font-size: 2.3vh; 33 | margin-left: 2vh; 34 | position: absolute; 35 | margin-top: 2.3vh; 36 | } 37 | 38 | .chartBox { 39 | width: 3vh; 40 | height: 3vh; 41 | border-radius: 4px; 42 | background-color: white; 43 | color: black; 44 | display: inline-flex; 45 | justify-content: center; 46 | align-items: center; 47 | font-size: 1.6vh; 48 | position: relative; 49 | margin-right: 3vh; 50 | margin-top: 1.2vh; 51 | top: -0.3vh; 52 | } 53 | 54 | .hashtag { 55 | position: relative; 56 | right: 2vh; 57 | font-size: 2.3vh; 58 | top: 0; 59 | margin-top: 1.5vh; 60 | } 61 | 62 | .sagUst { 63 | position: absolute; 64 | right: 0; 65 | top: 0.95vh; 66 | } 67 | 68 | .topLine { 69 | width: 95%; 70 | height: 0.1vh; 71 | background-color: white; 72 | position: absolute; 73 | top: 6.2vh; 74 | left: 50%; 75 | transform: translate(-50%); 76 | border-radius: 2pxs; 77 | } 78 | 79 | .voteName { 80 | font-size: 2.1vh; 81 | position: absolute; 82 | margin-left: 2vh; 83 | margin-top: 7vh; 84 | } 85 | 86 | .chooseText { 87 | font-size: 1.6vh; 88 | position: absolute; 89 | margin-right: 2vh; 90 | right: 0; 91 | margin-top: 7vh; 92 | } 93 | 94 | 95 | .voteCon { 96 | 97 | width: 100%; 98 | height: 72%; 99 | position: absolute; 100 | top: 15%; 101 | overflow-y: auto; 102 | } 103 | 104 | .Vote { 105 | background-color: #83C86B; 106 | border-radius: 3px; 107 | font-family: 'Roboto', sans-serif; 108 | outline: none; 109 | border: none; 110 | width: 15vh; 111 | height: 3vh; 112 | position: absolute; 113 | right: 0; 114 | bottom: 0; 115 | margin-right: 2vh; 116 | margin-bottom: 2vh; 117 | } 118 | 119 | .newSelect { 120 | background-color: #30475B; 121 | width: 95%; 122 | height: 18.5%; 123 | border-radius: 2px; 124 | position: relative; 125 | left: 50%; 126 | margin-top: 3vh; 127 | transform: translate(-50%); 128 | margin-bottom: 1.5vh; 129 | 130 | } 131 | 132 | .selectName { 133 | font-size: 2.2vh; 134 | position: absolute; 135 | margin-top: 1.6vh; 136 | margin-left: 2vh; 137 | } 138 | 139 | .selectDesc { 140 | position: absolute; 141 | bottom: 0; 142 | margin-bottom: 2vh; 143 | font-size: 1.9vh; 144 | margin-left: 2vh; 145 | } 146 | 147 | .VoteForThis { 148 | width: 8vh; 149 | height: 8vh; 150 | background-color: white; 151 | border-radius: 5px; 152 | border: none; 153 | outline: none; 154 | position: absolute; 155 | top: 50%; 156 | right: 0; 157 | transform: translateY(-50%); 158 | margin-right: 2vh; 159 | } 160 | 161 | .checkemoji { 162 | opacity: 0; 163 | 164 | font-size: 6vh; 165 | color: #30475B; 166 | } 167 | 168 | ::-webkit-scrollbar-track { 169 | background: #1F282F; 170 | } 171 | 172 | .bottompart { 173 | display: none; 174 | } 175 | 176 | .yourOption { 177 | font-size: 1.8vh; 178 | position: absolute; 179 | left: 50%; 180 | top: 45%; 181 | color: white; 182 | transform: translate(-50%); 183 | white-space: nowrap; 184 | 185 | } 186 | 187 | .thankU { 188 | font-size: 2.2vh; 189 | position: absolute; 190 | left: 50%; 191 | top: 65%; 192 | color: white; 193 | transform: translate(-50%); 194 | white-space: nowrap; 195 | 196 | } -------------------------------------------------------------------------------- /vC-vote/inv-img/votingpin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vCodeScripts/vC-vote/3c8a4750247ac8b43bfe156a8c11227a5f043ebf/vC-vote/inv-img/votingpin.png -------------------------------------------------------------------------------- /vC-vote/readme.md: -------------------------------------------------------------------------------- 1 | vCode Scripts https://github.com/vCodeScripts & https://discord.gg/37KhvMstyx 2 | 3 | What is This Script? This Script Allows You To Start Votings For An Election. It simplifies the whole process of voting and choosing a mayor/president in-game. 4 | Everytime you start a election you have to delete everything in votes.json and replace it with {} . This just clears out the table of who voted and for who. To add new candidates and change some settings you can always edit vCode.lua. This is the config of this script. 5 | 6 | Some Examples: 7 | 8 | Photo: https://prnt.sc/bkNn0jwDz2i9 9 | 10 | Video: https://streamable.com/e8y9jt 11 | 12 | Metadata Item Photo: https://prnt.sc/s2LvRV1XQ5P 13 | 14 | Dependencies: 15 | qb-core 16 | qb-inventory (If you want the votingpin item option) 17 | 18 | 19 | Installation: If you don't want to give a Voting Pin After Someone Voted, You Can Just Drag And Drop Our Script Into Your Resources Folder. 20 | 21 | 22 | ### FOR PEOPLE WHO WANT THE META-ITEM OPTION 23 | 24 | FIRST: Enable vCode.GiveItem in vCode.lua, you can do that by changing the option from false to true. 25 | 26 | Secondly, add this line of code into your items.lua (qb-core/shared/items.lua) 27 | ['votingpin'] = {['name'] = 'votingpin', ['label'] = 'I Voted!', ['weight'] = 0, ['type'] = 'item', ['image'] = 'votingpin.png', ['unique'] = false, ['useable'] = false, ['shouldClose'] = false, ['combinable'] = nil, ['description'] = 'You Voted'}, 28 | 29 | Then, Add The Image Inside The inv-img folder into your qb-inventory/html/images/ folder. 30 | 31 | Then Head On Into the js folder in qb-inventory/html. Open the app.js file. 32 | 33 | Once Opened, Search For FormatItemInfo. You Should find a function named FormatItemInfo. 34 | 35 | Paste The Below Given Code Into The Function 36 | 37 | else if (itemData.name == "votingpin") { 38 | console.log('geldi') 39 | $(".item-info-title").html("

" + itemData.label + "

"); 40 | $(".item-info-description").html( 41 | "

Election: " + 42 | itemData.info.election + 43 | "

"); 44 | } 45 | 46 | Your Code Should Look Something Like This: https://prnt.sc/V1P80U12F3wO 47 | 48 | Then You Are Finished And Ready To Go, Startup Your Server And Have Fun. 49 | 50 | 51 | ### DISCLAIMER ! DONT FORGET TO RESTART YOUR SERVER AFTER YOU ADDED THE CHANGES IN SHARED.LUA 52 | 53 | 54 | Have Fun, 55 | 56 | whit3 and poyraz - vCode 2022 57 | 58 | 59 | -------------------------------------------------------------------------------- /vC-vote/server.lua: -------------------------------------------------------------------------------- 1 | local QBCore = exports['qb-core']:GetCoreObject() 2 | 3 | 4 | 5 | 6 | 7 | 8 | QBCore.Functions.CreateCallback('vC-vote:hasPlayerVoted', function(source,cb) 9 | local loadFile= LoadResourceFile(GetCurrentResourceName(), "./votes.json") 10 | local Player = QBCore.Functions.GetPlayer(source) 11 | local cid = Player.PlayerData.citizenid 12 | local tablo = json.decode(loadFile) 13 | print(json.encode(tablo)) 14 | 15 | 16 | if json.encode(tablo) == '{}' then 17 | cb(true) 18 | end 19 | 20 | if tablo[cid] == nil then 21 | print('burda') 22 | cb(true) 23 | else 24 | cb(false) 25 | 26 | 27 | end 28 | 29 | 30 | end) 31 | 32 | 33 | 34 | 35 | RegisterServerEvent('vC-vote:voteWithData', function(data) 36 | 37 | local loadFile= LoadResourceFile(GetCurrentResourceName(), "./votes.json") 38 | local Player = QBCore.Functions.GetPlayer(source) 39 | local cid = Player.PlayerData.citizenid 40 | local tablo = json.decode(loadFile) 41 | tablo[cid] = {vote = data} 42 | SaveResourceFile(GetCurrentResourceName(), "votes.json", json.encode(tablo), -1) 43 | if vCode.GiveItem then 44 | local info = { 45 | election = vCode.ElectionName, 46 | } 47 | Player.Functions.AddItem('votingpin',1, false, info) 48 | end 49 | end) 50 | 51 | 52 | QBCore.Functions.CreateCallback('vC-vote:countCallback', function(source,cb) 53 | local toplamvotes = 0 54 | local loadFile= LoadResourceFile(GetCurrentResourceName(), "./votes.json") 55 | 56 | 57 | for k,v in pairs(vCode.Options) do 58 | v.count = 0 59 | end 60 | local tablo = json.decode(loadFile) 61 | for k, v in pairs(tablo) do 62 | vote = v.vote 63 | 64 | toplamvotes = toplamvotes + 1 65 | vCode.Toplam = toplamvotes 66 | print(k, json.encode(v)) 67 | 68 | vCode.Options[vote].count = vCode.Options[vote].count + 1 69 | 70 | end 71 | 72 | cb(vCode) 73 | 74 | end) 75 | --[[ 76 | local tablo = json.decode(loadFile) 77 | table.insert(tablo, information) 78 | table.insert(tablo, info1rmation) 79 | SaveResourceFile(GetCurrentResourceName(), "votes.json", json.encode(tablo), -1) 80 | 81 | 82 | 83 | ]]-- 84 | -------------------------------------------------------------------------------- /vC-vote/vCode.lua: -------------------------------------------------------------------------------- 1 | vCode = {} 2 | 3 | vCode.Options = { 4 | ['poy'] = { 5 | name = 'Poyraz', 6 | desc = 'vCode', 7 | count = 0, 8 | }, 9 | ['whit3'] = { 10 | name = 'whit3', 11 | desc = 'vCode', 12 | count = 0, 13 | }, 14 | } 15 | 16 | vCode.ElectionName = "Mayor Elections" 17 | 18 | vCode.ElectionHashtag = '#VoteForMayor' 19 | 20 | 21 | vCode.Locations = { 22 | vector3(-1310.33, -1277.15, 4.7), 23 | vector3(-1450.71, -236.83, 61.13) 24 | } 25 | 26 | vCode.Toplam = 0 27 | 28 | vCode.GiveItem = true 29 | -------------------------------------------------------------------------------- /vC-vote/votes.json: -------------------------------------------------------------------------------- 1 | {} 2 | --------------------------------------------------------------------------------