Create a level.allies + same team in new map
Moderator: Core Staff
Create a level.allies + same team in new map
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.
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.
Re: Create a level.allies + same team in new map
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)
Re: Create a level.allies + same team in new map
Thank you for your fast and with perfect information provided answer, I will try it tomorrow
Re: Create a level.allies + same team in new map
remember, according to the dev notes it should save it.IzNoGoD wrote: this should save player.pers (persistent vars)
I wouldnt count on it though, but storing this is some cvars might do the trick.
Re: Create a level.allies + same team in new map
The loop works great, thank you for that.
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?
It doesn't work, you are rightIzNoGoD wrote:remember, according to the dev notes it should save it.IzNoGoD wrote: this should save player.pers (persistent vars)
I wouldnt count on it though, but storing this is some cvars might do the trick.
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?
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Create a level.allies + same team in new map
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.
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.
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
Re: Create a level.allies + same team in new map
Ok, I will give it a try.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.
But when there are like 30 players the server will lagg or only if it isn't scripted right?
Re: Create a level.allies + same team in new map
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
}
Re: Create a level.allies + same team in new map
Thank you very much
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
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
Re: Create a level.allies + same team in new map
Damn, forgot to include that function (custom function )
Code: Select all
isinarray(var,array)
{
for(i=0;i<array.size;i++)
{
if(array[i]==var)
return true;
}
return false;
}
Re: Create a level.allies + same team in new map
Thank you, I am going to test it
Who is online
Users browsing this forum: No registered users and 0 guests