Create a level.allies + same team in new map

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

Post Reply
Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Create a level.allies + same team in new map

Post by Moustache » March 11th, 2011, 8:46 pm

Is it possible to create a mod where you have an array with level.allies? A same array just as level.players but then for the players inside the allies team?
I use it allot for my mod and I think it is better to let the server update the array instead of counting the players each time.

And is it possible to place players inside the same team in the next map?
So the maps ends, the scripts looks which player is in which team. Then it saves that and in the next map the players will be placed in the same team again.

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: Create a level.allies + same team in new map

Post by IzNoGoD » March 11th, 2011, 8:53 pm

Code: Select all

getteam(team) //the team is either "allies" or "axis" (or whatever cod4 supports)
{
	players=getentarray("player","classname");
	level.teams[team]=[]; //empty the array
	for(i=0;i<players.size;i++)
	{
		if(players[i].pers["team"]==team)
			level.teams[team][level.teams[team].size]=players[i];
	}
}

save players:
make sure you call maprotate(true); in the script instead of maprotate(false);
this should save player.pers (persistent vars)
LMGTFY!

Its not a glitch... Its the future!

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Create a level.allies + same team in new map

Post by Moustache » March 11th, 2011, 9:04 pm

Thank you for your fast and with perfect information provided answer, I will try it tomorrow :)

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: Create a level.allies + same team in new map

Post by IzNoGoD » March 12th, 2011, 12:36 pm

IzNoGoD wrote: this should save player.pers (persistent vars)
remember, according to the dev notes it should save it.
I wouldnt count on it though, but storing this is some cvars might do the trick.
LMGTFY!

Its not a glitch... Its the future!

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Create a level.allies + same team in new map

Post by Moustache » March 12th, 2011, 2:40 pm

The loop works great, thank you for that.
IzNoGoD wrote:
IzNoGoD wrote: this should save player.pers (persistent vars)
remember, according to the dev notes it should save it.
I wouldnt count on it though, but storing this is some cvars might do the trick.
It doesn't work, you are right :)

Do you know how I can store it in a dvar (it is for CoD4)?

Should I store all the player names and their guids in a dvar or something?

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Create a level.allies + same team in new map

Post by Drofder2004 » March 12th, 2011, 3:21 pm

You would probably have to store each persons GUID into a DVAR or series of Dvar.

so, instead of creating an array, you could create a DVAR per person. And then when they connect, parse the DVARs to retrieve the team relating to that player. and then force them on to that team.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Create a level.allies + same team in new map

Post by Moustache » March 13th, 2011, 10:18 am

Drofder2004 wrote:You would probably have to store each persons GUID into a DVAR or series of Dvar.

so, instead of creating an array, you could create a DVAR per person. And then when they connect, parse the DVARs to retrieve the team relating to that player. and then force them on to that team.
Ok, I will give it a try.

But when there are like 30 players the server will lagg or only if it isn't scripted right?

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: Create a level.allies + same team in new map

Post by IzNoGoD » March 13th, 2011, 11:23 am

Code: Select all

endofgame()
{
	//call this one before the scoreboard appears
	players=getentarray("player","classname");
	allies=[];
	axis=[];
	for(i=0;i<players.size;i++)
	{
		if(players[i].pers["team"]=="axis")
			axis[axis.size]=players[i];
		else if(players[i].pers["team"]=="allies")
			allies[allies.size]=players[i];
	}
	for(i=0;i<axis.size;i++)
	{
		setcvar("axis"+i,axis[i] getguid()+"");
	}
	setcvar("axis"+(i+1),"-1"); //terminate the list
	for(i=0;i<allies.size;i++)
	{
		setcvar("allies"+i,allies[i] getguid()+"");
	}
	setcvar("allies"+(i+1),"-1"); //terminate the list
}

startofgame()
{
	//call this thread at the start of a new round
	allies=[];
	axis=[];
	i=0;
	while(getcvar("allies"+i)!="-1")
	{
		if(getcvar("allies"+i)!="0")
			level.allies[level.allies.size]=getcvar("allies"+i)+""; //force it into a string
		i++;
	}

	i=0;
	while(getcvar("axis"+i)!="-1")
	{
		if(getcvar("axis"+i)!="0")
			level.axis[level.axis.size]=getcvar("axis"+i)+""; //force it into a string
		i++;
	}
	thread waitforconnect();
}

waitforconnect()
{
	//thread is called by the other threads
	//dont call it manually
	while(1)
	{
		level waittill("connecting",player); //might have to be "connected",player in order to wait for the player to be ready to join a team
		if(isinarray(player getguid()+"",level.axis))
		{
			player.team="axis";
		}
		else if(isinarray(player getguid()+"",level.allies))
		{
			player.team="allies";
		}
		if(isdefined(player.team))
			player forcetoteam(player.team);
	}
}

forcetoteam(team)
{
	//make sure the player gets into "team"
	//you will have to write this one yourself
}
LMGTFY!

Its not a glitch... Its the future!

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Create a level.allies + same team in new map

Post by Moustache » March 13th, 2011, 11:47 am

Thank you very much :mrgreen:

I can figure out the team thing myself. But CoD doesn't know the function isinarray. I think it needs to be changed in a for loop? I will give it a try :)

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: Create a level.allies + same team in new map

Post by IzNoGoD » March 13th, 2011, 12:33 pm

Damn, forgot to include that function (custom function :P)

Code: Select all


isinarray(var,array)
{
	for(i=0;i<array.size;i++)
	{
		if(array[i]==var)
			return true;
	}
	return false;
}

LMGTFY!

Its not a glitch... Its the future!

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Create a level.allies + same team in new map

Post by Moustache » March 13th, 2011, 5:35 pm

Thank you, I am going to test it :)

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests