I'm programming a game in which I have to set a team based on the position of the player when the game starts. Can you help me?
var playerz = [];
room.onPlayerJoin = function () {
playerz.push({
name: player.name,
id: player.id,
team: 0,
position: { x: null, y: null },
});
room.onGameStart = function () {
TeamRed = playerz.filter(
(p) => p.position["x"] === 103 && p.position["y"] === -178.5
);
TeamYellow = playerz.filter(
(p) => p.position["x"] === -206 && p.position["y"] === 0
);
TeamBlue = playerz.filter(
(p) => p.position["x"] === 103 && p.position["y"] === 178.5
);
};
What I've done is to rename the player based on the position, but I actually need to rename the team based on these positions. Of course, I could do it manually verifying the position of each player but in some maps players are more than 10 so I need to do it automatically. Can someone help me?
P.S. Never mind about player, it's a built-in-game parameter.
TeamRed.forEach(plr => playerz.find(o => o.id == plr.id).name = "Red");
I think this is what you're trying to accomplish?