BlackEmperor94
Chieftain
- Joined
- Feb 2, 2021
- Messages
- 6
How can I code this event, and where please?
Use some python in onBeginPlayerTurnHow can I code this event, and where please?
iBuilding = gc.getInfoTypeForString("BUILDING_PALACE")
pCity.setNumRealBuilding(iBuilding, 1)
@Set: Sounds like onEndGameTurn isn't getting called unless Python scripts get reloaded. You could verify that by writing something to PythonDbg.log at the start of onEndGameTurn (after setting LoggingEnabled to 1 in CivilizationIV.ini). E.g. just
print("onEndGameTurn called")Are you working with a BUG-based mod? Maybe the BugEventManager is interfering.
def onBeginGameTurn(self, argsList):
'Called at the beginning of the end of each turn'
iGameTurn = argsList[0]
CvTopCivs.CvTopCivs().turnChecker(iGameTurn)
pPlot = CyMap().plot(x,y)
pDamascus = pPlot.getPlotCity()
###Finds the X and Y coordinates of Damascus and gives us a pointer variable that represents a city we can now work with, you should substitute these coordinates for x and y
iTurn = CyGame.getGameTurn()
##Finds the current game turn
iPalace = gc.getInfoTypeForString("BUILDING_PALACE")
##Create an integer variable to represent the palace. This checks the appropriate XML file and assigns the variable based on the Palace's location in that list
if (iTurn == 100):
pDamascus.setNumRealBuilding(iPalace, 1)
##If it's the correct turn (replace 100 with the correct turn) place a palace in Damascus
def onEndPlayerTurn(self, argsList):
'Called at the end of a players turn'
iGameTurn, iPlayer = argsList
print("OnEndPlayerTurn is Called")
iCultureVictoryReq = 1000
for iLoopPlayer in range(gc.getMAX_CIV_PLAYERS()):
pPlayer = gc.getPlayer(iLoopPlayer)
iPlayerCulture = pPlayer.countTotalCulture()
if (iPlayerCulture >= iCultureVictoryReq):
CyGame().setWinner(pPlayer.getTeam(), gc.getInfoTypeForString("VICTORY_NEW_CULTURE"))
if (gc.getGame().getElapsedGameTurns() == 1):
if (gc.getPlayer(iPlayer).isHuman()):
if (gc.getPlayer(iPlayer).canRevolution(0)):
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_CHANGECIVIC)
popupInfo.addPopup(iPlayer)
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
Traceback (most recent call last):
File "<string>", line 1, in ?
File "<string>", line 52, in load_module
File "CvEventInterface", line 13, in ?
File "<string>", line 52, in load_module
File "CvEventManager", line 32, in ?
File "CvEventManager", line 386, in CvEventManager
NameError
:
name 'iPlayer' is not defined
Failed to load python module CvEventInterface.
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
if (gc.getGame().getElapsedGameTurns() == 1):
I don't think this is the source of your errors, but are you sure this line
and the following ones are supposed to be inside your for loop? They certainly aren't in original BtS code.Code:if (gc.getGame().getElapsedGameTurns() == 1):
Anyways, which is line 386 in your file?
CvAdvisorUtils.resetAdvisorNags()
def onEndPlayerTurn(self, argsList):
'Called at the end of a players turn'
iGameTurn, iPlayer = argsList
print("OnEndPlayerTurn")
iCultureVictoryReq = 2000
for iLoopPlayer in range(gc.getMAX_CIV_PLAYERS()):
pPlayer = gc.getPlayer(iLoopPlayer)
iPlayerCulture = pPlayer.countTotalCulture()
if (iPlayerCulture >= iCultureVictoryReq):
CyGame().setWinner(pPlayer.getTeam(), gc.getInfoTypeForString("VICTORY_NEW_CULTURE"))
if (gc.getGame().getElapsedGameTurns() == 1):
if (gc.getPlayer(iPlayer).isHuman()):
if (gc.getPlayer(iPlayer).canRevolution(0)):
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_CHANGECIVIC)
popupInfo.addPopup(iPlayer)
##This is line 385. The line directly below this comment is line 386
CvAdvisorUtils.resetAdvisorNags()
CvAdvisorUtils.endTurnFeats(iPlayer)
And this happens even with a mod that makes no changes to any other files? I'm attaching a mod that has only this one file with that one extra line (and the auto-generated .ini file). I'm getting one line of log output with this each time that I end my turn, as expected.With no other changes to the CvEventManager I added a print statement to onEndGameTurn. It prints a single time in the log on game start and never again unless I reload the python modules in which case it prints again.
I've made lots of changes to the XML, but nothing else to python and I haven't touched the dllAnd this happens even with a mod that makes no changes to any other files? I'm attaching a mod that has only this one file with that one extra line (and the auto-generated .ini file). I'm getting one line of log output with this each time that I end my turn, as expected.
The two files we've uploaded have the same contents apart from the print call. Something in your file properties then? Access permissions (of the .py fileCopying my base game CvEventManager file over the one in your TestMod and adding the print() line doesn't work properly either.
in CvGameCoreUtils.cpp on line 595 ? I never used it but seems to be there. Let us know how it goes.
// FUNCTION: getCombatOdds
// Calculates combat odds, given two units
// Returns value from 0-1000
// Written by DeepO
int getCombatOdds(CvUnit* pAttacker, CvUnit* pDefender)