Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 103 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked
Page
Next Page
subscribe
Author Topic: Random Player
Leal
General Member
Since: Feb 5, 2010
Posts: 196
Last: Aug 18, 2013
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Monday, Nov. 8, 2010 11:54 am
Hey all [wave]

I want to choose a random player. For that there is this function:

Code:
random_player = players[randomint(players.size)];

But, I would like to choose a random player of a specific team or a random player except a specific player!
How would that work? Does anyone have an idea or knows how?

Thanks in anticipation.
Share |
IzNoGoD
General Member
Since: Nov 29, 2008
Posts: 694
Last: Nov 10, 2012
[view latest posts]
Level 6
Category: CoD2 Scripting
Posted: Monday, Nov. 8, 2010 01:21 pm
make
Code:

team="allies";
teamplayers=[];
for(i=0;i<players.size;i++)
{
if(players[i].pers["team"]==team)
     teamplayers[teamplayers.size]=players[i];
}
randomplayer=teamplayers[randomint(players.size)];

or
Code:

exceptplayer=self;
otherplayers=[];
for(i=0;i<players.size;i++)
{
if(players[i]!=exceptplayer)
      otherplayers[otherplayers.size]=players[i]
}
randomplayer=otherplayers[randomint(otherplayers.size)];
Share |
Leal
General Member
Since: Feb 5, 2010
Posts: 196
Last: Aug 18, 2013
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Monday, Nov. 8, 2010 03:25 pm
Thank you very much! I'm going to test it.
Share |
Leal
General Member
Since: Feb 5, 2010
Posts: 196
Last: Aug 18, 2013
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Monday, Nov. 8, 2010 04:26 pm
It seems to work :D. Thank you very much IzNoGoD!
Share |
Leal
General Member
Since: Feb 5, 2010
Posts: 196
Last: Aug 18, 2013
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Tuesday, Nov. 9, 2010 04:18 pm
But before the "for" we need to declare players:

Code:
players = getentarray("player", "classname");
Share |
Leal
General Member
Since: Feb 5, 2010
Posts: 196
Last: Aug 18, 2013
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Tuesday, Nov. 9, 2010 04:44 pm
I'm getting confused now :S.

Code:
if(players[i].pers["team"]==team)
     teamplayers[teamplayers.size]=players[i];
}
randomplayer=teamplayers[randomint(players.size)];

Does this mean, that it will only choose a random player, if all the players in the server are in the spectator team?
I'm not really sure about what i'm asking, but I have the next problem:

If there is 1 axis player and 3 spectators, "sometimes" (:S) the 3 spectators become the random players. Why is this happening?
Share |
IzNoGoD
General Member
Since: Nov 29, 2008
Posts: 694
Last: Nov 10, 2012
[view latest posts]
Level 6
Category: CoD2 Scripting
Posted: Tuesday, Nov. 9, 2010 05:10 pm
Thats because you most likely set a random team, and you need to set
team="allies";
correct

Code:

if(randomint(1)==0)
     team="allies";
else
     team="axis";

or something like that
Share |
liltc64
General Member
Since: Feb 12, 2007
Posts: 906
Last: Oct 22, 2012
[view latest posts]
Level 7
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Nov. 9, 2010 05:13 pm
try this

Code:
teamPlayers = [];
teamPlayer["allies"] = [];

players = getentarray("player", "classname");
for(i=0; i<players.size; i++)
{
   plr = players[i];
      
   if(isDefined(plr.pers["team"]) && isDefined(level.teamPlayers[plr.pers["team"]]))
      level.teamPlayers[plr.pers["team"]][level.teamPlayers[plr.pers["team"]].size] = plr;
}

randomPlayer = [];

if(teamPlayer["allies"].size > 0)
{
   randomPlayer["allies"] = teamPlayers["allies"][randomInt[teamPlayers["allies"].size
}
Share |
Leal
General Member
Since: Feb 5, 2010
Posts: 196
Last: Aug 18, 2013
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Tuesday, Nov. 9, 2010 05:39 pm
IzNoGoD writes...
Quote:
Thats because you most likely set a random team, and you need to set
team="allies";
correct

Code:

if(randomint(1)==0)
     team="allies";
else
     team="axis";

or something like that


Oh sorry, I copied wrong, I wanted to ask it about this code:


Code:
		teamplayers=[];				
		players = getentarray("player", "classname");			
		for(i = 0 ; i < players.size ; i++)
		{
			if(players[i].pers["team"] == "spectator")
				teamplayers[teamplayers.size] = players[i];
		}		
		level.randomAxis = teamplayers[randomint(players.size)];


Do I need to apply what you said anyway?
Share |
Leal
General Member
Since: Feb 5, 2010
Posts: 196
Last: Aug 18, 2013
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Tuesday, Nov. 9, 2010 05:42 pm
liltc64 writes...
Quote:
try this

Code:
teamPlayers = [];
teamPlayer["allies"] = [];

players = getentarray("player", "classname");
for(i=0; i<players.size; i++)
{
   plr = players[i];
      
   if(isDefined(plr.pers["team"]) && isDefined(level.teamPlayers[plr.pers["team"]]))
      level.teamPlayers[plr.pers["team"]][level.teamPlayers[plr.pers["team"]].size] = plr;
}

randomPlayer = [];

if(teamPlayer["allies"].size > 0)
{
   randomPlayer["allies"] = teamPlayers["allies"][randomInt[teamPlayers["allies"].size
}

Okay, I will try it, the bad thing is that like I said it only happens "sometimes" so I need to try it a lot of times to be sure that it works.
Share |
Restricted Access Topic is Locked
Page
Next Page
subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»