GarretSidzaka
Modder
- Joined
- Dec 17, 2002
- Messages
- 4,700
How I add custom events to a Mod???? I've seen some neat MODCOMPS for python, but not knowing python has caused me to be stupid. HeLp Me! 

I think that you may use "BeginGameTurn" and "EndGameTurn" ( or "Begin/EndPlayerTurn" ) as general purpose catch-all event for such kind of events. or "cityAcquired" event for adding unit to captured city.GarretSidzaka said:I want to add units "From Iraq" to areas on the map at certain turns for america and such
I want to add random events like "Secret Monetary Contributions"
I want to add the unit 'Resistants' to the map when a city is captured under the capturer's control (like reverse Civ2 partisans) if the capturer is one of 3 rebel civs
I want to add a game begin screen, much like starts when a normal game starts.
I would like to add random barbarians as resistants and infantry
and more
SimCutie said:I think that you may use "BeginGameTurn" and "EndGameTurn" ( or "Begin/EndPlayerTurn" ) as general purpose catch-all event for such kind of events. or "cityAcquired" event for adding unit to captured city.
If you really needs custom event that can not be covered by above events,
You can add custom events without using SDK DLL. Use my "CvSimCutieEventManager". Add a line to "CvCustomEvent.py" file and you can trigger the event with "triggerEvent()" call in "CvUtilCustom.py"
For usage example see this thread : http://forums.civfanatics.com/showthread.php?t=164589
You can get my CvSimCutieEventManager attached here. It it bit old but has custom event facility and works with Update 1.61. I will post more updated version for version 1.61 soon.
Good thing about my Event manager is that it does not need any editing or addition on the Event manager code. You don't have to understand it. Not a single line. I promise it.GarretSidzaka said:ok i downloaded and checked it out. the code looks really good but i have not enough python smarts to edit itand so im very sad.
EVENT_GAMEBEGIN = "gameBegin" # combinded virtual event of 'GameStart' and 'OnLoad'.
# Events from "CvCustomOption.py"
EVENT_OPTIONBEGIN = "optionBegin" # User Option screen is opened. Draw option control
EVENT_OPTIONEND = "optionEnd" # User Option screen is closed. Get option value again
# Events from SDK "CvCustom.h"
EVENT_BUTTONSHOW = "buttonShow" # Unit selected. add buttons to show.
EVENT_BUTTONACTION = "buttonAction" # Unit button pressed. do action.
# Events from SDK "CvUnit.h"
EVENT_UNITREBORN = "unitReborn" # Unit Reborn/converted by gift or upgrade command
EVENT_COMBATBEGIN = "combatBegin" # Combat started
EVENT_COMBATHIT = "combatHit" # One round of combat damage
EVENT_MAINBEGIN = "mainBegin" # Main interface screen opened. Good time to init mod.
EVENT_MAINEND = "mainEnd" # Main interface screen closed. Good time to finish mod.
EVENT_CITYACQUIRED = "cityAcquired"
CUSTOM_EVENTLIST = [
EVENT_GAMEBEGIN,
EVENT_OPTIONBEGIN,
EVENT_OPTIONEND,
EVENT_BUTTONSHOW,
EVENT_BUTTONACTION,
EVENT_UNITREBORN,
EVENT_COMBATBEGIN,
EVENT_COMBATHIT,
# Don't touch events above this line
EVENT_MAINBEGIN,
EVENT_MAINEND,
# Add new event type here...
EVENT_CITYACQUIRED
]
# Civ4 game user data directory under "My Documents"
CIV4_USERDIR = str(path_join ( getRegValue(
"HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Personal" ),
"My Games", __instdir ))
def EventHandlerRegister( evt_mgr, unused = None ):
qPrint(__name__, "CvUtilCustom Register OK.")
return { CvCustomEvent.EVENT_GAMEBEGIN + "+" : InitUtilCustom,
'OnSave-' : onSaveUtil, 'OnLoad+' : onLoadUtil,
'unitLost-' : onUnitLost,
# CvCustomEvent.EVENT_UNITUPGRADED + '+' : onUnitUpgraded,
'combatResult+': onCombatResult,
# 'unitCreated+' : onUnitCreated,
}
Fully automatic mod addition and removal.TheLopez said:SimCutie, what are the advantages of using your custom event manager over Dr Elmer Jiggle's custom event manager?
The The "cityAquired" event is existing event in original EventManager. So You don't need to define it as custom event. That CvCustomEvent.py file is for defining "brand new" custom event.GarretSidzaka said:can you see what ive changed so far? ive added the city aquired thingie you told me about, am i on right track?
and where was it that i defined mod? here?
... in your_mod.py file ( in Assets/python/custom folder or subfolder of it )
def EventHandlerRegister( evt_mgr, unused = None ):
# To print log message
CvUtil.pyPrint( __name__ + ": GarretSidzaka MOD Register OK." ) .
return { "BeginGameTurn": onBeginGameTurn,
"EndGameTurn": onEndGameTurn }
def onBeginGameTurn(argsList):
.... Your code to handle the event here....
def onEndGameTurn(argsList):
.... Your code to handle the event here....
How do you do all of this? If I understand you correctly, you've made it possible to combine various python mods very painlessly and easily. This is something the community has been asking for for a while.SimCutie said:Fully automatic mod addition and removal.
Just drop in Mod file to specified folder, then it will work automagically.
Feel like to remove it? Easy! Just remove the mod file from the folder.
No manual editing of any EventManager related code. Not a single line.
No "CvPath" stuff...
It has priority system too. Multiple mod can share same Event harmonically with orderly manner. Custom Event? Of course.. It has advanced Keyboard/mouse support. and popup event interface, too.
Wanna replace some Advisor screen by subclassing exiting screen or receive input to your handleInput()? Good.. Just Dropin the mod file..
No need to modify "CvScreenIntarface.py". Modded/subclassed advisor screen will replace stock screen on the fly...
SimCutie, I'm sorry to say but the mod at the thread: http://forums.civfanatics.com/showthread.php?t=164589SimCutie said:I think that you may use "BeginGameTurn" and "EndGameTurn" ( or "Begin/EndPlayerTurn" ) as general purpose catch-all event for such kind of events. or "cityAcquired" event for adding unit to captured city.
If you really needs custom event that can not be covered by above events,
You can add custom events without using SDK DLL. Use my "CvSimCutieEventManager". Add a line to "CvCustomEvent.py" file and you can trigger the event with "triggerEvent()" call in "CvUtilCustom.py"
For usage example see this thread : http://forums.civfanatics.com/showthread.php?t=164589
You can get my CvSimCutieEventManager attached here. It it bit old but has custom event facility and works with Update 1.61. I will post more updated version for version 1.61 soon.
See follow-up posting of mine, not his first original posting.TheLopez said:SimCutie, I'm sorry to say but the mod at the thread: http://forums.civfanatics.com/showthread.php?t=164589
is using Dr Elmer Jiggles event manager code, not yours.
That is my very intention abd objective. I'd like to make the MOD-merging process as easy as possible and self-contained and self-configuring. General Civ player (without knowledge of modding/python ) should be able to add or remove a mod he would like, automatically without or with minimal manual editing of python file.Shqype said:How do you do all of this? If I understand you correctly, you've made it possible to combine various python mods very painlessly and easily. This is something the community has been asking for for a while.
I haven't looked through the code yet, I'll wait until you release the 1.61 version, and I hope to see it soon. But what would need to be done to merge python mods?
#"I named this file 'SecondRevolution.py' and this is the WHOLE thing so far..."
def EventHandlerRegister( evt_mgr, unused = None ):
# To print log message
# "is this where i put the name? the name is SecondRevolution."
CvUtil.pyPrint( __name__ + ": SecondRevolution Register OK." ) .
return { "BeginGameTurn": onBeginGameTurn,
"EndGameTurn": onEndGameTurn }
def onBeginGameTurn(argsList):
#"here im tryint to define that on the beginning of mod turn 1, i want the dawn of man screen to show up."
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
popupInfo.setText(u"showDawnOfMan")
popupInfo.addPopup(iPlayer)
#what else am i going to need? what will this SecondRevolution.py have for a program?