• Hey! Register here to create your account, engage with the community, and talk about what is new!

How do i make a map voting system?

StopDoughnut46

New member
Joined
Apr 16, 2022
Messages
2
Reaction score
0
I want to make a map voting system for my game (I have no ranks). How can i do that?
 

ARMcPro

Forum adept
Overlord
Joined
Oct 20, 2020
Messages
1,255
Reaction score
352
You first need a way to make the player choose which map they vote for, you can use multiple items in the hotbar and the player right clicks them, make sure to store the map the player chose in a %default variable (so we can allow changing votes), let's call it %default map_vote, but before you store it, what you need to do is:
First create a Dictionary (a public one that doesn't have %default in its name) with the Map Names as keys and a Number 0 as the Value, let's call it map_voting only once (so just when the voting starts). That will give us a structure that stores which map has how many votes.

Now, before you store the voted map in %default map_vote, we need to decrease the old voting by 1, then store the new map. To do that in a compact way, we can use a number that has %math and %entry and %var, what each of these does is, %math does math operations (careful cuz doesn't follow the math order and doesn't allow brackets), %entry gets the value of a key and %var gets the value of a variable.
so what we do is, we can place a Set Variable: Set Dictionary Value (i think it was called that), in the first slot, you place your public map_voting variable, in the 2nd slot, you put the %default map_vote variable (as the key parameter, because we want to decrease the old voting), and in the 3rd slot, you put a Number with the value of %math(%entry(map_voting, %var(%default map_vote)) - 1), what that does is, first, it replaces the %var() part with the value of the variable inside, then %entry gets the key the %var got renamed into from the map_voting dictionary and the %math decreases the number by 1. Now after this, you set your %default map_vote to the map name that the player voted to and you repeat the last step, except you replace the -1 with +1, so your 3rd value in the (2nd) set dictionary will be %math(%entry(map_voting, %var(%default map_vote)) - 1).
And now all you need to do is, sort dictionary by values and see which map has the most votes!

You might get a "0" key in the dictionary due to how we coded it but it shouldn't matter as that 0 key will be negative (and shouldnt get picked out)
 
Top Bottom