HowTo assign a player to a team in an event?

wotan321

Emperor
Joined
Oct 25, 2001
Messages
1,228
Location
NC, USA
I want to put a player on a team using python in an event.

How is that done?

Thanks for any help.
 
Here's a code snippet from FFH.

Code:
			iMercurianPlayer = pPlayer.initNewEmpire(gc.getInfoTypeForString('LEADER_BASIUM'), gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'))
			if iMercurianPlayer != PlayerTypes.NO_PLAYER:
				pMercurianPlayer = gc.getPlayer(iMercurianPlayer)
				iTeam = pPlayer.getTeam()
				iMercurianTeam = pMercurianPlayer.getTeam()
				if iTeam < iMercurianTeam:
					gc.getTeam(iTeam).addTeam(iMercurianTeam)
				else:
					gc.getTeam(iMercurianTeam).addTeam(iTeam)
 
So CyTeam.addTeam() makes all players belonging to another team join that team? What about the other team, does it become obsolete? What if you wanna extract one player of some team and adjoin it to another team?
 
Thanks. The code is a bit mysterious to me, so if you can explain the process I would appreciate it.

Also, I found this bit of code on another thread.

gc.getTeam(gc.getPlayer(PlayerA_ID)).addTeam(gc.ge tTeam(gc.getPlayer(PlayerB_ID)))

Would the PlayerA_ID and PlayerB_ID be a number, the player number from the game?

Again, thanks for any feedback.
 
wotan321, do you know any basic Python? I mean like syntax or indentation levels? What about functions/methods?
 
So CyTeam.addTeam() makes all players belonging to another team join that team? What about the other team, does it become obsolete? What if you wanna extract one player of some team and adjoin it to another team?

Interesting question. addTeam() shouldn't be called on a player that is already on a team (it will work, but I imagine it would result in all sorts of weird diplomacy issues). However, I don't see any functions to remove a player from a team. Looks like you would have to make a new function for that (or edit the addTeam() function).
 
Well, here goes:

What the CyTeam.addTeam() method does, is it adds all players of one team (identified by a TeamType value or a Team ID - an integer basically) to another team (identified by the CyTeam instance on which the method is invoked one). Are you with me so far?

So firstly we have to get the CyTeam instance of the team on which the player will be adjoined. Supposing that we have the TeamType/Team ID of that team, we can use the CyGlobalContext.getTeam() method with the TeamType value as the parameter and get the CyTeam object as the return value.

Next, we need to know what TeamType/Team ID the player in question has. Luckily there is a CyPlayer.getTeam() method that returns this value, but unless you already have the CyPlayer object you need to fetch it with CyGlobalContext.getPlayer() - using the PlayerType/Player ID as the parameter.

So we might end up with something like this (where eTeam and ePlayer have already been defined):
Code:
pTeam = gc.getTeam(eTeam)
pPlayer = gc.getPlayer(ePlayer)
ePlayerTeam = pPlayer.getTeam()
pTeam.addTeam(ePlayerTeam)
This could also be expressed on a single line as:
Code:
gc.getTeam(eTeam).addTeam(gc.getPlayer(ePlayer).getTeam())
Its the exact same thing, its only somewhat more confusing to look at.

If you're doing this with a scenario where all players are the only members of each team and where all the Player/Team IDs match exactly, then this becomes somewhat easier, as you will be able to substitute any PlayerType with its corresponding TeamType, and vice versa.
 
Again, thanks, this information is very helpful. I know a little Python simply from Frankensteining parts from various mods for my own use. The various tutorials you all contribute to are excellent resources. It usually occurs that I am able to cobble something to work without gleaning a clear understanding of the mechanics of my creation.
 
Top Bottom