the better method

12/09/2014 22:24 XDestroyer2011#1
Now guys I am doing a TeamsWar and I don't know how to do the automatic team choice for every player that sign up !
so I made two methods may you please tell me if they will work properly.
and tell me what method to choose from, BTW I am not a good coder I am still a beginner so just don't come here to make fun of me. if you have a better way to do it may you please explain how :)

Here is the code !
12/09/2014 23:01 pro4never#2
Nothing in that example will work.

-You're creating 'new' clients... you cannot do that...
-You're over complicating things


There's no reason to have bools for isTeam in the player.

#1: Create a 'team' enum.
#2: Create an 'event' class. Assign starting/ending events to sort players into teams
#3: Create a 'team' class. Have it store team score and members


When starting an event you take a collection of all signed up players (players on waiting map or add them in via npc/command/etc) and sort them into teams. You can sort them by level/battlepower to try to balance teams if needed or simply randomize the collection.

Something like

var teamCounter = 0;//Starting team index
var teamCounts = 3;//4 possible teams
foreach(var player in awaitingPlayers)
{
teamCounter++;
if(teamCounter > teamCounts)
teamCounter = 0;
Teams[teamCounter].AddMember(player);
}


Again, there's lots of ways to simplify and make your events system easier to build on.



This way you can check in your combat handler if you are part of an event with something like

if(character.Event != null)

You can modify their team's score and perform any needed actions (freezing, changing teams, etc)
character.Team.ScorePoint(target)



Just boils down to coding the base event systems in a way that you can have them support any event you can imagine. I know in albetros I wrote a BASIC system (it's messy but it could give you a basic idea of how to code an event system)
12/09/2014 23:17 XDestroyer2011#3
well that's true that I am always complicating thing up.
all of that is just good.
but my question was on how to sort the teams, how can I do that
and on your answer here you just explained every thing beside
sorting the teams, I know you said "You can sort them by level/battlepower to try to balance teams if needed or simply randomize the collection. "
but what I want is to random every one into a team of the 4 but all the teams should have equal players or a nearly equal players.
thanks for your answer and time
12/09/2014 23:29 pro4never#4
Code:
but what I want is to random every one into a team of the 4 but all the teams should have equal players or a nearly equal players.
yes, that's the example I gave you. You need to get a collection of ALL players signed up. Query the map of the event or a 'waiting room' for the event or build it as people sign up. Either way you have a collection of all players.

Sort that collection based on criteria (level for example)

var awaitingPlayers = registeredPlayers.OrderBy(I=>I.Level);

Then loop through all elements and cycle them into teams evendly (first element = team 1, second element = team 2, etc)

var teamCounter = 0;//Starting team index
var teamCounts = 3;//4 possible teams
foreach(var player in awaitingPlayers)
{
teamCounter++;
if(teamCounter > teamCounts)
teamCounter = 0;
Teams[teamCounter].AddMember(player);
}
12/09/2014 23:38 XDestroyer2011#5
but this will work for one team ?
or I can use this method in as many teams as I want
12/09/2014 23:48 pro4never#6
You can use it for as many teams as you want.

The idea is you create an array of teams of any length and then you assign players to each team.

want 10 teams? Change 0 lines of code and it'll work the same as 2 teams.
12/09/2014 23:56 XDestroyer2011#7
thats what I did


and I got this error

[Only registered and activated users can see links. Click Here To Register...]

Sorry man, I am just a noob :(
12/10/2014 00:33 pro4never#8
Enums is just making text out of a number. You need a collection (list, array, dictionary, etcetc) containing the teams themselves (a separate class)

It's not handled all that well but I really do suggest looking through the albetros source as it will at least demonstrate an idea of how you could write an event system.
12/10/2014 01:03 XDestroyer2011#9
Wow just downloaded albetros source and looked in the TDM wow ! it is amazing !
12/10/2014 01:06 turk55#10
Updated your code a bit (can be done better, but you will atleast get the idea):

12/10/2014 01:27 XDestroyer2011#11
Quote:
Originally Posted by turk55 View Post
Updated your code a bit (can be done better, but you will atleast get the idea):

ahhahahah that's not a bit :D
thanks