How I add custom events to a Mod????

What kind of custom events are you looking for?
 
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
 
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
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.
 

Attachments

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.

ok i downloaded and checked it out. the code looks really good but i have not enough python smarts to edit it :( and so im very sad.
 
GarretSidzaka said:
ok i downloaded and checked it out. the code looks really good but i have not enough python smarts to edit it :( and so im very sad.
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.
Just define EventHanderRegister function to YOUR mod file and return a dict with { 'eventname' : eventhandler_name }. That is all.
the registered event handler will be called upon the incidence of the event.
Custom event can be added by just adding event name to a event list in the CvCustomEvent.py file. As Simple as it can be. And call triggerEvent() like triggerEvent('my-custom-event', arg1, arg2, .... ) to initiate new event.
then your event handler will be called with same argument like handler(arg1, arg2,...)
 
SimCutie, what are the advantages of using your custom event manager over Dr Elmer Jiggle's custom event manager?
 
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
]

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?

# 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,
}

what do i do with this chunk of code?
 
TheLopez said:
SimCutie, what are the advantages of using your custom event manager over Dr Elmer Jiggle's custom event manager?
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...
 
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?
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.

Define EventHandlerRegister() in *YOUR* mod file as global function.
and return a dict value : for example.. If you want to add a handler for "BeginGameTurn" and "EndGameTurn"event...
Code:
... 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....
That's all.

Word of caution: this version of CvSimCutieEventManager is currently undergoing major revision due to change in Update 1.61.. So there mabe be some bugs...
I will publish version fully upgraded for 1.61 version soon....
 
can i cut/paste code from existing pythons like "DawnofMan" screen write for the initial pop up, and for the unit spawn and gold spawn, is there a good place to find this code as well. (btw i have bookmarked a python tutorial and am going to read it after i wake up :D )
 
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...
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?
 
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.
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.
 
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.
See follow-up posting of mine, not his first original posting.
http://forums.civfanatics.com/showpost.php?p=3863360&postcount=8
And the attachment http://forums.civfanatics.com/attachment.php?attachmentid=121356&d=1143534614
I modified his ShowInfo MOD to use my EventHandler (What he needed is to use my custom option screen) and uploaded it in the 8 th posting.

The version I posted in that tread has various other components of mine including my EventManager, little older. The version in this thread has only EventManager related files.
 
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?
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.
 
hey simcutie :)
i was wondering if you wanted to write or already had a readme for those with no python skills.
no matter, im going to move ahead tonite and start working with this.
 
Code:
#"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?

what the heck am i trying to do????!!? I don't know!! Help me SimCutie, you're my only hope...
 
Back
Top Bottom