Help me python programmers!

cfkane

Emperor
Joined
Feb 7, 2006
Messages
1,196
I just can't get this python function to work. It's supposed to spawn a barbarian world unit, a dragon in this case.

Code:
def applyDragon(argsList):
	iEvent = argsList[0]
	kTriggeredData = argsList[1]
	iPlayer = gc.getPlayer(kTriggeredData.ePlayer)
	pPlayer = gc.getPlayer(iPlayer)

	listPlots = []
	map = gc.getMap()	
	for i in range(map.numPlots()):
		plot = map.plotByIndex(i)
		if (plot.getOwner() == -1 and not plot.isWater() and not plot.isImpassable() and plot.area().getCitiesPerPlayer(kTriggeredData.ePlayer) > 0 and plot.isAdjacentPlayer(kTriggeredData.ePlayer, true)):
			listPlots.append(i)
	
	if 0 == len(listPlots):
		return
			
	newUnit = iPlayer.initUnit(gc.getInfoTypeForString('UNIT_DRAGON'), UnitAITypes.UNITAI_PILLAGE, DirectionTypes.DIRECTION_SOUTH)

	barbPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
	for i in range(iNumUnits):
		barbPlayer.initUnit(iUnitType, plot.getX(), plot.getY(), UnitAITypes.UNITAI_ATTACK_CITY_LEMMING, DirectionTypes.DIRECTION_SOUTH)

I'm getting the error message:

Argument error: python argument types in
CyGlobalContext.getPlayer(CyGlobalContext, CyPlayer)
did not match C++ signature:
getPlayer(class CyGlobalContext {lvalue}, int)


So, what's my next step?
 
Try just:

pPlayer = gc.getPlayer(kTriggeredData.ePlayer)

instead of:

iPlayer = gc.getPlayer(kTriggeredData.ePlayer)
pPlayer = gc.getPlayer(iPlayer)

(of course then also change the iplayer to pplayer when you initunit later on)
 
Are you trying to have the dragon spawn for iPlayer or barbarian?

as your defining newunit but at the same time trying to intunit for iplayer (and also not giving cordinates for where to initunit

so

if you're spawning it for barbarian:

your newunit = line should be something like this:

newunit = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), 'UNIT_DRAGON')

and your last line something like this:

barbPlayer.initUnit(newunit, plot.getX(), plot.getY(), UnitAITypes.UNITAI_ATTACK_CITY_LEMMING, DirectionTypes.DIRECTION_SOUTH)
 
However you also need to define inumunits and plot

Try this code:

Code:
def applyDragon(argsList):
	iEvent = argsList[0]
	kTriggeredData = argsList[1]
	pPlayer = gc.getPlayer(kTriggeredData.ePlayer)

	listPlots = []
	map = gc.getMap()
	for i in range(map.numPlots()):
		plot = map.plotByIndex(i)
		if (plot.getOwner() == -1 and plot.isWater() and not plot.isImpassable() and not plot.getNumUnits() > 0 and not plot.isLake() and plot.isAdjacentPlayer(kTriggeredData.ePlayer, true)):
			listPlots.append(i)

	if 0 == len(listPlots):
		return

	plot = map.plotByIndex(listPlots[gc.getGame().getSorenRandNum(len(listPlots), "Dragon event location")])

	iNumUnit1  = 1

	iUnitType1 = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), 'UNIT_DRAGON')

	barbPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
	for i in range(iNumUnit1):
		barbPlayer.initUnit(iUnitType1, plot.getX(), plot.getY(), UnitAITypes.UNITAI_ATTACK_CITY_LEMMING, DirectionTypes.DIRECTION_SOUTH)
 
Top Bottom