Herostratus
Grim Harbinger of Things to Come
- Joined
- Jul 24, 2009
- Messages
- 116
In my mod I want to make it possible for gunpowder units (and only gunpowder units, at least for now) to dismantle roads via an action button that only shows up on the button bar when they're on a road.
My thinking is that pressing the button should trigger an event that uses iRouteChange. It seems to me that this should be possible. This thread was where I started, but I'm not able to make it work. When I start a game, it doesn't show the 4000 BC splash screen, the button bar, the city screen after founding the first city--all the interface is gone, really.
I should clarify that I'm still a Python noob. After turning on exceptions, I think where I'm going wrong is that I don't have the right code to actually trigger the event.
Here's what I have in MainInterface.py, adapted from the linked thread above:
The line in the second one containing "EVENT_TRIGGER_DISMANTLE" came up when I turned on exceptions. I'm sure I'm stumbling blindly here, so any guidance would be appreciated--whether it's rewriting my code
or just pointing me to a mod that definitely has an action button that triggers an event. Or maybe there's an even simpler way that doesn't require events at all.
P.S. I'm sure there's a way through the SDK to enable such a button, but I'm not willing to go that deep down the rabbit-hole, so I gotta do it via Python.
My thinking is that pressing the button should trigger an event that uses iRouteChange. It seems to me that this should be possible. This thread was where I started, but I'm not able to make it work. When I start a game, it doesn't show the 4000 BC splash screen, the button bar, the city screen after founding the first city--all the interface is gone, really.
I should clarify that I'm still a Python noob. After turning on exceptions, I think where I'm going wrong is that I don't have the right code to actually trigger the event.
Here's what I have in MainInterface.py, adapted from the linked thread above:
Code:
pUnit = g_pSelectedUnit
iUnitCombatType = pUnit.getUnitCombatType()
pUnitOwner = gc.getPlayer( pUnit.getOwner( ))
if pUnitOwner.isTurnActive( ):
if iUnitCombatType == gc.getInfoTypeForString('UNITCOMBAT_GUNPOWDER'):
screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_DISMANTLE").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 300, 300, False )
screen.show( "BottomButtonContainer" )
iCount = iCount + 1
Code:
if (inputClass.getNotifyCode() == 11 and inputClass.getData1() == 300 and inputClass.getData2() == 300):
self.pPushedButtonUnit = g_pSelectedUnit
iX = self.pPushedButtonUnit.getX()
iY = self.pPushedButtonUnit.getY()
pDismantle = CyMap().plot(iX, iY)
if pDismantle.getRouteType('ROUTE_ROAD'):
triggerData = pPlayer.initTriggeredData(gc.getPlayer(0).trigger(gc.getInfoTypeForString("EVENT_TRIGGER_DISMANTLE")))
g_pSelectedUnit.changeMoves(60)

P.S. I'm sure there's a way through the SDK to enable such a button, but I'm not willing to go that deep down the rabbit-hole, so I gotta do it via Python.