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

Members Online

»
0 Active | 62 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 4
Category: CoD4 Scripting
Scripting and coding with Call of Duty 4.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername, novemberdobby
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: picking a random player
Opel
General Member
Since: Dec 18, 2008
Posts: 21
Last: Sep 4, 2011
[view latest posts]
Level 1
Category: CoD4 Scripting
Posted: Wednesday, Apr. 7, 2010 12:52 pm
ok so im trying to make something pick a random player and move them to the other team after 45 seconds have passed when the game starts but im having trouble doing it so i had a look in the _teams.gsc and tried making it but it just isnt getting through to me how i would do it. this is what i did.
Code:
   

 playerres()
{
p = getEntArray( "player", "classname" );


for(i=0;i<p.size;i++)
{
if(p[i].sessionstate != "spectating")
	{
	p[i].switching_teams = true;
	p[i].joining_team = "axis";
	p[i].leaving_team = "allies";
	p[i].sessionteam = "axis";
	p[i].pers["team"] = "axis";
	p[i].team = "axis";
	p[i].cur_kill_streak = 0;
	p[i] maps\mp\gametypes\_globallogic::spawnplayer();
	
	thread pickRandom();
	}

	}	

}


pickRandom()
{
p = getEntArray( "player", "classname" );

rand = randomInt(p.size);
if(p[rand].sessionstate == "playing")
	{
wait 45;
	p[rand] suicide();
	}
else
	thread pickRandom();
}       
Share |
DemonSeed
General Member
Since: Apr 30, 2009
Posts: 1362
Last: Feb 19, 2018
[view latest posts]
Level 8
Im a fan of MODSonair
Category: CoD4 Scripting
Posted: Wednesday, Apr. 7, 2010 01:28 pm
Try this (untested):

Code:
start()		
{
	candidateteam = self.pers["team"];
	
	if( candidateteam != "allies" && candidateteam != "axis" )
		return;
	
	level thread SelectCandidate( candidateteam, 45 );
}

SelectCandidate( team, delay )
{
	wait delay;
	
	candidate = undefined;
	candidate_credit = 0;

	for( ;; )
	{
		players = level.players;

		// Increase randomly the credit of all living players of the team
		for (i = 0; i < players.size; i ++)
		{
			player = players[i];
		
			if( !isdefined( player.pers["team"] ) || player.pers["team"] != team )
				continue;

			if( !isdefined( player.move_credit ) )
				player.self_credit = 0;
		
			if( player.sessionstate == "playing" )
				player.move_credit += randomInt( players.size );
		}
	
		// Choose the new move candidate = the alive player with the highest credit
		for(i = 0; i < players.size; i ++)
		{
			player = players[i];
		
			if( !isdefined( player.pers["team"] ) || player.pers["team"] != team )
				continue;
		
			if( player.move_credit > candidate_credit )
			{
				candidate = player;
				candidate_credit = player.move_credit;
			}
		}

		if( isdefined( candidate ) && candidate.sessionstate == "playing" )
			break;
		
		wait 1;
	}
	
	newTeam = undefined;

	if( candidate.pers["team"] == "axis" ) 
		newTeam = "allies";
	else if( candidate.pers["team"] == "allies" ) 
		newTeam = "axis";

	candidate.pers["team"] = newTeam;
	if(candidate.pers["team"] == "allies")
		candidate thread switchteams( "allies" );
	else
		candidate thread switchteams( "axis" );
	
}

switchteams( Team )
{

	if(self.sessionstate != "dead")
	{
		self.switching_teams = true;
		self.joining_team = Team;
		self.leaving_team = self.pers["team"];
		self suicide();
	}
	
	self.pers["lockteams"] = true;
	self.pers["team"] = Team;
	self.team = Team;
	self.pers["teamTime"] = undefined;
	self.sessionteam = self.pers["team"];
	self maps\mp\gametypes\_globallogic::updateObjectiveText();
	
	self maps\mp\gametypes\_spectating::setSpectatePermissions();
	
	self notify( "end_respawn" );
}


edited on Apr. 7, 2010 09:29 am by DemonSeed

edited on Apr. 7, 2010 09:34 am by DemonSeed
Share |
Opel
General Member
Since: Dec 18, 2008
Posts: 21
Last: Sep 4, 2011
[view latest posts]
Level 1
Category: CoD4 Scripting
Posted: Wednesday, Apr. 7, 2010 01:46 pm
i fixed the other error and now get this saying when 45 seconds is up and it switches whole team not just one player

cannot cast undefined bool

pair 'undefined' and '1' has unmatching types 'undefined and 'int'
player.move_credit += randomint( player.size );
Share |
DemonSeed
General Member
Since: Apr 30, 2009
Posts: 1362
Last: Feb 19, 2018
[view latest posts]
Level 8
Im a fan of MODSonair
Category: CoD4 Scripting
Posted: Wednesday, Apr. 7, 2010 02:14 pm
Right, this works because I tested it:

Code:
onStartGameType()
{

	level thread SelectCandidate( randomizeTeam(), 45 );
}

randomizeTeam()
{
	team = [];
	team[0] = "allies";
	team[1] = "axis";
	
	string = team[ randomint( team.size ) ];
	return string;	

}
	
SelectCandidate( team, delay )
{
	wait delay;
	
	candidate = undefined;
	candidate_credit = 0;

	for( ;; )
	{
		players = level.players;

		// Increase randomly the credit of all living players of the team
		for (i = 0; i < players.size; i ++)
		{
			player = players[i];
		
			if( !isdefined( player.pers["team"] ) || player.pers["team"] != team )
				continue;

			if( !isdefined( player.move_credit ) )
				player.move_credit = 0;
		
			if( player.sessionstate == "playing" )
				player.move_credit += randomInt( 100 );
		}
	
		// Choose the new move candidate = the alive player with the highest credit
		for(i = 0; i < players.size; i ++)
		{
			player = players[i];
		
			if( !isdefined( player.pers["team"] ) || player.pers["team"] != team )
				continue;
		
			if( player.move_credit > candidate_credit )
			{
				candidate = player;
				candidate_credit = player.move_credit;
			}
		}

		if( isdefined( candidate ) && candidate.sessionstate == "playing" )
			break;
		
		wait 1;
	}
	
	newTeam = undefined;

	if( candidate.pers["team"] == "axis" ) 
		newTeam = "allies";
	else if( candidate.pers["team"] == "allies" ) 
		newTeam = "axis";

	candidate.pers["team"] = newTeam;
	if(candidate.pers["team"] == "allies")
		candidate thread switchteams( "allies" );
	else
		candidate thread switchteams( "axis" );
	
}

switchteams( Team )
{

	if(self.sessionstate != "dead")
	{
		self.switching_teams = true;
		self.joining_team = Team;
		self.leaving_team = self.pers["team"];
		self suicide();
	}
	
	self.pers["lockteams"] = true;
	self.pers["team"] = Team;
	self.team = Team;
	self.pers["teamTime"] = undefined;
	self.sessionteam = self.pers["team"];
	self maps\mp\gametypes\_globallogic::updateObjectiveText();
	
	self maps\mp\gametypes\_spectating::setSpectatePermissions();
	
	self notify( "end_respawn" );
}


The onStartGameType() function is Callback_StartGametype() - it must be started from there.

edited on Apr. 7, 2010 10:22 am by DemonSeed
Share |
Opel
General Member
Since: Dec 18, 2008
Posts: 21
Last: Sep 4, 2011
[view latest posts]
Level 1
Category: CoD4 Scripting
Posted: Wednesday, Apr. 7, 2010 02:38 pm
i didnt really understand where to put it so this goes in the globallogic under callback_startgametype?

edit: Nevermind I got it working. Thanks DemonSeed


edited on Apr. 7, 2010 10:49 am by liamo7
Share |
DemonSeed
General Member
Since: Apr 30, 2009
Posts: 1362
Last: Feb 19, 2018
[view latest posts]
Level 8
Im a fan of MODSonair
Category: CoD4 Scripting
Posted: Wednesday, Apr. 7, 2010 02:51 pm
liamo7 writes...
Quote:
i didnt really understand where to put it so this goes in the globallogic under callback_startgametype?


Well, yes - the first thread has to start in the callback_startgametype() function, but _globallogic.gsc isnt the only GSC file with that function in it. There is also _callbacksetup.gsc, which is where the "real" codecallbacks are made.

the rest of the functions can go in any GSC file you want - custom or otherwise. Just make sure you thread to where ever they are properly.
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 4 : CoD4 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

»