//written by Lighto //players can cast a map votation like the ingame votes, why that isnt in the game btw //v3 24/10/'24' v2 quickest hotfix ever v3 quickest hotfix of hotfix ever if not LTB_vote then rawset(_G,"LTB_vote",{ isvoting = false, caller = -1, map = "northern district" , forcemap = '', encore = '', time = 0, votes = 0, voters = {}, cooldown = 0, topass = 0, passed = 0, failed = 0 }) end local wannavote,voteslide,x,y,xs,flags, vtbtn, myvote, forcerelease x = 322 y = 170 - 10 voteslide = FRACUNIT flags = V_SNAPTOTOP|V_SNAPTORIGHT vtbtn = {"TLB_F","TLB_FB",""} myvote = 0 forcerelease = false local function initpvote(p) p.LTB_vote = {} p.LTB_vote.zb = false p.LTB_vote.init = true p.LTB_vote.forcerelease = false p.LTB_vote.wannavote = false p.LTB_vote.myvote = 0 end local function resetvars() x = 322 y = 170 - 10 voteslide = FRACUNIT flags = V_SNAPTOTOP|V_SNAPTORIGHT vtbtn = {"TLB_F","TLB_FB",""} myvote = 0 forcerelease = false LTB_vote.isvoting = false LTB_vote.time = 0 LTB_vote.votes = 0 LTB_vote.passed = 0 LTB_vote.failed = 0 LTB_vote.forcemap = '' LTB_vote.encore = '' for p in players.iterate do initpvote(p) end end local function fontspacing(v,str) return v.stringWidth(str, V_SNAPTOTOP|V_SNAPTORIGHT) end //synch to joiners addHook("NetVars",function(net) LTB_vote = net($) end) COM_AddCommand("vm", function(p,...) if p and {...} then COM_BufInsertText(p,'votemap '+...) end end) COM_AddCommand("votemap", function(p,...) if not p then CONS_Printf(server,"someone tried a command but died?????") return end if LTB_vote.isvoting then CONS_Printf(p,"theres already an ongoing voting, vote or wait!") return end if LTB_vote.cooldown > 0 then CONS_Printf(p,"last map vote was too recent, wait for "..G_TicsToSeconds(LTB_vote.cooldown).." seconds") return end if not {...} then CONS_Printf(p,"type a map name! can have spaces and cas specify act number") return end //if p == server or IsPlayerAdmin(p) then CONS_Printf(p,"youre the owner/admin, use the map command instead") return end local _, test, cnt, map map = '' cnt = 1 //your vote already accounted for _,i in ipairs({...}) do if i and type(i) == "string" then if i == "-f" then LTB_vote.force = ' -f ' continue end if i == "-e" then LTB_vote.encore = ' -e ' continue end if _ > 1 then map = $ +' ' end map = $ + i end end if map and (map == "random" or map == "r" or map == "randommap" or map == "0" or map == "-1") then local randommap = P_RandomRange(1,#mapheaderinfo - 1) while not ((mapheaderinfo[randommap].typeoflevel & 0x0001) //TOL_RACE or (mapheaderinfo[randommap].typeoflevel & 0x0002)) //TOL_BATTLE do randommap = P_RandomRange(1,#mapheaderinfo - 1) end map = G_BuildMapTitle(randommap) end _,test = G_FindMap(map) if not test then CONS_Printf(p,"cant find a map with that name - "..map) return end LTB_vote.isvoting = true LTB_vote.caller = p LTB_vote.map = test LTB_vote.time = 15*TICRATE LTB_vote.votes = 1 LTB_vote.cooldown = 0 LTB_vote.voters = {p} local ptotal = 0 for p2 in players.iterate do if p2 and not p2.bot and not p2.spectator and p2 ~= server then ptotal = $ + 1 end if not p2 or p2 == p or p2.bot == true or p2.spectator or p2 == server then continue end cnt = $ + 1 end if cnt > 2 then cnt = min(max(2,($/2))+1,ptotal - (1+(ptotal/5))) end //lone players can vote how much they desire :) if cnt == 1 then LTB_vote.votes = 1 LTB_vote.cooldown = 0 end LTB_vote.topass = cnt end) local function pvotetic() for p in players.iterate do if not p then continue end if not (p.LTB_vote and p.LTB_vote.init) then initpvote(p) end p.LTB_vote.zb = (p.cmd.buttons & 1<<7) if p.LTB_vote.zb then if not p.LTB_vote.wannavote then p.LTB_vote.wannavote = true p.LTB_vote.forcerelease = true end if p.LTB_vote.forcerelease == false and p.LTB_vote.wannavote and LTB_vote.passed <= 0 and LTB_vote.failed <= 0 then //voting... p.LTB_vote.myvote = min($ + 1,TICRATE*2 +1) end else if p.LTB_vote.wannavote then p.LTB_vote.forcerelease = false end //force to release button to vote if p.LTB_vote.myvote < TICRATE then p.LTB_vote.myvote = 0 end //cancel voting if p.LTB_vote.myvote >= TICRATE then p.LTB_vote.myvote = TICRATE + 1 end //cancel the voting cancel (?) end //vote caller dont have to vote also it shows automatically also cant cancel if p == LTB_vote.caller or p.spectator then p.LTB_vote.myvote = TICRATE + 1 p.LTB_vote.wannavote = true end //check if a the player already voted if p.LTB_vote.myvote == TICRATE then local canvote = true for i = 1, #LTB_vote.voters do if p == LTB_vote.voters[i] then canvote = false break end end //you can and voted successfuly if canvote then LTB_vote.votes = $ + 1 table.insert(LTB_vote.voters,p) p.LTB_vote.forcerelease = true p.LTB_vote.myvote = TICRATE + 1 S_StartSound(nil, sfx_gshad) //omg congrats on voting end end //cancel your vote //the caller CANNOT cancel their votes, of course if p.LTB_vote.myvote == TICRATE*2 then local canunvote, is = false //look for yourself on the voters table to know if you can cancel for i = 1, #LTB_vote.voters do is = i if p == LTB_vote.voters[i] then canunvote = true break end end //you voted and can unvote if canunvote then LTB_vote.votes = $ - 1 table.remove(LTB_vote.voters,is) p.LTB_vote.forcerelease = true S_StartSound(nil, sfx_buzz4) //omg congrats on UNvoting p.LTB_vote.myvote = 0 end end if LTB_vote.passed < TICRATE / 3 and LTB_vote.cooldown > 0 then p.LTB_vote.wannavote = false end if LTB_vote.failed < TICRATE / 3 and LTB_vote.cooldown > 0 then p.LTB_vote.wannavote = false end end end addHook("ThinkFrame",do if LTB_vote.cooldown then LTB_vote.cooldown = max(0,$-1) end if LTB_vote.isvoting then pvotetic() if LTB_vote.time == 15*TICRATE then S_StartSound(nil, sfx_cdfm67) //hii new votation started end LTB_vote.time = max($ - 1, 0) if leveltime % 64 == 0 and LTB_vote.passed <= 0 and LTB_vote.failed <= 0 then S_StartSound(nil, sfx_s3kd2s) //dont forget the votation, its hereeeee end //BAIL BAIL if not LTB_vote.caller or not (LTB_vote.caller and LTB_vote.caller.valid) then LTB_vote.failed = 3*TICRATE LTB_vote.passed = 0 LTB_vote.cooldown = 4*TICRATE S_StartSound(nil, sfx_adderr) //vote failed :((((((((( S_StartSound(nil, sfx_adderr) //FAILED LOUDLY end end if LTB_vote.passed then LTB_vote.passed = max($ -1 ,0) end if LTB_vote.failed then LTB_vote.failed = max($ -1 ,0) end if LTB_vote.isvoting and LTB_vote.votes >= LTB_vote.topass and LTB_vote.time > 0 and LTB_vote.passed <= 0 then LTB_vote.passed = 4*TICRATE S_StartSound(nil, sfx_kc48) //vote passed hooray end if LTB_vote.passed == 1 then local gametype,tabtypes = 0, {0x0001,0x0002,0x0004,0x0008,0x0010} for i = 1, #tabtypes do if mapheaderinfo[G_FindMap(LTB_vote.map)].typeoflevel & tabtypes[i] then gametype = i - 1 break end end if netgame and (gametype == 2 or gametype == 4) then gametype = 0 LTB_vote.force = ' -f ' end //sealed star and tutorial - go to race if netgame and gametype == 3 then gametype = 1 LTB_vote.force = ' -f ' end //versus "boss" - go to battle COM_BufInsertText(server, 'map '+LTB_vote.map+LTB_vote.force+LTB_vote.encore+' -g '+gametype) LTB_vote.cooldown = 30*TICRATE if LTB_vote.topass == 1 then LTB_vote.cooldown = 0 end resetvars() end //vote failed if LTB_vote.isvoting and LTB_vote.time <= 0 and LTB_vote.passed <= 0 and LTB_vote.votes < LTB_vote.topass and LTB_vote.failed <= 0 then LTB_vote.failed = 4*TICRATE LTB_vote.cooldown = 15*TICRATE S_StartSound(nil, sfx_adderr) //vote failed :((((((((( end if LTB_vote.failed == 1 then resetvars() end end) local slide2 = FRACUNIT local function votehud(v,p) if not p or not v or not LTB_vote.isvoting then return end local ZB,sha = (p.cmd.buttons & 1<<7) sha = v.stringWidth("a", V_SNAPTOTOP|V_SNAPTORIGHT) //BAIL BAIL if not LTB_vote.caller or not (LTB_vote.caller and LTB_vote.caller.valid) then LTB_vote.failed = 3*TICRATE LTB_vote.passed = 0 LTB_vote.cooldown = 5*TICRATE S_StartSound(nil, sfx_adderr) //vote failed :((((((((( S_StartSound(nil, sfx_adderr) //FAILED LOUDLY return end if p.LTB_vote.zb then vtbtn[3] = vtbtn[2] else vtbtn[3] = vtbtn[1] end if p.LTB_vote.wannavote then //may player names be longer than map name, use the longest local biggerfont = LTB_vote.map //if LTB_vote.caller.name:len() > //LTB_vote.map:len() then biggerfont = LTB_vote.caller.name end slide2 = ease.outsine(FRACUNIT / (TICRATE /4),$,(fontspacing(v,biggerfont)+(fontspacing(v,"a")))*FRACUNIT) else vtbtn[3] = vtbtn[max(1,(leveltime/(TICRATE/4)) % 3)] //z button blinking slide2 = ease.outsine(FRACUNIT / (TICRATE /4),$,FRACUNIT) end //drawing zaza v.drawScaled(((x-26) - FixedInt(slide2))*FRACUNIT,(y)*FRACUNIT,FRACUNIT,v.cachePatch("TLSBE0"),flags) v.drawScaled(((x-16) - FixedInt(slide2))*FRACUNIT,(y+12)*FRACUNIT,FRACUNIT,v.cachePatch(vtbtn[3]),flags) v.drawString(x - FixedInt(slide2), y,LTB_vote.map,flags) v.drawFill(x - FixedInt(slide2), y+sha+1 ,FixedInt(slide2)+18, 10, 29) v.drawFill((x-4) - (((FixedInt(slide2)/5))*((min(TICRATE,p.LTB_vote.myvote) or 1 )/ (TICRATE / 5))), y+sha+1 ,FixedInt(slide2)+18, 10, 6) if p.LTB_vote.myvote > TICRATE + 1 then //cancel your vote v.drawFill((x-4) - (((FixedInt(slide2)/5))*(((p.LTB_vote.myvote /2) or 1 )/ (TICRATE / 5))), y+sha +1,FixedInt(slide2)+18, 10, 34) end //green confirmation for succesful voting if LTB_vote.passed > 0 then if leveltime % 2 == 0 then v.drawFill((x-4) - (((FixedInt(slide2)/5))*(((p.LTB_vote.myvote % TICRATE) or 1 )/ (TICRATE / 5))), y+sha+1 ,FixedInt(slide2)+18, 10, 6) else v.drawFill((x-4) - (((FixedInt(slide2)/5))*(((p.LTB_vote.myvote % TICRATE) or 1 )/ (TICRATE / 5))), y+sha+1 ,FixedInt(slide2)+18, 10, 97) v.drawFill(x - FixedInt(slide2), y+sha+1 ,FixedInt(slide2)+18, 10, 97) end end if LTB_vote.failed > 0 then if leveltime % 2 == 0 then v.drawFill((x-4) - (((FixedInt(slide2)/5))*((min(TICRATE,p.LTB_vote.myvote) or 1 )/ (TICRATE / 5))), y+sha+1 ,FixedInt(slide2)+18, 10, 6) else v.drawFill((x-4) - (((FixedInt(slide2)/5))*((min(TICRATE,p.LTB_vote.myvote) or 1 )/ (TICRATE / 5))), y+sha +1,FixedInt(slide2)+18, 10, 35) v.drawFill(x - FixedInt(slide2), y+sha +1,FixedInt(slide2)+18, 10, 35) end end v.drawString(x - FixedInt(slide2) + (fontspacing(v,LTB_vote.map)/2) - 1 , y+sha+2,LTB_vote.votes.."/"..LTB_vote.topass,flags) //voters icons local yadd = 0 for i = 1, #LTB_vote.voters do if not (v and LTB_vote.voters[i] and LTB_vote.voters[i].valid) then continue end yadd = 12*(i/7) local shit = v.getSprite2Patch(LTB_vote.voters[i].skin, "XTRA",false, C, 0)// v.getSpritePatch("STIN", 1,1) local xs = x - FixedInt(slide2) v.drawScaled((xs+(((shit.width/2)+1)*((i-1)%7)))*FRACUNIT, (y+sha*2 +4+ yadd)*FRACUNIT, FRACUNIT, shit, flags, v.getColormap(LTB_vote.voters[i].skin,LTB_vote.voters[i].skincolor or 0)) end end hud.add(votehud)