Code Doesn't Work At All

deanej

Deity
Joined
Apr 8, 2006
Messages
4,859
Location
New York State
I'm trying to make it so that you can only have 5 of a certain unit at any given time. Unfortunately, the code for this doesn't work at all - it doesn't do anything, not errors, no nothing, it's like its not even there. Here's what I added:
at the start of CvFinalFrontierEvents, after #globals:
Code:
iNumKazon = 0

in onGameStart:
Code:
		global iNumKazon

		iNumKazon = 0

in onUnitBuilt:
Code:
		iKazonUU = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_KAZON_TORPEDO')
		global iNumKazon

		if(pUnit.getUnitType() == iKazonUU):
                    iNumKazon += 1

in onUnitLost:
Code:
		iKazonUU = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_KAZON_TORPEDO')
		global iNumKazon

		if(unit.getUnitType() == iKazonUU):
                    iNumKazon -= 1

in cannotTrain of CvGameUtils:
Code:
		FinalFrontier = CvEventInterface.getEventManager()

		if (eUnit == iKazonUU):
                    if (FinalFrontier.iNumKazon == 5):
                        return True

What on Earth am I doing wrong? :confused: I NEED this limit in my mod. Please help.
 
Do you have added the pythonCallBack needed in "PythonCallbackDefines.xml" ?

Wouldn't it be easier to do like this in cannotTrain :

Code:
		pCity = argsList[0]
		eUnit = argsList[1]
		ePlayer = pCity.getOwner()

                iKazonUU = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_KAZON_TORPEDO')
                iKazonUUClass = gc.getUnitInfo(iKazonUU).getUnitClassType()

                if (eUnit == iKazonUU) :
                        if gc.getPlayer(ePlayer).getUnitClassCountPlusMaking(iKazonUUClass) >= 5 :
                                return True

Or change XML to have iKazonUU its own unit class ... with all the work with building , civilization editing .

Tcho !
 
If you only want X amount of a unit at any given time, why don't you just use the national limit tag in XML, like with missionaries?
 
I've just tested the code with UNIT_WARRIOR and it works fine for me ???
 
I figured out what happened: Before the starbase code, there is a line that says #block out the rest, which is followed by return False. No idea why the starbase code was working (and maybe it wasn't; I didn't really pay that much attention), but removing the return False solves the problem. Thanks!
 
The only reason I could see for doing this would be if you wanted to start out with no limits, and then wanted to limit the number of units if a special trigger occurred. But surely there is still a better way to do that...?
 
The only reason I could see for doing this would be if you wanted to start out with no limits, and then wanted to limit the number of units if a special trigger occurred. But surely there is still a better way to do that...?

Create an SDK function that allows changing of the national limit, then expose to python and write the hook into the events function in python.

You'd end up with something like: player.changeUnitLimit(unitType, change)
 
Back
Top Bottom