Forum

> > CS2D > Scripts > Vote - HudTxt
Forums overviewCS2D overview Scripts overviewLog in to reply

English Vote - HudTxt

5 replies
To the start Previous 1 Next To the start

old Vote - HudTxt

limonata
User Off Offline

Quote
Hi all i wanna make a vote system when you click the map it will be like this for example i clicked the de_dust2 then there will be hudTxt like

De_Dust2: 1 -- mean taken 1 vote. but i got error: "LUA ERROR: sys/lua/olric.lua:18: attempt to perform arithmetic on field '?' (a nil value)" pls fix it. Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
map1 = {"de_dust2"}
vote = {}
--map2 = "de_cs2d"
--map3 = "aim_shotgun"

addhook("say","voteSay")
function voteSay(id,txt)
if txt == "!vote" then
menu(id,"Vote Map,"..map1[id].."")
end
end

addhook("menu","vMenu")
function vMenu(id,tit,but)
if tit == "Vote Map" then
if but == 1 then
vote[id] = vote[id] + 1
parse('hudtxt2 '..id..' 1 "©000255000De_Dust: '..vote[id]..'" 13 250')
end
end
end

old Re: Vote - HudTxt

Avo
User Off Offline

Quote
Vote is a table storing votes for map, right? So why do you use id parameter for it if doesn't store player's data?

old Re: Vote - HudTxt

Avo
User Off Offline

Quote
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
voted = {}

maps = 	{
			{"de_dust", 0},
			{"de_cs2d", 0},
			{"aim_shotgun", 0}
		}

addhook("say","voteSay")
function voteSay(id,txt)
	if txt == "!vote" then
		menu(id,"Vote Map,"..maps[1][1]..","..maps[2][1]..","..maps[3][1])
	end
end

addhook("menu","vMenu")
function vMenu(id,tit,but)
	if tit == "Vote Map" then
		if tonumber(but) and but ~=0 then
			if maps[voted[id]] then
				maps[voted[id]][2] = maps[voted[id]][2] - 1
				maps[but][2] = maps[but][2] + 1
			else
				maps[but][2] = maps[but][2] + 1
			end
		end
		voted[id] = tonumber(but)
	end
	updateHud()
end

updateHud = function()
	parse('hudtxt 0 "©255255255 '..maps[1][1]..':'..maps[1][2]..' votes" 2 100')
	parse('hudtxt 1 "©255255255 '..maps[2][1]..':'..maps[2][2]..' votes" 2 120')
	parse('hudtxt 2 "©255255255 '..maps[3][1]..':'..maps[3][2]..' votes" 2 140')
end

updateHud()

Doesn't support infinite menus, but it's just example, which (if you're not a faggot) can simply edit.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview