English Votemap script request

7 replies
Goto Page
To the start Previous 1 Next To the start
30.05.20 04:11:05 am
Up
mrc
User
Offline Off
So basically Im looking for this:

if CT or T scores 13 rounds, a votemap menu appears with map A,B,C,etc including the current map. If people vote to the current map (60%), it just restarts. if people vote on othermap, then changemap.
CS2D Brazilian Community - http://cs2dbr.tk
30.05.20 08:39:04 am
Up
Alpha Beta
User
Offline Off
You can try and edit my poll system:
file cs2d XPoll v2.3 (20)

But if you don't want, I can write it from scratch.
30.05.20 03:02:53 pm
Up
mrc
User
Offline Off
Editing that seems to be harder thsn making from scratch.
CS2D Brazilian Community - http://cs2dbr.tk
30.05.20 07:35:27 pm
Up
Alpha Beta
User
Offline Off
I tried my best. Do whatever you want with this code.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
votemap = {}
votemap.title = "Vote for the next map"
votemap.rounds = 13
votemap.maps = {"de_dust", "de_dust2", "de_aztec"}
votemap.temptime = 0
votemap.time = 15000

votemap.votes = initArray(9)
votemap.voted = initBoolArray(32)
votemap.showmenu = true
votemap.running = false

addhook("startround", "votemap.round")
function votemap.round()
     if (game("score_t") == votemap.rounds or 
          game("score_ct") == votemap.rounds) then
          votemap.running = true
          
          parse("sv_msg Type 'vote' to vote for the next map! You have "..tostring(votemap.time/1000)     .." seconds of time.")
          
          if (votemap.showmenu) then
               for i=1, 32 do
                    if (player(i, "exists")) then
                         votemap.menu(i)
                    end
               end
          end
     end
end

function votemap.menu(id)
     local buttons = ""
     
     for i=1, #votemap.maps do
          buttons = buttons..""..votemap.maps[i].."|"..votemap.votes[i]
          
          if not (i==#votemap.maps) then
               buttons = buttons..","
          end
     end
     
     menu(id, votemap.title..","..buttons)
end

addhook("menu", "votemap.vote")
function votemap.vote(id, menu, button)
     if (votemap.running) then
          if (menu == votemap.title) then
               if not (votemap.voted[id]) then
                    votemap.votes[button] = votemap.votes[button]+1
                    parse("sv_msg "..player(id, "name").." voted "..votemap.maps[button])
                    votemap.voted[id] = true
               else
                    parse("sv_msg2 "..id.." You voted already!@C")
               end
          end
     end
end

addhook("say", "votemap.say")
function votemap.say(id, txt)
     if (string.lower(txt) == "vote") then
          votemap.menu(id)
     end
end

addhook("second", "votemap.second")
function votemap.second()
     if (votemap.running) then
          votemap.temptime = votemap.temptime+1000
          
          parse("sv_msg "..tostring((votemap.time-votemap.temptime)/1000).." seconds left to vote!@C")
          
          if (votemap.temptime == votemap.time) then
               local indexmap = 1
               for i=1, #votemap.maps do
                    if (votemap.votes[i] > votemap.votes[indexmap]) then
                         print(i)
                         indexmap = i
                    end
               end
               
               parse("changemap "..votemap.maps[indexmap])
               
               votemap.running = false
          end
     end
end
31.05.20 01:03:37 am
Up
mrc
User
Offline Off
LUA ERROR: sys/lua/autorun/votemap.lua:8: attempt to call global 'initArray' (a nil value)
CS2D Brazilian Community - http://cs2dbr.tk
31.05.20 01:54:09 am
Up
Cure Pikachu
User
Offline Off
Add this too.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function initBoolArray(m)
     local array = {}
     for id = 1, m do
          array[id] = false
     end
     return array
end

function initArray(m)
     local array = {}
     for id = 1, m do
          array[id] = 0
     end
     return array
end

Also user Alpha Beta's script doesn't really fulfill that requirement of yours where if the vote is on the same map as the one being played, it restarts the game instead. So for that, replace line 83 of his code with this:
Code:
1
2
3
4
5
6
if votemap.maps[indexmap] == map("name") then
     parse("restart 10")
     votemap.temptime = 0
else
     parse("changemap "..votemap.maps[indexmap])
end
edited 1×, last 31.05.20 02:19:35 am
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
31.05.20 02:17:46 am
Up
mrc
User
Offline Off
Ty guys, I fixed and changed some things to fit my needs. U guys are the best!
edited 2×, last 31.05.20 05:48:25 am
CS2D Brazilian Community - http://cs2dbr.tk
31.05.20 11:01:30 am
Up
Alpha Beta
User
Offline Off
user Cure Pikachu has written:
Add this too.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function initBoolArray(m)
     local array = {}
     for id = 1, m do
          array[id] = false
     end
     return array
end

function initArray(m)
     local array = {}
     for id = 1, m do
          array[id] = 0
     end
     return array
end

Also user Alpha Beta's script doesn't really fulfill that requirement of yours where if the vote is on the same map as the one being played, it restarts the game instead. So for that, replace line 83 of his code with this:
Code:
1
2
3
4
5
6
if votemap.maps[indexmap] == map("name") then
     parse("restart 10")
     votemap.temptime = 0
else
     parse("changemap "..votemap.maps[indexmap])
end

Oh yeah I didn't copy that part for a reason.
To the start Previous 1 Next To the start