Forum

> > CS2D > Scripts > How to make player count into % ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to make player count into % ?

16 replies
To the start Previous 1 Next To the start

old How to make player count into % ?

Rainoth
Moderator Off Offline

Quote
I didn't really think up of a descriptive title but oh well (sorry about that).

What I actually mean is whether there is an easy way to get total player count then get a number (e.g. 24) then make it seem as (100%) then check if more than X amount of players did something.

For short, I want to make a vote system. Downloading others isn't a solution (I looked up many files and threads) as they all would make problems when put with my own scripts. I just want to know the mechanism of how to get player count then check if player said or pressed sth (like menu button)..

Thank you in advance.

old Re: How to make player count into % ?

Rainoth
Moderator Off Offline

Quote
What does the last line mean ?

And about "maxplayers" it's not really a defined count. There can be any amount of players in server.

E.g.

Server has 30 people in it (not likely but whatever)

maxplayers = Current Amount of Players (30 in this case)
players = Percentage of players who pressed and/or did something. Like 10 people voted for map1 and 4 people voted for map 2 and so on so the script would get :

map1 = 10/30 * 100(%)
map2 = 4/30 * 100

It gets total percentage, if it's above X amount (e.g. above 80%) then execute : change map to mapname.map

And could you explain what "math.floor" is/does ?

old Re: How to make player count into % ?

Yates
Reviewer Off Offline

Quote
Players = current that voted a certain map. Count this by using a loop with a custom function.
Maxplayers = game("sv_maxplayers")

Do you even learn math at school? This is the ultimate basic 5 year old stuff.
edited 1×, last 22.04.13 05:20:23 pm

old Re: How to make player count into % ?

Rainoth
Moderator Off Offline

Quote
@user krabob: Actually, I solve a lot, what I ask in threads is just a little part. And your reply isn't really helpful. If you don't have anything usefull to say, please don't.

@user Yates: You didn't quite understand what I meant.
Max Players is not the actual limit that the server allows but rather the current amount of players,whereas the players differ for what kind of map they choose.

old Re: How to make player count into % ?

Rainoth
Moderator Off Offline

Quote
user Avo has written
1
#player(0, "table")


That's for current max players. Thanks. But what about when it comes to each separate group (as I stated like 15 Players for map 1 and another amount for another group)

old Re: How to make player count into % ?

Alistaire
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
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
function array(v)
	local a = {}
	for i = 1, 32 do
		a[i] = v
	end
	return a;
end

plr = {}
plr.voted = array(false)
plr.menuTable = array(0)

function addVote(id, vote)
	if not plr.voted[id] then
		plr.voted[id] = vote
	end
end

function allVotes()
	local a = 0
	for i = 1, 32 do
		if plr.voted[i] then
			a = a + 1
		end
	end
	return a;
end

function votedMaps()
	local a = {}
	for i = 1, 32 do
		if a[plr.voted[i]] then
			a[plr.voted[i]] = a[plr.voted[i]] + 1
		else
			a[plr.voted[i]] = 1
		end
	end
	return a;
end

function checkVotes()
	local table, votes, i = votedMaps(), allVotes(), 1
	local newTable = {}
	for k, v in pairs(table) do
		newTable[i] = {name = k, votes = v, percent = math.ceil(table[i] / votes * 100)}
		i = i + 1
	end
	plr.menuTable[id] = newTable
	return newTable;
end

function generateVotingMenu(id)
	local table, string = checkVotes(), ''
	for i = 1, #table do
		string = string..','..table[i].percent..'% - '..table[i].votes..' votes|'..table[i].name
	end
	menu(id, Voting'..string)
end

function serveractionHook(id, action)
	if action == 1 then
		generateVotingMenu(id)
	end
end

function menu(id, title, button)
	if title == 'Voting' then
		--got bored
	end
end

old Re: How to make player count into % ?

mafia_man
User Off Offline

Quote
user Alistaire has written
code >


Using this array function is waste of memory.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview