Counting players

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
digitac
Sergeant
Posts: 58
Joined: Mon Jul 28, 2003 3:30 pm

Counting players

Post by digitac »

How can i count my players ?

i have this but it doesn't work

Code: Select all

local.as = 0
local.al = 0
for ( local.n = 1 ; local.n <= $player.size ; local.n++ ) 
{ 
	if ( $player[local.n].dmteam == "axis" )
	{
		local.as++
	}
	else
		local.al++
	}
}
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Re: Counting players

Post by Bjarne BZR »

Try this:

Code: Select all

local.as = 0
local.al = 0
for ( local.n = 0 ; local.n < $player.size ; local.n++ ) 
{ 
	if ( $player[local.n].dmteam == "axis" )
	{
		local.as++
	}
	else
	{
		local.al++
	}
}
You forgot a bracket after 'else' and arrays start at index 0
If you looked at the console, you would probably have seen the script error printed out there ;)
Not sure if you will count spectators as allied in this way...
Admin .MAP Forums
Image
Head above heels.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Re: Counting players

Post by jv_map »

Bjarne BZR wrote:You forgot a bracket after 'else' and arrays start at index 0.
Nope, not targetname arrays, they start at 1. Vector arrays and strings start indexing at 0 though :?
Image
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post by Bjarne BZR »

Ehr... yes... :oops:
I guess c / C++ and a naive wish for standardization took over there. :oops:
jv is once again correct. thanx. :)

What the h**l was the language designer thinking? :lol:
Admin .MAP Forums
Image
Head above heels.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Well to be honest I like starting arrays at 1... it just seems more convenient :)
Image
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post by Bjarne BZR »

I dont mind starting at 1, its starting different arrays in different ways I cant see the point of. :twisted:
Admin .MAP Forums
Image
Head above heels.
Post Reply